2006 Sep 15 2:57 AM
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
2006 Sep 15 3:04 AM
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
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
2006 Sep 15 3:04 AM
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
2006 Sep 15 3:04 AM
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
2006 Sep 15 3:04 AM
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.
2006 Sep 15 3:12 AM
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.
2006 Sep 15 3:14 AM
2006 Sep 15 3:16 AM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |