01-12-2007 5:26 PM
Hi All,
I am having 9 internal tables as posted below with different fields, and one final internal table which contains all the fields containd by the 9 internal tables,
I want to append the data of the 9 internal tables to the final internal table ,
suggest what is the way or I have to change the fields in the internal table.
DATA:BEGIN OF it_stpo OCCURS 0,
menge LIKE stpo-menge,
postp LIKE stpo-postp,
meins LIKE stpo-meins,
aennr LIKE stpo-aennr,
pswrk LIKE stpo-pswrk,
stlnr LIKE stpo-stlnr,
stlkn LIKE stpo-stlkn,
END OF it_stpo.
DATA:BEGIN OF it_makt OCCURS 0,
maktx LIKE makt-maktx,
matnr LIKE makt-matnr,
END OF it_makt.
DATA:BEGIN OF it_mast OCCURS 0,
matnr LIKE mast-matnr,
werks LIKE mast-werks,
stlal LIKE mast-stlal,
stlnr LIKE mast-stlnr,
andat LIKE mast-andat,
annam LIKE mast-annam,
totprc TYPE i,
END OF it_mast.
DATA:BEGIN OF it_marc OCCURS 0,
lgpro LIKE marc-lgpro,
matnr LIKE marc-matnr,
beskz LIKE marc-beskz,
END OF it_marc.
DATA:BEGIN OF it_mkol OCCURS 0,
slabs LIKE mkol-slabs,
matnr LIKE mkol-matnr,
sinsm LIKE mkol-sinsm,
END OF it_mkol.
DATA: BEGIN OF it_mbew OCCURS 0,
stprs LIKE mbew-stprs,
matnr LIKE mbew-matnr,
verpr LIKE mbew-verpr,
peinh LIKE mbew-peinh,
vmvpr LIKE mbew-vmvpr,
bwkey LIKE mbew-bwkey,
END OF it_mbew.
DATA:BEGIN OF it_mard OCCURS 0,
labst LIKE mard-labst,
matnr LIKE mard-matnr,
lgort LIKE mard-lgort,
insme LIKE mard-insme,
END OF it_mard.
DATA:BEGIN OF it_eord OCCURS 0,
lifnr LIKE eord-lifnr,
END OF it_eord.
DATA:BEGIN OF it_plpo OCCURS 0,
vgw03 LIKE plpo-vgw03,
END OF it_plpo.
DATA:BEGIN OF it_final OCCURS 0 ,
menge LIKE stpo-menge,
matnr LIKE mast-matnr,
werks LIKE mast-werks,
postp LIKE stpo-postp,
meins LIKE stpo-meins,
aennr LIKE stpo-aennr,
pswrk LIKE stpo-pswrk,
vgw03 LIKE plpo-vgw03,
lifnr LIKE eord-lifnr,
labst LIKE mard-labst,
lgort LIKE mard-lgort,
insme LIKE mard-insme,
stprs LIKE mbew-stprs,
verpr LIKE mbew-verpr,
peinh LIKE mbew-peinh,
stlal LIKE mast-stlal,
vmvpr LIKE mbew-vmvpr,
bwkey LIKE mbew-bwkey,
slabs LIKE mkol-slabs,
sinsm LIKE mkol-sinsm,
lgpro LIKE marc-lgpro,
beskz LIKE marc-beskz,
stlnr LIKE stpo-stlnr,
totprc TYPE i,
stlkn LIKE stpo-stlkn,
END OF it_final.
01-12-2007 5:39 PM
Hi,
1. Loop one of the main tables.
2. Read all the remaining 8 tables based on some key field from the first table.
3. Assign all fields for all teh tables to the work area of the final table.
3. Once you get all the data in work area, append that work area to the final table.
Reward points if the answer is helpful.
Regards,
Mukul
01-12-2007 5:30 PM
to append all into final one...u need to do a loop at one internal table...and read all other internal tables so that u can append the final data...try to put primary keys of all 8 tables in the first one so that u can loop first one and use read for all other 8.
01-12-2007 5:32 PM
Hi
In order to merge the data into a single internal table, use the following steps;
1. Identify the key fields (same fields in different internal tables).
2. Loop at one of those internal tables
3. Use the READ statement.
This should solve the problem.
PLZ REWARD POINTS
01-12-2007 5:32 PM
Hi,
What are the key fields in those tables ? Because to compile data from 9 tables into a single table, you will need some key fields which will be used to match the data from different tables.
Regards,
Mukul
01-12-2007 5:33 PM
From a logical perspective, there is not a common field between all 9 tables. I would expect to find MATNR in all 9; and it does not exist.
How do you plan to have data consistency / "balance" with different objects?
What is your business goal?
01-12-2007 5:39 PM
Hi,
1. Loop one of the main tables.
2. Read all the remaining 8 tables based on some key field from the first table.
3. Assign all fields for all teh tables to the work area of the final table.
3. Once you get all the data in work area, append that work area to the final table.
Reward points if the answer is helpful.
Regards,
Mukul
01-12-2007 5:50 PM
Mukul,
Please note that these tables share no common key field(s).
Rahul has a design flaw here that needs to be resolved first.
01-12-2007 6:18 PM
Hi Rahul,
Your problem looks different as people are explaining something different.
Let me explain it .
1. First of all you have to find the relationship among the tables with their key fields.
As in your case i have analysed that the table 'it_eord' contain only one field 'lifnr' and another table contain 'it_plpo' contain 'vgw03'. which are not present in any other table which you defined ( not talking about your final table).
As a result you can't insert these value into the final internal table. either you have to add one more field in the above internal table which are present in any table or you add lifnr and vgw03 field in any other table except 'it_eord' and 'it_plpo' .
Then loop on one table and read the content from the other table with their keys and populate the data into the Final table.
Thanks,
Chidanand.
PS: Try to create a realtionship among all the table and then proceed.
01-12-2007 6:12 PM
Hi,
Put some Common field in these tables also then only you can follow other steps of Looping at one internal table and then reading other tables and filling the final internal table.
it_stpo
it_eord
it_plpo
The common field in other tables is MATNR.
Regards,
Aman
01-12-2007 6:40 PM
Rahul,
I think that everyone has clarified your design flaw well enough, and provided options once the flaw is addressed.
Please reward points accordingly and close this thread.
Thanks in advance.
01-13-2007 3:37 AM
Hi,
I've a similar code of my program as follows:
SELECT QMNUM
IWERK
EQUNR
BTPLN
AUSWK
INGRP
QMDAB
BEZDT
TPLNR
SWERK
MSGRP
FROM VIQMEL INTO TABLE ITABMEL
WHERE IWERK = 'M011' and
AUSWK = 'A' and
INGRP = 'SLM' and
QMDAB NE '00000000' and
BEZDT GE SDATE-LOW and BEZDT LE SDATE-HIGH and
SWERK IN S_WERK.
IF SY-SUBRC = 0.
SELECT QMNUM MNGRP MNCOD FROM QMMA
INTO CORRESPONDING FIELDS OF TABLE ITABMA
FOR ALL ENTRIES IN ITABMEL
WHERE QMNUM = ITABMEL-QMNUM and
MNGRP = 'RESTLT01' and
MNCOD = '0350'.
SORT ITABMA BY QMNUM.
LOOP AT ITABMEL.
READ TABLE ITABMA WITH KEY QMNUM = ITABMEL-QMNUM BINARY
SEARCH.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING ITABMA TO ITABMEL.
MODIFY ITABMEL TRANSPORTING QMNUM.
ENDIF.
ENDLOOP.
SELECT TPLNR PLTXT FROM IFLO
INTO CORRESPONDING FIELDS OF TABLE ITABLO
FOR ALL ENTRIES IN ITABMEL
WHERE TPLNR = ITABMEL-TPLNR.
SORT ITABLO BY TPLNR.
LOOP AT ITABMEL.
READ TABLE ITABLO WITH KEY TPLNR = ITABMEL-TPLNR BINARY
SEARCH.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING ITABLO TO ITABMEL.
MODIFY ITABMEL TRANSPORTING PLTXT.
ENDIF.
ENDLOOP.
SELECT QMNUM
URKAT
URGRP
URCOD FROM QMUR
INTO CORRESPONDING FIELDS OF TABLE ITABMUR
FOR ALL ENTRIES IN ITABMEL
WHERE QMNUM = ITABMEL-QMNUM.
SORT ITABMUR BY QMNUM.
LOOP AT ITABMEL.
READ TABLE ITABMUR WITH KEY QMNUM = ITABMEL-QMNUM
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING ITABMUR TO ITABMEL.
MODIFY ITABMEL TRANSPORTING URKAT URGRP URCOD.
ENDIF.
ENDLOOP.
SELECT KATALOGART
CODEGRUPPE
CODE
KURZTEXT FROM QPCT
INTO CORRESPONDING FIELDS OF TABLE ITABPCT
FOR ALL ENTRIES IN ITABMEL
WHERE KATALOGART = ITABMEL-URKAT and
CODEGRUPPE = ITABMEL-URGRP and
CODE = ITABMEL-URCOD.
SORT ITABPCT BY KATALOGART CODEGRUPPE CODE.
LOOP AT ITABMEL.
READ TABLE ITABPCT WITH KEY KATALOGART = ITABMEL-URKAT
CODEGRUPPE = ITABMEL-URGRP
CODE = ITABMEL-URCOD
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE-CORRESPONDING ITABPCT TO ITABMEL.
MODIFY ITABMEL TRANSPORTING KURZTEXT.
ENDIF.
ENDLOOP.
SELECT OBJEK ATINN ATFLV FROM AUSP
INTO CORRESPONDING FIELDS OF TABLE ITABUSP
FOR ALL ENTRIES IN ITABMEL
WHERE OBJEK = ITABMEL-EQUNR and
ATINN = '0000000190'.
SORT ITABUSP BY OBJEK.
LOOP AT ITABMEL.
READ TABLE ITABUSP WITH KEY OBJEK = ITABMEL-EQUNR
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE ITABUSP-ATFLV TO ITABMEL-ATFLV1.
MODIFY ITABMEL TRANSPORTING ATFLV1.
ENDIF.
CLEAR ITABUSP.
ENDLOOP.
SELECT OBJEK ATINN ATWRT FROM AUSP
INTO CORRESPONDING FIELDS OF TABLE ITABWRT
FOR ALL ENTRIES IN ITABMEL
WHERE OBJEK = ITABMEL-EQUNR and
ATINN = '0000000191'.
SORT ITABWRT BY OBJEK.
LOOP AT ITABMEL.
READ TABLE ITABWRT WITH KEY OBJEK = ITABMEL-EQUNR
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE ITABWRT-ATWRT TO ITABMEL-ATWRT2.
MODIFY ITABMEL TRANSPORTING ATWRT2.
ENDIF.
CLEAR ITABWRT.
ENDLOOP.
SELECT OBJEK ATINN ATFLV FROM AUSP
INTO CORRESPONDING FIELDS OF TABLE ITABUSP
FOR ALL ENTRIES IN ITABMEL
WHERE OBJEK = ITABMEL-EQUNR and
ATINN = '0000000193'.
SORT ITABUSP BY OBJEK.
LOOP AT ITABMEL.
READ TABLE ITABUSP WITH KEY OBJEK = ITABMEL-EQUNR
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE ITABUSP-ATFLV TO ITABMEL-ATFLV3.
MODIFY ITABMEL TRANSPORTING ATFLV3.
ENDIF.
CLEAR ITABUSP.
ENDLOOP.
SELECT OBJEK ATINN ATWRT FROM AUSP
INTO CORRESPONDING FIELDS OF TABLE ITABWRT
FOR ALL ENTRIES IN ITABMEL
WHERE OBJEK = ITABMEL-EQUNR and
ATINN = '0000000194'.
SORT ITABWRT BY OBJEK.
LOOP AT ITABMEL.
READ TABLE ITABWRT WITH KEY OBJEK = ITABMEL-EQUNR
BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE ITABWRT-ATWRT TO ITABMEL-ATWRT4.
MODIFY ITABMEL TRANSPORTING ATWRT4.
ENDIF.
CLEAR ITABWRT.
ENDLOOP.
Hope it helps.
Reward if helpful.
Regards,
Sipra