2007 Jun 05 10:31 AM
I need to combine 3 internal tables into 1 internal table. The 3 internal tables are
for the sales docs, delivery docs and billing docs. What I did was to loop my
sales docs table and from there I have a loop for the delivery docs table and
billing docs table. My problem is, there can be multiple delivery docs and billing
docs for a given sales doc. Please take a look at my code below:
METHOD combine_data.
FIELD-SYMBOLS: <fs_sales_tab> LIKE LINE OF im_sales_tab,
<fs_cust_tab> LIKE LINE OF im_cust_tab,
<fs_dlv_tab> LIKE LINE OF im_dlv_tab,
<fs_bill_tab> LIKE LINE OF im_bill_tab.
DATA: wa_output LIKE LINE OF ex_output.
LOOP AT im_sales_tab ASSIGNING <fs_sales_tab>.
wa_output-creation_date = <fs_sales_tab>-erdat. "SO creation date
wa_output-creation_time = <fs_sales_tab>-erzet. "SO creation time
wa_output-sales_doc = <fs_sales_tab>-vbeln. "Sales document
wa_output-cust_code = <fs_sales_tab>-kunnr. "SO customer code
* Customer description and ship-to description
READ TABLE im_cust_tab ASSIGNING <fs_cust_tab> WITH KEY kunnr = <fs_sales_tab>-kunnr.
IF sy-subrc = 0.
MOVE <fs_cust_tab>-name1 TO: wa_output-cust_desc, wa_output-ship_to_desc.
ENDIF.
wa_output-po_num = <fs_sales_tab>-bstnk. "PO number
wa_output-doc_type = <fs_sales_tab>-auart. "SO document type
wa_output-req_dlv_date = <fs_sales_tab>-vdatu. "SO req. delivery date
wa_output-created_by = <fs_sales_tab>-ernam. "SO created by
* Ship-to code and delivery document
LOOP AT im_dlv_tab ASSIGNING <fs_dlv_tab> WHERE vgbel = <fs_sales_tab>-vbeln.
wa_output-ship_to_code = <fs_dlv_tab>-kunnr. "Ship-to code
wa_output-del_doc = <fs_dlv_tab>-vbeln. "Delivery document
ENDLOOP.
* Billing document
LOOP AT im_bill_tab ASSIGNING <fs_bill_tab> WHERE vbelv = <fs_sales_tab>-vbeln
AND vbtyp_n = 'M'.
wa_output-bill_doc = <fs_bill_tab>-vbeln. "Billing document
ENDLOOP.
ENDLOOP.
ENDMETHOD. "combine_data
Thank you guys and take care!
I need to combine 3 internal tables into 1 internal table. The 3 internal tables are
for the sales docs, delivery docs and billing docs. What I did was to loop my
sales docs table and from there I have a loop for the delivery docs table and
billing docs table. My problem is, there can be multiple delivery docs and billing
docs for a given sales doc. Please take a look at my code below:
METHOD combine_data.
FIELD-SYMBOLS: <fs_sales_tab> LIKE LINE OF im_sales_tab,
<fs_cust_tab> LIKE LINE OF im_cust_tab,
<fs_dlv_tab> LIKE LINE OF im_dlv_tab,
<fs_bill_tab> LIKE LINE OF im_bill_tab.
DATA: wa_output LIKE LINE OF ex_output.
LOOP AT im_sales_tab ASSIGNING <fs_sales_tab>.
wa_output-creation_date = <fs_sales_tab>-erdat. "SO creation date
wa_output-creation_time = <fs_sales_tab>-erzet. "SO creation time
wa_output-sales_doc = <fs_sales_tab>-vbeln. "Sales document
wa_output-cust_code = <fs_sales_tab>-kunnr. "SO customer code
* Customer description and ship-to description
READ TABLE im_cust_tab ASSIGNING <fs_cust_tab> WITH KEY kunnr = <fs_sales_tab>-kunnr.
IF sy-subrc = 0.
MOVE <fs_cust_tab>-name1 TO: wa_output-cust_desc, wa_output-ship_to_desc.
ENDIF.
wa_output-po_num = <fs_sales_tab>-bstnk. "PO number
wa_output-doc_type = <fs_sales_tab>-auart. "SO document type
wa_output-req_dlv_date = <fs_sales_tab>-vdatu. "SO req. delivery date
wa_output-created_by = <fs_sales_tab>-ernam. "SO created by
* Ship-to code and delivery document
LOOP AT im_dlv_tab ASSIGNING <fs_dlv_tab> WHERE vgbel = <fs_sales_tab>-vbeln.
wa_output-ship_to_code = <fs_dlv_tab>-kunnr. "Ship-to code
wa_output-del_doc = <fs_dlv_tab>-vbeln. "Delivery document
ENDLOOP.
* Billing document
LOOP AT im_bill_tab ASSIGNING <fs_bill_tab> WHERE vbelv = <fs_sales_tab>-vbeln
AND vbtyp_n = 'M'.
wa_output-bill_doc = <fs_bill_tab>-vbeln. "Billing document
ENDLOOP.
ENDLOOP.
ENDMETHOD. "combine_data
Thank you guys and take care!
2007 Jun 05 10:36 AM
Hi,
The Rule Is prety simple.
Always Loop at the table which has the most number of records and read the other tables
so loop at delivery and read billing and sales..should work fine until..u have a delivery doc existing for every sales doc.
santhosh
2007 Aug 27 7:16 AM
could someone please solve this problem...
one is a header table and the second one is line item and third is sub line item...
how can u combine all three internal tables into one... as item line is having multiple lines with same document no...
how can we achieve this..
thanks
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |