Skip to Content

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.

Selection screen

Selection Screen

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.

The logic.

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’.
  ENDIF.

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.

  ENDIF.

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’
      EXPORTING
        report              = wa_varid-report
      TABLES
        field_info          = int_finfo
      EXCEPTIONS
        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’
      EXPORTING
        report               = wa_varid-report
        variant              = wa_varid-variant
        move_or_write        = ‘W’
      TABLES
        valutab              = int_valuetab
      EXCEPTIONS
        variant_non_existent = 1
        variant_obsolete     = 2
        OTHERS               = 3.

    CLEAR wa_valuetab.

    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.
        CLEAR wa_output.
      ENDIF.

    ENDLOOP.

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.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Michelle Crapo
    Have you tried program RPR_ABAP_SOURCE_SCAN?  I usually just put a Z* for the first parameter.  Then SAPMZ*.   Then let it do it’s scan.  That would compliment your blog nicely.  It wouldn’t find the variants.  Just the information in the code.

    I honestly can say no one has asked me to find a certain variant.  But I’ve bookmarked this in case they do 🙂

    Nice blog,

    Michelle

    (0) 
    1. Michelle Crapo
      Ahh – but then I wouldn’t have been educated.  I do try to search – I’m not always successful.  However I read a lot of blogs. 

      Really this is a how to blog – BUT it adds the story behind the how to, so it becomes a blog.  The pain points were interesting to me because I have never needed to search for variants.

      So this post helped me get the links that you have!  Thank you Andrea!  Thank you Raghavendra Prabhu!

      What a fun way to learn something new.  A great details of the variant hunt!

      Michelle

      (0) 

Leave a Reply