Programming Change() BAPIs 

Use

The BAPI Change() changes an existing instance of an SAP business object type, for example, a sales order.

The BAPI Change() is an instance method, whereas the BAPI ChangeMultiple() is a class method (instance-independent).

Features

BAPI interface

Import Parameters

You should keep the following points in mind when defining the import parameters:

For the associated method definition in the BOR, the key fields must not also be specified as parameters. For this reason, the BOR/BAPI Wizard does not include the function module parameters for the key fields in the method definition, when it creates a BAPI.

By contrast, if the Change by comparison concept is implemented, you must create an additional equivalent parameter for every parameter with fields containing modified values. For more information, see Change Parameters.

Export Parameters

You should keep the following points in mind when defining the export parameters:

You should keep the following points in mind:

If the complete key exceeds the maximum capacity of MESSAGE_V2 (that is, 50 characters), it is divided up between the fields MESSAGE_V2 and MESSAGE_V3. The first 50 characters are stored in MESSAGE_V2 and the remaining characters in MESSAGE_V3.

The meaning of the various fields is the same as for successful execution.

BAPI Coding

Possible Strategies for Implementing a Change() BAPI

In BAPIs that cause database changes (for example, Change() and Create() BAPIs), you must be able to distinguish between parameter fields that are to be modified (change-relevant fields) and parameter fields that are to remain unmodified.

Using an initial value is no solution because an initial value could also represent a valid new value. Also, in the ABAP programming language as well as on other development platforms, the value "NULL" should not be assigned to a data type to indicate an empty field.

For this reason, the change-relevant fields must be identified using a "workaround". This can take two forms:

  1. Flagging Fields to Identify Fields Containing Modified Values

In this approach, parameter fields containing modified values are identified by including a flag in an additional "change parameter".

This way the BAPI can identify both modified and unmodified fields in the parameter.

Follow the conventions below when you create change parameters to identify modified fields:

   

X:
This value means that the corresponding parameter field contains a modified value.

   

(no value):
This means that the corresponding parameter field does not have to be updated.

For more information about this concept, see Change Parameters.

  1. Comparing Fields to Identify Fields Containing Modified Values

In this approach, fields containing modified values are identified by comparing two parameters, one containing the current valid data and the other the new, modified data.

When the Change() BAPI is called, the current data in the database and the new, modified data must be entered in the corresponding parameters. The current data set can be transferred, for instance, from a GetDetail() BAPI that has been called.

The following comparisons can be made:

Note the following when you are comparing fields containing modified data.

For example, if the parameter with the current valid data is called EquiSales, the parameter with the modified data is called EquiSalesNew.

Avoiding Incompatibilities with Customizing Settings

It could be possible that certain values set by Customizing appear differently in the BAPI interface. These values cannot be overwritten by a Change() BAPI.

To avoid incompatibility with Customizing settings, you should implement a Change() BAPI in the following way:

See also:

Example of a Change () BAPI