SAP BW/4HANA, BW (SAP Business Warehouse)

ABAP Code identification/Search in SAP BW or SAP BW/4HANA system

Introduction

I need to search a piece of ABAP code in my SAP BW system or in the SAP BW/4HANA System over the Custom/Standard Class/Methods, Start Routine, End Routine, Expert routines, Transformations, Include Programs and on Custom/Standard Function modules.

There was a situation for me to find a particular function module used in all of the transformations and in the custom datasource’s within the SAP BW system and “where used list” on the function module did not highlight the transformations or start or end or expert routines where the function module was used. There was one more requirement to identify where all “Select * ” had been used in all the transformations, datasource’s and to fix the “*” with required fields. So I came up with this program to identify the code snippets used. This can be used in ECC system too if you are using the Embedded Analytics within the ECC system.

Applies to:

SAP BW 7.x system and BW/4HANA systems,

Summary

This Document describes how to search within the SAP BW start, end, expert routines, transformations, custom methods(BADI’s), Include Programs and custom function modules within the SAP BW system.

Body

Requirement

Many a times, code within the SAP BW system will be in the methods of BADI, inside of the Transformations, Function modules and in the Include programs. For example if I need to find the code/logic used for a customer exit variable in SAP BW system, then I need to manually search in all the BADI’s/Methods. Manual search is complex and time consuming, hence I created a program and this program makes the code search easy, just i will type the code snippet to be searched then the output will be in the form of ALV grid showing line numbers and the area where the code is being used.

Note

The existing program searches in custom class/methods and custom Include Programs and in custom Function Modules. This can be changed by modifying the code as below, but i dont recommend this as search will take a long time.

select clsname from seoclass into table lt_clsname bypassing buffer where clsname like ‘Z%’ . —> Remove the where clause to search in all class and methods

select progname from reposrc into table lt_include_programs where r3state = ‘A’ and ( progname like ‘LZ%UXX’ or progname like ‘LZ%TOP’). —> Remove the “and ( progname like ‘LZ%UXX’ or progname like ‘LZ%TOP’)” to search in all Include programs.

select * from tfdir into table lt_tfdir where funcname like ‘Z%’. —> Remove the where clause to search in all function modules

ABAP Code

*&---------------------------------------------------------------------*
*& Report  ZBW_CODE_SEARCH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
************************************************************************
*  Program Title        : Code Search in SAP BW system                 *
*  Description          : To search code snippet in the                *
*                       : Start Routine, End Routine, Expert Routine,  *
*                       : of all the transformations(SAP               *
*                       : as well as user defined transformations).In  *
*                       : User defined Class as well as Methods(Z*).   *
*                       : In case of classes, Include program,         *
*                       : & Function module only the custom generated  *
*                       : objects are considered.(Z* Objects).          *
*                       : count of lines of code added to the display  *
*----------------------------------------------------------------------*
report zbw_code_search.

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,
          tranprog     type rstran_progid,
        end of lty_tranid.

types : begin of lty_abap_code,
          codeid  type rscodeid,
          line_no type rslineno,
          line    type string,
        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 sobj_name,   " source of the transformation
         sourcename type sobj_name,   " target of the transformation
         string     type string,     " String which was searched
       end of  lty_abap_det.

types: begin of lty_class_det,
         class_name type seoclsname,    " Class Name
         method     type seocpdname,    " Method Name
         string     type string,       " String which was searched
       end of  lty_class_det.

types: begin of lty_include_prgm_det,
         progname type progname,    " Include Program Name
         string   type string,     " String which was searched
       end of  lty_include_prgm_det.

types: begin of lty_fm_det,
         fm     type progname,    " Function Module Name
         string type string,     " String which was searched
       end of  lty_fm_det.

types : begin of lty_objects,
          objects type c length 20, " Type of Objects(Transformation, Class, Include and Function Module
          lines   type i,
        end of lty_objects.

types : begin of lty_code_table,
          line   type i,
          string type string,
        end of lty_code_table.


