on 2022 Nov 29 10:38 AM
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
Request clarification before answering.
I hope that you will ask some questions about the code below, so that you understand, and next time you will be able to find by yourself.
Old code:
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.
New code (I couldn't check the syntax because you didn't provide a reproducible example):
it_deep = VALUE #( FOR <wa_head> IN it_head
( VALUE #( BASE CORRESPONDING #( <wa_head> )
HeaderToItemNav = VALUE #( FOR <wa_item> IN it_item
WHERE ( id = <wa_head>-id )
( <wa_item> ) ) ) ) ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You have old and new code, you could understand.
VALUE type( field1 = .... field 2 = .. ). <-- set data into a structure with one statement
FOR my_field IN my_data <-- more or less like a LOOP where my_field get value of the field of my_data one by one
my_result = CORRESPONDING output_structure( input_structure ) <-- little bit like move-corresponding with additionnal tool
These are two different parts that you can analyze separately and in order:
Hi, in case that "headerSet" is an entity then try reading related entities instead of implementing (Select *) and after that work with the results from Header and Item.
Header:
READ ENTITY headerSet\\alias FROM VALUE #( FOR <header_key> IN keys ( %key-ID = <header_key>-ID ) )
RESULT DATA(lt_headerSet).
Item:
READ ENTITY itemSet\\alias FROM VALUE #( FOR <item_key> IN keys ( %key-ID = <item_key>-ID ) )
RESULT DATA(lt_itemSet).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nitish2027
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
6 | |
6 | |
4 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.