*---------------------------------------------------------------------*
* 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 (70) type 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.
The 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 -'.
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' '000000 '.
Perform bdc_field using 'bdc _ cursor'
'Rsrd1-tbma_val '.
Perform bdc_field using 'bdc _ okcode'
'= Show '.
Perform bdc_field using 'rsrd1-tbm'
'X '.
Perform bdc_field using 'rsrd1-tbma_val'
SF-value.
Perform bdc_dynpro using 'saplsd41' '000000 '.
Call transaction 'se11' using it_bdcdata mode 'e 'update '.
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.
* Specify lidating 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 = 'pooled ').
* 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