Creating BAPI and Business Object

Developing BAPI and Business Object in SAP, working with BAPI development

+ -

We know BAPI is a remote enable function module but when ever we are creating a BAPI, we need to follow some rules.

Rules and standards (as per SAP) for creating a BAPI:

  • Every BAPI must start with BAPI or ZBAPI(Custom).
  • All importing and exporting parameters must be of type structures (not direct type entries).
  • All importing and exporting parameter names must start with BAPI or ZBAPI.
  • All importing and exporting parameters must pass by value, as pass by reference is not supported for remote communications.
  • BAPI must have return parameter (to return messages like success, warning, error etc.) of type BAPIRET2 or RETURN.

Follow the below steps to create a custom BAPI.

  • Create structures in SE11 for importing and exporting parameters.
  • Create a remote enabled function module with importing and exporting parameters (must be of type structure) in SE37.
  • Create a business object in SWO1.
  • Insert RFC function module into business object.

Requirement: Develop a custom BAPI to get material details.

Step 1: Create structures for required importing and exporting parameters in SE11.

Go to SE11, create a structure ZBAPI_MATNR as below for importing parameter.

Creating BAPI and Business Object in SAP

Similarly create another structure ZBAPI_MARA as below for exporting parameter.

Creating BAPI and Business Object in SAP

Step 2: Go to SE37, create a remote enabled Function module to get material details for material input.

Go to SE37, provide name as ZBAPI_GET_MATERIALS and create

Creating BAPI and Business Object in SAP

A popup will come provide function group and short text, enter.

Go to attributes tab, select ‘Remote-Enabled module’ radio button.

Creating BAPI and Business Object in SAP

Go to import tab, add parameter as below.

Creating BAPI and Business Object in SAP

Go to export tab, add parameters as below.

Creating BAPI and Business Object in SAP

Go to Source code and add below code.

Creating BAPI and Business Object in SAP

SELECT SINGLE MATNR
                MTART
                MEINS
                MATKL
                MEINS
           FROM MARA INTO MATERIAL_DETAILS WHERE MATNR = MATERIAL.
  IF SY-SUBRC NE 0. "add message to return parameter
    RETURN-TYPE = 'E'.
    RETURN-MESSAGE = 'Material not found'.
  ENDIF.

Save and activate the function module, test.

Step 3: Go SWO1, create a business object.

Go to T-code SWO1, provide name as ZBUSMAT01 and create.

Creating BAPI and Business Object in SAP

A popup will come, provide details as below.

Do not save it in a local object, we cannot make BAPI methods with non-transportable objects.

Creating BAPI and Business Object in SAP

Save it in a package and create a transport request.

Creating BAPI and Business Object in SAP

Step 4: Insert RFC function module into business object.

To insert RFC into business object, click on Utilities -> API Methods -> Add Method.

Creating BAPI and Business Object in SAP

A popup will come, provide RFC function module name and enter.

Creating BAPI and Business Object in SAP

A popup will come, click on next icon.

Creating BAPI and Business Object in SAP

Again click on next icon.

Creating BAPI and Business Object in SAP

A confirmation popup will come, click yes.

We have inserted a RFC function module into methods of business object, now we need to do two things.

  • Change 'change release status' to 'implemented'
  • Again 'change release status' to 'released'

Creating BAPI and Business Object in SAP

Creating BAPI and Business Object in SAP

A popup will come just press enter.

Once object is released, you will find released icon as below.

Creating BAPI and Business Object in SAP

BAPI is created, now it can be usable by SAP and NON-SAP systems.

Learner Questions


No Questions by learners, be first one to ask ..!!

    Please Sign in to ask a question

    Was this lesson helpful to you? Yes No 56 People out of 60 think this lesson helpful


    Lesson Navigation

    ←Previous Chapter
    Next Chapter →