<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: BAPI_PO_CREATE1 in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528550#M241760</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample code from one of my programs that create a PO using BAPI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


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'
     exporting
          poheader         = pohead
          poheaderx        = poheadx
          testrun          = ' '
     importing
          exppurchaseorder = ex_po_number
          expheader        = exp_head
     tables
          return           = return
          poitem           = poitem
          poitemx          = poitemx
          poschedule       = posched
          poschedulex      = poschedx.

call function 'BAPI_TRANSACTION_COMMIT'
     exporting
          wait = 'X'.

if not ex_po_number is initial.
  call function 'DEQUEUE_ALL'.
else.
  call function 'DEQUEUE_ALL'.
*  message i036.
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Aug 2006 19:04:42 GMT</pubDate>
    <dc:creator>RichHeilman</dc:creator>
    <dc:date>2006-08-01T19:04:42Z</dc:date>
    <item>
      <title>BAPI_PO_CREATE1</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528549#M241759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does any body have report/program which creates PO using BAPI &amp;lt;b&amp;gt;BAPI_PO_CREATE1&amp;lt;/b&amp;gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having issues/could not create it with this.&lt;/P&gt;&lt;P&gt;Would appreciate for any inputs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regards,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 19:00:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528549#M241759</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-01T19:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: BAPI_PO_CREATE1</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528550#M241760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample code from one of my programs that create a PO using BAPI.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;


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'
     exporting
          poheader         = pohead
          poheaderx        = poheadx
          testrun          = ' '
     importing
          exppurchaseorder = ex_po_number
          expheader        = exp_head
     tables
          return           = return
          poitem           = poitem
          poitemx          = poitemx
          poschedule       = posched
          poschedulex      = poschedx.

call function 'BAPI_TRANSACTION_COMMIT'
     exporting
          wait = 'X'.

if not ex_po_number is initial.
  call function 'DEQUEUE_ALL'.
else.
  call function 'DEQUEUE_ALL'.
*  message i036.
endif.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Rich Heilman&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 19:04:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528550#M241760</guid>
      <dc:creator>RichHeilman</dc:creator>
      <dc:date>2006-08-01T19:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: BAPI_PO_CREATE1</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528551#M241761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mark,&lt;/P&gt;&lt;P&gt;DATA : l_po_header LIKE bapimepoheader.&lt;/P&gt;&lt;P&gt;DATA : l_po_headerx LIKE bapimepoheaderx.&lt;/P&gt;&lt;P&gt;DATA : l_purchaseorder LIKE bapimepoheader-po_number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF t_return OCCURS 0.&lt;/P&gt;&lt;P&gt;INCLUDE STRUCTURE bapiret2.&lt;/P&gt;&lt;P&gt;DATA : END OF t_return.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF t_po_items OCCURS 0.&lt;/P&gt;&lt;P&gt;INCLUDE STRUCTURE bapimepoitem.&lt;/P&gt;&lt;P&gt;DATA : END OF t_po_items.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : BEGIN OF t_po_itemsx OCCURS 0.&lt;/P&gt;&lt;P&gt;INCLUDE STRUCTURE bapimepoitemx.&lt;/P&gt;&lt;P&gt;DATA : END OF t_po_itemsx.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Populate these parameters according to your requirement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'BAPI_PO_CREATE1'&lt;/P&gt;&lt;P&gt;EXPORTING&lt;/P&gt;&lt;P&gt;poheader = l_po_header&lt;/P&gt;&lt;P&gt;poheaderx = l_po_headerx&lt;/P&gt;&lt;P&gt;IMPORTING&lt;/P&gt;&lt;P&gt;exppurchaseorder = l_purchaseorder&lt;/P&gt;&lt;P&gt;TABLES&lt;/P&gt;&lt;P&gt;return = t_return&lt;/P&gt;&lt;P&gt;poitem = t_po_items&lt;/P&gt;&lt;P&gt;poitemx = t_po_itemsx&lt;/P&gt;&lt;P&gt;poaccount = t_po_account&lt;/P&gt;&lt;P&gt;poaccountx = t_po_accountx.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;keerthi.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 19:10:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528551#M241761</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2006-08-01T19:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: BAPI_PO_CREATE1</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528552#M241762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Refer this blog&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/people/sap.user72/blog/2005/03/22/sample-code-to-create-purchase-order-using-bapi-in-r3&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regds&lt;/P&gt;&lt;P&gt;Manohar&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Aug 2006 19:10:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/bapi-po-create1/m-p/1528552#M241762</guid>
      <dc:creator>Manohar2u</dc:creator>
      <dc:date>2006-08-01T19:10:56Z</dc:date>
    </item>
  </channel>
</rss>

