Tuesday, July 12, 2011

Extending Standard BAPI’s to include extra fields which is not handled by BAPI

Extending Standard BAPI’s to include fields which is not available
Standard BAPI’s will contain only few fields that are most often used. Sometimes we need to include few fields which are not available in BAPI. For that SAP has given the provision to extend the standard fields available in the BAPI. One approach to do that is by having Business Transaction Events (BTE’s).
Example:  Posting FI Documents in FB01 transaction.
Extending BAPI BAPI_ACC_DOCUMENT_POST to include posting key.
Step by step procedure is given below:
1.To create Business Transaction Event, please follow the guideline below.
Step 1: Go to TCode "FIBF".
Step 2: Go to Settings -> Products -> ... of a customer
Step 3: Create a new entry and check the box to activate the product
Step 4: Create a new function module based on the sample(SAMPLE_INTERFACE_RWBAPI01) given by SAP.
Step 5: Go to Settings -> Process Modules -> ... of a customer
Step 6: Create a new entry by specifying the name of the function module name and product name created earlier.
2. Once the Function Module (FM) is created, You will have to code inside that FM.

               Inside that FM, code like this:
                  IF NOT extension IS INITIAL.
                         LOOP AT extension.
                                READ TABLE it_accit WITH KEY posnr = extension(3).
                                  IF sy-subrc IS INITIAL.
                                     it_accit-bschl = extension+3(2).
                                     MODIFY it_accit INDEX sy-tabix.
                                 ENDIF.
                         ENDLOOP.
                  ENDIF.
In all the BAPI’s, there will be one extension internal table which contains all the fields related to that transaction. All we have to do to extend the BAPI is to fill this internal table whichever value we need. In our above example, we have included posting key.
The reason to create a BTE is, we need to fill this extension internal table before the BAPI is called actually. The configuration of BTE is such that this will trigger the function module and the code inside will execute and fill the extension tables.
In the BAPI, we have fill the extension internal table like this,
FORM fill_pst_key .
    *first 3 character represent item number
    *next 2 character represent posting key
 CLEAR: gt_extension.
 gt_extension(3)    = sy-index(3).
 gt_extension+3(2) = 'New Posting Key'.
 APPEND gt_extension.
ENDFORM.



No comments:

Post a Comment