2006 Dec 05 1:27 AM
hi!
can anyone explain me how to add the contents of an internal table to another one provided there is one common field in them and each record in one table has multiple records in the other?
thx
2006 Dec 06 12:26 AM
Hi,
Try this..
DATA: IT_FINAL_TMP LIKE IT_FINAL OCCURS 0 WITH HEADER LINE.
IT_FINA_TMP = IT_FINAL.
REFRESH IT_FINAL.
LOOP AT IT_FINAL_TMP.
MOVE IT_FINAL_TMP TO IT_FINAL.
LOOP AT IT_PUR_STOCK WHERE MATNR = IT_FINAL_TMP-MATNR.
MOVE-CORRESPONDING IT_PUR_STOCK TO IT_FINAL.
APPEND IT_FINAL.
ENDLOOP.
IF SY-SUBRC <> 0.
APPEND IT_FINAL.
ENDIF.
ENDLOOP.
Thanks,
Naren
Hi,
Try this..
DATA: IT_FINAL_TMP LIKE IT_FINAL OCCURS 0 WITH HEADER LINE.
IT_FINA_TMP = IT_FINAL.
REFRESH IT_FINAL.
LOOP AT IT_FINAL_TMP.
MOVE IT_FINAL_TMP TO IT_FINAL.
LOOP AT IT_PUR_STOCK WHERE MATNR = IT_FINAL_TMP-MATNR.
MOVE-CORRESPONDING IT_PUR_STOCK TO IT_FINAL.
APPEND IT_FINAL.
ENDLOOP.
IF SY-SUBRC <> 0.
APPEND IT_FINAL.
ENDIF.
ENDLOOP.
Thanks,
Naren
2006 Dec 05 1:31 AM
2006 Dec 05 1:38 AM
suppose u have 2 internal table itab1 itab2
loop at itab1.
read table itab2 with key common_field = itab1-common_field.
if sy-subrc = 0.
move-corresponding itab1 to it_final.
move-corresponding itab2 to it_final.
append it_final.
endif.
clear itab1,itab2.
endloop.
Regards
- Gopi
2006 Dec 05 3:44 AM
hi
good
you can use the INSERT statement in this case.
go through this report
REPORT demo_int_tables_insert.
DATA: BEGIN OF line,
land(3) TYPE c,
name(10) TYPE c,
age TYPE i,
weight TYPE p DECIMALS 2,
END OF line.
DATA itab LIKE SORTED TABLE OF line
WITH NON-UNIQUE KEY land name age weight.
line-land = 'G'. line-name = 'Hans'.
line-age = 20. line-weight = '80.00'.
INSERT line INTO TABLE itab.
line-land = 'USA'. line-name = 'Nancy'.
line-age = 35. line-weight = '45.00'.
INSERT line INTO TABLE itab.
line-land = 'USA'. line-name = 'Howard'.
line-age = 40. line-weight = '95.00'.
INSERT line INTO TABLE itab.
line-land = 'GB'. line-name = 'Jenny'.
line-age = 18. line-weight = '50.00'.
INSERT line INTO TABLE itab.
line-land = 'F'. line-name = 'Michele'.
line-age = 30. line-weight = '60.00'.
INSERT line INTO TABLE itab.
line-land = 'G'. line-name = 'Karl'.
line-age = 60. line-weight = '75.00'.
INSERT line INTO TABLE itab.
LOOP AT itab INTO line.
WRITE: / line-land, line-name, line-age, line-weight.
ENDLOOP.
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb361f358411d1829f0000e829fbfe/content.htm
thanks
mrutyun^
2006 Dec 05 3:46 AM
Hi,
loop at itab1.
move-corresponding itab1 to itab.
loop at itab2 where f1 = itab1-f1.
move-corresponding itab2 to itab.
append itab.
endloop.
endloop.
2006 Dec 05 11:57 PM
> hi!
>
> can anyone explain me how to add the contents of an
> internal table to another one provided there is one
> common field in them and each record in one table has
> multiple records in the other?
>
> thx
hi all!
thx for all ur replies. Unfortunately my problem is still unsolved. Let me be more clear.
I have the following tables:
data: begin of it_pur_stock occurs 100,
matnr like ekpo-matnr,
ebeln like ekko-ebeln,
eq_eindt like ekko-eq_eindt,
menge like ekpo-menge,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
end of it_pur_stock.
DATA: BEGIN OF IT_FINAL OCCURS 0,
MATNR LIKE MARA-MATNR,
LABST LIKE MARD-LABST,
STOCK_ON_HAND LIKE MARD-LABST,
BMENG LIKE VBEP-BMENG,
WMENG LIKE VBEP-WMENG,
ebeln like ekko-ebeln,
eq_eindt like ekko-eq_eindt,
menge like ekpo-menge,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
END OF IT_FINAL.
it_final is the result table where matnr and other columns are already filled. it_pur_stock is also filled with data and all the fields in it_pur_stock are also in it_final. I want to add the data from it_pur_stock to it_final in such a way that each matnr in it_final contains multiple records from it_pur_stock. In other words it_pur_stock contains multiple purchase orders (ebeln) and corresponding material numbers (matnr). But it_final should contain unique matnr and its corresponding purchase orders (ebeln).
thx
2006 Dec 06 12:26 AM
Hi,
Try this..
DATA: IT_FINAL_TMP LIKE IT_FINAL OCCURS 0 WITH HEADER LINE.
IT_FINA_TMP = IT_FINAL.
REFRESH IT_FINAL.
LOOP AT IT_FINAL_TMP.
MOVE IT_FINAL_TMP TO IT_FINAL.
LOOP AT IT_PUR_STOCK WHERE MATNR = IT_FINAL_TMP-MATNR.
MOVE-CORRESPONDING IT_PUR_STOCK TO IT_FINAL.
APPEND IT_FINAL.
ENDLOOP.
IF SY-SUBRC <> 0.
APPEND IT_FINAL.
ENDIF.
ENDLOOP.
Thanks,
Naren
2006 Dec 06 3:54 AM
thanks a lot Naren for ur time.
it works but my problem is I'm unable to create a formatted output from the table it_final. I want an ouput like the following:
Material Number PO Number
**************
M746857 Pt54768
-
M873259 P74859
P8576h58
P76r6578
-
M546589 P87u4899
-
M857689 P65768
P767t5657
-
2006 Dec 06 4:08 AM
Hi,
cnt = 0.
loop at itab_final.
at new matnr.
uline.
write matnr.
cnt = 1.
endat.
if cnt = 1.
write itab_final-ebeln.
else.
write : / itab_final-ebeln.
endif.
cnt = cnt + 1.
endloop.
2006 Dec 06 4:28 AM
Thx a lot Jayanthi!
You have solved my problem.
cheers.
Srikanth.
2006 Dec 06 4:23 AM
Hi,
supoose there are two internal tables. itab1 and itab2
itab 1 has the parent data and the itab 2 has the child data.
itab 1 has less records and itab2 has more records. i.e. one record in itab1 has N number of records in itab 2.
u can merge them in a internal table itab 3 which has a structurewhich includes fields of both the internal table itab1+ itab2.
before merging in the third internal table just sort both the internal tables by thier respective key fields.
LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY <ANY KEY FIELD> = <ITAB2-KEY FIELD>.
MOVE-CORRESPONDING ITAB1 TO ITAB3.
MOVE-CORRESPONDING ITAB2 TO ITAB3.
APPEND ITAB3.
ENDLOOP.
SORT ITAB3 BY <KEY FIELD>.
another method.
LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY <ANY KEY FIELD> = <ITAB2-KEY FIELD>.
move all the fields one by one.
APPEND ITAB3.
ENDLOOP.
SORT ITAB3 BY <KEY FIELD>.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |