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_CHANGE enhancement

Former Member
0 Likes
5,802

Hi,

I am working with Bapi_PO_CHANGE and need to change some dat in the custom fields of EKKO and EKPO table.....

can someone tell me the procedure to reate proper enhancement to change data in customer fields of these tabls using this BAPI?

Regards,

Tarun Bahal

4 REPLIES 4
Read only

Former Member
0 Likes
2,295

Pls Help

Read only

Former Member
0 Likes
2,295

Short Description

Change Enjoy Purchase Orders

Function Module

BAPI_PO_CHANGE

Description

Functionality

STYLE S_DOCUS1 Function module BAPI_PO_CHANGE enables you to change purchase orders. The Change method uses the technology behind the online transaction ME22N. Alternatively, the IDoc type PORDCH1 is available. The data from this IDoc populates the interface parameters of the function module BAPI_PO_CHANGE. STYLE *

Functionality in Detail

STYLE S_DOCUS1

Authorization

When you create (activity 02) an Enjoy purchase order, the following authorization objects are checked: 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 use your own parameters in the associated X parameter (e.g. PoItemX) to determine whether fields are to be set initial, values inserted via the interface, or default values adopted from Customizing or master records, etc. (for example, it is not mandatory to adopt the material group from an underlying requisition - you can change it with the BAPI).

Transfer

Purchase order number

The PurchaseOrder field uniquely identifies a purchase order. This field must be populated in order to execute the Change method.

Header data

The header data of the Enjoy purchase order is transferred in the PoHeader table.

Item data

The item data of the Enjoy purchase order is stored in the PoItem (general item data) tables. Changes in the quantity and delivery date/time are to be made in the PoSchedule table. Use the PoAccount table to change the account assignment information.

Services and limits

Changes to existing items cannot be carried out with the Change method. It is only possible to create new items.

Conditions

Conditions are transferred in the table PoCond; header conditions in the table PoCondHeader. A new price determination process can be initiated via the parameter CALCTYPE in the PoItem table.

Vendor and delivery address

The vendor address in the table PoAddrVendor and the delivery address in the table PoAddrDelivery can only be replaced by another address number that already exists in the system (table ADRC). Changes to address details can only be made using the BAPI_ADDRESSORG_CHANGE method.

Partner roles

You can change all partners except the partner role "vendor" via the PoPartner table.

Export/import data

You can specify export/import data per item in the PoExpImpItem table. Foreign trade data can only be transferred as default data for new items. Changes to the export/import data of existing items are not possible.

Texts

You can transfer header and item texts in the PoTextHeader and PoTextItem tables. You import texts for services in the PoServicesText table. Texts can only be replaced complete.

Version Management

You can make use of the Version Management facility via the AllVersions table.

Return

If the PO was changed successfully, the header and item tables are populated with the information from the PO.

Return messages

Messages are returned in the Return parameter. This also contains information as to whether interface data has been populated wrongly or probably wrongly (heuristical interface check). If a PO has been created successfully, the PO number is also placed in the return table with the appropriate message. STYLE * STYLE S_DOCUS1

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

Change foreign trade data

Change service data

Change or reexplode BOMs

A firewall prevents the manipulation of data that is not changeable in Purchasing according to the business logic of the

purchase order (e.g. PO number, vendor, etc.).

PO items with an invoicing plan cannot be created or changed using the BAPIs

In this connection, please refer to current information in Note 197958. To change addresses with numbers from Business Address Services (cantral address management), please use the function module BAPI_ADDRESSORG_CHANGE. To change variant configurations, please use the function module BAPI_UI_CHANGE. More information is available in the BAPI Explorer under the Logistics General node. In the case of changes that are to be made via the BAPI_PO_CHANGE, a firewall first checks whether the relevant fields are changeable. This approach follows that of the online transaction. Here it is not possible to change the vendor or the document type, for example. STYLE *

Example

STYLE S_DOCUS1

Example of changes made to a purchase order with:

