Where-used list for multiple data elements

For the tutorial, click here.

*---------------------------------------------------------------------*
*              Where used list for multiple data elements              
*---------------------------------------------------------------------*
* Program               : ZWHEREUSEDLIST
* Program type          : Report
* Title                 : Where used list for multiple data elements
* Author                : Venkatraman N
* Date written          : 09.10.2009
*---------------------------------------------------------------------*
* Description :
*    This program is mainly useful for finding out the tables, in which
* more than one data element have been used.
*---------------------------------------------------------------------*

REPORT  zwhereusedlist.

TABLES : rsrd1.

TYPE-POOLS : slis.

* Types declaration.
TYPES : BEGIN OF ty_where,
          tabname TYPE tabname,
          fieldname TYPE fieldname,
          rollname TYPE rollname,
        END OF ty_where,

        BEGIN OF ty_input,
          element TYPE rsrd1-ddtype_val,
        END OF ty_input,

        BEGIN OF ty_table,
          tabname TYPE tabname,
        END OF ty_table,

        BEGIN OF ty_result,
          tabname TYPE tabname,
        END OF ty_result,

        BEGIN OF ty_display,
          tabname TYPE tabname,
          ddtext TYPE as4text,
        END OF ty_display.

* Internal tables declaration.
DATA  : it_where TYPE TABLE OF ty_where,
        it_input TYPE TABLE OF ty_input,
        it_table TYPE TABLE OF ty_table,
        it_result TYPE TABLE OF ty_result,
        it_display TYPE TABLE OF ty_display,
        it_fcat TYPE slis_t_fieldcat_alv,
        it_bdcdata TYPE TABLE OF bdcdata.

* Work areas declaration.
DATA  : wa_where TYPE ty_where,
        wa_input TYPE ty_input,
        wa_table TYPE ty_table,
        wa_result TYPE ty_result,
        wa_display TYPE ty_display,
        wa_fcat TYPE slis_fieldcat_alv,
        wa_layout TYPE slis_layout_alv,
        wa_bdcdata TYPE bdcdata.

