Not again!! I exclaimed. This reaction was in response to a requirement from client for updating variants. Well, to be more precise they wanted to check the variants of all report programs for a particular value ‘XX’ in a selection parameter and add a value ‘YY’, if found.The requirement sounds very simple, but the biggest task is not in updating the variants but in finding those program variants which had this ‘XX’, and of course we did not have any documentation on the number of reports or variants which makes the task more uphill.
I made up my mind not to do this scan task manually again as this is going to be a task with no value addition and also time consuming. Did some basic research like an F1 on the report name in ABAP editor gave me the underlying SAP table TRDIR, went about finding more T tables storing dictionary objects by using T*DIR wild card, found that the TADIR table stores the package information which will help me in filtering reports based on packages, and a VAR* popped up a number of tables and I finally zeroed in on VARI table which stores the variants, now I need to fetch the variant values for the reports variants, did some google search but found the results not so useful, now if I remember correctly, SAP provides a lot of resusable function modules starting with RS*, and so went ahead with my search in se37, and finally gotcha!! the function module I needed, RS_VARIANT_CONTENTS gives me all I need. As always, there are more ways than one to solve a problem, I decided to write a scanner report to come out of this predicament with all the information I gathered. The report is a simple one with a few selection screen parameters and very few lines of code but it was really handy and I hope some one will find it useful.
Report Name can be any wildcard and package has been included for making search faster and more specific. Search value is any string and there is not reference to any specific parameter or select-option of a report.
1. Get all the reports from TADIR for the selection criteria
SELECT obj_name FROM tadir
INTO TABLE int_tadir
WHERE pgmid = ‘R3TR’
AND object = ‘PROG’
AND obj_name LIKE p_name
AND devclass in s_pckg.
TADIR is a repository of all reports.
2. Filter the result by querying across TRDIR to eliminate unwanted programs
IF int_tadir IS NOT INITIAL.
SELECT name FROM trdir
INTO TABLE int_trdir
FOR ALL ENTRIES IN int_tadir
WHERE name = int_tadir-obj_name
AND subc = ‘1’ AND
uccheck = ‘X’.
3. Select all the report variants for the reports from table VARID
IF int_trdir IS NOT INITIAL.
SELECT report variant FROM varid
INTO TABLE int_varid
FOR ALL ENTRIES IN int_trdir
WHERE report = int_trdir-name.
4. loop across the variants for cross checking the values
LOOP AT int_varid INTO wa_varid.
**This is necessary to see if there is a selection screen or the program will dump
CALL FUNCTION ‘RS_SELSCREEN_INFO’
report = wa_varid-report
field_info = int_finfo
no_selections = 1
report_not_existent = 2
subroutine_pool = 3
OTHERS = 4.
CHECK sy-subrc IS INITIAL.
**This is an amazing FM by SAP, it will give you all the variant values.
CALL FUNCTION ‘RS_VARIANT_CONTENTS’
report = wa_varid-report
variant = wa_varid-variant
move_or_write = ‘W’
valutab = int_valuetab
variant_non_existent = 1
variant_obsolete = 2
OTHERS = 3.
LOOP AT s_abkrs.
READ TABLE int_valuetab INTO wa_valuetab WITH KEY low = s_abkrs-low.
IF sy-subrc EQ 0.
wa_output-prog_name = wa_varid-report.
wa_output-variant = wa_varid-variant.
wa_output-value = wa_valuetab-low.
APPEND wa_output TO int_output.
That is the end of the core logic, you can display the scanned variants in an ALV format.
So next time you get a similar requirement just automate it.