Monday, April 18, 2011

Purchase Order BAPI SAP ABAP

If you wish to transfer Purchase Order related Data to SAP, you can do so by using the following BAPI.

BAPI_PO_CREATE

Many a times there is a requirement to transfer purchase order data from a third party to SAP, it can be done by the following methods.

1) BAPI
3) BDC
3) EDI

This this tutorial we will see how to create a Purchase Order using the above mentioned BAPI.

Please note that if you wish to create Real Time Purchase Orders from an external system into SAP R/3 then you need to use either the JCO connector, .NET connector or XI. The example below shows creation of a single purchase order, if you have data required to create purchase orders then you first need to upload it into an internal table and then pass the table to the BAPI.

Please find the code below to create a Purchase order using the BAPI BAPI_PO_CREATE

REPORT ZEX_POCREATE .



Data: int_pohead like BAPIEKKOC,
      int_poitem like BAPIEKPOC occurs 0 with header line,
      int_posched like BAPIEKET occurs 0 with header line,
      int_ret like BAPIRETURN occurs 0 with header line.
Data: d_purchord like BAPIEKKOC-PO_NUMBER.

Move: 'NB' to int_pohead-DOC_TYPE,
      '1000' to int_pohead-PURCH_ORG,
      '001' to int_pohead-PUR_GROUP,
      '0000001234' to int_pohead-vendor,


      '00010' to int_poitem-po_item,
      'Material' to int_poitem-material,
      'Material' to int_poitem-pur_mat,
      '1000' to int_poitem-plant,


      '00010' to int_posched-PO_ITEM,
      '20080531' to int_posched-DELIV_DATE,
      '2'        to int_posched-QUANTITY.


Append int_poitem.
Clear int_poitem.
APPEND int_posched.
CLEAR int_posched.

CALL FUNCTION 'BAPI_PO_CREATE'
  EXPORTING
   PO_HEADER                        = int_pohead
*   PO_HEADER_ADD_DATA               =
*   HEADER_ADD_DATA_RELEVANT         =
*   PO_ADDRESS                       =
    SKIP_ITEMS_WITH_ERROR            = 'X'
*   ITEM_ADD_DATA_RELEVANT           =
 IMPORTING
   PURCHASEORDER                     = d_purchord
  TABLES
    PO_ITEMS                         = int_poitem
*   PO_ITEM_ADD_DATA                 =
    PO_ITEM_SCHEDULES                = int_posched
*   PO_ITEM_ACCOUNT_ASSIGNMENT       =
*   PO_ITEM_TEXT                     =
    RETURN                           = int_ret
*   PO_LIMITS                        =
*   PO_CONTRACT_LIMITS               =
*   PO_SERVICES                      =
*   PO_SRV_ACCASS_VALUES             =
*   PO_SERVICES_TEXT                 =
*   PO_BUSINESS_PARTNER              =
*   EXTENSIONIN                      =
*   POADDRDELIVERY                   =
          .

If sy-subrc = 0.
  Write:/ 'Purchase Order Number is', d_purchord.
endif.

No comments:

Post a Comment