COLLECT: -
Collect keyword first, checks the internal table whether the record is available or not based on the key field. If not it acts like append (record adds last). Other wise it adds the numeric fields from work area to number field in the internal table.
Syntax: - Collect <wa> into <it> .
Ex: - Collect WA into IT.
NOTE: Whenever we are working with collect keyword then we
must declare other than numeric (data types) files are unique.
PROGRAM:
*&---------------------------------------------------------------------*
*& Report ZR_COLLECT_KEYWORD
*&
*&---------------------------------------------------------------------*
REPORT ZR_COLLECT_KEYWORD.
Data: begin of WA,
Eid(10) type C,
Esal type I,
End of WA.
Data IT like hashed table of WA with unique key Eid.
WA-Eid = '1'.
WA-Esal = '10000'.
Collect WA into IT.
WA-Eid = '2'.
WA-Esal = '30000'.
Collect WA into IT.
WA-Eid = '4'.
WA-Esal = '60000'.
Collect WA into IT.
Loop at IT into WA.
Write: / WA-Eid, WA-Esal.
Endloop.
Uline.
WA-Eid = '3'.
WA-Esal = '30000'.
Collect WA into IT.
Loop at IT into Wa.
Write: / WA-Eid, WA-Esal.
Endloop.
Collect keyword first, checks the internal table whether the record is available or not based on the key field. If not it acts like append (record adds last). Other wise it adds the numeric fields from work area to number field in the internal table.
Syntax: - Collect <wa> into <it>
*& Report ZR_COLLECT_KEYWORD
*&
*&---------------------------------------------------------------------*
REPORT ZR_COLLECT_KEYWORD.
Data: begin of WA,
Eid(10) type C,
Esal type I,
End of WA.
Data IT like hashed table of WA with unique key Eid.
WA-Eid = '1'.
WA-Esal = '10000'.
Collect WA into IT.
WA-Eid = '2'.
WA-Esal = '30000'.
Collect WA into IT.
WA-Eid = '4'.
WA-Esal = '60000'.
Collect WA into IT.
Loop at IT into WA.
Write: / WA-Eid, WA-Esal.
Endloop.
Uline.
WA-Eid = '3'.
WA-Esal = '30000'.
Collect WA into IT.
Loop at IT into Wa.
Write: / WA-Eid, WA-Esal.
Endloop.