You are on page 1of 2

The BAPI (Business Application Programming Interface) for creating a Purchase Order (PO) in SAP is

BAPI_PO_CREATE1. Here's an overview of the input and output parameters:

Input Parameters:

- POHEADER: Structure containing header data for the PO.

- POITEM: Table containing item data for the PO.

- POSCHEDULE: Table containing schedule data for the PO.

Output Parameters:

- RETURN: Table containing return messages from the function module.

- PURCHASEORDER: The newly created PO number.

You can call this BAPI in your ABAP program or using an external system to create a PO in SAP. Make
sure to pass the necessary input parameters with correct values to create a valid PO.

Here's an example code snippet for using the BAPI_PO_CREATE1 to create a purchase order in SAP:

```

DATA: lv_po_number TYPE ekko-ebeln.

DATA: ls_poheader TYPE bapimepoheader,

lt_poitem TYPE bapimepoitem,

lt_poschedule TYPE bapimeposchedule,

lt_return TYPE bapiret2_tab.

ls_poheader-doc_type = 'NB'.

ls_poheader-vendor = '10000001'.

ls_poheader-purch_org = '1000'.

ls_poheader-purch_group = '001'.

ls_poheader-comp_code = '1000'.

ls_poitem-po_item = '00010'.
ls_poitem-material = 'M-1001'.

ls_poitem-plant = '1000'.

ls_poitem-quantity = 10.

ls_poitem-net_price = 100.

APPEND ls_poitem TO lt_poitem.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = ls_poheader

TABLES

poitem = lt_poitem

poschedule = lt_poschedule

return = lt_return

IF sy-subrc EQ 0.

COMMIT WORK.

lv_po_number = lt_return-po_number.

WRITE: / 'Purchase order', lv_po_number, 'created successfully.'.

ELSE.

ROLLBACK WORK.

WRITE: / 'Error creating purchase order:', lt_return-message.

ENDIF.

```

In this example, we are creating a PO with a header and one item. We first define the header and
item data in the appropriate structures (ls_poheader and ls_poitem), and then append the item to a
table (lt_poitem). We then call the BAPI_PO_CREATE1 function module, passing the header and item
data as input parameters. If the function call is successful, we commit the changes to the database
and display the newly created PO number. If the function call fails, we roll back the changes and
display the error message.

You might also like