Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Creating PO's - Batch Program

Former Member
0 Kudos

Hi All,

According to my requirement I have to create PO's from the open PR's and make it as a batch job.

What logic do I need to use for this, please help me out in this.

Thanks,

Praveen

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You have few options:

1. Choose LSMW , in first step of it define Direct/Batch input available related to PO.

Execute all the steps.

Ultimetly it will create a data.

2. Query all open PR's and collect the data. Use BAPI to process it. Relevent BAPI you will get from BAPI transaction.

3. Through BDC you can again do it by recording transaction through SHDB.

Reward if useful!

6 REPLIES 6

Former Member
0 Kudos

Hi,

You have few options:

1. Choose LSMW , in first step of it define Direct/Batch input available related to PO.

Execute all the steps.

Ultimetly it will create a data.

2. Query all open PR's and collect the data. Use BAPI to process it. Relevent BAPI you will get from BAPI transaction.

3. Through BDC you can again do it by recording transaction through SHDB.

Reward if useful!

0 Kudos

Hi,

Thanks for your reply if i use teh BAPI, what code do I need to use.

Thanks,

Praveen

0 Kudos

Probably BAPI_PO_CREATE1.

If not, check all BAPI_PO* in transaction SE37.

Also, you can check in transaction BAPI, under Purchasing branch.

You must read the selected BAPI documentation, and once you know which one to use, you must load the needed parameters and call the function from your program.

Please reward if useful.

0 Kudos

REPORT ZTEST_BAPI .

*- BAPI related declarations

DATA : g_pohdr TYPE bapimepoheader,

g_pohdrx TYPE bapimepoheaderx,

gt_poitem TYPE TABLE OF bapimepoitem,

gt_poitemx TYPE TABLE OF bapimepoitemx,

gt_posched TYPE TABLE OF bapimeposchedule,

gt_poschedx TYPE TABLE OF bapimeposchedulx,

gt_poacct TYPE TABLE OF bapimepoaccount,

gt_poacctx TYPE TABLE OF bapimepoaccountx,

gt_poservice TYPE TABLE OF bapiesllc,

gt_posrvacc TYPE TABLE OF bapiesklc,

gt_return TYPE TABLE OF bapiret2.

perform prepare_header.

PERFORM prepare_items.

PERFORM prepare_schedule.

perform create_po.

&----


*& Form prepare_header

&----


  • Set up header structure

----


FORM prepare_header.

g_pohdr-comp_code = '2000'.

g_pohdrx-comp_code = 'X'.

  • set up doc type

g_pohdr-doc_type = 'NB'.

g_pohdrx-doc_type = 'X'.

g_pohdr-vendor = '0008000330'.

g_pohdrx-vendor = 'X'.

g_pohdr-langu = sy-langu.

g_pohdrx-langu = 'X'.

g_pohdr-purch_org = 'BA01'.

g_pohdrx-purch_org = 'X'.

g_pohdr-pur_group = '800'.

g_pohdrx-pur_group = 'X'.

g_pohdr-currency = 'USD'.

g_pohdrx-currency = 'X'.

ENDFORM. " prepare_header

&----


*& Form prepare_items

&----


  • Set up item values

----


FORM prepare_items.

DATA : ls_poitem TYPE bapimepoitem,

ls_poitemx TYPE bapimepoitemx.

ls_poitem-po_item = '00010'.

ls_poitemx-po_item = '00010'.

ls_poitemx-po_itemx = 'X'.

ls_poitem-short_text = 'ABSORBER,SHOCK:PALLETIZER'.

ls_poitemx-short_text = 'X'.

ls_poitem-material = '000000000001070062'.

ls_poitemx-material = 'X'.

ls_poitem-vend_mat = 'xyz'.

ls_poitemx-vend_mat = 'X'.

ls_poitem-quantity = '100'.

ls_poitemx-quantity = 'X'.

ls_poitem-po_unit = 'EA'.

ls_poitemx-po_unit = 'X'.

ls_poitem-po_unit_iso = 'EA'.

ls_poitemx-po_unit_iso = 'X'.

ls_poitem-net_price = '6.32'.

ls_poitemx-net_price = 'X'.

