Code Search in the SAP BW system
Applies to:
SAP BW 7.x system. For more information, visit the Business Intelligence homepage https://help.sap.com/saphelp_nw73ehp1/helpdata/en/b2/e50138fede083de10000009b38f8cf/frameset.htm
Summary
This Document describes how to search within the SAP BW start, end and expert routines using a custom program.
Author : Lakshminarasimhan Narasimhamurthy
Created on : 03/SEP/2015
Author Bio
Lakshminarasimhan Narasimhamurthy is BW certified and ABAP certified consultant and worked on multiple implementation, development and support project's within India and outside of India. He has worked for fortune 500 clients like Nestle, Warner Bros, General Electric. He is strong in HANA modeling and BO/BI tools like WEBI, Dashboard, IDT, Lumira.
Details
There is a requirement to search for a particular event or a function module or hard coded break-points or comments within the start routine or at the end routine or in the expert routine. But going inside every transformation and checking is simply impossible task. Hence I have created a custom program to search for the string within all the start, end and expert routines. The “Where-used” list will not show if the function module is used in the transformations and in the generated BW programs, and hence we are going to use the custom program.
Scenario
We are using a function module to fix the invalid characters. We are replacing these invalid characters by blanks. Now the system is “Unicode” enabled and we want to remove this function module from all the transformations, where it was being used. Another scenario is that the previous developers have put the hardcoded “break-points” and have transported transformations to PRD system along with these break-points. Now we need to comment out these “break-points” by finding in all the transformation where it is being used.
We have 2 tables
- RSTRAN – Contains all the transformations.
- RSAABAP – Contains all the ABAP code written in the start end expert routines.
Note – RSAROUT – This is an optional table where you can check if your routines are active and then join with RSAABAP table or you can ignore it.
This contains all start routines, end routines, global transfer routines, expert routines ID’s etc.
Pseudo logic –
- Take all of the active transformations from RSTRAN table and take the start routine, end routine and expert routine ID’s and pass all these routine ID’s to table RSAABAP. Then check if each line of the code matches with the entered string. If the string matches then display the transformation id, source and the target in the ALV grid.
Code explanation –
Line is the input parameter to get the string.
The below select statement takes the active version transformation where the start routine or end routine or expert routine are not null, into the internal table LT_TRANID
SELECT
TRANID
STARTROUTINE
ENDROUTINE
EXPERT
SOURCENAME
TARGETNAME
FROM
RSTRAN AS A " Transformation Table
INTO TABLE LT_TRANID
WHERE
A~OBJVERS = 'A'
AND
( STARTROUTINE <> ' ' OR ENDROUTINE <> ' ' OR EXPERT <> ' ' ). " Picking only records where the routines are not empty
Each codeid obtained in the previous internal table is checked against the table RSAABAP and the matching entries are put into the table LT_ABAP. This table contains the all the lines of the routines, including the comments.
SELECT
B~CODEID
B~LINE_NO
B~LINE
FROM
RSAABAP AS B " ABAP routine - source code
INTO TABLE LT_ABAP
FOR ALL ENTRIES IN
LT_TRANID
WHERE
B~CODEID = LT_TRANID-STARTROUTINE OR
B~CODEID = LT_TRANID-ENDROUTINE OR
B~CODEID = LT_TRANID-EXPERT.
For each transformation id, check the LT_ABAP internal table line by line to see if the code contains our search string. The comparison is not case sensitive as we are using CS(Contain String) operator.
Finally display the result in the ALV grid.
Actual Program –
*&---------------------------------------------------------------------*
*& Report ZBW_SEARCH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBW_SEARCH.
TABLES : RSAABAP.
TYPE-POOLS : SLIS. " ALV Grid display
TYPES : BEGIN OF LTY_TRANID,
TRANID TYPE RSTRANID,
STARTROUTINE TYPE RSSGUID25,
ENDROUTINE TYPE RSSGUID25,
EXPERT TYPE RSSGUID25,
SOURCENAME TYPE SOBJ_NAME,
TARGETNAME TYPE SOBJ_NAME,
END OF LTY_TRANID.
TYPES : BEGIN OF LTY_ABAP_CODE,
CODEID TYPE RSCODEID,
LINE_NO TYPE RSLINENO,
LINE TYPE EDPLINE,
END OF LTY_ABAP_CODE.
TYPES: BEGIN OF LTY_ABAP_DET,
TRANID TYPE RSTRANID, " Transaction ID
ROUTINE TYPE C LENGTH 25, " Start or end or expert
TARGETNAME TYPE RSTRAN-SOURCENAME, " source of the transformation
SOURCENAME TYPE RSTRAN-TARGETNAME, " target of the transformation
STRING TYPE RSAABAP-LINE, " String which was searched
END OF LTY_ABAP_DET.
DATA : LT_TRANID TYPE STANDARD TABLE OF LTY_TRANID,
LA_TRANID TYPE LTY_TRANID,
LT_ABAP TYPE STANDARD TABLE OF LTY_ABAP_CODE,
LA_ABAP TYPE LTY_ABAP_CODE,
LT_ABAP_DET TYPE STANDARD TABLE OF LTY_ABAP_DET,
LA_ABAP_DET TYPE LTY_ABAP_DET.
*********************** ALV Grid *********************************
DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
GD_LAYOUT TYPE SLIS_LAYOUT_ALV.
GD_LAYOUT-COLWIDTH_OPTIMIZE = ABAP_TRUE.
*********************** ALV Grid *********************************
PARAMETERS : LINE TYPE RSAABAP-LINE. " String Input which needs to be searched
SELECT
TRANID
STARTROUTINE
ENDROUTINE
EXPERT
SOURCENAME
TARGETNAME
FROM
RSTRAN AS A " Transformation Table
INTO TABLE LT_TRANID
WHERE
A~OBJVERS = 'A'
AND
( STARTROUTINE <> ' ' OR ENDROUTINE <> ' ' OR EXPERT <> ' ' ). " Picking only records where the routines are not empty
IF SY-SUBRC = 0. " Entries are present in the table LT_TRANID
SELECT
B~CODEID
B~LINE_NO
B~LINE
FROM
RSAABAP AS B " ABAP routine - source code
INTO TABLE LT_ABAP
FOR ALL ENTRIES IN
LT_TRANID
WHERE
B~CODEID = LT_TRANID-STARTROUTINE OR
B~CODEID = LT_TRANID-ENDROUTINE OR
B~CODEID = LT_TRANID-EXPERT.
IF SY-SUBRC = 0. " Entries are present in the table LT_ABAP
LOOP AT LT_TRANID INTO LA_TRANID. " Looping for every transaction Id
LOOP AT LT_ABAP INTO LA_ABAP WHERE CODEID = LA_TRANID-STARTROUTINE.
IF LA_ABAP-LINE CS LINE.
LA_ABAP_DET-TRANID = LA_TRANID-TRANID. " Transaction ID
LA_ABAP_DET-ROUTINE = 'START'. " Start
LA_ABAP_DET-SOURCENAME = LA_TRANID-SOURCENAME. " Source name
LA_ABAP_DET-TARGETNAME = LA_TRANID-TARGETNAME. " Target name
LA_ABAP_DET-STRING = LA_ABAP-LINE.
APPEND LA_ABAP_DET TO LT_ABAP_DET.
ENDIF.
ENDLOOP.
LOOP AT LT_ABAP INTO LA_ABAP WHERE CODEID = LA_TRANID-ENDROUTINE.
IF LA_ABAP-LINE CS LINE.
LA_ABAP_DET-TRANID = LA_TRANID-TRANID. " Transaction ID
LA_ABAP_DET-ROUTINE = 'END'. " Start
LA_ABAP_DET-SOURCENAME = LA_TRANID-SOURCENAME. " Source name
LA_ABAP_DET-TARGETNAME = LA_TRANID-TARGETNAME. " Target name
LA_ABAP_DET-STRING = LA_ABAP-LINE.
APPEND LA_ABAP_DET TO LT_ABAP_DET.
ENDIF.
ENDLOOP.
LOOP AT LT_ABAP INTO LA_ABAP WHERE CODEID = LA_TRANID-EXPERT.
IF LA_ABAP-LINE CS LINE.
LA_ABAP_DET-TRANID = LA_TRANID-TRANID. " Transaction ID
LA_ABAP_DET-ROUTINE = 'EXPERT'. " Start
LA_ABAP_DET-SOURCENAME = LA_TRANID-SOURCENAME. " Source name
LA_ABAP_DET-TARGETNAME = LA_TRANID-TARGETNAME. " Target name
LA_ABAP_DET-STRING = LA_ABAP-LINe.
APPEND LA_ABAP_DET TO LT_ABAP_DET.
ENDIF.
ENDLOOP.
ENDLOOP.
FIELDCATALOG-FIELDNAME = 'TRANID'.
FIELDCATALOG-SELTEXT_M = 'TRANSFORMATION'.
FIELDCATALOG-OUTPUTLEN = '40'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'ROUTINE'.
FIELDCATALOG-SELTEXT_M = 'ROUTINE'.
FIELDCATALOG-OUTPUTLEN = '20'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'SOURCENAME'.
FIELDCATALOG-SELTEXT_M = 'SOURCE DATAPROVIDER'.
FIELDCATALOG-OUTPUTLEN = '50'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'TARGETNAME'.
FIELDCATALOG-SELTEXT_M = 'TARGET'.
FIELDCATALOG-OUTPUTLEN = '30'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
FIELDCATALOG-FIELDNAME = 'STRING'.
FIELDCATALOG-SELTEXT_M = 'SEARCHED STRING'.
FIELDCATALOG-OUTPUTLEN = '72'.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR FIELDCATALOG.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
* I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE' "see FORM
* I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = FIELDCATALOG[]
I_SAVE = 'X'
* IS_VARIANT = G_VARIANT
TABLES
T_OUTTAB = LT_ABAP_DET
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDIF.
Note :
- If you have some declaration in the global area of the start or end or expert routine then it becomes the part of the global program and hence the search will not include them. It will search only for the code between the method and end method.
Related Content
For more information visit the webpage SAP Business Warehouse – SAP Help Portal Page