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

appending internal tables

Former Member
0 Likes
728

Hi friends,

Can you provide me an example for appending an internal table to another internal table which has different structures (with some similar fields)?

For example, itab1 has some fields which are similar to that of itab2. I want to append records in itab1 to itab2.

Thanks.

Krishen

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
695

Hi,

loop at itab1.

move-corresponding itab1 to itab2.

  • Instead of move-correponding you also can move

  • the values by giving each field like

  • itab2-matnr = itab1-matnr..

append itab2.

endloop.

Otherwise you can use the body operator to move the values if the common fields in itab1 and itab2 are in the left most...

ex..

begin of itab1 occurs 0,

matnr type matnr,

werks type werks,

field3 type c,

end of itab1.

begin of itab2 occurs 0,

matnr type matnr,

werks type werks,

end of itab2.

itab2 = itab1.

Thanks,

Naren

6 REPLIES 6
Read only

Former Member
0 Likes
695

Hi,

Types : begin of t_tab1,

matnr type mara-matnr,

maktx type makt-maktx,

end of t_tab1,

begin of t_tab2,

matnr type mara-matnr,

amount type i,

qty type i,

end of t_tab2.

data : itab1 type standard table of t_tab1,

itab2 type standard table of t_tab2,

watab1 type t_tab1,

watab2 type t_tab2.

  • Assume that ITAB1 has data and ITAB2 is to be populated with MATNR from ITAB1.

Loop at itab1 into watab1.

clear : watab2.

watab2-matnr = watab1-matnr.

watab2-amount = 10.

watab2-qty = 5.

append watab2 to itab2.

endloop.

Best regards,

Prashant

Read only

Former Member
0 Likes
696

Hi,

loop at itab1.

move-corresponding itab1 to itab2.

  • Instead of move-correponding you also can move

  • the values by giving each field like

  • itab2-matnr = itab1-matnr..

append itab2.

endloop.

Otherwise you can use the body operator to move the values if the common fields in itab1 and itab2 are in the left most...

ex..

begin of itab1 occurs 0,

matnr type matnr,

werks type werks,

field3 type c,

end of itab1.

begin of itab2 occurs 0,

matnr type matnr,

werks type werks,

end of itab2.

itab2 = itab1.

Thanks,

Naren

Read only

Former Member
0 Likes
695

hi,

try doing this...

loop at itab2.

read table itab1 with key f1 = itab1-f1.

itab2-f1 = itab1-f1.

itab2-f2 = itab1-f2.

-


---

append itab2.

endloop.

hope this helps,

priya.

Read only

0 Likes
695

Priya,

I think if you do that way, won't it read only first suitable record and ignore others? Thanks for your input.

Thanks Naren and Prasanth too.

Read only

Former Member
0 Likes
695

Hi,

Please award points for helpful answers..

THanks,

Naren

Read only

abdul_hakim
Active Contributor
0 Likes
695

hi use the below code..

data: begin of itab1 occurs 0,

col1 type i,

col2 type i,

col3 type i,

end of itab1,

begin of itab2 occurs 0,

col1 type i,

col2 type i,

end of itab2.

loop at itab1.

move-corresponding itab1 to itab2.

append itab2.

endloop.

Cheers,

Abdul Hakim