Skip to Content
author's profile photo Former Member
Former Member



Does any body have report/program which creates PO using BAPI <b>BAPI_PO_CREATE1</b>.

I am having issues/could not create it with this.

Would appreciate for any inputs.

Best Regards,


Add comment
10|10000 characters needed characters exceeded

3 Answers

  • Best Answer
    Posted on Aug 01, 2006 at 07:04 PM

    Here is a sample code from one of my programs that create a PO using BAPI.

    report zrich_0001.
    constants : c_x value 'X'.
    data: del_date type sy-datum.
    data: pohead  type bapimepoheader.
    data: poheadx type bapimepoheaderx.
    data: exp_head type bapimepoheader.
    data: return  type table of bapiret2 with header line.
    data: poitem  type table of bapimepoitem with header line.
    data: poitemx type table of bapimepoitemx with header line.
    data: posched  type table of bapimeposchedule with header line.
    data: poschedx type table of bapimeposchedulx with header line.
    data: ex_po_number type bapimepoheader-po_number.
    parameters: p_matnr type ekpo-matnr.
    parameters: p_werks type ekpo-werks.
    parameters: p_lgort type ekpo-menge.
    parameters: p_menge type ekpo-menge.
    * Header Level Data
    * Get the company code
    select single  bukrs into pohead-comp_code
           from t001w
                inner join t001k
                   on t001w~bwkey = t001k~bwkey
                        where t001w~werks = p_werks.
    pohead-doc_type   = 'NB'     .
    pohead-creat_date = sy-datum   .
    * Get vendor and purchasing order from source list
    select single lifnr ekorg into (pohead-vendor, pohead-purch_org)
             from eord
                    where matnr = p_matnr
                      and werks = p_werks
                      and bdatu = '29991231'.
    * Get purchasing group from purchasing view of MM
    select single ekgrp into pohead-pur_group
            from marc
                  where matnr = p_matnr
                    and werks = p_werks.
    * Hardcode EMG as purchasing group.
    pohead-pur_group = 'EMG'.
    pohead-langu      = sy-langu   .
    pohead-doc_date   = sy-datum.
    poheadx-comp_code  = c_x.
    poheadx-doc_type   = c_x.
    poheadx-creat_date = c_x.
    poheadx-vendor     = c_x.
    poheadx-langu      = c_x.
    poheadx-purch_org  = c_x.
    poheadx-pur_group  = c_x.
    poheadx-doc_date   = c_x.
    * Item Level Data
    poitem-po_item  = 1.
    poitem-material = p_matnr.
    poitem-plant    = p_werks.
    poitem-stge_loc = p_lgort.
    poitem-quantity = p_menge.
    append poitem.
    poitemx-po_item    = 1.
    poitemx-po_itemx   = c_x.
    poitemx-material   = c_x.
    poitemx-plant      = c_x .
    poitemx-stge_loc   = c_x .
    poitemx-quantity   = c_x .
    poitemx-tax_code   = c_x .
    poitemx-item_cat   = c_x .
    poitemx-acctasscat = c_x .
    append poitemx.
    * Schedule Line Level Data
    posched-po_item        = 1.
    posched-sched_line     = 1.
    posched-del_datcat_ext = 'D'.
    del_date = sy-datum + 1.
    write del_date to posched-delivery_date.
    posched-deliv_time     = '000001'.
    posched-quantity       = p_menge.
    append posched.
    poschedx-po_item        = 1.
    poschedx-sched_line     = 1.
    poschedx-po_itemx       = c_x.
    poschedx-sched_linex    = c_x.
    poschedx-del_datcat_ext = c_x.
    poschedx-delivery_date  = c_x.
    poschedx-quantity       = c_x.
    append poschedx.
    call function 'BAPI_PO_CREATE1'
              poheader         = pohead
              poheaderx        = poheadx
              testrun          = ' '
              exppurchaseorder = ex_po_number
              expheader        = exp_head
              return           = return
              poitem           = poitem
              poitemx          = poitemx
              poschedule       = posched
              poschedulex      = poschedx.
    call function 'BAPI_TRANSACTION_COMMIT'
              wait = 'X'.
    if not ex_po_number is initial.
      call function 'DEQUEUE_ALL'.
      call function 'DEQUEUE_ALL'.
    *  message i036.


    Rich Heilman

    Message was edited by: Rich Heilman

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 07:10 PM

    Hi Mark,

    DATA : l_po_header LIKE bapimepoheader.

    DATA : l_po_headerx LIKE bapimepoheaderx.

    DATA : l_purchaseorder LIKE bapimepoheader-po_number.

    DATA : BEGIN OF t_return OCCURS 0.


    DATA : END OF t_return.

    DATA : BEGIN OF t_po_items OCCURS 0.

    INCLUDE STRUCTURE bapimepoitem.

    DATA : END OF t_po_items.

    DATA : BEGIN OF t_po_itemsx OCCURS 0.

    INCLUDE STRUCTURE bapimepoitemx.

    DATA : END OF t_po_itemsx.

    DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.

    DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.

    Populate these parameters according to your requirement



    poheader = l_po_header

    poheaderx = l_po_headerx


    exppurchaseorder = l_purchaseorder


    return = t_return

    poitem = t_po_items

    poitemx = t_po_itemsx

    poaccount = t_po_account

    poaccountx = t_po_accountx.



    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2006 at 07:10 PM

    Refer this blog




    Add comment
    10|10000 characters needed characters exceeded