Change in header data Change in item Change in delivery schedule Change in account assignment Change in conditions Change in partners Parameter: PURCHASEORDER ,,,,4500049596 Parameter: POHEADER PMNTTRMS,,=,,0002 PUR_GROUP,,=,,002 Parameter: POHEADERX PMNTTRMS,,=,,X PUR_GROUP,,=,,X Parameter: POITEM PO_ITEM,,=,,00001 CONF_CTRL,,=,,0001 Parameter: POITEMX PO_ITEM,,=,,00001 PO_ITEMX,,=,,X CONF_CTRL,,= ,,X Parameter: POSCHEDULE PO_ITEM,,=,,00001 SCHED_LINE,,=,,0001 QUANTITY,,=,,10.000 PO_ITEM,,=,,00001 SCHED_LINE,,=,,0003 DELETE_IND,,= ,,X Parameter: POSCHEDULEX PO_ITEM,,= ,,00001 SCHED_LINE,,= ,,0001 PO_ITEMX,,= ,,X SCHED_LINEX,,= ,,X QUANTITY,,= ,,X PO_ITEM,,= ,,00001 SCHED_LINE,,= ,,0003 PO_ITEMX,,= ,,X SCHED_LINEX,,= ,,X DELETE_IND,,=,,X Parameter: POACCOUNT PO_ITEM,,=,,00001 SERIAL_NO,,=,,01 GL_ACCOUNT,,=,,0000400020 Parameter: POACCOUNTX PO_ITEM,,=,,00001 SERIAL_NO,,=,,01 PO_ITEMX,,=,,X SERIAL_NOX,,=,,X GL_ACCOUNT,,=,,X Parameter: POCOND ITM_NUMBER,,=,,000001 COND_TYPE,,=,,RA02 COND_VALUE,,=,,2.110000000 CURRENCY,,=,,% CHANGE_ID,,=,,U Parameter: POCONDX ITM_NUMBER,,=,,000001 COND_ST_NO,,=,,001 ITM_NUMBERX,,=,,X COND_ST_NOX,,=,,X COND_TYPE,,=,,X COND_VALUE,,=,,X CURRENCY,,=,,X CHANGE_ID,,=,,X Parameter: POPARTNER PARTNERDESC,,= ,,GS LANGU,,= ,,EN BUSPARTNO,,=,,0000001000 STYLE *

Help in the Case of Problems

RESET N1 STYLE S_DOCUS1

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. STYLE *

Customer Enhancements

STYLE S_DOCUS1 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. STYLE *

Further information

RESET N1 STYLE S_DOCUS1

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. STYLE *

Pattern

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

PURCHASEORDER =

" POHEADER =

" POHEADERX =

" POADDRVENDOR =

" TESTRUN =

" MEMORY_UNCOMPLETE =

" MEMORY_COMPLETE =

" POEXPIMPHEADER =

" POEXPIMPHEADERX =

" VERSIONS =

" NO_MESSAGING =

" NO_MESSAGE_REQ =

" NO_AUTHORITY =

" NO_PRICE_FROM_PO =

" IMPORTING

" EXPHEADER =

" EXPPOEXPIMPHEADER =

" TABLES

" 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 =

" POHISTORY =

" POHISTORY_TOTALS =

" POCONFIRMATION =

.

if help full to you Please rewad me.

Read only

Former Member
0 Likes
2,295

Hi,

BAPI_PO_CHANGE - Change purchase order

Functionality

You can use this method to change Enjoy purchase orders.

Код:

PARAMETERS: p_ebeln LIKE ekko-ebeln OBLIGATORY.

PARAMETERS: p_ebelp LIKE ekpo-ebelp OBLIGATORY.

DATA: t_item LIKE bapimepoitem OCCURS 0 WITH HEADER LINE.

DATA: t_itemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE.

DATA: t_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

t_item-po_item = p_ebelp.

t_item-no_more_gr = 'X'.

t_item-final_inv = 'X'.

APPEND t_item.

t_itemx-po_item = p_ebelp.

t_itemx-po_itemx = 'X'.

t_itemx-no_more_gr = 'X'.

t_itemx-final_inv = 'X'.

APPEND t_itemx.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = p_ebeln

TABLES

return = t_return

poitem = t_item

poitemx = t_itemx.

LOOP AT t_return WHERE type = 'A' OR type = 'E'.

