Skip to end of metadata
Go to start of metadata


Link to Content's target Space :

http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Development+and+Programming 

Summary

This program explains about the collect and append statement purpose+.+ APPEND: This keyword will append the current contents of the table header or the structure to the end of the table as a new record.. This will not affect the any existing record of the table..whereas COLLECT : This keyword is used for summation purposes.. when you collect a record to an internal table, it will find that is the table already have any record with the same key values? If yes, then it will add all the numeric values of the new record to the existing record without changing the non numeric values.

Author(s):  

Dhayalinie Ganesh

DATA: BEGIN OF POINTS OCCURS 5,
     TITLE(4)  TYPE C,
     NAME(20)  TYPE C,
     MARKS(3)  TYPE P DECIMALS 0,
    END OF POINTS.
*******************************************
    POINTS-TITLE = 'MR.'.
    POINTS-NAME  = 'AKSHAYA KUMMAR'.
    POINTS-MARKS = 100.
    COLLECT POINTS.

    POINTS-MARKS = 250.
    COLLECT POINTS.

    POINTS-MARKS = 200.
    APPEND POINTS.

    POINTS-TITLE = 'MISS'.
    POINTS-NAME  = 'KATRINA KAIF'.
    POINTS-MARKS = 100.
    COLLECT POINTS.

   POINTS-MARKS = 150.
  COLLECT POINTS.

   COLLECT POINTS.

   READ TABLE POINTS INDEX 2.
   POINTS-TITLE = 'M/S.'.
  POINTS-NAME  = 'KAREENA KAPOOR'.
   MODIFY POINTS INDEX 2.
   LOOP AT POINTS.
   WRITE:/5 POINTS-TITLE, POINTS-NAME, POINTS-MARKS.
 ENDLOOP.
DATA: STR(5) TYPE C OCCURS 5 WITH HEADER LINE,
      CNT1   TYPE I.
STR = 'XELL'.

DO 6 TIMES.
CNT1 = SY-INDEX + 7.
STR+0(1) = SY-ABCDE+CNT1(1).
 IF STR+0(1) <> 'I' AND STR+0(1) <> 'O'.
  APPEND STR.
 ENDIF.
ENDDO.
**************
LOOP AT STR.
WRITE: /10 STR.
ENDLOOP.
DATA: CNT  TYPE I,
      BUF  TYPE I.
DO.
IF SY-INDEX GT 10.
  EXIT.
ENDIF.
BUF = SY-INDEX MOD 3.
IF BUF = 0.
  CNT = CNT + SY-INDEX.
ELSE.
  CNT = CNT - SY-INDEX.
ENDIF.
ENDDO.
WRITE:/5(3) CNT.