This website is not affiliated with, sponsored by, or approved by SAP AG.

0044 - Defining A Default Variant

Moderators: Snowy, thx4allthefish, Rich, ilya

0044 - Defining A Default Variant

Postby Rich » Sat Mar 28, 2009 8:49 am

Defining a default variant.

There are 2 different ways to define a default variant.
Method 1 - By assigning a variant directly on the transaction code. This is the easiest way but if the program was called from another program or directly from SE38, the default variant will be ignored.

Method 2 - By assigning a variant in the code, here is a short example of this:

Code: Select all
* The code must be in the INITIALIZATION section
INITIALIZATION.
* We must check if a default variant was already entered by the user in a batch job or in the transaction code
* we do not want to overwrite it ! the current variant is store in the sy-slset field
IF sy-slset IS INITIAL.
    CALL FUNCTION 'RS_SUPPORT_SELECTIONS'
    EXPORTING
        report = sy-cprog                "actual program name
        variant = 'SAPDEFAULT'     "default variant name
    EXCEPTIONS
        variant_not_existent = 0
        variant_obsolete = 0
        OTHERS = 0.
ENDIF.

* After the initialization we start the real code of our program in the section START-OF-SELECTION
START-OF-SELECTION.


Here is how to create a the variant "SAPDEFAULT" always using as a default date today minus 30 days:

Goto -> variant -> save as variant

Here is the standard variant save screen. Enter a name and a description and press "execute". Very few know how to handle the weird looking bottom part of this screen:

Image

  1. Check the variables for which you want to maintain default values
  2. Choose selection variables button and see the next one

Image

The first part is a legend of the column headers (T D B Z). Because we want to create a date, we double click on the traffic lights of the column "D" for Dynamic date calculation. when the traffic light turn green, you can press on the down arrow in the "T" column. This will bring a popup with all possibilities you can imagine for defaulting a date. From a usability point of view, this is not really good screens but nevertheless, this tool is very powerful.

(Courtesy Dany Charbonneau)
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com
Rich
 
Posts: 7112
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool

Return to ABAPers

Who is online

Users browsing this forum: No registered users and 1 guest





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.