data : lt_tranid           type standard table of lty_tranid,
       lt_tranid_1         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_start   type standard table of lty_abap_det,
       lt_abap_det_end     type standard table of lty_abap_det,
       lt_abap_det_expert  type standard table of lty_abap_det,
       lt_abap_det_1       type standard table of lty_abap_det,
       la_abap_det         type                   lty_abap_det,
       la_abap_det_1       type                   lty_abap_det,
       source              type                   seop_source_string,
       wa_source           like line of           source,
       source_1            type                   seop_source_string,
       cifkey              type                   seoclskey,
       cifref              type ref to            if_oo_clif_incl_naming,
       clsref              type ref to            if_oo_class_incl_naming,
       pool_source         type                   seop_source_string,
       source_line         type line of           seop_source_string,
       tabix               type                   sytabix,
       l_string            type                   string,
       includes            type                   seop_methods_w_include,
       include             type                   seop_method_w_include,
       lt_clsname          type standard table of seoclsname,
       la_clsname          type                   seoclsname,
       la_class_det        type                   lty_class_det,
       lv_code_row_no      type                   c length 10,
       lt_class_det        type standard table of lty_class_det,
       la_object           type                   lty_objects,
       lt_object           type standard table of lty_objects,
       lt_include_programs type standard table of progname,
       la_include_programs type                   progname,
       la_fm_prg_name      type                   progname,
       lt_include_prgm_det type standard table of lty_include_prgm_det,
       la_include_prgm_det type                   lty_include_prgm_det,
       lt_fm_det           type standard table of lty_fm_det,
       la_fm_det           type                   lty_fm_det,
       lt_tfdir            type standard table of tfdir,
       la_tfdir            type                   tfdir,
       lv_tran_prgm        type                   progname,
       la_code_table       type                   lty_code_table,
       lt_code_table       type standard table of lty_code_table,
       lv_tabix            type                   syst-tabix,
       lv_tabix_1          type                   syst-tabix,
       lv_lines            type                   i.
*********************** ALV Grid *********************************
data: fieldcatalog         type slis_t_fieldcat_alv with header line,
      gd_layout            type slis_layout_alv,
      fieldcatalog_objects type slis_t_fieldcat_alv with header line.

gd_layout-colwidth_optimize = abap_true.
*********************** ALV Grid *********************************

selection-screen begin of block b1 with frame title text-001.
parameters : line          type edpline obligatory. " String Input/Code snippet which needs to be searched
selection-screen end of block b1.

select
tranid
startroutine
endroutine
expert
sourcename
targetname
tranprog
from
rstran  as a          " Transformation Table
into table lt_tranid bypassing buffer
where
a~objvers = 'A'
and
( startroutine <> ' ' or  endroutine <> ' ' or expert <> ' ' ). " Picking only records where the routines are not empty

if sy-subrc  = 0. " If 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

    " Start Routine, End Routine and Expert Routine only
    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
          shift la_abap-line left deleting leading space.
          la_abap_det-string = la_abap-line.

          append la_abap_det to lt_abap_det_start.

        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'.            " End
          la_abap_det-sourcename  = la_tranid-sourcename. " Source name
          la_abap_det-targetname  = la_tranid-targetname. " Target name
          shift la_abap-line left deleting leading space.
          la_abap_det-string = la_abap-line.

          append la_abap_det to lt_abap_det_end.

        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'.          " Expert
          la_abap_det-sourcename  = la_tranid-sourcename. " Source name
          la_abap_det-targetname  = la_tranid-targetname. " Target name
          shift la_abap-line left deleting leading space.
          la_abap_det-string = la_abap-line.

          append la_abap_det to lt_abap_det_expert.

        endif.

      endloop.

    endloop.
  endif.
endif.

" Selecting only Custom classes
" Only the Custom classes are created for Variables exit / F4 Exit / Virtual Char Exit etc and start with 'Z'
select clsname from seoclass into table lt_clsname bypassing buffer
where clsname like 'Z%' . 
" Remove the where clause to search in all classes, not only in Custom classes

