What is a BAPI Wrapper?   |  Testing BAPI Wrappers  |  What is a SyncBO?

 

BAPI Wrapper Types

In this section, we'll look at general rules for BAPI Wrappers and then examine the specifics of each BAPI Wrapper type (that is: GetList, GetDetail, Create, Change & Delete) separately.

General Rules of BAPI Wrapper

For an ABAP function module to be a BAPI wrapper, certain rules (interface and behavior) need to be followed by each function module. Basically, any BAPI wrapper needs to cover the BAPI development rules (please see service.sap.com/bapi for detailed information on BAPI development rules); however, there are some BAPI wrapper specific development rules, that all types of BAPI wrappers must comply with:

Rules for BAPI Wrappers

  • Processing type of a function module must be remote-enabled module.
  • Parameter named “RETURN” where the type is BAPIRET2 structure needs to be defined as either Export or Tables parameter
  • Parameters can only refer to either a structure or a field of a structure (<structure>-<field>)
  • Changing parameter can NOT be used
  • Exceptions can NOT be used
  • Parameters can NOT refer to structures that include other structures within: the reference structure needs to be a flat structure, and fields in the structure can NOT refer to types
  • Consistency within the business object must be ensured by defining Export/Import/Tables parameters of 5 types of BAPI wrappers appropriately
  • “Commit Work and Wait” needs to be executed in the update BAPI wrappers (Create/Change/Delete)

 

Please also observe the following:

The following diagram describes the interface requirements for each type of BAPI wrappers. The details are covered in the sections below.


BAPI wrappers required for a business object depend on the synchronization type of the SyncBO. For more information, refer to Synchronization Types of SyncBO.

GetList function

This function is used to populate a list of business object header data from the backend system, based on the selection criteria specified in the import parameters.

The function module must have the following parameters defined:

  • Make sure Import parameters refer to a field of a structure (<structure>-<field>).
  • The Export parameter of GetDetail function and the Import parameter of Create/Change need to refer to the same structure as that of the Tables parameter of GetList function, with an exception of Create BAPI wrapper used for a SyncBO where the synchronization type is upload. Similarly, the reference type of the object key Import/Export parameters of GetDetail/Create/Delete must be the corresponding object key field name of the structure in the Tables parameter of GetList function (for example, <header_structure_name>-<key_field_name>).

 

The SyncBO will call the function based on the following SyncBO mapping:


When a SyncBO has a GetList function mapped, the HEADER structure of the SyncBO will be the structure of the Tables parameter of the GetList BAPI wrapper function. Then, the client view of the HEADER of the SyncBO will be the subset of the HEADER structure of the SyncBO.

Example

GetDetail function

This function is used to extract one business object header data and list(s) of associated item data from the backend system.

If a SyncBO has Create/Change/Delete BAPI wrappers, the GetDetail function for the SyncBO needs to be specified, even if no item data is required (for example, with no Tables parameter).

 

The function module must have the following parameters defined:

  • It is important that each item data is uniquely identifiable within the item table. Some BAPIs do not specify key(s) to uniquely identify item data. In such a case, the key field(s) needs to be added to the structure of the corresponding Tables parameter, and the corresponding logic needs to be added in the BAPI wrapper (for example, assigning values to key fields).
    If the type of a key field is NUMC and the field does not allow external numbering, a special handling is required.
  • The Export parameter needs to refer to the same structure as that of the Table parameter of GetList function. Similarly, the reference type of the object key Import parameters must be the corresponding object key field name of the structure in the Tables parameter of GetList function (for example, <header_structure_name>-<key_field_name>).

 

If a GetDetail function is intended for a SyncBO where the synchronization type is download, the Export parameter to return the header data is not mandatory. However, it is recommended to always define the Export parameter to return the header data, in case that it is reused for 2-way or timed 2-way SyncBO (For more information on the synchronization type, refer to Synchronization Type).

 

The SyncBO will call the function based on the following SyncBO mapping:

Example

Look at the sample GetDetail function module MEREP_CONTACT_GETDETAIL in any SAP system with mySAP Technology 6.20 or higher.

This function module contains one Import parameter to uniquely specify the HEADER. Note that the parameter refers to PERSNUMBER structure field in PERSON Tables parameter in MEREP_CONTACT_GETLIST.

It has 2 Export parameters: one of which is “RETURN” parameter and the other is the header structure to hold the header data. Note that the structure is the same as that of the Tables parameter in “MEREP_CONTACT_GETLIST”.

