2024 Mar 14 9:18 PM
Hello Everyone,
Please can you help me with new abap code?
I need to change values of some fields of an internal table depending other tables but i would achieve it without loop, because i have lots of record in my internal table.
With old abap code I would do:
Loop at Internal_tableA.
read table Internal_tableB with key fieldA-xx = fieldB-xx fieldA-zz = fieldB-zz.
if sy-subrc = 0.
Read Internal_tableC wiht key fieldC-kk = fieldB-kk.
IF sy-subrc = 0.
fieldA-NNN = fieldC-XXX.
fieldA-WWW = fieldC-HHH.
MODIFY Internal_tableA.
ENDIF.
ENDIF.
ENDLOOP.
I should do the same but without loop.
Thank you in advance
fieldA-NNN = fieldC-XXX.
2024 Mar 15 6:46 AM
Do you think that a constructor expression has better performance?
That's a wrong assertion. The goal of constructor expressions is to clarify the ABAP code.
2024 Mar 15 6:54 AM
2024 Mar 15 8:27 AM
You say "I should do the same but without loop." It means you probably want to use what newbies call incorrectly "new ABAP", which is without "LOOP AT" (but in fact it remains a loop with only a different syntax), its real name is a Constructor Expression. Newbies incorrectly think that it has a better performance, that's completely wrong. I hope you understand now.
2024 Mar 15 8:47 AM
Sandra, I apologize for my errors but my intentions were to ask an help to avoid the use of loop because i have lots of records into internal table.
Whit for iteraction, actually the loop is by-passed but I don't know how to write code to obtain my goal.
Basically, i have to fill fields of first internal table getting data from two other internal tables, with read table.
If i use loop i have problems for perfomance
2024 Mar 15 9:03 AM
You can fix performance on READ TABLE. It could be the same performance issue with constructor expressions.
The first thing to do is to use SORTED or HASHED tables instead of STANDARD. By default, you should never use STANDARD tables (use them only in the rare cases of doing a unique loop at all the lines).
2024 Mar 15 9:12 AM
Sandra,
yes my internal tables are Sorted tables.
Please tell me the syntax for constructor expressions (If you can)
2024 Mar 15 1:23 PM
There should be no performance issue with your current code if you have sorted tables with the right fields. Constructor expressions are useless to solve your performance issue. Especially because you have a MODIFY. Constructor expressions should never be used if you have MODIFY. You desperately want to use constructor expressions, I tell you to not use them, but it seems you don't want to understand my arguments. Good luck.
PS: you can find in the forum all my answers about constructor expressions.
2024 Mar 15 8:05 AM
How about select directly from the SQL without performing a loop?
Below is an example to get NAME_TEXT by BNAME (SAP ID).
SELECT A~BNAME C~NAME_TEXT
INTO CORRESPONDING FIELDS OF TABLE GT_USR02
FROM USR02 AS A
INNER JOIN USR21 AS B
ON A~BNAME = B~BNAME
INNER JOIN ADRP AS C
ON B~PERSNUMBER = C~PERSNUMBER.
2024 Mar 15 8:50 AM
Hi Siri i cannot because I need to work with these 3 internal tables. 😞
2024 Mar 15 10:08 AM
You didn't provide a 'why' answer... Nevertheless read this answer
2024 Mar 15 2:58 PM
To get better performance, SAP is suggested to go with CDS view. Try this approach and see if your problem can solve