loop at lt_clsname into la_clsname.

  clear : la_class_det, source.

  cifkey = la_clsname.
  " Search in class
  " In the classes we use variables exit and F4 exit
  call method cl_oo_include_naming=>get_instance_by_cifkey
    exporting
      cifkey = cifkey
    receiving
      cifref = cifref
    exceptions
      others = 1.

  if sy-subrc <> 0.
* Implement suitable error handling here

  else.

    case cifref->clstype.
      when seoc_clstype_class.
        clsref ?= cifref.
        read report clsref->class_pool
          into pool_source.

        read report clsref->locals_old
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
        read report clsref->locals_def
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
        read report clsref->locals_imp
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
        read report clsref->macros
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
        read report clsref->public_section
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.

        read report clsref->protected_section
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.

        read report clsref->private_section
          into source.
        loop at source
          into source_line.
          if source_line ns '*"*'.
            if source_line cs line and source_line is not initial.
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
        concatenate 'CLASS' cifkey 'IMPLEMENTATION' into l_string separated by space.
        loop at pool_source
          from tabix
          into source_line.
          if source_line cs 'ENDCLASS'.
            if ( source_line cs line and source_line is not initial ).
              shift source_line left deleting leading space.
              lv_code_row_no = sy-tabix.
              concatenate lv_code_row_no source_line into source_line separated by space.
              la_class_det-class_name = la_clsname.
              la_class_det-string = source_line.
              append la_class_det to lt_class_det.
            endif.
          endif.
        endloop.
* method implementation
        includes = clsref->get_all_method_includes( ).
        loop at includes
          into include.
          read report include-incname
            into source.
          loop at source
            into source_line.
            if source_line cs line.
              if source_line is not initial.
                shift source_line left deleting leading space.
                lv_code_row_no = sy-tabix.
                concatenate lv_code_row_no source_line into source_line separated by space.
                la_class_det-class_name = la_clsname.
                la_class_det-method = include-cpdkey-cpdname.
                la_class_det-string = source_line.
                append la_class_det to lt_class_det.
              endif.
            endif.
          endloop.
        endloop.
    endcase.
  endif.
endloop.

" Include program
" Top include and UXX includes only
select progname from reposrc into table lt_include_programs where
r3state = 'A' and ( progname like 'LZ%UXX' or progname like 'LZ%TOP').
" The staement "and ( progname like 'LZ%UXX' or progname like 'LZ%TOP')" can be 
" removed to search in all Includes not only the Custom Includes

if sy-subrc = 0.
  loop at lt_include_programs into la_include_programs.

    read report la_include_programs into source.

    if sy-subrc = 0.
      loop at source
      into source_line.
        if source_line cs line.
          la_include_prgm_det-progname = la_include_programs.
          la_include_prgm_det-string   = source_line.
          append la_include_prgm_det to lt_include_prgm_det.
        endif.
      endloop.
    endif.

  endloop.
endif.

" Function modules
select * from tfdir into table lt_tfdir where funcname like 'Z%'.
" The code "where funcname like 'Z%'" can be removed to search in all Function Modules
" not only limiting it to Custom Function Modules

if sy-subrc = 0.
  loop at lt_tfdir into la_tfdir.

    replace 'SAP' in la_tfdir-pname with ''.
    condense la_tfdir-pname.

    concatenate la_tfdir-pname 'U' la_tfdir-include into la_tfdir-pname.

    read report la_tfdir-pname into source.

    if sy-subrc = 0.
      loop at source into source_line.
        if source_line cs line.
          la_fm_det-fm = la_tfdir-funcname.
          shift source_line left deleting leading space.
          lv_code_row_no = sy-tabix.
          concatenate lv_code_row_no source_line into source_line separated by space.
          condense source_line.
          la_fm_det-string = source_line.
          append la_fm_det to lt_fm_det.
        endif.
      endloop.
    endif.
  endloop.
endif.

" Transformations
" Code present in the areas other than
" start/end/expert routines
select
tranid
startroutine
endroutine
expert
sourcename
targetname
tranprog
from
rstran  as a          " Transformation Table
into table lt_tranid bypassing buffer
where
a~objvers = 'A'.

