Application Development and Automation 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: 
Read only

BAPI_PO_CREATE1

jaiprasad_naidu5
Participant
0 Likes
1,047

Hi Gurus,

I am using BAPI_PO_CREATE1 for creating STO's. We are using SAP 4.7 Version. After executing the function module system is not saving the STO but it is skipping number range. any one please help me where the problem is. I am attaching the code I have written for this

REPORT ZJP_TEMP5 NO STANDARD PAGE HEADING

LINE-SIZE 80

LINE-COUNT 65(0)

message-id zus.

DATA : l_POHEADER LIKE BAPIMEPOHEADER,

li_POHEADER TYPE STANDARD TABLE OF BAPIMEPOHEADER,

l_POHEADER_x LIKE BAPIMEPOHEADERX,

li_POHEADER_x TYPE STANDARD TABLE OF BAPIMEPOHEADERX.

DATA : L_POITEM LIKE BAPIMEPOITEM,

Li_POITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,

L_POITEM_x LIKE BAPIMEPOITEMX,

Li_POITEM_x TYPE STANDARD TABLE OF BAPIMEPOITEMX,

L_POSCHEDULE LIKE BAPIMEPOSCHEDULE,

Li_POSCHEDULE type standard table of BAPIMEPOSCHEDULE,

L_POSCHEDULE_x LIKE BAPIMEPOSCHEDULx,

Li_POSCHEDULE_x type standard table of BAPIMEPOSCHEDULx.

DATA L_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.

DATA: lv_obj_key TYPE balnrext,

lv_ebeln TYPE ebeln,

lv_po_item TYPE ebelp,

lv_output TYPE c.

*PARAMETERS: p_po like L_POHEADER-PO_NUMBER default '490055035'.

start-of-selection.

*CLEAR: L_POHEADER, L_POITEM.

*, L_PO_ITEM_SCHEDULES, L_PO_ACCT_ASSIGN,

*L_PO_LIMITS, L_PO_SRV_ACCSS.

*REFRESH: L_POHEADER, L_POITEM.

*, L_PO_ITEM_SCHEDULES, L_PO_ACCT_ASSIGN,

*L_PO_LIMITS, L_PO_SRV_ACCSS.

CLEAR l_POHEADER.

  • PO Header record

*L_POHEADER-PO_NUMBER = '7500000090'. "MN = Marketing PO

L_POHEADER-doc_type = 'UB '. "MN = Marketing PO

L_POHEADER-SUPPL_PLNT = 'ML13'.

L_POHEADER-DOC_DATE = SY-DATUM.

L_POHEADER-purch_org = 'ML01'.

L_POHEADER-pur_group = 'STO'.

L_POHEADER-STATUS = '9'.

L_POHEADER-COMP_CODE = '1000'. "Company Code

L_POHEADER-LANGU = SY-LANGU.

L_POHEADER-LANGU_ISO = SY-LANGU.

L_POHEADER-CURRENCY = 'INR'.

L_POHEADER-CURRENCY_ISO = 'INR'.

APPEND L_POHEADER TO Li_POHEADER.

*Update Flag

CLEAR l_POHEADER_x.

*L_POHEADER_X-PO_NUMBER = 'X'.

L_POHEADER_x-doc_type = 'X'.

L_POHEADER_X-SUPPL_PLNT = 'X'.

L_POHEADER_X-DOC_DATE = 'X'.

L_POHEADER_X-purch_org = 'X'.

L_POHEADER_X-pur_group = 'X'.

L_POHEADER_X-COMP_CODE = 'X'.

L_POHEADER_X-STATUS = 'X'.

L_POHEADER_x-LANGU = 'X'.

L_POHEADER_x-LANGU_ISO = 'X'.

L_POHEADER_x-CURRENCY = 'X'.

L_POHEADER_x-CURRENCY_ISO = 'X'.

APPEND L_POHEADER_x TO Li_POHEADER_x.

  • PO Line Item

  • Line 10

CLEAR L_POITEM.

L_POITEM-po_item = '00010'.

L_POITEM-MATERIAL = 'FTINH0047'.

L_POITEM-STGE_LOC = 'FG01'.

L_POITEM-QUANTITY = '1000'.

L_POITEM-PO_UNIT = 'PC'.

L_POITEM-plant = 'ML57'.

APPEND L_POITEM TO Li_POITEM.

*Update Flag

CLEAR L_POITEM_x.

