Design of BAPIs

Team-Fly

The development of a BAPI begins in the design stage, in which you determine the function that needs to be done and which business objects it will affect. BAPIs can be broadly defined into two categories, Instance methods and Class methods. An Instance method deals with a single instance of an object, whereas a Class method deals with many or all of the objects that have been instantiated from a class. An example of an Instance BAPI is GetDetail, which returns specific information about a sales or purchase order. An example of a Class BAPI is GetList, which lists many sales or purchase orders.

The first part of the design step is to determine how the BAPI will interface with the object in the BOR. This step primarily means the identification of parameters that will be imported and exported, but also means a review of existing BAPIs for that object. You want to make sure that the new BAPI will not affect or repeat functionality that exists in the current BAPIs. The relationship between parameters in the BOR, Function Builder, and Data Dictionary are shown in Figure 18.1.

When determining the import and export parameters, make sure to determine whether the parameters will be mandatory or not. Also, if your BAPI is going to be creating things, return the keys of the newly created objects in separate parameters (not in the RETURN parameter).

Specific naming conventions are used in the development of BAPIs. The name of the function module should be BAPI_<OBJECT_NAME>_<METHOD>. In addition, you should use the prefix BAPI for any objects you create in the Data Dictionary.

When creating a normal function module you do not have to define the input parameter's data structure. If you leave the reference field blank, the parameter takes on

Parameter and Table Handling

When you are setting up the call to a BAPI (or any RFC), you must remember that parameters are not passed the same way as they are if you were making a normal function call. Most function modules set up their parameters to be passed by reference. This method is more efficient than passing the values themselves, because only the pointer to the variable needs to be moved around when the function module is called. With RFCs, parameters cannot be passed by reference because two different environments are involved. Therefore, the value of the parameter must be passed.

Tables are also dealt with differently when using an RFC versus when a function module is called on the same SAP system. With an RFC call, we are dealing with two different environments; the results in the entire contents of the table are passed during the initial call to the RFC. This action creates a local copy of the table on the server. The original table on the client is not updated until the RFC call is finished.

With this information in mind, make sure to select parameters and tables carefully. You want to pass as little data as possible between SAP and the calling system.

click to expand

Figure 18.1: The relationship of parameters between BOR, Function Builder, and Data Dictionary

the characteristics of the variable that the calling program passes. However, this information is not available to your BAPI if it is called remotely, because all that is coming to it is the value of the parameter. Therefore, you must define the characteristics for every parameter for a function module that is used as a BAPI.

Note 

A parameter's length does not have to exactly match that of the calling variable. If you declare a parameter as 100 characters long and the calling program passes in a 30-character variable, the remaining 70 characters are padded with spaces. You must make sure, however, that your parameters are at least as long as the variables that will be passed to them.

An example of a BAPI function module follows.