loop at lt_tranid into la_tranid.

  clear : lv_tran_prgm, source, lt_code_table, la_code_table, lv_tabix, lv_tabix_1.

  concatenate 'GP' la_tranid-tranprog into lv_tran_prgm.

  read report lv_tran_prgm into source.

  loop at source
  into source_line.

    la_code_table-line = syst-tabix.
    la_code_table-string = source_line.

    append la_code_table to lt_code_table.

  endloop.

  " End Routine removed
  loop at lt_code_table into la_code_table where string  cs 'method end_routine.'.

    lv_tabix = syst-tabix.

    loop at lt_code_table into la_code_table where string  cs 'endmethod.' and line >= lv_tabix.

      lv_tabix_1 = syst-tabix.
      exit.

    endloop.

    delete lt_code_table where line between lv_tabix and lv_tabix_1.

  endloop.

  " Start Routine removed
  loop at lt_code_table into la_code_table where string  cs 'method start_routine.'.

    lv_tabix = syst-tabix.

    loop at lt_code_table into la_code_table where string  cs 'endmethod.' and line >= lv_tabix.

      lv_tabix_1 = syst-tabix.
      exit.

    endloop.

    delete lt_code_table where line between lv_tabix and lv_tabix_1.

  endloop.

  loop at lt_code_table
    into la_code_table.

    if la_code_table-string cs line.
      if la_code_table-string is not initial.

        lv_code_row_no = la_code_table-line.
        shift la_code_table-string left deleting leading space.

        concatenate lv_code_row_no la_code_table-string into la_code_table-string separated by space.
        la_abap_det_1-sourcename = la_tranid-sourcename.
        la_abap_det_1-tranid = la_tranid-tranid.
        la_abap_det_1-targetname = la_tranid-targetname.
        la_abap_det_1-string = la_code_table-string.
        append la_abap_det_1 to lt_abap_det_1.

      endif.
    endif.
  endloop.

endloop.

fieldcatalog_objects-fieldname   = 'OBJECTS'.
fieldcatalog_objects-seltext_m   = 'OBJECTS'.
fieldcatalog_objects-outputlen  = '40'.
fieldcatalog_objects-row_pos = 1.
fieldcatalog_objects-col_pos = 1.
fieldcatalog_objects-hotspot = 'X'.

append fieldcatalog_objects to fieldcatalog_objects.
clear  fieldcatalog_objects.

fieldcatalog_objects-fieldname   = 'LINES'.
fieldcatalog_objects-seltext_m   = 'LINES COUNT'.
fieldcatalog_objects-outputlen  = '40'.
*fieldcatalog_objects-row_pos = 1.
fieldcatalog_objects-col_pos = 2.
*fieldcatalog_objects-hotspot = 'X'.

append fieldcatalog_objects to fieldcatalog_objects.
clear  fieldcatalog_objects.

la_object-objects = 'START ROUTINE'.
DESCRIBE TABLE lt_abap_det_start lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object-objects = 'END ROUTINE'.
DESCRIBE TABLE lt_abap_det_end lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object-objects = 'EXPERT ROUTINE'.
DESCRIBE TABLE lt_abap_det_expert lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object-objects = 'TRANFORMATIONS'.
DESCRIBE TABLE lt_abap_det_1 lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object-objects = 'CLASS'.
DESCRIBE TABLE lt_class_det lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object-objects = 'INCLUDE PROGRAMS'.
DESCRIBE TABLE lt_include_prgm_det lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.

la_object = 'FUNCTION MODULES'.
DESCRIBE TABLE lt_fm_det lines lv_lines.
la_object-lines = lv_lines.
append la_object to lt_object.


call function 'REUSE_ALV_GRID_DISPLAY'
  exporting
    i_callback_program      = sy-repid
    i_callback_user_command = 'USER_COMMAND'
    it_fieldcat             = fieldcatalog_objects[]
  tables
    t_outtab                = lt_object
  exceptions
    program_error           = 1
    others                  = 2.
if sy-subrc <> 0.
* Implement suitable error handling here
endif.



