Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Copy one Internal table data to another without loop

0 Likes
13,949

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?

1 ACCEPTED SOLUTION
Read only

joltdx
Active Contributor
12,377

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 ) ) ).

🙂

7 REPLIES 7
Read only

joltdx
Active Contributor
12,378

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 ) ) ).

🙂

Read only

0 Likes
12,377

Thanks Jorgen, I am trying to improve performance so looking for any alternate solution which improves performance.

Read only

joltdx
Active Contributor
0 Likes
12,377

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?

Read only

Sandra_Rossi
Active Contributor
12,377

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.

Read only

Patrick_vN
Active Contributor
12,377

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.

Read only

0 Likes
12,377

Thanks all for your inputs!!!

Read only

Jelena_Perfiljeva
Active Contributor
12,377

If your question is answered then please accept the answer (see this blog). Thanks!