2023 Oct 23 5:46 PM
Hi Experts,
I am working on Updating Material Text using MATMAS interface.
In that, there are multiple Sales area segments, considered as one internal table and multiple long Text segments, considered as another internal table. Both doesn't have any unique value but all the texts (Material master texts) must be mapped / extended to all the Sales area.
For ex: Sales area segment records would be 8 entries and the Material long text entries would be 5.
Since there is no unique key to validate or match the entries between the two, using the parallel cursor technique to avoid nested loops cannot be achieved (as per my understanding).
Please help me out with your valuable solution using ABAP 7.4 or avoid a performance issue.
Thanks.
2023 Nov 09 9:25 AM
SORT itab_1 BY key_1.
SORT itab_2 BY key_2.
index_2 = 0.
LOOP AT itab_1 INTO line_1.
WHILE index_2 < lines( itab_2 )
AND ( index_2 = 0
OR line_2-key_2 < line_1-key_1 ).
index_2 = index_2 + 1.
line_2 = itab_2[ index_2 ].
ENDWHILE.
IF line_1-key_1 = line_2-key_2.
" Processing
ENDIF.
ENDLOOP.
2023 Oct 23 7:34 PM
Why do you want to change your code? Is there any performance issue?
FYI, Constructor Expressions are not faster than classic ABAP (note sure where this myth comes from...)
2023 Nov 02 7:45 AM
Please use the COMMENT button for comments, asking for complements, adding details, replying to a comment or a proposed solution or to the OP question, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.
2023 Nov 02 7:55 AM
Note that there's no reason to avoid nested loops for the reason that the internal tables have non-unique key.
Also, the "parallel cursor technique" is based on using nested loops, so it's difficult to do the technique and avoid nested loops. Reminder (pseudo code of one possible variant):
SORT itab_1 BY key_1.
SORT itab_2 BY key_2.
index_2 = 0.
LOOP AT itab_1 INTO line_1.
WHILE index_2 < lines( itab_2 )
AND ( index_2 = 0
OR line_2-key_2 < line_1-key_1 ).
index_2 = index_2 + 1.
line_2 = itab_2[ index_2 ].
ENDWHILE.
IF line_1-key_1 = line_2-key_2.
" Processing
ENDIF.
ENDLOOP.
2023 Nov 02 9:41 AM
Hi sandra.rossi
Thanks for your solution. This answered to my question.
2023 Nov 09 9:24 AM
Hi sandra.rossi,
Thanks again for your prompt response.
The problem here is parallel cursor cannot be used and directly to use two loops as nested loops, since both doesn't have any unique key to validate.
I can't change the data declaration to have an indicator because the two segment entry counts doesn't match as well.
For ex: Sales area segment may have 10 entries but the Text segment could be 1 or 2.
So why I asked a question here.
Thanks again for clearing my myth as well.
2023 Nov 09 9:25 AM
SORT itab_1 BY key_1.
SORT itab_2 BY key_2.
index_2 = 0.
LOOP AT itab_1 INTO line_1.
WHILE index_2 < lines( itab_2 )
AND ( index_2 = 0
OR line_2-key_2 < line_1-key_1 ).
index_2 = index_2 + 1.
line_2 = itab_2[ index_2 ].
ENDWHILE.
IF line_1-key_1 = line_2-key_2.
" Processing
ENDIF.
ENDLOOP.