EXIT.

ENDLOOP.

IF sy-subrc = 0.

WRITE: / 'FAILED'.

ELSE.

WRITE: / 'SUCCESS'.

COMMIT WORK.

ENDIF.

Код:

DATA i_list LIKE i_listado OCCURS 0 WITH HEADER LINE.

DATA : t_bapi_poheader LIKE bapimepoheader OCCURS 0 WITH HEADER LINE,

t_bapi_poheaderx LIKE bapimepoheaderx OCCURS 0

WITH HEADER LINE,

t_bapi_poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,

t_bapi_poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,

t_bapireturn LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

LOOP AT i_listado INTO i_list WHERE check = 'X'.

APPEND i_list.

ENDLOOP.

SORT i_list.

LOOP AT i_list INTO i_listado.

AT NEW ebeln.

  • REFRESH t_bapi_poheader.

  • CLEAR t_bapi_poheader.

  • t_bapi_poheader-po_number = i_listado-ebeln.

  • t_bapi_poheader-delete_ind = 'X'.

  • APPEND t_bapi_poheader.

  • REFRESH t_bapi_poheaderx.

  • CLEAR t_bapi_poheaderx.

  • t_bapi_poheaderx-delete_ind = 'X'.

  • APPEND t_bapi_poheaderx.

REFRESH: t_bapi_poitem,

t_bapi_poitemx.

ENDAT.

CLEAR t_bapi_poitem.

t_bapi_poitem-po_item = i_listado-ebelp.

t_bapi_poitem-delete_ind = 'X'.

APPEND t_bapi_poitem.

CLEAR t_bapi_poitemx.

t_bapi_poitemx-po_item = i_listado-ebelp.

t_bapi_poitemx-delete_ind = 'X'.

APPEND t_bapi_poitemx.

AT END OF ebeln.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = i_listado-ebeln

  • poheader = t_bapi_poheader

  • poheaderx = t_bapi_poheaderx

TABLES

return = t_bapireturn

poitem = t_bapi_poitem

poitemx = t_bapi_poitemx.

READ TABLE t_bapireturn WITH KEY type = 'E'.

IF sy-subrc NE 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

READ TABLE t_bapireturn WITH KEY type = 'S'.

LOOP AT i_listado WHERE check = 'X'

AND ebeln = i_list-ebeln.

i_listado-message = t_bapireturn-message.

MODIFY i_listado.

ENDLOOP.

ELSE.

LOOP AT i_listado WHERE check = 'X'

AND ebeln = i_list-ebeln.

i_listado-message = t_bapireturn-message.

MODIFY i_listado.

ENDLOOP.

ENDIF.

ENDAT.

ENDLOOP.

*******************************************

if help full rewad me.

Read only

Former Member
0 Likes
2,295

HI,

Try to create purchase order manually using me21n and see what it does. create item numbers 130, 170, 171 like this. if this allow you to save PO then there is a problem in your bapi otherwise there is a config issue for this.

check out the bapi documentation.

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 bar

For most tables, you can determine via your own parameters in the associated X bar 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 managementfacility.

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. If a PO has been successfully created, the PO number is also placed in the return table with the appropriate message.

Please also refer to current information in Note 197958 in this connection.

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

DELIVERY_DATE = 02.12.2002

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

1. Note 197958 lists answers to frequently asked questions (FAQs). (Note 499626 contains answers to FAQs relating to External Services Management.)

2. If you have detected an error in the function of a BAPI, kindly create a reproducible example in the test data directory in the Function Builder (transaction code SE37). Note 375886 tells you how to do this.

3. If the problem persists, please create a Customer Problem Message for the componente MM-PUR-PO-BAPI, and document the reproducible example where necessary.

Customer Enhancements

The following user 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 user exits (function modules) are available for the BAPI 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 customer-specific fields for header, item, or account assignment data via the parameter EXTENSIONIN.

Further information

1. Note 197958 contains up-to-date information on the purchase order BAPIs.

2. 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, please take a look at Note 420646.

3. 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 only the document number is populated and the initiator has change authorizations for purchase orders.

4. 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.

5. 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 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

Exceptions

Function Group

2012