2007 Dec 13 5:21 AM
hi friends,
i am very new to bapi i have requiremet to upload purchase order
using bapi can any one tell me how to use bapi_po_create
which parameter i hvae to pass .plz do the need ful.
regards
sonu
hi friends,
i am very new to bapi i have requiremet to upload purchase order
using bapi can any one tell me how to use bapi_po_create
which parameter i hvae to pass .plz do the need ful.
regards
sonu
2007 Dec 13 5:23 AM
Hi,
FU BAPI_PO_CREATE1
____________________________________________________
Short Text
Create Purchase Order
Functionality
Function module BAPI_PO_CREATE1 enables you to create purchase orders. The BAPI uses the technology behind the Enjoy purchase order transaction ( ME21N).
Alternatively, the IDoc type PORDCR1 is available. The data from this IDoc automatically populates the interface parameters of the function module BAPI_PO_CREATE1.
Functionality in Detail
Authorization
The following authorization objects are checked when an Enjoy purchase order is created (activity 01):
M_BEST_BSA (document type in PO)
M_BEST_EKG (purchasing group in PO)
M_BEST_EKO (purchasing organization in PO)
M_BEST_WRK (plant in PO)
Controlling adoption of field values via X parameter
For most tables, you can determine via your own parameters in the associated X parameter in each case (e.g. PoItemX) whether fields are to be set initial, values inserted via the interface, or default values adopted (e.g. from Customizing or master records) (for example, it is not mandatory to adopt the material group from an underlying purchase requisition - you can change it with the BAPI).
Transfer
Header data
The header data of the Enjoy purchase order is transferred in the table PoHeader.
Item data
The item data of the Enjoy purchase order is stored in the table PoItem (general item data). The delivery schedule lines are stored in the table PoSchedule.
Use the table PoAccount to specify the account assignment information. If account assignments have been specified for services and limits, you show the relevant account assignment line in PoAccount in the table PoSrvAccessValues via the package number of the service or the limit.
Services and limits
Services, free limits and limits with contract reference can be specified in the tables PoServices, PoLimits, and PoContractLimits.
Conditions
Conditions are transferred in the table PoCond; header conditions in the table PoCondHeader. Price determination is reinitiated via the parameter CALCTYPE in the table PoItem.
Vendor and delivery address
The vendor's address can be specified individually in the table PoAddrVendor; the delivery address in the table PoAddrDelivery. If you do not make any individual specification, the fields will be populated via the central address management facility.
Note
In this method, the following restrictions apply with regard to addresses:
Addresses can only be created with this method - they cannot be changed. You can only change address data with the method BAPI_ADDRESSORG_CHANGE.
When you create addresses, they are not checked by the method. An Enjoy purchase order may therefore contain faulty address data.
Partner roles
The partners can be maintained individually via the table PoPartner (with the exception of the partner role "vendor").
Import/export data
Import/Export data can be specified per item in the table PoExpImpItem. Foreign trade data can only be transferred as default data for new items.
Texts
Header and item texts can be transferred in the tables PoTextHeader and PoTextItem. Texts for services are imported in the table PoServicesText.
Version Management
You can make use of the Version Management facility via the table AllVersions.
Return
The PO number is returned in the parameter ExpPurchaseOrder. In addition, all information except the service and export/import tables is placed in the output structures.
Return messages
Messages are returned in the parameter Return. This also contains information as to whether interface data has been wrongly or probably wrongly (heuristical interface check) populated. When a PO has been created successfully, the PO number is also placed in the return table with the appropriate message.
Restrictions
With this function module, it is not possible to:
Create subcontracting components (you can only use existing ones)
Create configurations (you can only use existing ones)
Change message records (table NAST) and additional message data (this data can only be determined via the message determination facility (Customizing))
Attach documents to the purchase order
See also further information in SAP Note 197958.
Example
Example of population of BAPI interface in the Function Builder
Parameter: POHEADER
COMP_CODE = 1000
DOC_TYPE = NB
ITEM_INTVL = 00001
VENDOR = 0000001000
PMNTTRMS = 0001
PURCH_ORG = 1000
PUR_GROUP = 001
CURRENCY = EUR
Parameter: POHEADERX
COMP_CODE = X
DOC_TYPE = X
ITEM_INTVL = X
VENDOR = X
PMNTTRMS = X
PURCH_ORG = X
PUR_GROUP = X
Parameter: POITEM
PO_ITEM = 00001
MATERIAL = 100-100
PLANT = 1000
STGE_LOC = 0001
QUANTITY = 15.000
TAX_CODE = V0
ITEM_CAT = 0
ACCTASSCAT = K
Parameter: POITEMX
PO_ITEM = 00001
MATERIAL = X
PLANT = X
STGE_LOC = X
QUANTITY = X
TAX_CODE = X
ITEM_CAT = X
ACCTASSCAT = X
Parameter: POSCHEDULE
PO_ITEM = 00001
SCHED_LINE = 0001
QUANTITY = 6.000
PO_ITEM = 00001
SCHED_LINE = 0002
DELIVERY_DATE = 03.12.2002
QUANTITY = 5.000
PO_ITEM = 00001
SCHED_LINE = 0003
DELIVERY_DATE = 04.12.2002
QUANTITY = 4.000
Parameter: POSCHEDULEX
PO_ITEM = 00001
SCHED_LINE = 0001
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0002
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
PO_ITEM = 00001
SCHED_LINE = 0003
PO_ITEMX = X
SCHED_LINEX = X
DELIVERY_DATE = X
QUANTITY = X
Parameter: POACCOUNT
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = 15.000
GL_ACCOUNT = 0000400000
COSTCENTER = 0000001000
CO_AREA = 1000
Parameter: POACCOUNTX
PO_ITEM = 00001
SERIAL_NO = 01
QUANTITY = X
GL_ACCOUNT = X
COSTCENTER = X
CO_AREA = X
Parameter: POCOND
ITM_NUMBER = 000001
COND_ST_NO = 001
COND_TYPE = PB00
COND_VALUE = 79.900000000
CURRENCY = EUR
CURRENCY_ISO = EUR
COND_UNIT = KG
COND_P_UNT = 1
CHANGE_ID = U
Parameter: POCONDX
ITM_NUMBER = 000001
COND_ST_NO = 000
ITM_NUMBERX = X
COND_TYPE = X
COND_VALUE = X
CURRENCY = X
CHANGE_ID = X
Parameter: POPARTNER
PARTNERDESC = OA
LANGU = EN
BUSPARTNO = 0000001100
PARTNERDESC = GS
LANGU = EN
BUSPARTNO = 0000001200
PARTNERDESC = PI
LANGU = EN
BUSPARTNO = 0000001000
Help in the Case of Problems
SAP Note 197958 lists answers to frequently asked questions (FAQs). (Note 499626 contains answers to FAQs relating specifically to External Services Management.)
If you have detected an error in the function of a BAPI, create a reproducible example in the test data directory in the Function Builder (transaction code SE37). SAP Note 375886 tells you how to do this.
If the problem persists, create a Customer Problem Message for the componente MM-PUR-PO-BAPI, and document the reproducible example where appropriate.
Customer Enhancements
The following customer exits (function modules) are available for the BAPI BAPI_PO_CREATE1:
EXIT_SAPL2012_001 (at start of BAPI)
EXIT_SAPL2012_003 (at end of BAPI)
The following customer exits (function modules) are available for the BAPI BAPI_PO_CHANGE:
EXIT_SAPL2012_002 (at start of BAPI)
EXIT_SAPL2012_004 (at end of BAPI)
These exits belong to the enhancement SAPL2012 (see also transaction codes SMOD and CMOD).
There is also the option of populating customers' own fields for header, item, or account assignment data via the parameter EXTENSIONIN.
Further information
Further information on purchase order BAPIs is available in SAP Note 197958.
If you test the BAPIs BAPI_PO_CREATE1 or BAPI_PO_CHANGE in the Function Builder (transaction code SE37), no database updates will be carried out. If you need this function, take a look at Note 420646.
The BAPI BAPI_PO_GETDETAIL serves to read the details of a purchase order. The BAPI cannot read all details (e.g. conditions). However, you can use the BAPI BAPI_PO_CHANGE for this purpose if just the document number is populated and the invoker has change authorizations for purchase orders.
Frequently used BAPIs for purchase orders are BAPI_PO_CREATE, BAPI_PO_CREATE1, BAPI_PO_CHANGE, BAPI_PO_GETDETAIL, BAPI_PO_GETITEMS, BAPI_PO_GETITEMSREL, and BAPI_PO_GETRELINFO.
For more information on purchase orders, refer to the SAP library (under MM Purchasing -> Purchase Orders) or the Help for the Enjoy Purchase Order, or choose the path Tools -> ABAP Workbench -> Overview -> BAPI Explorer from the SAP Easy Access menu.
Parameters
POHEADER
POHEADERX
POADDRVENDOR
TESTRUN
MEMORY_UNCOMPLETE
MEMORY_COMPLETE
POEXPIMPHEADER
POEXPIMPHEADERX
VERSIONS
NO_MESSAGING
NO_MESSAGE_REQ
NO_AUTHORITY
NO_PRICE_FROM_PO
EXPPURCHASEORDER
EXPHEADER
EXPPOEXPIMPHEADER
RETURN
POITEM
POITEMX
POADDRDELIVERY
POSCHEDULE
POSCHEDULEX
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
Exceptions
Function Group
2012
Regards,
PRashant
Message was edited by:
Prashant Patil
2007 Dec 13 5:26 AM
Hi Sir,
I am sending you the code in which i have implemented bapi pocreate.Please go through the FM ,you will easily understand it.
Plz do reward if useful.
Thankx.
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.
2007 Dec 13 5:27 AM
2007 Dec 13 5:27 AM
Another simpler code for your answer.
Plz do reward if useful.
Thankx.
*CALL METHOD SUPER->DO_HANDLE_EVENT
EXPORTING
EVENT =
HTMLB_EVENT =
HTMLB_EVENT_EX =
GLOBAL_MESSAGES =
RECEIVING
GLOBAL_EVENT =
.
data: event_id type string.
data zreturn type zsn_bapiret2.
data ret type bapireturn-type.
data message type bapi_msg.
data po_num type ebeln.
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 zitem1 type BAPIMEPOITEM.
data zitemx1 type BAPIMEPOITEMx.
data : ZPOHEADER type BAPIMEPOHEADER.
DATA zPOHEADERx type BAPIMEPOHEADERx.
ZITEM type ZBAPIMEPOITEM_TAB,
ZITEMx type ZBAPIMEPOITEMX_TAB,
data po_num_head type bapimepoheader.
data zpoheader_it type zbapimepoheader_tab.
data zpoheaderx_it type zbapimepoheaderx_tab.
dispatch_input( ).
*event_id = event.
*if htmlb_event is not initial.
event_id = htmlb_event->id.
*endif.
*case event_id.
when 'add'.
if htmlb_event is bound and htmlb_event->server_event = 'onadd'.
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' ).
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' ).
data: temp_tabx1 type zrmheaderx.
delete from zrmheaderx.
zpoheaderx-vendor = 'x'.
zpoheaderx-purch_org = 'x'.
zpoheaderx-pur_group = 'x'.
zpoheaderx-doc_type = 'x'.
zpoheaderx-comp_code = 'x'.
temp_tabx1-vendor = 'x'.
temp_tabx1-purch_org = 'x'.
temp_tabx1-pur_group = 'x'.
temp_tabx1-doc_type = 'x'.
temp_tabx1-comp_code = '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.
select * from zrmheader into corresponding fields of table zpoheader.
*crt_view = create_view( view_name = 'view1.htm' ).
crt_view->set_attribute( name = 'item11' value = zitem ).
call_view( crt_view ).
*
*endcase.
*
case event_id.
when 'save'.
elseif htmlb_event is bound and htmlb_event->server_event = 'onsave'.
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.
select * from zrmitemx into corresponding fields of table zitemx.
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.
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' ).
zpoheaderx-vendor = 'x'.
zpoheaderx-purch_org = 'x'.
zpoheaderx-pur_group = 'x'.
zpoheaderx-doc_type = 'x'.
zpoheaderx-comp_code = 'x'.
select * from zrmheader into corresponding fields of table zpoheader_it.
select * from zrmheaderx into corresponding fields of table zpoheaderx_it.
data zitem1 type BAPIMEPOITEM.
zitem1-acctasscat = '1'.
zitem1-item_cat = 'A'.
zitem1-material = '787A'.
zitem1-quantity = '567'.
zitem1-po_unit = 'PC'.
zitem1-net_price = '5600'.
zitem1-plant = 'PB2B'.
zitem1-po_item = '00010'.
zitem1-stge_loc = 'PB2B'.
zitem1-customer = '787'.
zitem1-incoterms2 = 'XDFGRT'.
append zitem1 to zitem.
data zitemx1 type BAPIMEPOITEMx.
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.
data zreturn1 type bapiret2.
data: zreturn1 type ref to bapiret2 value is initial.
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 =
POSCHEDULEX =
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.
endif.
endcase.
*select * from zrmitem into corresponding fields of table zitem.
select * from zrmheader into corresponding fields of table zpoheader.
*
endmethod.
2007 Dec 13 5:28 AM
Hi,
Check the code.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
poheader = lwa_bapimepoheader
poheaderx = lwa_bapimepoheaderx
IMPORTING
exppurchaseorder = lv_po
TABLES
return = li_return.
.
In header populate Company code Doc_type and purchasing organization, purchasing group and doc date in structure lwa_bapimepoheader.
Pass 'X' to all these fields in lwa_bapimepoheaderx.
Run the program PO created will be present in lv_po.
Thanks,
Kasiraman R