DATA : lt_request LIKE bapideliciousrequest
OCCURS 0 WITH HEADER LINE,
lt_createditems LIKE bapideliciouscreateditems
OCCURS 0 WITH HEADER LINE,
lt_return LIKE bapiret2
OCCURS 0 WITH HEADER LINE.
IF px_infile-type = 'PO' . "If Purchase order
lt_request-document_type = 'B'.
lt_request-document_numb = lv_ebeln.
lt_request-document_item = lv_posnr.
ELSE. "If Sales Order
lt_request-document_type = 'A'.
lt_request-document_numb = lv_ebeln.
lt_request-document_item = lv_posnr.
ENDIF.
lt_request-material = lv_matnr.
lt_request-plant = lv_werks.
lt_request-stge_loc = lv_lgort.
lt_request-quantity_base__uom = lv_base_uom_qty.
lt_request-delivery_date = sy-datum.
APPEND lt_request.
CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'
TABLES
request = lt_request
createditems = lt_createditems
return = lt_return.
LOOP AT lt_return WHERE type = 'A' OR type = 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ENDLOOP.
IF sy-subrc <> 0.
* Use the BAPI for Commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'H'.
ENDIF.