‎2009 May 26 6:45 AM
DATA : BEGIN OF ITAB1 OCCURS 0,
BLDAT LIKE BKPF-BLDAT, "Document Date in Document
BLART LIKE BKPF-BLART, "Document type
BUKRS LIKE BKPF-BUKRS, "Company Code
BUDAT LIKE BKPF-BUDAT, "Posting Date in the Document
MONAT LIKE BKPF-MONAT, "Fiscal period
WAERS LIKE BKPF-WAERS, "Currency Key
XBLNR LIKE BKPF-XBLNR, "Reference Document Number
bstat LIKE bkpf-bstat, "Document Status
BELNR like bkpf-BELNR,
end of itab1.
data : begin of itab2 occurs 0,
BELNR LIKE BSEG-BELNR, "Accounting Document Number
BSCHL LIKE BSEG-BSCHL, "Posting Key for the Next Line Item
KUNNR LIKE BSEG-KUNNR, "Customer Number 1
WRBTR LIKE BSEG-WRBTR, "Amount in document currency
BUPLA LIKE BSEG-BUPLA, "Business Place
SGTXT LIKE BSEG-SGTXT, "Item Text
GSBER LIKE BSEG-GSBER, "Business Area
SHKZG LIKE BSEG-SHKZG, "Debit(s)(+) or credit(h)(-)
END OF ITAB2.
data : begin of itab4 occurs 0,
BLDAT LIKE BKPF-BLDAT, "Document Date in Document
BLART LIKE BKPF-BLART, "Document type
BUKRS LIKE BKPF-BUKRS, "Company Code
BUDAT LIKE BKPF-BUDAT, "Posting Date in the Document
MONAT LIKE BKPF-MONAT, "Fiscal period
WAERS LIKE BKPF-WAERS, "Currency Key
XBLNR LIKE BKPF-XBLNR, "Reference Document Number
bstat LIKE bkpf-bstat, "Document Status
BELNR like bkpf-BELNR,
BELNR1 LIKE BSEG-BELNR, "Accounting Document Number
BSCHL LIKE BSEG-BSCHL, "Posting Key for the Next Line Item
KUNNR LIKE BSEG-KUNNR, "Customer Number 1
WRBTR LIKE BSEG-WRBTR, "Amount in document currency
BUPLA LIKE BSEG-BUPLA, "Business Place
SGTXT LIKE BSEG-SGTXT, "Item Text
GSBER LIKE BSEG-GSBER, "Business Area
SHKZG LIKE BSEG-SHKZG,
END OF ITAB4.
parameters : year type bkpf-GJAHR default '2009'.
Select * from bkpf into corresponding fields of table itab1 where gjahr = year.
select * from bseg into corresponding fields of table itab2 where gjahr = year. -
now i want to creat fill ITAB4 from ITAB1 and ITAB2 but HOW ?
please help me...
Manoj..
Edited by: manoj pise on May 26, 2009 7:45 AM
‎2009 May 26 6:49 AM
Hello,
You can fill itab4 by looping at table itab1 and reading the corresponding entry from itab2 and fill itab4.
Example:
loop at itab1.
read table itab2 with key gjahr = itab1-gjahr.
itab4-xxx = itab1-xxx.
itab4-yyy = itab2-yyy.
endloop.
‎2009 May 26 6:49 AM
Hello,
You can fill itab4 by looping at table itab1 and reading the corresponding entry from itab2 and fill itab4.
Example:
loop at itab1.
read table itab2 with key gjahr = itab1-gjahr.
itab4-xxx = itab1-xxx.
itab4-yyy = itab2-yyy.
endloop.
‎2009 May 26 7:04 AM
make sure that itab3 has got all the fields in itab1 and itab2 (or all the fileds that you want from the first two tables). Have a common field (preferably a key field like EBELN, MATNR) in the first two internal tables.
Loop at itab1 into wa_itab1.
move wa_itab1-f1 to wa_itab3-f1.
move wa_itab1-f2 to wa_itab3-f2.
read table itab2 into wa-itab2 with key f1 = wa_itab1-f1.
move wa_itab2-f3 to wa_itab3-f3.
move wa_itab2-f4 to wa_itab3-f4.
append wa_itab3 to itab3.
clear: wa-itab1, wa-itab2, wa-itab3.
endloop.
This should work. You can use the same logic for many tables aswell.
‎2009 May 26 7:01 AM
hi,
Itab2 contains Bseg data (Accounting Document Segment) and itab1 contains data from bkpf (Header table ), so always copy itab2 data into itab4 first as bseg may have multiple line item and then loop at itab4 and read the itab1 with key bukrs, belnr, gjahr and update it in itab4.
Hope this will solve your issue.
Thanks & Regards,
Kimaya
‎2009 May 26 7:04 AM
Hi,
use the following code.... this will resolve your issue...
DATA :
BEGIN OF ITAB1 OCCURS 0,
BLDAT LIKE BKPF-BLDAT,
BLART LIKE BKPF-BLART,
BUKRS LIKE BKPF-BUKRS,
BUDAT LIKE BKPF-BUDAT,
MONAT LIKE BKPF-MONAT,
WAERS LIKE BKPF-WAERS,
XBLNR LIKE BKPF-XBLNR,
bstat LIKE bkpf-bstat,
BELNR like bkpf-BELNR,
end of itab1.
data :
begin of itab2 occurs 0,
BUKRS LIKE BSEG-BUKRS, " Add this line
BELNR LIKE BSEG-BELNR,
BSCHL LIKE BSEG-BSCHL,
KUNNR LIKE BSEG-KUNNR,
WRBTR LIKE BSEG-WRBTR,
BUPLA LIKE BSEG-BUPLA,
SGTXT LIKE BSEG-SGTXT,
GSBER LIKE BSEG-GSBER,
SHKZG LIKE BSEG-SHKZG,
END OF ITAB2.
data :
begin of itab4 occurs 0,
BLDAT LIKE BKPF-BLDAT,
BLART LIKE BKPF-BLART,
BUKRS LIKE BKPF-BUKRS,
BUDAT LIKE BKPF-BUDAT,
MONAT LIKE BKPF-MONAT,
WAERS LIKE BKPF-WAERS,
XBLNR LIKE BKPF-XBLNR,
bstat LIKE bkpf-bstat,
BELNR like bkpf-BELNR,
"BELNR1 LIKE BSEG-BELNR, " Remove this line, its of no use
BSCHL LIKE BSEG-BSCHL,
KUNNR LIKE BSEG-KUNNR,
WRBTR LIKE BSEG-WRBTR,
BUPLA LIKE BSEG-BUPLA,
SGTXT LIKE BSEG-SGTXT,
GSBER LIKE BSEG-GSBER,
SHKZG LIKE BSEG-SHKZG,
END OF ITAB4.
parameters : year type bkpf-GJAHR default '2009'.
Select * from bkpf into corresponding fields of table itab1 where gjahr = year.
select * from bseg into corresponding fields of table itab2 where gjahr = year.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB4.
LOOP AT ITAB2 WHERE BUKRS = ITAB1-BUKRS AND BELNR = ITAB1-BELNR.
MOVE-CORRESPONDING ITAB1 TO ITAB4.
MOVE-CORRESPONDING ITAB2 TO ITAB4.
APPEND ITAB4.
CLEAR ITAB4.
ENDLOOP.
ENDLOOP.Regards,
Siddarth
‎2009 May 26 7:17 AM
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB4.
LOOP AT ITAB2 WHERE BUKRS = ITAB1-BUKRS AND BELNR = ITAB1-BELNR.
MOVE-CORRESPONDING ITAB1 TO ITAB4.
MOVE-CORRESPONDING ITAB2 TO ITAB4.
APPEND ITAB4.
CLEAR ITAB4.
ENDLOOP.
ENDLOOP.
Don't use a loop within a loop. (Nested Loop)
Use this
Loop at itab1.
move-corresponding itab1 to itab4.
reab table itab2 where bukrs = itab1-bukrs and belnr = itab1-belnr.
move-corresponding itab2 to itab4.
append itab4.
clear itab4.
Endloop.
Hope this will solve your issue.
‎2009 May 26 9:58 AM
Hi,
Here we need to consider nested loops since the BSEG table contains many line items.
First loop the internal table 1 inside which loop the second internal table equating BELNR, GJAHR and BUKRS. Move the corresponding entries of table 1 and table 2 to the final required internal table 4.
Hope this will resolve your query.
‎2009 May 26 10:40 AM
This post was copied from Siddharth Chordia's above, and is under investigation
Hi,
use the following code.... this will resolve your issue...
DATA :
BEGIN OF ITAB1 OCCURS 0,
BLDAT LIKE BKPF-BLDAT,
BLART LIKE BKPF-BLART,
BUKRS LIKE BKPF-BUKRS,
BUDAT LIKE BKPF-BUDAT,
MONAT LIKE BKPF-MONAT,
WAERS LIKE BKPF-WAERS,
XBLNR LIKE BKPF-XBLNR,
bstat LIKE bkpf-bstat,
BELNR like bkpf-BELNR,
end of itab1.
data :
begin of itab2 occurs 0,
BUKRS LIKE BSEG-BUKRS,
BELNR LIKE BSEG-BELNR,
BSCHL LIKE BSEG-BSCHL,
KUNNR LIKE BSEG-KUNNR,
WRBTR LIKE BSEG-WRBTR,
BUPLA LIKE BSEG-BUPLA,
SGTXT LIKE BSEG-SGTXT,
GSBER LIKE BSEG-GSBER,
SHKZG LIKE BSEG-SHKZG,
END OF ITAB2.
data :
begin of itab4 occurs 0,
BLDAT LIKE BKPF-BLDAT,
BLART LIKE BKPF-BLART,
BUKRS LIKE BKPF-BUKRS,
BUDAT LIKE BKPF-BUDAT,
MONAT LIKE BKPF-MONAT,
WAERS LIKE BKPF-WAERS,
XBLNR LIKE BKPF-XBLNR,
bstat LIKE bkpf-bstat,
BELNR like bkpf-BELNR,
BSCHL LIKE BSEG-BSCHL,
KUNNR LIKE BSEG-KUNNR,
WRBTR LIKE BSEG-WRBTR,
BUPLA LIKE BSEG-BUPLA,
SGTXT LIKE BSEG-SGTXT,
GSBER LIKE BSEG-GSBER,
SHKZG LIKE BSEG-SHKZG,
END OF ITAB4.
parameters : year type bkpf-GJAHR default '2009'.
Select * from bkpf into corresponding fields of table itab1 where gjahr = year.
select * from bseg into corresponding fields of table itab2 where gjahr = year.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB4.
LOOP AT ITAB2 WHERE BUKRS = ITAB1-BUKRS AND BELNR = ITAB1-BELNR.
MOVE-CORRESPONDING ITAB2 TO ITAB4.
APPEND ITAB4.
CLEAR ITAB4.
ENDLOOP.
ENDLOOP.
Regards,
Munibabu.K
Edited by: Matt on May 26, 2009 1:17 PM
‎2009 May 26 12:18 PM
The above post was copied from Siddharth Chordia's above, and is under investigation