Programming Delete()/Undelete() BAPIs
The BAPI Delete() deletes an instance of an SAP business object type from the database. Likewise, the BAPI DeleteMultiple() deletes several instances of a business object type. Delete() BAPIs must always delete entire instances, for example, a whole material master.
In contrast, the BAPI Cancel() cancels an instance of a business object, that is the instance to be canceled remains in the database and an additional instance is created that is canceled. For more information, see Programming Cancel() BAPIs.
A Delete() BAPI can delete immediately or at a later time by setting the deletion flag. The type of deletion you use in your BAPI is irrelevant to the caller, so you do not have to include these details in the BAPI interface.
The BAPI Undelete() is used to reset a deletion flag that has been set for a specific object.
The BAPIs Delete() and Undelete() are instance methods, whereas the BAPIs DeleteMutliple() and UndeleteMutliple() are class methods (instance-independent).
The interfaces of the Delete() and Undelete() BAPIs should be identical.
You should keep the following points in mind when defining the import parameters:
- If a single instance is to be deleted, you have to create an import parameter in the function module for each key field of the associated business object type. The names of the parameters must be identical to the names of the object keys in the BOR and must have the same data elements.
If several instances are to be deleted, you must create a table for the key fields of the business object type. You can do this using a range table.
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.
- The BAPI must also have a TestRun parameter that enables it to execute test runs. If this parameter contains the value "X", the BAPI executes normally, but does not write the results to the update task. In this way, after the BAPI BapiService.TransactionCommit executes, all results, such as the application log, for example, can be evaluated, but the BAPI has not modified the database.
For more information, see
Test Run Parameters.
Customer Enhancements to BAPIs.
- If customers are to be enabled to enhance the import parameters of the BAPI without modifications being necessary, you must create the parameter ExtensionIn. For information about extension parameters and recommendations on how the customer enhancement concept should be implemented in a Delete() BAPI, see
- When the BAPI DeleteMultiple() is used, it must be possible to use the selection criteria to select the object instances to be deleted. To do this you can create selection parameters.
- When the BAPI DeleteMultiple() is used, it should be possible to use the selection criteria to select the object instances to be deleted. To do this you can create selection parameters.
For more information about these parameters, see
Implement the interface of a Delete() BAPI so that it is not possible to delete all the instances simply by parameterizing the interface, for example by specifying default settings.
You should keep the following points in mind when defining the export parameters:
Customer Enhancements to BAPIs.
- If customers are to be allowed to extend the export parameters of the BAPI without modifications being necessary, you must create the parameter ExtensionOut. For information about extension parameters and recommendations on how the customer enhancement concept should be implemented in a Delete() BAPI, see
- To report messages from the method call back to the calling program, you should create only the export parameter Return. To ensure the results of a Delete() BAPI, called either synchronously or asynchronously, are monitored extensively, the following conventions for filling the Return parameter must be observed:
- If the Delete() BAPI executes successfully, in other words, the desired instance is deleted, the following standardized T100 message must be passed in the Return parameter:
You should keep the following points in mind:
- The field MESSAGE_V1 contains the external name of the business object type, such as SalesOrder.
- The key under which the object to be deleted can be accessed at subsequent calls is returned in the field MESSAGE_V2. This is the external key when external number assignment is used, or the internal key when internal number assignment is used. If the object has several key fields, the values of these key fields must be concatenated in MESSAGE_V2. The sequence in which the key fields are defined in the BOR must be adhered to for the concatenation. Moreover, the maximum length must be used for each key field. This may require the use of padding.
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.
When an Undelete() BAPI executes successfully, the following standardized T100 message is used:
- If an error occurs during the execution of the Delete() BAPI, in addition to the application-specific error messages the following standardized T100 message must be passed in the Return parameter:
The meaning of the various fields is the same as for successful execution.
If an error occurs during the execution of an Undelete() BAPI, the following standardized T100 message is used:
- In addition to the standardized message, further messages can be written in the Return parameter. It is of particular importance when errors occur that messages describing the errors in detail are returned. You should, therefore, use all of the fields of the structure BAPIRET2. You should, in particular, fill the fields Parameter, Row and Field.
For more information about this parameter, see
Return Parameters (Error Handling).
Example of a Delete() BAPI