Sample Program On COLLECT Keyword / Statement - 1 (Standard Internal Table).


Submitted By: Shilpa Gunjan (LnT Infotech)

This sample code will help you to understand better how collect keyword works or functions.


SAMPLE CODE:

REPORT zcollect.


TYPES: BEGIN OF x_mara,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
brgew TYPE mara-brgew,
ntgew TYPE mara-ntgew,
END OF x_mara.

DATA: it_mara type STANDARD TABLE OF x_mara,
wa_mara TYPE x_mara.

SELECT mtart matkl brgew ntgew FROM mara UP TO 5 ROWS
INTO TABLE it_mara
WHERE mtart = 'HAWA'
AND matkl NE ''
AND brgew NE ''
AND ntgew NE ''.

wa_mara-mtart = 'HAWA'.
wa_mara-matkl = 'C01143'.
wa_mara-brgew = 100.
wa_mara-ntgew = 200.

COLLECT wa_mara INTO it_mara.

WRITE: / 'Test Program - Collect Keyword - Standard Internal Table.'.

LOOP AT it_mara INTO wa_mara.
WRITE:/ wa_mara-mtart, wa_mara-brgew, wa_mara-ntgew.
ENDLOOP.

OUTPUT:

Say the five records in the table are:

HAWA       P03              100.000     100.000
HAWA       MPMSPR        1.000         1.000
HAWA       C01143         1.000         1.000
HAWA       C01143         1.000         1.000
HAWA       C01143         1.000         1.000

After the program is executed the output looks as:



Here 2 things can be noted:

1) Collect statement has not appended any new record in this case. The 3rd row of the table was overwritten with the new one, and the numeric values were added up.

2) Since the internal table is defined as a standard table, the combination of both material type and material group field (both non-numeric fields) is treated as key.



ALSO READ:

- COLLECT Keyword - Introduction, Syntax & It's Importance.

- Sample Program On COLLECT Keyword / Statement - 1 (Standard Internal Table).


- Sample Program On COLLECT Keyword / Statement - 2 (Performance Analysis).


- Sample Program On COLLECT Keyword / Statement - 3 (Performance Analysis).



Your suggestions and comments are welcome in this section.

Please mail all your contributions to administrator@abapmadeeasy.com We request you to mention your Name, Designation, Experience & Organization you are working for. Your posts will be verified and posted in this site with your name.


No comments:

Post a Comment