‎2021 Feb 04 11:30 AM
HI Experts,
I have some data it_tab1(with 3 columns A,B and C) and want to update this data into it_tab2(with 4 columns A,X,Y,Z) as below.
A= A
X = A+B
Y = "Hello"
Z = First 4 characters of C
We are using advanced ABAP and want to update it_tab2 without loop. Could you please help with the logic?
‎2021 Feb 04 11:51 AM
Hi!
At first I was thinking about the CORRESPONDING operator with the mapping addition. But I'm not aware of any option of doing for instance A+B or First 4 Characters of C in it. I don't think so, based on the nature of that operator, but somebody might have an idea... 🙂
So then it depends on your definition of "without loop". I mean, technically, this is a looping technique, but it's not a LOOP statement in ABAP:
it_tab2 = VALUE #( FOR tab1 IN it_tab1
( a = tab1-a
x = |{ tab1-a }{ tab1-b }|
y = 'Hello'
z = substring( val = tab1-c off = 0 len = 4 ) ) ).
🙂
‎2021 Feb 04 11:51 AM
Hi!
At first I was thinking about the CORRESPONDING operator with the mapping addition. But I'm not aware of any option of doing for instance A+B or First 4 Characters of C in it. I don't think so, based on the nature of that operator, but somebody might have an idea... 🙂
So then it depends on your definition of "without loop". I mean, technically, this is a looping technique, but it's not a LOOP statement in ABAP:
it_tab2 = VALUE #( FOR tab1 IN it_tab1
( a = tab1-a
x = |{ tab1-a }{ tab1-b }|
y = 'Hello'
z = substring( val = tab1-c off = 0 len = 4 ) ) ).
🙂
‎2021 Feb 04 12:26 PM
Thanks Jorgen, I am trying to improve performance so looking for any alternate solution which improves performance.
‎2021 Feb 04 12:37 PM
Got it. That would depend mainly on what you do INSIDE of the loop, I would say...Not the loop itself...
For instance, SELECT SINGLE inside a loop is bad. SELECT everything first and then READing internal table (with a proper key) inside the loop will be better.
Also proper table types are increasingly more important for performance when the tables grow in size.
If you're willing to share the code for your loop, we might be able to help you more... And also the sizes of your tables and the performance requirements. Or is what you shared exactly your business requirement?
‎2021 Feb 04 12:38 PM
Anyway, it doesn't make much sense to use CORRESPONDING when it's about only one common component. I don't think CORRESPONDING is for making calculations, VALUE is the only appropriate solution.
‎2021 Feb 04 12:44 PM
Is it an option to move these calculations to the SQL statement that fills your [it_tab1]?
And anyway, the question you need to ask as well is if the LOOP statement is really less performant as the VALUE one. If you have a million lines in your internal table, there are a million records to deal with.
‎2021 Feb 08 7:15 AM
‎2021 Feb 08 5:21 PM
If your question is answered then please accept the answer (see this blog). Thanks!