‎2014 Oct 28 7:38 AM
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
‎2014 Oct 28 7:52 AM
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
‎2014 Oct 28 7:49 AM
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
‎2014 Oct 28 9:24 AM
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
‎2014 Oct 28 9:43 AM
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
‎2014 Oct 28 7:52 AM
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
‎2014 Oct 28 9:27 AM
Hi Raju,
Thanks for responding. As i said earlier, i want to know the options other than looping of internal tables.
Thanks & Regards
Siva
‎2014 Oct 28 9:34 AM
I think there are no other options, apart from what you've listed
‎2014 Oct 28 9:43 AM
Hi Raju,
I dont think it's possible to work on your requirements without using a loop statement.
Best Regards,
Charlie
‎2014 Oct 28 9:56 AM
‎2014 Oct 28 10:03 AM
Hi Matthew,
Didn't know anything about the new release yet, but thanks for the information.
Cheers,
Charlie
‎2014 Oct 29 5:43 AM
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.
‎2014 Oct 29 6:14 AM
Hi Siva,
Can you explain how you are selecting data in itab1 ?
Regards
Yogendra
‎2014 Oct 29 7:38 AM
The only effective way is to loop through one table, and read the other (HASHED) table. There's nothing else really to say.
‎2014 Nov 03 4:31 AM
Hi Yogendra,
Through select query i am getting data into internal table itab1[].
Regards
Siva
‎2014 Oct 28 9:58 AM
Hi shiva,
I don't think it possible without using LOOP but to increase the performance you can make use of FIELDSYMBOLS...
Regards,
Shashikanth
‎2014 Oct 29 8:37 AM
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