Function Module BAPI_PO_GETDETAIL *"----------------------------------- *" *"local interface: *"--------IMPORTING *"             VALUE(PURCHASEORDER) LIKE  BAPIEKKO-PO_NUMBER *"             VALUE(ITEMS) LIKE  BAPIMMPARA-SELECTION DEFAULT ‘X' *"             VALUE(ACCOUNT_ASSIGNMENT) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"             VALUE(SCHEDULES) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"             VALUE(HISTORY) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"             VALUE(ITEM_TEXTS) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"             VALUE(HEADER_TEXTS) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"             VALUE(SERVICES) LIKE  BAPIMMPARA-SELECTION *"                             DEFAULT SPACE *"       EXPORTING *"             VALUE(PO_HEADER) LIKE  BAPIEKKOL STRUCTURE  BAPIEKKOL *"             VALUE(PO_ADDRESS) LIKE  BAPIADDRESS *"                             STRUCTURE  BAPIADDRESS *"       TABLES *"              PO_HEADER_TEXTS STRUCTURE  BAPIEKKOTX OPTIONAL *"              PO_ITEMS STRUCTURE  BAPIEKPO OPTIONAL *"              PO_ITEM_ACCOUNT_ASSIGNMENT STRUCTURE  BAPIEKKN *"                             OPTIONAL *"              PO_ITEM_SCHEDULES STRUCTURE  BAPIEKET OPTIONAL *"              PO_ITEM_TEXTS STRUCTURE  BAPIEKPOTX OPTIONAL *"              PO_ITEM_HISTORY STRUCTURE  BAPIEKBE OPTIONAL *"              PO_ITEM_HISTORY_TOTALS STRUCTURE  BAPIEKBES OPTIONAL *"              PO_ITEM_LIMITS STRUCTURE  BAPIESUH OPTIONAL *"              PO_ITEM_CONTRACT_LIMITS STRUCTURE  BAPIESUC OPTIONAL *"              PO_ITEM_SERVICES STRUCTURE  BAPIESLL OPTIONAL *"              PO_ITEM_SRV_ACCASS_VALUES STRUCTURE  BAPIESKL *"                             OPTIONAL *"              RETURN STRUCTURE  BAPIRETURN OPTIONAL *"----------------------------------- * reset all structures and tables CLEAR: PO_HEADER, PO_ADDRESS, PO_ITEMS, PO_HEADER_TEXTS,         PO_ITEM_ACCOUNT_ASSIGNMENT, PO_ITEM_SCHEDULES,         PO_ITEM_TEXTS, RETURN, EKPOKEY, PO_ITEM_HISTORY,         PO_ITEM_HISTORY_TOTALS, PO_ITEM_LIMITS, PO_ITEM_SERVICES,         PO_ITEM_CONTRACT_LIMITS, PO_ITEM_SRV_ACCASS_VALUES,         CEKKO, CEKPO, CEKKN, CEKET, CEKAN, SEKKO, SEKPO, CADR.REFRESH:_        PO_HEADER_TEXTS, PO_ITEM_ACCOUNT_ASSIGNMENT, PO_ITEM_SCHEDULES,         PO_ITEM_TEXTS, PO_ITEMS, RETURN, EKPOKEY, PO_ITEM_HISTORY,         PO_ITEM_HISTORY_TOTALS, PO_ITEM_LIMITS, PO_ITEM_SERVICES,         PO_ITEM_CONTRACT_LIMITS, PO_ITEM_SRV_ACCASS_VALUES,         CEKKN, CEKET, SEKKO, SEKPO. * select the header data from database SELECT SINGLE * FROM EKKO WHERE EBELN EQ PURCHASEORDER. IF SY-SUBRC NE 0.     PERFORM FILL_BAPIRETURN TABLES RETURN                            USING  ‘E'                                   ‘W5'                                   ‘107'                                   PURCHASEORDER                                   SPACE                                   SPACE                                   SPACE.     EXIT. ENDIF. * authority check PERFORM PO_AUTHORITY_HEADER TABLES RETURN                         USING  EKKO. IF NO_AUTHORITY NE SPACE.    PERFORM FILL_BAPIRETURN TABLES RETURN                            USING  ‘E'                                   ‘W5'                                   ‘033'                                   SPACE                                   SPACE                                   SPACE                                   SPACE.     EXIT. ENDIF. ……. ……. SORT PO_ITEMS BY PO_NUMBER PO_ITEM. SORT PO_ITEM_ACCOUNT_ASSIGNMENT BY PO_ITEM SERIAL_NO. SORT PO_ITEM_SCHEDULES BY PO_ITEM SERIAL_NO. SORT PO_ITEM_HISTORY BY PO_ITEM SERIAL_NO.SORT PO_ITEM_HISTORY_TOTALS BY PO_ITEM SERIAL_NO. SORT PO_ITEM_LIMITS BY PCKG_NO SORT PO_ITEM_CONTRACT_LIMITS BY PCKG_NO LINE_NO. SORT PO_ITEM_SERVICES BY PCKG_NO LINE_NO. SORT PO_ITEM_SRV_ACCASS_VALUES BY PCKG_NO LINE_NO SERNO_LINE. ENDFUNCTION.

Setting the REMOTE Status and Configuration

To enable a function module to be called as a BAPI, two things must be done in addition to the actual ABAP coding. The first concerns the attributes section of the function module configuration, shown in Figure 18.2. In this screen, make sure to verify that the module can be called via a remote call.

Second, you need to make sure that the system that will be calling your function module is entered in the RFCDES table; the system administrator usually does this. The basics of the RFCDES table are discussed later in this chapter in the section titled 'The Purpose of RFCDES.'

click to expand

Figure 18.2: Attributes for a function module that can be used as an RFC


Team-Fly


Java & BAPI Technology for SAP
Java & BAPI Technology for SAP
ISBN: 761523057
EAN: N/A
Year: 1998
Pages: 199

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net