How To Enhance SAP BW Data Source
How To Enhance SAP BW Data Source
How To Enhance SAP BW Data Source
We need to enhance SAP standard or custom extractors when the required fields are not available in the standard datasource.Datasouces (Extractors) can be enhanced using two methods. 1. 2. User Exit BADI
In user exist method you right the logic for extracting new fields in an exit function module. This approach has some drawbacks like transport dependency, messier code etc. This is the old approach. SAP has recently (couple of years ago?) introduced BADIs to alleviate the drawbacks of user exits. Using BADIs will allow developers to write object oriented code for extractor logic. SAP recommends BADIs over user exits.
Irrespective of the approach you choose the first step is to add the new fields to extraction structure. First check if the fields you are looking for are hidden in the datasource before adding the new fields to the structure.
6. Enter the fields prefixed by ZZ in the first column and enter component type (For component type you can enter data element for that field which you can get from table definition in SE11)
7. Activate the append structure 8.Hit back utton twice and go to datasource definition. You will the new appended fields at the end. Unhide them.
First part of datasouce enhacement is complete. We have added the fields that we want to enhace to the the datasource. The next step is to write some code to populate these fields. As mentioned eariler there are two different ways to go about this. The first method is to use BADI which is recommended. Below steps show how to enhance an extractor using BADI. You can also use user exits for this see for the links to to the documents if you want to use user exits.
With this we have created BADI implementation. We are going to use this implementation to fill the new fields. 4. Go to transaction code SE19 and give the implementation that we just created and hit display.
5. Go to interface tab and double click on the implementing class name as shown below. This will take you to the methods secion of the implementation class.
7. The first method (DATA_TRANSFORM) method allows us put in the logic/code to fill in the our added fields. Double click on this method. 8. Click on 'Parameters' button to see the parameters passed to this method.
9. You should see following SAP standard paramters. Add these parameters if you don't see them in your system. Go back to methods tab by hitting 'Methods' button.
10. After coming back to methods tab double click on first method (DATA_TRANSFORM) . Copy and paste below ABAP code .
method IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM. DATA : L_METHOD TYPE SEOCMPNAME. CONCATENATE 'Z_' I_DATASOURCE INTO L_METHOD. CHECK C_T_DATA[] IS NOT INITIAL. SELECT SINGLE CMPNAME FROM SEOCOMPO INTO L_METHOD WHERE CLSNAME = 'ZCL_IM_RSU5_SAP_BADI' AND CMPNAME = L_METHOD.
CHECK SY-SUBRC EQ 0. CALL METHOD (L_METHOD) EXPORTING I_UPDMODE = I_UPDMODE I_T_SELECT = I_T_SELECT I_T_FIELDS = I_T_FIELDS CHANGING C_T_DATA = C_T_DATA C_T_MESSAGES = C_T_MESSAGES. endmethod. With this we are done with one time configuration. We need not do all the above steps for every datasource. To enhance a datasource all we need to do add a new cutom method to above class (ZCL_IM_RSU5_SAP_BADI) and write some ABAP codo to populate new fields.
3. Copy and paste following code. Note : You need to change the table and field names in this code as per your requirement. method Z_0FC_BP_ITEMS. * You need to change FKKOPBW_DELTA to the extraction structure of your datasource in below statement FIELD-SYMBOLS: <L_S_DATA> TYPE FKKOPBW_DELTA. * declare a structure with fields required the table on which you do the lookup. TYPES: BEGIN OF IT_DFKKKO, V_OPBEL TYPE OPBEL_KK, V_FIKEY TYPE FIKEY_KK, V_ERNAM TYPE ERNAM, V_CPUTM TYPE CPUTM, END OF IT_DFKKKO. * Declare an internal table and work area with above type
DATA: ZBW_DFKKKO TYPE STANDARD TABLE OF IT_DFKKKO, L_T_DATA TYPE STANDARD TABLE OF FKKOPBW_DELTA, " Replace FKKOPBW_DELTA with extraction structure of your datasource WA_DFKKKO TYPE IT_DFKKKO.
* Copy the incoming data into another internal table. C_T_DATA contains all the extracted records. L_T_DATA[] = C_T_DATA[]. IF NOT L_T_DATA IS INITIAL. * read the fields from DFKKKO table for all entries of L_T_DATA and put them in to IT_DFKKKO SELECT OPBEL FIKEY ERNAM CPUTM WWERT RLGRD STBEL STMET BLTYP AGINF AWSYS TATYP FROM DFKKKO INTO TABLE ZBW_DFKKKO FOR ALL ENTRIES IN L_T_DATA WHERE OPBEL = L_T_DATA-OPBEL. LOOP AT L_T_DATA ASSIGNING <L_S_DATA>. READ TABLE ZBW_DFKKKO INTO WA_DFKKKO WITH KEY V_OPBEL = <L_S_DATA>-OPBEL. IF SY-SUBRC = 0. <L_S_DATA>-ZZFIKEY = WA_DFKKKO-V_FIKEY. <L_S_DATA>-ZZERNAM = WA_DFKKKO-V_ERNAM. <L_S_DATA>-ZZCPUTM = WA_DFKKKO-V_CPUTM. ENDIF. ENDLOOP. ENDIF. * Now that we have filled new fileds, copy everything back to C_T_DATA which will be passed on to BW system C_T_DATA[] = L_T_DATA[]. REFRESH: L_T_DATA, ZBW_DFKKKO. endmethod. Thats it. We have enhanced the datasource using BADI. The ABAP code in the above method will be exuceuted when we run the infopackage to load the data from the datasource. Go to transaction code RSA3 to test and make sure that everything is working fine.
If you want to enhance the datasource using user exit (cmod) you can follow step by step instructions in SDN how to document at this link.