L_POITEM_x-po_item = '00010'.

L_POITEM_X-po_itemx = 'X'.

L_POITEM_x-MATERIAL = 'X'.

L_POITEM_x-STGE_LOC = 'X'.

L_POITEM_x-QUANTITY = 'X'.

L_POITEM_X-PO_UNIT = 'X'.

L_POITEM_x-plant = 'X'.

APPEND L_POITEM_x TO Li_POITEM_x.

**Line Item Schedules

CLEAR L_POSCHEDULE.

L_POSCHEDULE-po_item = '00010'.

L_POSCHEDULE-SCHED_LINE = '00001'.

L_POSCHEDULE-DEL_DATCAT_EXT = 'D'.

L_POSCHEDULE-DELIVERY_DATE = '01012008'.

L_POSCHEDULE-QUANTITY = '1000'.

APPEND L_POSCHEDULE TO Li_POSCHEDULE.

CLEAR L_POSCHEDULE_X.

L_POSCHEDULE_X-po_item = '00010'.

L_POSCHEDULE_X-SCHED_LINE = '00001'.

L_POSCHEDULE_X-po_itemX = 'X'.

L_POSCHEDULE_X-SCHED_LINEX = 'X'.

L_POSCHEDULE_X-DEL_DATCAT_EXT = 'X'.

L_POSCHEDULE_X-DELIVERY_DATE = 'X'.

L_POSCHEDULE_X-QUANTITY = 'X'.

APPEND L_POSCHEDULE_X TO Li_POSCHEDULE_X.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = L_POHEADER

POHEADERX = L_POHEADER_X

  • POADDRVENDOR =

  • TESTRUN = ''

MEMORY_UNCOMPLETE = 'X'

  • MEMORY_COMPLETE = 'X'

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING = 'X'

  • NO_MESSAGE_REQ = 'X'

  • NO_AUTHORITY =

NO_PRICE_FROM_PO = 'X'

  • IMPORTING

  • EXPPURCHASEORDER =

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = L_RETURN

POITEM = Li_POITEM

POITEMX = Li_POITEM_X

    • POADDRDELIVERY =

POSCHEDULE = Li_POSCHEDULE

POSCHEDULEX = Li_POSCHEDULE_X

  • POACCOUNT =

  • POACCOUNTPROFITSEGMENT =

  • POACCOUNTX =

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
846

Hi Hitesh,

I hav checked ur code wht i found was u should use Bapi_commit suc tht it should be stored in ur database...

try this hope tht this might solve ur problem..

Regards,

Satish.

Reward points if useful....

3 REPLIES 3
Read only

Former Member
0 Likes
847

Hi Hitesh,

I hav checked ur code wht i found was u should use Bapi_commit suc tht it should be stored in ur database...

try this hope tht this might solve ur problem..

Regards,

Satish.

Reward points if useful....

Read only

former_member404244
Active Contributor
0 Likes
846

Hi,

Use BAPI_TRANSACTION_COMMIT after ur bapi

and then pass value as 'X' to WAIT parameter.

Regards,

Nagaraj

Read only

Former Member
0 Likes
846

Hi Sir,

Please see below the code where i have used BAPI_PO_CREATE1, which will help u understand better .Call this function --->

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'.

*IMPORTING

*RETURN = i_return

to get values stored in DATABASE.SEE below for my entire code.

Please do reward if useful.

Thakx.

method do_handle_event.

*CALL METHOD SUPER->DO_HANDLE_EVENT

  • EXPORTING

  • EVENT =

  • HTMLB_EVENT =

    • HTMLB_EVENT_EX =

  • GLOBAL_MESSAGES =

  • RECEIVING

  • GLOBAL_EVENT =

  • .

data: event_id type string.

data zpr_num1 type banfn.

data zreturn type zsn_bapiret2.

data ret type bapireturn-type.

data message type bapi_msg.

data returnval type bapimepoheader-po_number.

data: r_view type ref to if_bsp_page.

data: crt_view type ref to if_bsp_page.

data po_num_head type bapimepoheader.

data zpoheader_it type zbapimepoheader_tab.

data zpoheaderx_it type zbapimepoheaderx_tab.

  • to add a new item to list

if htmlb_event is bound and htmlb_event->server_event = 'onadd'.

zpr_num = request->get_form_field( 'PRNo' ) .

data: zpr_num3 type banfn.

call function 'ZCONVERT_ALPHA'

exporting

input = zpr_num

