ABAP 7.5 Syntax - FOR Statement - Example 2

What does the below Report do?
There is an internal table with two fields. We need to capture the contents of more than one field of the internal table into another internal table. What will be done usually? We will use LOOP statement and append data for every row in the main internal table. Now we don't have to do that because of the introduction of the powerful FOR statement.

Report Example 2:
*&---------------------------------------------------------------------*
*& Report ZAG_TEST_FOR_TWO
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zag_test_for_two.

*-> Local Data Declarations
TYPESBEGIN OF lty_parent,
         no1 TYPE i,
         no2 TYPE i,
         no3 TYPE i,
       END OF lty_parent,

       BEGIN OF lty_child,
         field1 TYPE i,
         field2 TYPE i,
       END OF lty_child,

       ltt_parent TYPE STANDARD TABLE OF lty_parent WITH EMPTY KEY,
       ltt_child  TYPE STANDARD TABLE OF lty_child WITH EMPTY KEY.

DATA(lt_parentVALUE ltt_parentno1 no2 no3 )
                                    no1 no2 no3 )
                                    no1 no2 no3 )
                                    no1 no2 no3 )
                                    no1 no2 no3 ).

WRITE 'Parent table data:'.

LOOP AT lt_parent ASSIGNING FIELD-SYMBOL(<lfs_parent>).
  WRITE/ <lfs_parent>-no1<lfs_parent>-no2<lfs_parent>-no3.
ENDLOOP.

SKIP.

WRITE 'Child data:'.

DATA(lt_childVALUE ltt_childFOR <lfs_par> IN lt_parent
                                                      field1 <lfs_par>-no2
                                                        field2 <lfs_par>-no3 ).

LOOP AT lt_child ASSIGNING FIELD-SYMBOL(<lfs_child>).
  WRITE/ <lfs_child>-field1<lfs_child>-field2.
ENDLOOP.

Output:
Parent table data:
         1           2           3
         2           3           2
         3           4           1
         4           5           8
         5           6           9

Child data:
         2           3
         3           2
         4           1
         5           8

         6           9

Comments

Popular posts from this blog

EWM PPF Trigger the existing PPF Action through Custom Program

ABAP 7.5 - FILTER Statement

Useful Transaction Codes / Tools in OData ABAP Service / SAP UI5/ SAP Fiori