ls_poitem-price_unit = '1'.

ls_poitemx-price_unit = 'X'.

ls_poitem-item_cat = 'D'.

ls_poitemx-item_cat = 'X'.

ls_poitem-plant = '1575'.

ls_poitemx-plant = 'X'.

ls_poitem-ACCTASSCAT = 'K'.

ls_poitemx-ACCTASSCAT = 'X'.

  • ls_poitem-acctasscat = <fs_req>-knttp.

  • ls_poitemx-acctasscat = 'X'.

*

  • ls_poitem-distrib = <fs_req>-vrtkz.

  • ls_poitemx-distrib = 'X'.

*

  • ls_poitem-part_inv = <fs_req>-twrkz.

  • ls_poitemx-part_inv = 'X'.

*

  • ls_poitem-gr_ind = <fs_req>-wepos.

  • ls_poitemx-gr_ind = 'X'.

*

  • ls_poitem-gr_non_val = <fs_req>-weunb.

  • ls_poitemx-gr_non_val = 'X'.

*

  • ls_poitem-ir_ind = <fs_req>-repos.

  • ls_poitemx-ir_ind = 'X'.

  • ls_poitem-agreement = <fs_req>-konnr.

  • ls_poitemx-agreement = 'X'.

*

  • ls_poitem-agmt_item = <fs_req>-ktpnr.

  • ls_poitemx-agmt_item = 'X'.

*

  • ls_poitem-preq_no = <fs_req>-banfn.

  • ls_poitemx-preq_no = 'X'.

*

  • ls_poitem-preq_item = <fs_req>-bnfpo.

  • ls_poitemx-preq_item = 'X'.

*

  • ls_poitem-preq_name = <fs_req>-afnam.

  • ls_poitemx-preq_name = 'X'.

*

  • ls_poitem-pckg_no = <fs_req>-packno.

  • ls_poitemx-pckg_no = 'X'.

APPEND : ls_poitem TO gt_poitem,

ls_poitemx TO gt_poitemx.

ENDFORM. " prepare_items

&----


*& Form prepare_schedule

&----


  • Schedule data

----


FORM prepare_schedule.

DATA : ls_posched TYPE bapimeposchedule,

ls_poschedx TYPE bapimeposchedulx.

ls_poschedx-po_item = '00010'.

ls_posched-po_item = '00010'.

ls_poschedx-po_itemx = 'X'.

ls_posched-delivery_date = '10/31/2005'.

ls_poschedx-delivery_date = 'X'.

ls_posched-quantity = '100'.

ls_poschedx-quantity = 'X'.

  • ls_posched-preq_no = <fs_req>-banfn.

  • ls_poschedx-preq_no = 'X'.

*

  • ls_posched-preq_item = <fs_req>-bnfpo.

  • ls_poschedx-preq_item = 'X'.

APPEND : ls_posched TO gt_posched,

ls_poschedx TO gt_poschedx.

ENDFORM. " prepare_schedule

&----


*& Form create_po

&----


  • Create PO with ref to the req

----


FORM create_po.

DATA : lt_return TYPE TABLE OF bapiret2,

l_ponum TYPE banfn.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = g_pohdr

poheaderx = g_pohdrx

  • testrun = 'X'

IMPORTING

exppurchaseorder = l_ponum

TABLES

return = lt_return

poitem = gt_poitem

poitemx = gt_poitemx

poschedule = gt_posched

poschedulex = gt_poschedx

poaccount = gt_poacct

poaccountx = gt_poacctx

poservices = gt_poservice

posrvaccessvalues = gt_posrvacc.

APPEND LINES OF lt_return TO gt_return.

IF NOT l_ponum IS INITIAL.

MESSAGE s398(00) WITH 'Purchase document ' l_ponum

' successfully created'.

ENDIF.

ENDFORM. " create_po

<b>

Reward points</b>

Regards

0 Kudos

Hi Kiran,

When I test this program I am getting system stop message "Field Selection PTYF Not Defined".

Whats this error.

Thanks in Advance,

Praveen

Former Member
0 Kudos

yes it is possiable.

possiable way.

1.bdc

2.bapi.

3.lsmw