importing

output = zpr_num3.

zpr_num = zpr_num3.

data: temp_tab1 type zrmheader.

delete from zrmheader.

zpoheader-vendor = request->get_form_field( 'Vendor' ) .

zpoheader-purch_org = request->get_form_field( 'POrg' ).

zpoheader-pur_group = request->get_form_field( 'PGrp' ).

zpoheader-doc_type = 'NB'.

zpoheader-item_intvl = request->get_form_field( 'Item' ).

zpoheader-comp_code = request->get_form_field( 'CCode' ).

zpoheader-doc_date = request->get_form_field( 'DocDate' ).

delivdate_new = request->get_form_field( 'DelivDate' ).

temp_tab1-vendor = request->get_form_field( 'Vendor' ) .

temp_tab1-purch_org = request->get_form_field( 'POrg' ).

temp_tab1-pur_group = request->get_form_field( 'PGrp' ).

temp_tab1-doc_type = 'NB'.

temp_tab1-item_intvl = request->get_form_field( 'Item' ).

temp_tab1-comp_code = request->get_form_field( 'CCode' ).

temp_tab1-doc_date = request->get_form_field( 'DocDate' ).

data: temp_tabx1 type zrmheaderx.

delete from zrmheaderx.

temp_tabx1-vendor = 'x'.

temp_tabx1-purch_org = 'x'.

temp_tabx1-pur_group = 'x'.

temp_tabx1-doc_type = 'x'.

temp_tabx1-comp_code = 'x'.

temp_tabx1-doc_date = 'x'.

insert into zrmheader values temp_tab1.

insert into zrmheaderx values temp_tabx1.

data: temp_tab type zrmitem .

data: temp_tabx type zrmitemx.

zitem1-acctasscat = request->get_form_field( 'A' ).

temp_tab-acctasscat = request->get_form_field( 'A' ).

zitem1-item_cat = request->get_form_field( 'I' ).

temp_tab-item_cat = request->get_form_field( 'I' ).

zitem1-material = request->get_form_field( 'Material' ).

temp_tab-material = request->get_form_field( 'Material' ).

zitem1-quantity = request->get_form_field( 'POQuantity' ).

temp_tab-quantity = request->get_form_field( 'POQuantity' ).

zitem1-po_unit = request->get_form_field( 'OUN' ).

temp_tab-po_unit = request->get_form_field( 'OUN' ).

zitem1-net_price = request->get_form_field( 'NetPrice' ).

temp_tab-net_price = request->get_form_field( 'NetPrice' ).

zitem1-plant = request->get_form_field( 'Plnt' ).

temp_tab-plant = request->get_form_field( 'Plnt' ).

zitem1-po_item = request->get_form_field( 'Item' ).

temp_tab-po_item = request->get_form_field( 'Item' ).

zitem1-stge_loc = request->get_form_field( 'Sloc' ).

temp_tab-stge_loc = request->get_form_field( 'Sloc' ).

zitem1-customer = request->get_form_field( 'Customer' ).

temp_tab-customer = request->get_form_field( 'Customer' ).

zitem1-incoterms2 = 'XDFGRT'.

temp_tab-incoterms2 = 'XDFGRT'.

  • append zitem1 to zitem.

insert into zrmitem values temp_tab.

zitemx1-acctasscat = 'x'.

zitemx1-item_cat = 'x'.

zitemx1-material = 'x'.

zitemx1-quantity = 'x'.

zitemx1-net_price = 'x'.

zitemx1-plant = 'x'.

zitemx1-po_item = 00010.

zitemx1-po_itemx = 'x'.

zitemx1-stge_loc = 'x'.

zitemx1-customer = 'x'.

zitemx1-incoterms2 = 'x'.

  • append zitemx1 to zitemx.

temp_tabx-acctasscat = 'x'.

temp_tabx-item_cat = 'x'.

temp_tabx-material = 'x'.

temp_tabx-quantity = 'x'.

temp_tabx-net_price = 'x'.

temp_tabx-plant = 'x'.

temp_tabx-po_item = 00010.

temp_tabx-po_itemx = 'x'.

temp_tabx-stge_loc = 'x'.

temp_tabx-customer = 'x'.

temp_tabx-incoterms2 = 'x'.

insert into zrmitemx values temp_tabx.

select * from zrmitem into corresponding fields of table zitem.

zpr_num = request->get_form_field( 'PRNo' ) .

