Skip to Content

The sample code has four parts:

  1. selection screen
  2. Data Population
  3. BAPI call
  4. output from BAPI call

The (*) indicates that those are comments and are not executed in the program.
This Program creates the Purchase Order only for one item.
User should change the default values while executing the program. Current default values are valid for the custom settings made at our R/3 system.
This code is useful before creating a WebDynpro application to test the functionality of BAPI.It has all mandatory fields populated to create the purchase order document with standard type ‘NB’. User can directly upload this code in R/3 system using tcode SE38.

Code Sample:

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Ramakant Singh
    Sorry to be rude but this is silly. This weblog assumes that people can’t figure out which BAPI to call to create purchase order and explaining the basics of Abap.
    (0) 
    1. Anonymous
      Here it is not assumed that people does not know which BAPI to be used but tried to help people by giving ready to use code to save the coding effort. So think it is not at all silly but an effort to help.
      (0) 
      1. Bhavani Prasad Bandi
        hi buddy,

        Sorry to say, please avoid this type of blogs…Waste of time (yours and readers)
        The reasons
        1. Normally, there wont be a selection screen for creating a PO in the first place.(It would be rather a file).
        2. The documentation of BAPI provides more help and available options than this blog.
        3. None of the code can re-used.
        4. And last of all, its not so simple to create a PO using BAPI. Trying a different configuration of pricing, ur BAPI goes for a toss!!

        Hope you will use your time effectively and not for simply posting a blog for posting sake.

        (0) 
        1. Cenk Uysal
          Documentation of the BAPI itself is not useful as you say. Like all other documentaions of SAP BAPIs, this BAPI’s doc sucks. Or maybe something wrong with my system. Because i can not see anything in that documentation.
          (0) 
  2. Arul Selvan
    This ready-to-use code can be used for legacy PO uploads if modified to suit requirements. Beginners in ABAP/BAPI will definitly find the weblog very useful.

    (0) 
  3. John Patterson
    To transfer legacy PO’s through an ABAP program I would suggest either BDC or RM06EEI0 with the migration workbeanch (LSMW).

    The BAPI you used creates ME21N Enjoy PO transaction, I would suggest as a newbie wanting to learn how to program BAPI calls look at BAPI_PO_CREATE, plenty of examples in where used.

    (0) 
    1. Community User Post author
      hi,
      code is write below………..

      REPORT  ZBAPI.

      Data: int_pohead TYPE BAPIEKKOC ,
            int_poitem TYPE TABLE OF BAPIEKPOC  with header line ,
            int_posched TYPE TABLE OF  BAPIEKET  with header line ,
            int_ret TYPE TABLE OF  BAPIRETURN  with header line ,
            d_purchord LIKE BAPIEKKOC-PO_NUMBER ,
            G LIKE BAPIRET2.

      *START-OF-SELECTION .
            int_pohead-DOC_TYPE =  ‘NB’ .
            int_pohead-PURCH_ORG =  ‘501’.
            int_pohead-PUR_GROUP =  ‘sap’ .
            int_pohead-vendor =   ‘0000001234’.

             int_poitem-PO_NUMBER = ‘501’ .
             int_poitem-po_item =  ‘1231’ .
             int_poitem-material = ‘Material’ .
             int_poitem-pur_mat = ‘Material’ .
             int_poitem-plant =  ‘1000’ .

            int_posched-PO_ITEM = ‘00010’.
            int_posched-DELIV_DATE =   ‘20080531’ .
            int_posched-QUANTITY =  ‘2’ .

      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                   =

      .

           CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
             EXPORTING
               WAIT          = ‘E’
             IMPORTING
               RETURN        = G .

      LOOP AT  int_ret .
      WRITE :/  int_ret-MESSAGE .
      WRITE : / int_ret-TYPE.
      WRITE : /’PURCHASE ORDER IS :’ ,   d_purchord.
      ENDLOOP.

      (0) 

Leave a Reply