Monday, December 3, 2007

Defining BAPI Methods in the BOR

To represent the remote enabled function module as a BAPI, BAPI Wizard is used. The wizard generates some additional code to allow the BAPI to be called as a workflow method apart from being called by an outside program.
When creating a new object type in BOR (Business Object Repository), there can be two possibilities. Either it is created as a subtype of an existing business object or it is created as a new business object from scratch.

Create a business object using the T-Code SWO1


When create button is clicked, the following popup screen appears:

NOTE:
Enter any logical name in the Program that does not already exist. The program is generated by the wizard for the object type and not for the function module that we have already created.


Press enter and the new business object gets created. The business object gets created with the standard interface that contains an Interface IFSAP, an Attribute ObjectType, and two methods namely ExistenceCheck and Display. All these cannot be changed. It looks something like this:


Now we will add a method to the business object. For this, we will choose from the menu path, Utillities -> API methods -> Add method. The following window appears


Write the name of the function module in the dialog box and press enter.

The following dialog box will appear. This is the start screen of the BAPI wizard. Proceed with wizard by pressing the button.


The next screen that appears is given below:


Again press the button. A popup appears prompting to generate the template automatically. Click the Yes button in the screen as given below.


On completing the process in the wizard, you will find that the GetBillitems has been added to the business object:


To use the business object Object type status has to be set to Implemented.


The BAPI wizard adds a wrapper class for the function module which can be used as method in the business object. Click on the Program button or select Goto  Program from the menu. A code something like this can be seen.

***** Implementation of object type ZBILLITEMS *****
INCLUDE OBJECT.
BEGIN_DATA OBJECT. " Do not change.. DATA is generated
* only private members may be inserted into structure private
DATA:
" begin of private,
" to declare private attributes remove comments and
" insert private attributes here ...
" end of private,
KEY LIKE SWOTOBJID-OBJKEY.
END_DATA OBJECT. " Do not change.. DATA is generated

BEGIN_METHOD GETBILLITEMS CHANGING CONTAINER.
DATA:
IVBILLNO LIKE ZBAPI_BILL_ITEMS-VBELN,
RETURN LIKE BAPIRETURN,
ITVBRP LIKE ZBAPI_BILL_ITEMS OCCURS 0.

SWC_GET_ELEMENT CONTAINER 'IvBillno' IVBILLNO.
SWC_GET_TABLE CONTAINER 'ItVbrp' ITVBRP.

CALL FUNCTION 'ZBAPI_GET_BILL_ITEMS'
EXPORTING
IV_BILLNO = IVBILLNO
IMPORTING
RETURN = RETURN
TABLES
IT_VBRP = ITVBRP
EXCEPTIONS
OTHERS = 01.
CASE SY-SUBRC.
WHEN 0. " OK
WHEN OTHERS. " to be implemented
ENDCASE.

SWC_SET_ELEMENT CONTAINER 'Return' RETURN.
SWC_SET_TABLE CONTAINER 'ItVbrp' ITVBRP.
END_METHOD.



Generate & Release

After finishing the above steps, do the following:

Go to SE37 and release the API enabled Function module




In the Object created in the BOR, set the status of Object Type Component to Released


Set the status of Object Type to Implemented


You can now display the BAPI in the BAPI Explorer. Invoke the same using the T-code BAPI

No comments:

Blog Archive