call function 'ZCONVERT_ALPHA'

exporting

input = zpr_num

importing

output = zpr_num1.

  • LEN =

.

call function 'BAPI_REQUISITION_GETDETAIL'

exporting

number = zpr_num1

  • ACCOUNT_ASSIGNMENT = ' '

  • ITEM_TEXTS = ' '

  • SERVICES = ' '

  • SERVICE_TEXTS = ' '

tables

requisition_items = item_tab

  • REQUISITION_ACCOUNT_ASSIGNMENT =

  • REQUISITION_TEXT =

  • REQUISITION_LIMITS =

  • REQUISITION_CONTRACT_LIMITS =

  • REQUISITION_SERVICES =

  • REQUISITION_SERVICES_TEXTS =

  • REQUISITION_SRV_ACCASS_VALUES =

  • RETURN =

.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'.

*IMPORTING

*RETURN = i_return

  • to save the item details and generate a PO number

elseif htmlb_event is bound and htmlb_event->server_event = 'onsave'.

zpr_num = request->get_form_field( 'PRNo' ) .

data: zpr_num4 type banfn.

call function 'ZCONVERT_ALPHA'

exporting

input = zpr_num

importing

output = zpr_num4.

zpr_num = zpr_num4.

data: temp_t2 type zrmsched,

count2 type n,

a2 type n value 1.

data:temp_t type zrmitem,

count type n,

a type n value 1.

select * from zrmitem into corresponding fields of table data_tab.

count = sy-dbcnt.

do count times.

read table data_tab into temp_t index a.

a = a + 1.

zitem1-po_item = temp_t-po_item.

zitem1-acctasscat = temp_t-acctasscat.

zitem1-item_cat = temp_t-item_cat.

zitem1-material = temp_t-material.

zitem1-quantity = temp_t-quantity.

zitem1-po_unit = temp_t-po_unit.

zitem1-net_price = temp_t-net_price.

zitem1-plant = temp_t-plant.

zitem1-stge_loc = temp_t-stge_loc.

zitem1-customer = temp_t-customer.

zitem1-incoterms2 = temp_t-incoterms2.

append zitem1 to zitem.

zitemx1-acctasscat = 'x'.

zitemx1-item_cat = 'x'.

zitemx1-material = 'x'.

zitemx1-quantity = 'x'.

zitemx1-net_price = 'x'.

zitemx1-plant = 'x'.

zitemx1-po_item = temp_t-po_item.

zitemx1-po_itemx = 'x'.

zitemx1-stge_loc = 'x'.

zitemx1-customer = 'x'.

zitemx1-incoterms2 = 'x'.

append zitemx1 to zitemx.

enddo.

  • count2 = sy-dbcnt.

zpoheader-vendor = request->get_form_field( 'Vendor' ) .

zpoheader-purch_org = request->get_form_field( 'POrg' ).

zpoheader-pur_group = request->get_form_field( 'PGrp' ).

zpoheader-doc_type = 'NB'.

zpoheader-item_intvl = request->get_form_field( 'Item' ).

zpoheader-comp_code = request->get_form_field( 'CCode' ).

zpoheader-doc_date = request->get_form_field( 'DocDate' ).

delivdate_new = request->get_form_field( 'DelivDate' ).

zpoheaderx-vendor = 'x'.

zpoheaderx-purch_org = 'x'.

zpoheaderx-pur_group = 'x'.

zpoheaderx-doc_type = 'x'.

zpoheaderx-comp_code = 'x'.

zpoheaderx-doc_date = 'x'.

data: zpovendor type elifn.

call function 'ZCONVERT_ALPHA'

exporting

input = zpoheader-vendor

importing

output = zpovendor.

zpoheader-vendor = zpovendor.

call function 'BAPI_PO_CREATE1'

exporting

poheader = zpoheader

poheaderx = zpoheaderx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

importing

exppurchaseorder = po_num

  • EXPHEADER = PO_NUM_HEAD

  • EXPPOEXPIMPHEADER =

tables

  • RETURN = zreturn

poitem = zitem

poitemx = zitemx

  • POADDRDELIVERY =

  • POSCHEDULE = zposched

  • POSCHEDULEX = zposchedx

  • POACCOUNT =

  • POACCOUNTPROFITSEGMENT =

  • POACCOUNTX =

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

  • POCOMPONENTS =

  • POCOMPONENTSX =

  • POSHIPPING =

  • POSHIPPINGX =

  • POSHIPPINGEXP =

