Application Development 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: 

Moving data between internal tables having different structures

0 Kudos
7,109

Hi All,

I would like to know if there is any better option for the following scenario.

Scenario: I am having two internal tables, say itab1 & itab2.

itab1 is having components comp1 comp2 comp3 comp4 comp5.

itab2 is having components comp3 comp4.

Here, I want to move data from itab1 to itab2. But my question is

I don't want to use following options for this.

1. Looping & Move-corresponding

2. I can't use append lines since both the internal tables having different line types(structure).

3. I can't use , itab1[] = itab2[] option.

Please let me know if there is any(better) option for this scenario.

My question may be weird, but the main purpose of this query is for better performance and dynamic assignment of data(without using loop statment).

Waiting for some interesting answers that can enlighten my ABAP knowledge.

Thanks & Regards

Siva

1 ACCEPTED SOLUTION

rajucd81
Participant
0 Kudos
696


Hi Siva,

I don't think so we have other options apart from the options you don't want to use..

But you can do like this..

Loop at itab1 into wa_itab1.

wa_itab2-comp3 = wa_itab1-comp3.

wa_itab2-comp4 = wa_itab1-comp4.

append wa_itab2 to itab2.

endloop

15 REPLIES 15

yogendra_bhaskar
Contributor
0 Kudos
696

Hi Siva ,

Your question was easy but conditions you stated have made it more interesting.

I think , considering your conditions of not using looping , move-corresponding etc

I would suggest you should change the structure of itab1 , like this

itab1 having components comp3 comp4 comp1 comp2 comp5.

itab2 having components comp3 comp4.

then ,

itab2[] = itab1[] .

that's it

Try it out

Regards

Yogendra Bhaskar

0 Kudos
696

Hi Yogendra,

Thank you very much for the reply. I tried the solution you provided, its working fine considering the order of fields in both the tables is same though the no. of fields are different. But here in my case i have certain constraints in changing the order of fields in itab1[].

And one more thing, If my second internal table itab2[] is of comp3 & comp5, then what ll be the solution.

itab1[] - comp1 comp2 comp3 comp4 comp5

itab2[] - comp3 comp5.

So please let me know the possibitlites for this.

Thanks & Regards

Siva

0 Kudos
696

Hi Siva ,

If you have constraints in changing the order , then the best way will be only by looping.

for the other question , you have to change the order like this

itab1[] - comp3 comp5 comp1 comp2 comp4

itab2[] - comp3 comp5.

then you can either use

itab2[] = itab1[].

or

append lines of itab1 to itab2.

Thanx and Regards

Yogendra Bhaskar

rajucd81
Participant
0 Kudos
697


Hi Siva,

I don't think so we have other options apart from the options you don't want to use..

But you can do like this..

Loop at itab1 into wa_itab1.

wa_itab2-comp3 = wa_itab1-comp3.

wa_itab2-comp4 = wa_itab1-comp4.

append wa_itab2 to itab2.

endloop

0 Kudos
696

Hi Raju,

Thanks for responding. As i said earlier, i want to know the options other than looping of internal tables.

Thanks & Regards

Siva

0 Kudos
696

I think there are no other options, apart from what you've listed

Former Member
0 Kudos
696

Hi Raju,

     I dont think it's possible to work on your requirements without using a loop statement.

Best Regards,
Charlie

matt
Active Contributor
0 Kudos
696

Of course it is.

1) Upgrade to 740 SP05.

2) Use move-corresponding

But, yes, if you're in a lower release, there is no other way than looping. Ensure that the table you'll look up from is a HASHED table, READ with TABLE KEY, and you shouldn't have performance issues.

Former Member
0 Kudos
696

Hi Matthew,

     Didn't  know anything about the new release yet, but thanks for the information.

Cheers,

Charlie

0 Kudos
696

Hi Matthew,

Thank you very much for the information. But unfortunately we are on the lower version, so unable to try that method(move-corresponding using internal tables) provided in that link. Hoping that it ll have some optimistic solution to my scenario.

Before closing this thread, I would like to wait for some more interesting answers.

0 Kudos
696

Hi Siva,

Can you explain how you are selecting data in itab1 ?

Regards

Yogendra

matt
Active Contributor
0 Kudos
696

The only effective way is to loop through one table, and read the other (HASHED) table. There's nothing else really to say.

0 Kudos
696

Hi Yogendra,

Through select query i am getting data into internal table itab1[].

Regards

Siva

Former Member
0 Kudos
696

Hi shiva,

I don't think it possible without using LOOP but to increase the performance you can make use of FIELDSYMBOLS...

Regards,

Shashikanth

Former Member
0 Kudos
696

There are other options available while defining structure.

Option 1. Include structure


types:

     begin of str1,

          c1 type n,

          c2 type c,

     end of str1.

types begin of str2.

include structure str1.

types: c3 type n,

     c4 type c,

end of str2.

data itab1 type standard table of str1.

data itab2 type standard table of str2.

....

itab1 = itab2.

Option 2. Sub Structure.


types:

     begin of str1,   

       c1 type n,

       c2 type c,

     end of str1.

types:

     begin of str2,

          s1 type str1,

          c1 type n,

           c2 type c,

     end of str2.

data itab1 type standard table of str1.

data itab2 type standard table of str2.

....

itab2 = itab1.

Option 3. substructure and loops

same as above but use the following method to copy.


loop at itab2 into ls_2.

     ls_1 = ls_2-s1.

     append ls_1 to itab1.

endloop.

Option 4. Faster Loop using field symbols

To improve loop performance on internal table you can use Field Symbols or References, which avoid copying data to wa of loop.


field-symbols <ls_s2> type str2.

field-symbols <ls_s1> type str1.

loop at itab2 assigning <ls_s2>.

     append initial line to itab1 assigning <ls_s1>.

     move-corresponding <ls_s2> to <ls_s1>.

endloop.

Option 5. Faster loop with reference variables


data lp_s_s2 type ref to str2.

data lp_s_s1 type ref to str1.

loop at itab2 reference into lp_s_s2.

     append initial line to itab1 reference into lp_s_s1.

     move-corresponding lp_s_s2->* to lp_s_s1->*.

     "lp_s_s1->c1 = lp_s_s2->c1.

endloop.

Thanks