BAPI- BO & API Method

Step1. Lets have the table with the following fields.

Step2. Maintain some table Entries.

Step3. Go to Tx- SWO1 and create a business object type ZEMP_2000.

Step4. provide the below details.

Step5. Create the key field of the Business Object.  Select the Key Field option and click on the Create button.

Step6. We need to create with reference to our data base table. So click on Yes button.

Step7. Provide the table name and hit the Enter key from key board. The primary fields of the table automatically appears on the list. Select it and click on the continue button.

Step8. Provide the key field name and text and at last click on Create button.

Step9. The key field is created.

Step10. Now lets create a method which should accept an employee Id as an input and returns the employee details. select the Methods and then click on the Create button.

Step11. This time we are not going to create with reference to the FM. So Click on No button.

Step12. Provide the Method, name & description . Click on ABAP tab.

Step13. Details of the method under ABAP tab. Click on Continue button.

Step14. The below method is generated without referring to any FM. To define the Method parameters, click on the Parameters Button.

Step15. Click on the Create button.

Step16. Click on yes.

Step17. Select the EMP_ID field and click on Continue button.

Step18.  Provide the parameter, name & description. Select the Import parameter & mandatory option and at last click on Continue button.

Step19. We have to define the exporting parameter as we need the details of the employee in a structure based on the input. So again click on the Create button.

Step20. As this time we are not going to refer any field of the table but to a structure itself. So click on No button.

Step21. Provide the parameter, name & description. Select this a Export parameter. Under the ABAP Dictionary , provide reference table as ZEM_HIS. At last click on the Continue button.

Step22. Now we have defined our import & export parameter as per the requirement. Go back.

Step23. as our method is an empty method Bcoz it didn’t refer to any FM so we have to code it for the Method in the program. So Select the Method and click on the Program button.

Step24. Click on Yes button.

Step25. The below code appears automatically for the method.

Step26. Put a simple select query in the program. Save it and go back.

Step27. Implement the Business Object along the path Under Edit Menu.

Step28. The BO is implemented.

Step29. Release the BO under the path .

Step30. The BO is released.

Step31. Implement the Method along the path.

Step32. Method is implemented.

Step33. Release the Method under the path.

Step34. Method is released.

Step35. generate the BO by clicking on the highlighted ICON.

Step36. The below message appears.

Step37. Select the method and click on the program button.

Step38. Put a debug point. Go back.

Step39. Select the method and click on the Test button.

Step40. Provide Emp_ID. This Emp_ID value is not the value that is passed to the method as an importing parameter. This is value is for the Key field of the BO.

Step41. Click on the Execute button against the method ‘GET_EMPLOYEE_INFO’.

Step42. Here provide the Emp_ID_INPUT value to the method.

Step43. Provide ‘0003’as the Emp_id_input value and click on the F8 button.

Step44. We already set the debug point in the program. Lets analyze some parameters here.

Step45. After the select query is executed and one more line below it. The details of the Export parameter is filled with the details of the employee details.

Step46. Lets have a look at the Container table. It stores all the import & export data in a structured format.

Step47. Press F8 to come out of the debug & we can see the details of the Employee in the export parameter.

Step48. Lets Create a program where we can instantiate a Business Object and set the importing parameter to the method, call the specific method of interest and get back the desired result.

REPORT  zbapi_bo_call.

DATA : objtype     TYPE swotobjid-objtype,

              objkey      TYPE swotobjid-objkey,

              object       TYPE swotrtime-object,

              lt_cont      TYPE TABLE OF swcont,

              ls_cont     TYPE swcont,

             return        TYPE  swotreturn,

              verb         TYPE swotinvoke-verb,

              ls_emp     TYPE zemp_his.

PARAMETERS : p_empid TYPE zemp_his-emp_id OBLIGATORY.

objtype = ‘ZEMP_2000’. ” Business Object Type Name

verb = ‘Get_Employee_Info’. “Method Name to be Invoked



    objtype = objtype


    object  = object ” run time object of the business object

    return  = return.

CALL FUNCTION ‘SWC_ELEMENT_SET’ ” Set the importing parameter before the Method Call


    element   = ‘EMP_ID_INPUT’

    field     =    p_empid


    container = lt_cont.

CALL FUNCTION ‘SWO_INVOKE’ ” this Fm calls the Method of the Business Object


    access    = ‘C’  ” C- to call method

    object    = object ” instance of the Business Object

    verb      = verb ” method name


    container = lt_cont.

IF sy-subrc = 0.

  LOOP AT lt_cont INTO ls_cont WHERE element = ‘EMP_DET_OUTPUT’.

    CASE ls_cont-tab_index.

      WHEN ‘000002’.

        ls_emp-emp_id = ls_cont-value.

      WHEN ‘000003’.

        ls_emp-name = ls_cont-value.

      WHEN ‘000004’.

        ls_emp-design = ls_cont-value.

      WHEN ‘000005’.

        ls_emp-doj = ls_cont-value.

      WHEN ‘000006’.

        ls_emp-dop  = ls_cont-value.

      WHEN ‘000007’.

        ls_emp-dor = ls_cont-value.

      WHEN ‘000008’.

        ls_emp-dept = ls_cont-value.

      WHEN ‘000009’.

        ls_emp-salary = ls_cont-value.





  WRITE :/ ‘Employee ID’, ls_emp-emp_id,

           ‘Name:’, ls_emp-name,

           ‘Design:’, ls_emp-design,

           ‘Date Of Join:’, ls_emp-doj,

           ‘Date Of Promotion:’, ls_emp-dop,

           ‘Date Of Resig:’, ls_emp-dor,

           ‘Department:’, ls_emp-dept,

           ‘Salary:’, ls_emp-salary.



Step49. Run/Execute the report. Provide the Employee ID as input.

Step50. We receive the below output of the Employee Details.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s