.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'

  • IMPORTING

  • RETURN =

.

delete from zrmitem.

delete from zrmitemx.

select * from zrmitem into corresponding fields of table zitem.

if po_num = ' '.

po_num = 'Try Again'.

endif.

  • to store po_num and corresponding pr number

data: temp_tt type zpo_pr_nums.

temp_tt-pr_num = zpr_num.

temp_tt-po_num = po_num.

insert into zpo_pr_nums values temp_tt.

  • to store po num and corresponding delivery date

data: wa11 type zpo_delivdate.

wa11-po_number = po_num.

wa11-deliv_date = delivdate_new.

insert into zpo_delivdate values wa11.

zpoheader-vendor = ' '.

zpoheader-purch_org = ' '.

zpoheader-pur_group = ' '.

zpoheader-doc_type = ' '.

zpoheader-item_intvl = ' '.

zpoheader-comp_code = ' '.

zpoheader-doc_date = ' '.

delivdate_new = ' '.

  • to enter a PR Number

elseif htmlb_event is bound and htmlb_event->server_event = 'onenter'.

delete from zrmitem.

delete from zrmitemx.

select * from zrmitem into corresponding fields of table zitem.

zpr_num = request->get_form_field( 'PRNo' ) .

call function 'ZCONVERT_ALPHA'

exporting

input = zpr_num

importing

output = zpr_num1.

  • LEN =

.

call function 'BAPI_REQUISITION_GETDETAIL'

exporting

number = zpr_num1

  • ACCOUNT_ASSIGNMENT = ' '

  • ITEM_TEXTS = ' '

  • SERVICES = ' '

  • SERVICE_TEXTS = ' '

tables

requisition_items = item_tab

  • REQUISITION_ACCOUNT_ASSIGNMENT =

  • REQUISITION_TEXT =

  • REQUISITION_LIMITS =

  • REQUISITION_CONTRACT_LIMITS =

  • REQUISITION_SERVICES =

  • REQUISITION_SERVICES_TEXTS =

  • REQUISITION_SRV_ACCASS_VALUES =

  • RETURN =

.

call function 'BAPI_TRANSACTION_COMMIT'

exporting

wait = 'X'.

*IMPORTING

*RETURN = i_return

  • to select an item from drop down item menu

elseif htmlb_event is bound and htmlb_event->server_event = 'select'.

data: zselection2 type bnfpo.

data: data type ref to cl_htmlb_dropdownlistbox.

zpr_num = request->get_form_field( 'PRNo' ) .

data: zpr_num2 type banfn.

call function 'ZCONVERT_ALPHA'

exporting

input = zpr_num

importing

output = zpr_num2.

data ?= cl_htmlb_manager=>get_data(

request = runtime->server->request

name = 'dropdownlistbox'

id = 'ItemSel'

).

if data is not initial.

zselection2 = data->selection.

endif.

zpoheader-vendor = request->get_form_field( 'Vendor' ) .

zpoheader-purch_org = request->get_form_field( 'POrg' ).

zpoheader-pur_group = request->get_form_field( 'PGrp' ).

zpoheader-doc_type = 'NB'.

zpoheader-item_intvl = request->get_form_field( 'Item' ).

zpoheader-comp_code = request->get_form_field( 'CCode' ).

zpoheader-doc_date = request->get_form_field( 'DocDate' ).

call function 'BAPI_REQUISITION_GETDETAIL'

exporting

number = zpr_num2

  • ACCOUNT_ASSIGNMENT = ' '

  • ITEM_TEXTS = ' '

  • SERVICES = ' '

  • SERVICE_TEXTS = ' '

tables

requisition_items = item_tab

  • REQUISITION_ACCOUNT_ASSIGNMENT =

  • REQUISITION_TEXT =

  • REQUISITION_LIMITS =

  • REQUISITION_CONTRACT_LIMITS =

  • REQUISITION_SERVICES =

  • REQUISITION_SERVICES_TEXTS =

  • REQUISITION_SRV_ACCASS_VALUES =

  • RETURN =

.

data wa1 type bapieban.

loop at item_tab into wa1.

if wa1-preq_item = zselection2.

item_new = wa1-preq_item.

material_new = wa1-material.

plant_new = wa1-plant.

quantity_new = wa1-quantity.

unit_new = wa1-unit.

delivdate_new = wa1-deliv_date.

endif.

endloop.

endif.