Mesh in ABAP- Forward & Inverse Association

TYPES BEGIN OF ty_tab1,
          col1(2),
          col2(2),
        END OF ty_tab1,
        BEGIN OF ty_tab2,
          col11(2),
          col22(2),
          col33(2),
        END OF ty_tab2.
TYPES tt_tab1 TYPE SORTED TABLE OF ty_tab1 WITH UNIQUE  KEY col1,
        tt_tab2 TYPE SORTED TABLE OF ty_tab2 WITH UNIQUE KEY col11.
TYPES BEGIN OF MESH my_tab,
          tab1 TYPE tt_tab1 ASSOCIATION to_tab2 TO tab2 ON col11 col1,
          tab2 TYPE tt_tab2,
        END OF MESH my_tab.

DATA ms_tab  TYPE my_tab,
       ls_tab1 TYPE ty_tab1,
       ls_tab2 TYPE ty_tab2.

ms_tabtab1 VALUE tt_tab1col1 ’11’ col2 ’12’ )
                                                             col1 ’21’ col2 ’22’ )
                                                             col1 ’31’ col2 ’32’ )
                                                             col1 ’41’ col2 ’42’ )
                                                             col1 ’51’ col2 ’52’ )
                                                           ).

ms_tabtab2 VALUE tt_tab2col11 ’11’ col22 ’12’  col33 ’13’ )
                                                             col11 ’21’ col22 ’22’  col33 ’23’ )
                                                             col11 ’31’ col22 ’32’  col33 ’33’ )
                                                             col11 ’41’ col22 ’42’  col33 ’43’ )
                                                             col11 ’51’ col22 ’52’  col33 ’53’ )
                                                           ).
WRITE :‘Table 1 ‘.
LOOP AT ms_tabtab1 INTO ls_tab1.
  WRITE :/ ls_tab1col1ls_tab1col2.
ENDLOOP.
ULINE.
WRITE :‘Table 2 ‘.
LOOP AT ms_tabtab2 INTO ls_tab2.
  WRITE :/ ls_tab2col11ls_tab2col22ls_tab2col33.
ENDLOOP.
ULINE.

* Forward Association
WRITE:‘Forward Association from table 1 to table 2 with col1 = 31’.
ls_tab2 ms_tabtab1\to_tab2[ ms_tabtab1[ col1 ’31’ ] ].
WRITE :/ ls_tab2col11ls_tab2col22ls_tab2col33.

* Inverse Assocition
WRITE:‘Inverse  Association from table 2 to table 1 with col11 = 11’.
ls_tab1 ms_tabtab2\^to_tab2~tab1[ ms_tabtab2[ col11 ’11’ ] ] .
WRITE :/ ls_tab1col1ls_tab1col2.


2


 

Leave a Reply