‎2006 Aug 15 11:23 PM
Hi,
Please see the below code wich will get execute in BDC session.
LOOP AT gt_rbkp.
CLEAR : ls_head,
lt_item,
lv_index,
lt_zadi_cr5760_inv.
REFRESH lt_item.
*-- Insert the Header Data
ls_head-invoice_ind = 'X'.
ls_head-comp_code = gt_rbkp-bukrs. " Company code
ls_head-doc_date = gt_rbkp-bldat. " Document date
ls_head-pstng_date = sy-datlo. " Posting date
ls_head-currency = gt_rbkp-waers. " Currency
ls_head-ref_doc_no = gt_rbkp-xblnr. " Reference doc.
ls_head-gross_amount = gt_rbkp-rmwwr. " Gross Amount
ls_head-calc_tax_ind = gt_rbkp-xmwst.
*-- Iterate through its line items
LOOP AT gt_rseg WHERE belnr = gt_rbkp-belnr AND " get the item
gjahr = gt_rbkp-gjahr. " for the invoice
CLEAR : lt_item.
lt_item-invoice_doc_item = sy-tabix. " Invoice item
lt_item-po_number = gt_rseg-ebeln. " PO number
read table gt_po with key ebeln = gt_rseg-ebeln
olditm = gt_rseg-ebelp.
lt_item-po_item = gt_po-newitm. " PO item
lt_item-po_unit = gt_rseg-bstme. " PO Unit
lt_item-tax_code = gt_rseg-mwskz. " Tax Code
lt_item-item_amount = gt_rseg-wrbtr. " Item Amount
lt_item-quantity = gt_rseg-menge. " Item Quantity
lt_item-item_text = text-m01. " RE-ROUTED text
APPEND lt_item. " Insert this Line
ENDLOOP.
*-- If Line items are collected
CHECK NOT lt_item[] IS INITIAL.
sort lt_item by invoice_doc_item po_number po_item.
REFRESH lt_ret[].
*-- Create the New invoice for the Re-routing process
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
headerdata = ls_head
IMPORTING
invoicedocnumber = lv_invoice
fiscalyear = lv_year
TABLES
itemdata = lt_item
return = lt_ret.
if sy-subrc = 0.
select * from
zadi_cr5760_inv
into table lt_zadi_cr5760_inv
where belnr = gt_rbkp-belnr
and gjahr = gt_rbkp-gjahr.
endif.
LOOP AT lt_ret WHERE type = 'E' OR
type = 'A'.
exit.
ENDLOOP.
if sy-subrc is initial.
message i024 with gt_rbkp-belnr text-t01.
endif.
*-- Commit the transaction
IF NOT sy-subrc IS INITIAL AND
NOT lv_invoice IS INITIAL.
delete zadi_cr5760_inv from table lt_zadi_cr5760_inv.
REFRESH lt_zadi_cr5760_inv.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDLOOP.
After creating the invoice the bapi commit woll work and it does not got for next record in the gt_rbkp internal table it directly get out of the program and continues with another transaction.
Please tell what is the problem with this BAPI commit. Sould not use the BAPI commit in BDC session.
Regards,
challa
‎2006 Sep 01 6:28 AM
Hi .
BAPI_TRANSACTION_COMMIT SHOULD BE called outside the loop.
‎2006 Sep 01 6:33 AM
hi chall,
put the FM 'BAPI_TRANSACTION_COMMIT' outside the loop and try out