Hi all,
In this post, I described
Step by Step Procedure of how to enhance SAP BW datasource/extractor using BADI
or User Exit.
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. User Exit
2. BADI
In the User Exit method, we
will write 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, we choose the first step is to add the new fields to extraction
structure. First check if the fields we are looking for are hidden in the
datasource before adding the new fields to the structure.
Step A : Appending new
fileds to Extraction Structure
1. Go to transaction
code RSA6
2. Find the datasource
that we want to enhance and click on change button.
3. If we need the fields are hidden, hide them.
4. Save the datasource
and click on "Enhance Extraction Structure"
5. Give a name to
append 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 button twice and go to datasource definition. We will find the new
appended fields at the end, do not hide them.
8. Hit back button twice and go to datasource definition. We will find the new
appended fields at the end, do not hide 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. We can also use user exits for
this. See the links for the documents, if you want to use user exits.
Step B: Writing code to
populate new fields using BADI
1.
First step is to create Implementation with the standard BADI Definition. For
this go to transaction code SE18 and
give BADI Name as RSU5_SAPI_BADI and
select create from 'Enhancement Implementation' menu.
2. Enter Implementation Name as ZRSU5_SAP_BADI and hit check icon.
3. Give the description and activate the implementation.
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 section of the implementation class.
6.
In this class first two methods are SAP standard methods.
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 want to see them in your system. Go back to methods tab by hitting
'Methods' button.
10.
After come 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 did 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.
Step C: Create a custom
method to populate new fields
1.
Create a custome method for the class (ZCL_IM_RSU5_SAP_BADI). Method name
should be Z_datasourcename . Here we are appending Z_ because method names can not
start with number and most of the BW datasources start with a number. You can
use you choice of prefix Z_ or M_ but you need to make sure that you are also
using same prefix in the concatenate statement in the in the standard method
(IF_EX_RSU5_SAPI_BADI~DATA_TRANSFORM) which calls our custom method at the tie
of data extraction.
2. So, for the example in this article the method name should be Z_0FC_BP_ITEMS.
To create the method in the method name field and select level as static and
visibility as Publick and give some description.
3.
Copy and paste following code.
Note: You need to change the table and field names in this code as per your requirement.
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.
That's
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
we want to enhance the datasource using user exit (CMOD), we can follow step by
step procedure @ View
the document
Read More (Reference Documents):
ABAP Development for SAP BW - User Exits and BAdis @ View the document)
How To Use ABAP Classes Instead of “CMOD” for BW
Datasource Enhancements @ View the document
How to Implement BADI for Enhancing the Datasource in ECC @ View the document
Read More (Reference Documents):
ABAP Development for SAP BW - User Exits and BAdis @ View the document)
How to Implement BADI for Enhancing the Datasource in ECC @ View the document
I am William..
ReplyDeleteI just browsing through some blogs and came across yours!
Excellent blog, good to see someone actually uses for quality posts.
Your site kept me on for a few minutes unlike the rest :)
Keep up the good work!Thanks for sharing a important information on sharepoint
Dear Writer,
ReplyDeleteThank you to post this blog, but unfortunately, I can't saw any screen shots. Could you please kindly let me know that how i can see it?
Please contact me at zhou_cherry2002@yahoo.com.
Thanks & regards,
Cherry Zhou
Well it was very good information for SAP learners. we are really happy seeing your article. we also provide Software courses online training @ SAP courses online training
ReplyDelete
ReplyDeleteThis article looks very Interesting. Please share more on badi
keep sharing this type of good informationsap hana training in
ReplyDeletehyderabad
We provide SAP MM training in Chennai with real time scenarios. For real time SAP MM training in Chennai join creating experts and become professional in SAP MM module
ReplyDeletehttp://thecreatingexperts.com/sap-mm-training-in-chennai/
SSC MTS Answer Key 2017
ReplyDelete