Searches for all references to the S120 table
Saber Mohamed
Sap Basis / Integration manager @ El Ezaby Pharmacy & Multipharma | SAP BASIS, HANA Implementation
REPORT zfind_s120_usage.
DATA: lv_table_name TYPE tabname VALUE 'S120',
lt_results TYPE TABLE OF trdir WITH EMPTY KEY,
lt_sources TYPE TABLE OF string,
lt_found_refs TYPE TABLE OF string,
lv_program TYPE trdir-name,
lv_search_string TYPE string.
PARAMETERS: p_table TYPE tabname DEFAULT 'S120'.
START-OF-SELECTION.
lv_table_name = p_table.
" Step 1: Get all report programs
SELECT name
FROM trdir
INTO TABLE lt_results
WHERE subc = '1'. " Only report programs
" Step 2: Search each program for references to the table
LOOP AT lt_results INTO lv_program.
" Read the source code of the program
READ REPORT lv_program INTO lt_sources.
IF sy-subrc = 0 AND NOT lt_sources IS INITIAL.
领英推荐
LOOP AT lt_sources INTO DATA(lv_line).
IF lv_line CP '*' && lv_table_name && '*'.
" Add to the found references table
APPEND |Program: { lv_program }, Line: { lv_line }| TO lt_found_refs.
EXIT. " Exit the loop if the table is found in this program
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
" Step 3: Display the results
IF lt_found_refs IS NOT INITIAL.
WRITE: / 'Programs using table', lv_table_name, ':'.
LOOP AT lt_found_refs INTO DATA(lv_result).
WRITE: / lv_result.
ENDLOOP.
ELSE.
WRITE: / 'No programs found using table', lv_table_name.
ENDIF.