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 itabs with different lengths/structure

Former Member
0 Likes
830

Hi everybody.

i have a basic abap question.

i have 3 itabs

itab1 has po and item(and other fields)

po1 item1

po2 item2

itab2 has so and item(and other fields)

so1 item1

so2 item2

now i want to add them to itab 3 which should like follows.

Itab3

PO po_ITEM SO SO_Item

_________________________

po1 item1 -- -- ( so and its item are blank)

po2 item2 -- --

-- -- so1 item1 ( po and its items are blank)

-- -- so2 item2

whats the efficient way of doing this.

curently i am looping on itab1 and itab2 separately and moving each field into itab3?

loop at itab1 into wa_itab1

itab3-po = wa_itab1-po,

itab3-po_item = wa_itab1-po_item,

endloop.

loop at itab2 into wa_itab2

itab3-so = wa_itab2-so,

itabs-so_item = wa_itab2-so_item,

endlop.

is there any better way?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
798

there is no more efficient way, you must loop over the 2 itabs, because you change also the format.

I have some doubts about the usefulness of this approach, I don't see why you mix two unrelated tables into one.

5 REPLIES 5
Read only

Former Member
0 Likes
798

Hi Ruel,

Instead of using loop statements,you can carry the same process by DO Statement.i guess Do statement works faster than loop when you know the number of records in the two table.

ex.count the number of records for both the tables and using DO pass the values to final internal table.

thanks,

Amit

Read only

Former Member
0 Likes
799

there is no more efficient way, you must loop over the 2 itabs, because you change also the format.

I have some doubts about the usefulness of this approach, I don't see why you mix two unrelated tables into one.

Read only

Former Member
0 Likes
798

Probably you could replace the first loop alone with append lines of just for this scenario, if two loops makes your program look bad.


append lines of itab1 to itab3.

loop at itab2 into wa_itab2
itab3-so = wa_itab2-so,
itabs-so_item = wa_itab2-so_item,
endlop.

As seigfried said there is no other efficient way.

Vikranth

Read only

Former Member
0 Likes
798

please be aware that the structure of itab3 seems to different from itab1 and itab2 !

=> 2 loops necessary!

but no performance problem because they are not nested !

please close the thread

Read only

0 Likes
798

Thanks to all. i gave points.

yeah I am not happy about the usefulness either, but thats the requirement.. just needed a second opinion on my approach.

thanks guys. closing thread

cheers!!

Edited by: Ruel Ralfson on Oct 9, 2009 5:00 PM