Whenever we have to run an SAP Program for which selection data needs to be entered, and in case same data needs to be entered along with the program run for every run, SAP offers option to save sets of input values for programs as “variants”. Therefore, an SAP Program and a variant name can be provided to setup a batch job; the variant taking care of the selection data in the program fields.
Sometimes a few fields in such variants need not keep the same data for the frequent run, but there is a need for “dynamic” update of selection data, for example dates. So a batch job will be scheduled as a one-time activity but for today’s run it takes a particular date; and for tomorrow’s run, it takes updated and new date, without the need to enter or update the variant every day. This is the concept of “dynamic variants” which we shall discuss in this document.
Process to create a dynamic variant is explained as follows:
1. Go to SE38 transaction; enter Program name and execute; then enter all the values in the input fields which are needed and click on “Save” button.
2. System will take you to variant screen; enter the name and description of the variant.
[Image 1- Variant attributes]
3. Select the line of your date – options field from the list and scroll right
4. Double click on “selection variable” column and select “D”
[Image 2- Variant attributes]
5. Double click on “Name of variable” last column and select “Current date – xxx,current date + yyy” system will provide you popup with “Enter a value xxx” and “Enter a value for yyy” and enter value 7 in xxx and 0 in yyy and save the variant .
[Image 3- Variant attributes]
After making the above changes, the “date range” in the date field will keep updating itself as “7 days before current date (date on which program will be run as part of batch job)” till “current date”, meaning it will select last 1 week.
[Image 4- Variant attributes]
Similarly, we can use any other options available in the screen, as per our requirement, namely:
- Current Date
- From month start to today
- Current date +/- ??? days
- current date +/- ??? work days
- First day of current month
- nth working day of current month
- First day of next month
- First day of previous month
- Last day of previous month
- Last Day of the Current Month
- First quarter ????
- Second quarter ????
- Third quarter ????
- Fourth quarter ????
- Current date – xxx,current date + yyy
- Date – xxx, Date + yyy (work days)
- Previous month
- Current period
- (Beginning of mth-xx months, end of mth+yy months)
Therefore, using any of the above options available, we can create a dynamic variable suitable for our respective needs.