0044 - Defining A Default Variant

Moderators: Snowy, thx4allthefish, Rich, ilya

Post Reply
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool

0044 - Defining A Default Variant

Post by 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
* 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.
        report = sy-cprog                "actual program name
        variant = 'SAPDEFAULT'     "default variant name
        variant_not_existent = 0
        variant_obsolete = 0
        OTHERS = 0.
* After the initialization we start the real code of our program in the section 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:

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

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)


Abap KC:http://www.richard-harper.me.uk/Kb

Post Reply