form user_command using fp_ucomm like sy-ucomm
                        fp_selfield type slis_selfield.

  clear : fieldcatalog, fieldcatalog[].

  if fp_ucomm = '&IC1'.

    if fp_selfield-value = 'START ROUTINE'.

      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'.
      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
          it_fieldcat        = fieldcatalog[]
          i_save             = 'X'
*         IS_VARIANT         = G_VARIANT
        tables
          t_outtab           = lt_abap_det_start
        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.

    elseif fp_selfield-value = 'END ROUTINE'.

      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'.
      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
          it_fieldcat        = fieldcatalog[]
          i_save             = 'X'
*         IS_VARIANT         = G_VARIANT
        tables
          t_outtab           = lt_abap_det_end
        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.

    elseif fp_selfield-value = 'EXPERT ROUTINE'.

      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'.
      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
          it_fieldcat        = fieldcatalog[]
          i_save             = 'X'
*         IS_VARIANT         = G_VARIANT
        tables
          t_outtab           = lt_abap_det_expert
        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.

    elseif fp_selfield-value = 'TRANFORMATIONS'.

      fieldcatalog-fieldname   = 'TRANID'.
      fieldcatalog-seltext_m   = 'TRANSFORMATION'.
      fieldcatalog-outputlen  = '40'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      fieldcatalog-fieldname   = 'SOURCENAME'.
      fieldcatalog-seltext_m   = 'SOURCE'.
      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
          it_fieldcat        = fieldcatalog[]
          i_save             = 'X'
*         IS_VARIANT         = G_VARIANT
        tables
          t_outtab           = lt_abap_det_1
        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.

    elseif fp_selfield-value = 'CLASS'.

      fieldcatalog-fieldname   = 'CLASS_NAME'.
      fieldcatalog-seltext_m   = 'Class Name'.
      fieldcatalog-outputlen  = '40'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      fieldcatalog-fieldname   = 'METHOD'.
      fieldcatalog-seltext_m   = 'Method Name'.
      fieldcatalog-outputlen  = '61'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      fieldcatalog-fieldname   = 'STRING'.
      fieldcatalog-seltext_m   = 'String'.
      fieldcatalog-outputlen  = '20'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program = sy-repid
          it_fieldcat        = fieldcatalog[]
          is_layout          = gd_layout
*         i_save             = 'X'
        tables
          t_outtab           = lt_class_det
        exceptions
          program_error      = 1
          others             = 2.

      if sy-subrc <> 0.
* Implement suitable error handling here
      endif.

    elseif fp_selfield-value = 'INCLUDE PROGRAMS'.

      fieldcatalog-fieldname   = 'PROGNAME'.
      fieldcatalog-seltext_m   = 'Include Program Name'.
      fieldcatalog-outputlen  = '40'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      fieldcatalog-fieldname   = 'STRING'.
      fieldcatalog-seltext_m   = 'String'.
      fieldcatalog-outputlen  = '61'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program = sy-repid
          it_fieldcat        = fieldcatalog[]
          is_layout          = gd_layout
*         i_save             = 'X'
        tables
          t_outtab           = lt_include_prgm_det
        exceptions
          program_error      = 1
          others             = 2.

    elseif fp_selfield-value = 'FUNCTION MODULES'.

      fieldcatalog-fieldname   = 'FM'.
      fieldcatalog-seltext_m   = 'Function Module Name'.
      fieldcatalog-outputlen  = '40'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      fieldcatalog-fieldname   = 'STRING'.
      fieldcatalog-seltext_m   = 'String'.
      fieldcatalog-outputlen  = '61'.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.

      call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program = sy-repid
          it_fieldcat        = fieldcatalog[]
          is_layout          = gd_layout
*         i_save             = 'X'
        tables
          t_outtab           = lt_fm_det
        exceptions
          program_error      = 1
          others             = 2.
    endif.
  endif.
endform.

Example

Execute the program, then i need to find where all the “select *” is used and then change it to select <fields list>.

press F8 or execute button, then the output will be as below.

Then if i click on start routine the drill down will show the below.

Rating: 0 / 5 (0 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *