Skip to Content
Author's profile photo Lakshminarasimhan N

Code search in the SAP BW

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  ” ABAP routine – source code
INTO TABLE LT_ABAP
FOR ALL ENTRIES IN
LT_TRANID
WHERE
B
~CODEID = LT_TRANIDSTARTROUTINE OR
B
~CODEID = LT_TRANIDENDROUTINE OR
B
~CODEID = LT_TRANIDEXPERT.

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 RSTRANSOURCENAME, ” source of the transformation
SOURCENAME  
TYPE RSTRANTARGETNAME, ” target of the transformation
STRING      
TYPE RSAABAPLINE,      ” 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 RSAABAPLINE. ” 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 SYSUBRC  = 0. ” Entries are present in the table LT_TRANID

SELECT
B
~CODEID
B
~LINE_NO
B
~LINE
FROM
RSAABAP 
AS  ” ABAP routine – source code
INTO TABLE LT_ABAP
FOR ALL ENTRIES IN
LT_TRANID
WHERE
B
~CODEID = LT_TRANIDSTARTROUTINE OR
B
~CODEID = LT_TRANIDENDROUTINE OR
B
~CODEID = LT_TRANIDEXPERT.

IF SYSUBRC = 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_TRANIDSTARTROUTINE.

IF LA_ABAPLINE CS LINE.

LA_ABAP_DETTRANID  = LA_TRANIDTRANID. ” Transaction ID
LA_ABAP_DET
ROUTINE = ‘START’.          ” Start
LA_ABAP_DET
SOURCENAME  = LA_TRANIDSOURCENAME. ” Source name
LA_ABAP_DET
TARGETNAME  = LA_TRANIDTARGETNAME. ” Target name
LA_ABAP_DET
STRING = LA_ABAPLINE.

APPEND LA_ABAP_DET TO LT_ABAP_DET.

ENDIF.

ENDLOOP.

LOOP  AT LT_ABAP INTO LA_ABAP WHERE CODEID = LA_TRANIDENDROUTINE.

IF LA_ABAPLINE CS LINE.

LA_ABAP_DETTRANID  = LA_TRANIDTRANID. ” Transaction ID
LA_ABAP_DET
ROUTINE = ‘END’.          ” Start
LA_ABAP_DET
SOURCENAME  = LA_TRANIDSOURCENAME. ” Source name
LA_ABAP_DET
TARGETNAME  = LA_TRANIDTARGETNAME. ” Target name
LA_ABAP_DET
STRING = LA_ABAPLINE.

APPEND LA_ABAP_DET TO LT_ABAP_DET.

ENDIF.

ENDLOOP.

LOOP  AT LT_ABAP INTO LA_ABAP WHERE CODEID = LA_TRANIDEXPERT.

IF LA_ABAPLINE CS LINE.
LA_ABAP_DET
TRANID  = LA_TRANIDTRANID. ” Transaction ID
LA_ABAP_DET
ROUTINE = ‘EXPERT’.          ” Start
LA_ABAP_DET
SOURCENAME  = LA_TRANIDSOURCENAME. ” Source name
LA_ABAP_DET
TARGETNAME  = LA_TRANIDTARGETNAME. ” Target name
LA_ABAP_DET
STRING = LA_ABAPLINe.

APPEND LA_ABAP_DET TO LT_ABAP_DET.

ENDIF.

ENDLOOP.

ENDLOOP.

FIELDCATALOGFIELDNAME   = ‘TRANID’.
FIELDCATALOG
SELTEXT_M   = ‘TRANSFORMATION’.
FIELDCATALOG
OUTPUTLEN  = ’40’.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOGFIELDNAME   = ‘ROUTINE’.
FIELDCATALOG
SELTEXT_M   = ‘ROUTINE’.
FIELDCATALOG
OUTPUTLEN  = ’20’.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOGFIELDNAME   = ‘SOURCENAME’.
FIELDCATALOG
SELTEXT_M   = ‘SOURCE DATAPROVIDER’.
FIELDCATALOG
OUTPUTLEN  = ’50’.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOGFIELDNAME   = ‘TARGETNAME’.
FIELDCATALOG
SELTEXT_M   = ‘TARGET’.
FIELDCATALOG
OUTPUTLEN  = ’30’.
APPEND FIELDCATALOG TO FIELDCATALOG.
CLEAR  FIELDCATALOG.

FIELDCATALOGFIELDNAME   = ‘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     
= SYREPID
*       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 SYSUBRC <> 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

Assigned Tags

      11 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mario Tibollo
      Mario Tibollo

      you could use RS_ABAP_SOURCE_SCAN

      M.

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      I will try to use the PRGM and let you know.

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      The Program RS_ABAP_SOURCE_SCAN tracks the changes in the ABAP program but it does not give the exact BW transformation.But the good point is we can supply all the generated program "G*" and search for a string and then we need to find the way to identify to which transformation, G* program belongs to. Please see the screen shot given below. I will try to find an way. Thanks Tibollo.

      Screen_Shot.PNG

      Author's profile photo Mario Tibollo
      Mario Tibollo

      if you open the program, you can see in the descriptive comment which routine it is.

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      Hi Tibollo,

      Can you please share a screen shot, because in the "descriptive comments" I am getting only G* names.

      Thanks.

      Descriptive.PNG

      Author's profile photo Mario Tibollo
      Mario Tibollo

      if you double-click on the report name you get as a result of the search, you go to the code of the program. there you can see the source and target:

      generated program TRFN.JPG

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      That's good,  by the way my program will give the exact transformation with no extra effort. I am impressed with RS_ABAP_SOURCE_SCAN. Thanks for your inputs.

      Author's profile photo Henry Jones
      Henry Jones

      Great Job!!! This works very well!!! 😎

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      Thanks Henry 🙂 I am happy that my code is helping my fellow SCN friends..

      Author's profile photo Vijay N
      Vijay N

      Great job!! 🙂 , this really helps me alot in my impact analysis

      Author's profile photo Lakshminarasimhan N
      Lakshminarasimhan N
      Blog Post Author

      Thanks Vijay 🙂