STEP 3 - Create the API Method Using the BAPI WIZARD

The BAPI wizard is used toTo expose the remote function module as a BAPI. The wizard will generate some additional code, so the function module is a valid method of the BOR. This allows the BAPi to be called as a workflow method in addition to be called by an outside program.

Note: Each functionmodule corresponds to a method in the BOR

Go to the Busines Object Builder SWO1.

You can either create the new Object type as a subtype of an existing business object or create a new business object from scratch. In this example it would be obvious to create the Object type as a subtype of BUS2005 Production order. However, to illustrate how to create a new Object type from scratch, we will do this.

In the Object/Interface type field write the name of the new Business Object: ZORDERSTAT. Press enter and fill in the additional fields necessary to create the object type.

Supertype: Not relevant because we are creating our object from scratch

Program. This is the name of the program where the wizard generates code for the Object type, NOT the function module we craeted earlier. The program name must not be the name of an existinbg program.

 

 

Press enter and create the new business object. Note that when you create the business object a standard interface, an attribute ObjectType and the methods ExistenceCheck and Display are automatically generated. These cannot be changed !

 

The next step is to add the Z_BAPI_GET_ORDER_STATUS method to the business object. Select Utillities -> API methods -> Add method and write the name of the functionmodule in the dialogbox. Next the dialogbox show below will be shown. This is the start screen of the BAPI wizard. Proceed with wizard by pressing the button.

After you have finished the wizard, tyou will notice that the ZGetOrderStatus has been added to the business object:

You can doubleclick on the method to see its properties. To use the business object you must change the Object type status to Implemented. Use menu Edit->Change releases status->Object type->To implemented. No you can test thge object (Press F8).

Note that the BAPI wizard has added a wrapper class for the function module so it can be sued as method in the business object. Choose menu Goto->Program to display the program:

*****           Implementation of object type ZORDERSTAT           *****
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 ZGETORDERSTATUS CHANGING CONTAINER.
DATA:
      BAPIORDERSTATUSIMPORT LIKE ZBAPI_ORDER_STATUS_IMPORT,
      RETURN LIKE BAPIRETURN,
      TBAPISTAT LIKE ZBAPISTAT OCCURS 0.
  SWC_GET_ELEMENT CONTAINER 'BapiOrderStatusImport'
       BAPIORDERSTATUSIMPORT.
  SWC_GET_TABLE CONTAINER 'TBapistat' TBAPISTAT.
  CALL FUNCTION 'Z_BAPI_GET_ORDER_STATUS'
    EXPORTING
      BAPI_ORDER_STATUS_IMPORT = BAPIORDERSTATUSIMPORT
    IMPORTING
      RETURN = RETURN
    TABLES
      T_BAPISTAT = TBAPISTAT
    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 'TBapistat' TBAPISTAT.
END_METHOD.
Converted from CHM to HTML with chm2web Standard 2.7 (unicode)