* Variables declaration.
DATA  : v_flag TYPE i,
        v_title TYPE string,
        v_text(70TYPE c,
        v_strlen TYPE i,
        v_tabname TYPE tabname.

INITIALIZATION.

* Disabling select-options high option.
   LOOP  AT SCREEN.
    IF screen-name = 'S_TYPE-HIGH'.
      screen-input = 0.
      screen-output = 0.
      screen-invisible = 1.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

* Selection screen.

  SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-000.
  SELECT-OPTIONS : s_type FOR rsrd1-ddtype_val.
  SELECTION-SCREEN END OF BLOCK b.

* Tables selection


START-OF-SELECTION.

  PERFORM get_tablenames.

  PERFORM get_multiple_matches.

* Outputing result
END-OF-SELECTION.

* Creating field catalog for ALV display.
  PERFORM create_fcat USING : 'TABNAME' 1 'Table name',
                              'DDTEXT' 2 'Short description'.

* Displaying the result tables.
  PERFORM display_result.


*&--------------------------------------------------------------------*
*&      Form  CREATE_FCAT
*&---------------------------------------------------------------------FORM create_fcat  USING v_fieldname TYPE c
                        v_colpos TYPE i
                        v_text TYPE c.
* Creating field catalogs
  CLEAR wa_fcat.
  wa_fcat-fieldname = v_fieldname.
  wa_fcat-col_pos = v_colpos.
  wa_fcat-seltext_l = v_text.
  wa_fcat-tabname = 'T_DISPLAY'.
  APPEND wa_fcat TO it_fcat.
ENDFORM.                    " CREATE_FCAT


*&--------------------------------------------------------------------*
*&      Form  DISPLAY_RESULT
*&--------------------------------------------------------------------*
FORM display_result .

* ALV grid title creation
  wa_layout-colwidth_optimize = 'X'.
  v_title = 'Where used list for-'.
  LOOP AT it_input INTO wa_input.
      CONCATENATE v_title wa_input-element ', ' INTO v_title.
  ENDLOOP.
  v_strlen = STRLEN( v_title ) - 1.
  v_title = v_title+0(v_strlen).
  v_text = v_title.

* List of tables display
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_callback_user_command = 'USER_COMMAND'
      i_grid_title            = v_text
      is_layout               = wa_layout
      it_fieldcat             = it_fcat
    TABLES
      t_outtab                = it_display.
ENDFORM.                    " DISPLAY_RESULT

*&---------------------------------------------------------------------
*&      Form  user_command
*&---------------------------------------------------------------------FORM user_command USING uco TYPE sy-ucomm sf TYPE slis_selfield.

* Validation of clicked table name and navigation to table using BDC
  v_tabname = sf-value.
  SELECT SINGLE
    tabname
  FROM
    dd03vv
  INTO
    v_tabname
  WHERE tabname = v_tabname.
  IF sy-subrc = 0.
    PERFORM bdc_dynpro      USING 'SAPMSRD0' '0102'.
    PERFORM bdc_field       USING 'BDC_CURSOR'
                                  'RSRD1-TBMA_VAL'.
    PERFORM bdc_field       USING 'BDC_OKCODE'
                                  '=SHOW'.
    PERFORM bdc_field       USING 'RSRD1-TBMA'
                                  'X'.
    PERFORM bdc_field       USING 'RSRD1-TBMA_VAL'
                                  sf-value.
    PERFORM bdc_dynpro      USING 'SAPLSD41' '2200'.
    CALL TRANSACTION 'SE11' USING it_bdcdata MODE 'E' UPDATE 'S'.
    CLEAR it_bdcdata[].
  ENDIF.
ENDFORM.                    "USER_COMMAND

*&---------------------------------------------------------------------
*&      Form  bdc_dynpro
*&---------------------------------------------------------------------FORM bdc_dynpro USING program dynpro.
  CLEAR wa_bdcdata.
  wa_bdcdata-program  = program.
  wa_bdcdata-dynpro   = dynpro.
  wa_bdcdata-dynbegin = 'X'.
  APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.                    "bdc_dynpro

*&---------------------------------------------------------------------
*&      Form  bdc_field
*&---------------------------------------------------------------------
FORM bdc_field USING fnam fval.
  CLEAR wa_bdcdata.
  wa_bdcdata-fnam = fnam.
  wa_bdcdata-fval = fval.
  APPEND wa_bdcdata TO it_bdcdata.
ENDFORM.                    " bdc_field


*&---------------------------------------------------------------------
*&      Form  GET_TABLENAMES
*&---------------------------------------------------------------------FORM get_tablenames.

* Consolidating selection inputs into an internal table.
  LOOP AT s_type.
    wa_input-element = s_type-low.
    APPEND wa_input TO it_input.
  ENDLOOP.

* Selecting the table names having the input data elements.
  SELECT
    tabname
    fieldname
    rollname
  FROM
    dd03vv
  INTO TABLE
    it_where
  FOR ALL ENTRIES IN it_input
  WHERE
    rollname   = it_input-element AND
    as4local   = 'A' AND
    ( tabclass = 'TRANSP' OR
      tabclass = 'CLUSTER' OR
      tabclass = 'POOL' ).

* Segregating the table names.
  LOOP AT it_where INTO wa_where.
    wa_table-tabname = wa_where-tabname.
    APPEND wa_table TO it_table.
  ENDLOOP.
  SORT it_table BY tabname.
  DELETE ADJACENT DUPLICATES FROM it_table COMPARING ALL FIELDS.


ENDFORM.                    " GET_TABLENAMES


*&---------------------------------------------------------------------
*&      Form  GET_MULTIPLE_MATCHES
*&---------------------------------------------------------------------FORM get_multiple_matches .

* Selecting the tables which are having all the input table names.
  LOOP AT it_table INTO wa_table.
    v_flag = 0.
    LOOP AT it_input INTO wa_input.
      READ TABLE it_where INTO wa_where WITH KEY 

                                        tabname = wa_table-tabname
                                        rollname = wa_input-element.
      IF sy-subrc NE 0.
        v_flag = 1.
      ENDIF.
    ENDLOOP.
    IF v_flag = 0.
      wa_result-tabname = wa_table.
      APPEND wa_result TO it_result.
    ENDIF.
  ENDLOOP.

* Retrieving table's short description.
  IF it_result[] IS NOT INITIAL.
    SELECT
      tabname
      ddtext
    FROM
      dd02t
    INTO TABLE
      it_display
    FOR ALL ENTRIES IN it_result
      WHERE
        tabname = it_result-tabname.
    IF sy-subrc = 0.
      SORT it_display BY tabname ddtext.
      DELETE ADJACENT DUPLICATES FROM it_display COMPARING tabname.
    ENDIF.
  ENDIF.
ENDFORM.                    " GET_MULTIPLE_MATCHES

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image