It has 2 Tables parameters, which are ADDRESS and E_MAIL. They are the item tables for the business object. Note that each item can be uniquely identified in each item table by the 3 fields defined as keys.

Create function

This function is used to create single business object (header data and multiple item data associated with the header data) in the backend system.

The function module must have the following parameters defined:

The structures in Import and Tables parameters (header and item(s)) need to refer to the corresponding structures defined in GetList and GetDetail functions. Similarly, the reference type of the object key Export parameters must be the corresponding object key field name of the structure in the Tables parameter of GetList function (for example, <header_structure_name>-<key_field_name>). However, this is not applicable if the synchronization type is upload. (For more information about the synchronization type, refer to Synchronization Type).

The function module needs to perform “commit and wait” (For more information, refer to General Rules of BAPI Wrapper).

Although BAPI development guideline states that a Create BAPI must return the created object, this is not necessary in the case of Create BAPI wrapper. In the runtime, Smart Synchronization calls GetDetail BAPI wrapper to obtain the created object using the object key(s) returned in the Export parameter of Create BAPI wrapper function.

The SyncBO will call the function based on the following SyncBO mapping:

If the synchronization type of the SyncBO is upload, mapping for Create BAPI wrapper determines the HEADER and ITEM structures.

Example

Look at the sample Create function module MEREP_CONTACT_CREATE in any SAP system with mySAP Technology 6.20 or higher.

This function module contains one Import parameter to hold the header data. Note that the structure refers to the structure of PERSON Tables parameter in MEREP_CONTACT_GETLIST.

It has 2 Export parameters: one of which is “RETURN” parameter and the other is the parameter to hold the newly assigned key by the backend system. Note that the parameter refers to PERSNUMBER field in the structure of PERSON Tables parameter in “MEREP_CONTACT_GETLIST”.

It has 2 Tables parameters, which are ADDRESS and E_MAIL. They are the item tables for the business object and refer to the corresponding structures of Tables parameters in MEREP_CONTACT_GETDETAIL.

Change function

This function is used to modify single business object (header data and multiple associated item data) in the backend system.

This BAPI wrapper needs to handle all the update operations (Add/Change/Create) of item data. Smart Synchronization calls the function with the entire set of item data (entries of the Tables parameter), and the function may need to determine which item is newly added, which is modified and which is deleted.

Depending on the BAPI called inside the function, the logic required in the function will be different. Some BAPIs, for example, update the item data automatically (determines which is added, changed and/or deleted within BAPI) if the entire set of item data is passed. Some other BAPIs, on the other hand, request to specify which entry is added, changed and/or deleted. In such a case, the BAPI wrapper function needs to identify them, for example, by calling GetDetail function and comparing them.

The function module must have the following parameters defined:

The structures in Import and Tables parameters (header and item) need to refer to the corresponding structures defined in GetList and GetDetail functions. Similarly, the reference type of the object key Import parameters must be the corresponding object key field name of the structure in the Tables parameter of GetList function (i.e. <header_structure_name>-<key_field_name>).

The function module needs to perform “commit and wait” (For more information, refer to General Rules of BAPI Wrapper).

The SyncBO will call the function based on the following SyncBO mapping:

Example

Look at the sample Change function module MEREP_CONTACT_MODIFY in any Basis 6.20 system.

This function module contains one Import parameter to hold the header data. Note that the structure refers to the structure of PERSON Tables parameter in MEREP_CONTACT_GETLIST. “RETURN” parameter is defined as Export parameter.

It has 2 Tables parameters, which are ADDRESS and E_MAIL. They are the item tables for the business object and refer to the corresponding structures of Tables parameters in MEREP_CONTACT_GETDETAIL.

Delete function

This function is used to delete one existing business object (header data and all associated item data) in the backend system.

The function module must have the following parameters defined:


The Import parameter needs to refer to the corresponding key field in the structure of the Tables parameter of GetList function. Similarly, the reference type of the object key Import parameters must be the corresponding object key field name of the structure in the Tables parameter of GetList function (for example, <header_structure_name>-<key_field_name>).

The function module needs to perform “commit and wait” (For more information, refer to General Rules of BAPI Wrapper).

The SyncBO will call the function based on the following SyncBO mapping:

Example

Look at the sample Delete function module MEREP_CONTACT_DELETE in any Basis 6.20 system.

This function module contains one import parameter to uniquely specify the header data. Note that the parameter refers to PERSNUMBER field in the structure of PERSON Tables parameter in MEREP_CONTACT_GETLIST. “RETURN” parameter is defined as Export parameter.