0% found this document useful (0 votes)
159 views

PO Creation Using BAPI

This document describes how to create a purchase order using BAPI in the following steps: 1) Define header and item structures to populate purchase order details 2) Call the BAPI_PO_CREATE1 function to create the purchase order, passing the header, item and schedule structures 3) Check for any error messages returned and commit the transaction if successful 4) Return the purchase order number and item details to the calling program

Uploaded by

chandra9000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views

PO Creation Using BAPI

This document describes how to create a purchase order using BAPI in the following steps: 1) Define header and item structures to populate purchase order details 2) Call the BAPI_PO_CREATE1 function to create the purchase order, passing the header, item and schedule structures 3) Check for any error messages returned and commit the transaction if successful 4) Return the purchase order number and item details to the calling program

Uploaded by

chandra9000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

How to create purchase order using BAPI

Take the help of the code and create a PO.


gs_poheader-ref_1 = delivery.
gs_poheader-creat_date = sy-datum.
gs_poheader-created_by = sy-uname.
gs_poheader-langu = sy-langu.
gs_poheader-doc_date = sy-datum.
CLEAR gs_poheaderx.
gs_poheaderx-doc_type = 'X'.
gs_poheaderx-purch_org = 'X'.
gs_poheaderx-vendor = 'X'.
gs_poheaderx-pur_group = 'X'.
gs_poheaderx-ref_1 = 'X'.
gs_poheaderx-creat_date = 'X'.
gs_poheaderx-created_by = 'X'.
gs_poheaderx-langu = 'X'.
gs_poheaderx-doc_date = 'X'.
IF gt_delitem[] IS NOT INITIAL.
LOOP AT gt_delitem INTO gs_delitem.
CLEAR: gs_poitem, gs_poitemx.
gs_poitem-po_item = gs_delitem-posnr.
gs_poitem-material = gs_delitem-matnr.
gs_poitem-plant = gv_plant.
gs_poitem-quantity = gs_delitem-lfimg.
gs_poitem-shipping = space.
gs_poitem-tax_code = gv_taxid.
gs_poitem-po_unit = gs_delitem-meins.
APPEND gs_poitem TO gt_poitem.
gs_poitemx-po_item = gs_delitem-posnr.
gs_poitemx-po_itemx = 'X'.
gs_poitemx-material = 'X'.
gs_poitemx-plant = 'X'.
gs_poitemx-quantity = 'X'.
gs_poitemx-shipping = 'X'.
gs_poitemx-tax_code = 'X'.
gs_poitemx-po_unit = 'X'.
APPEND gs_poitemx TO gt_poitemx.
CLEAR: gs_poschedule, gs_poschedulex.
gs_poschedule-po_item = gs_delitem-posnr.
gs_poschedule-delivery_date = lv_date.
APPEND gs_poschedule TO gt_poschedule.
gs_poschedulex-po_item = gs_delitem-posnr.
gs_poschedulex-po_itemx = 'X'.
gs_poschedulex-delivery_date = 'X'.
APPEND gs_poschedulex TO gt_poschedulex.
ENDLOOP.
ENDIF.
 Create Purchase Order.
IF gs_poheader IS NOT INITIAL.
CLEAR: gv_ponum.
REFRESH gt_return.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = gs_poheader
poheaderx = gs_poheaderx
testrun = testrun
IMPORTING
exppurchaseorder = gv_ponum
TABLES
return = gt_return
poitem = gt_poitem
poitemx = gt_poitemx
poschedule = gt_poschedule
poschedulex = gt_poschedulex.
 Check for error messages
LOOP AT gt_return INTO gs_return WHERE type = 'E'
OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc <> 0 AND gv_ponum IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
 Return the values to Calling Program
IF gv_ponum IS NOT INITIAL.
purchaseorder = gv_ponum.
IF gt_poitem IS NOT INITIAL.
LOOP AT gt_poitem INTO gs_poitem.
CLEAR gs_item.
MOVE-CORRESPONDING gs_poitem TO gs_item.
gs_item-po_number = gv_ponum.
APPEND gs_item TO po_items.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.

You might also like