A simple example of a call to BAPI_PO_CHANGE. A simple change to a standard SAP field as workable setup. In only a few steps backed by a source code example your BAPI call is explained.

4 steps to setting up your BAPI call

  1. data definitions of the function module call, which should match the called BAPI definitions of course. In this example the parameters PURCHASEORDER and table parameters POITEM and POITEMX along with RETURN are all that is required. The purchase order number is the key to the document that ie being changed, the tables POITEM and POITEMX represent the item fields for the Purchase Order and a structure of flag-fields for each item field.
  2. Preparing data, by filling in the internal tables with your new values (values to change to). Make sure the field values maintained on POITEM have the corresponding POITEMX field set to "X" (otherwise the change will simply be ignored).
  3. Execute the call (execute a call function)
  4. Handle the (potential) errors, which are handed back to the calling program via RETURN, which is an internal table with messages thrown, informational as well as errors. Look for an entry with type "E" to find out whether your change was done succesfully.

Example: Simple call to BAPI_PO_CHANGE

Data definition of a simple (very minimalistic) BAPI call, followed by setting up data for a change to PO 780000231 item 00010. The change is setting the deletion indicator on the PO item.

data:  l_ponumber like bapimepoheader-po_number,
       i_po_items type table of bapimepoitem with header line,
       i_po_itemsx type table of bapimepoitemx with header line,
       i_return type table of bapiret2 with header line.

clear: i_po_items, i_po_items[], 
       i_po_itemsx, i_po_itemsx[],
       i_return, i_return[]. 

  l_ponumber = '780000231'.
  i_po_items-po_item = '00010'. 
  i_po_items-delete_ind = 'L'.      "Actual value (deletion flag)
  i_po_itemsx-po_item = i_po_items-po_item. 
  i_po_itemsx-po_itemx = 'X'.       "Item holds changes         
  i_po_itemsx-delete_ind = 'X'.     "Deletion field is changed
  append: i_po_items, i_po_itemsx.          

Actual BAPI call:

* Call BAPI to change PO, the change is setting the deletion indicator.
call function 'BAPI_PO_CHANGE'
  EXPORTING
    purchaseorder = l_ponumber
    testrun       = space
  TABLES
    poitem        = i_po_items
    poitemx       = i_po_itemsx
    return        = i_return.  

  Read table i_return with key type eq 'E'. 
  if sy-subrc eq 0. 
* An error was found, no update was done
  else.
    call function 'BAPI_TRANSACTION_COMMIT'.
  endif. 

That's all there is to it...

Do note, a COMMIT WORK (or a call to function module BAPI_TRANSACTION_COMMIT) is needed to execute your change.