Skip to Content
0
Nov 29, 2022 at 10:38 AM

i need nested for loop for deep structure

373 Views Last edit Nov 29, 2022 at 02:26 PM 9 rev

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_EXPANDED_ENTITYSET.

    DATA :
      IT_DEEP TYPE STANDARD TABLE OF ZDEEP_S,
           WA_deep TYPE ZDEEP_S,
      IT_HEAD TYPE STANDARD TABLE OF ZHEADER,
           WA_HEAD TYPE ZHEADER,
      IT_ITEM TYPE STANDARD TABLE OF ZITEM1,

           WA_ITEM TYPE ZITEM1.


    CASE iv_entity_set_name.

      WHEN 'headerSet'.

        SELECT * FROM ZHEADER INTO TABLE IT_HEAD.
        IF SY-SUBRC EQ 0.
          SELECT * FROM ZITEM1 INTO TABLE IT_ITEM FOR ALL ENTRIES IN IT_HEAD WHERE ID EQ IT_HEAD-ID.

        ENDIF.


    ENDCASE.


    LOOP AT IT_HEAD INTO WA_HEAD.

      MOVE-CORRESPONDING wa_head to wa_deep.

      loop at IT_ITEM into WA_ITEM.

        if WA_HEAD-ID eq WA_ITEM-ID.

          APPEND WA_ITEM to WA_DEEP-HEADERTOITEMNAV.
          CLEAR WA_ITEM.

        ENDIF.






      ENDLOOP.
      APPEND WA_DEEP to IT_DEEP.
      clear WA_DEEP.
    ENDLOOP.







    COPY_DATA_TO_REF(
      exporting
        IS_DATA = IT_DEEP
      changing
        CR_DATA = ER_ENTITYSET
    ).

  endmethod.





in this code i have used nested loop in that place i need nested for loop