You probably have used screen variants in the past, but did you know that SAP can provide dynamic values in date fields?  Obviously, this is not very important if your screen does not contain dates.  However, for many of us who work with date sensitive information, the dynamic date trick I’ll show below can save you some time and provide more accurate results.  It is especially helpful for background executions of programs or results that need to have a specific date or date range.

The example below has screenshots from a variant created for an MRP background job, but the logic in defining the dates in the screen variant is consistent for any selection screen.  To get here, run transaction MDBT and click on the create variant icon.

In the popup window, type the name of the variant.

Click “Create” and continue until you get to the screen below.

Above shows the variant after entering all the necessary parameters.  The date defaults to the current date, but is only a static value.  Now we’ve reached the meat of this post – how can we make SAP dynamically change the date?  Once you click save, you’ll be shown the attributes screen (see below).

Please note that the table layout on your display may not look exactly like below.  I have shrunk the width of several columns to enable the capture program to show the ones that I want.  Specifically, there are three columns to the far right hand side of the table that we’ll be working with.

Find the appropriate field in the table – in this example, we are interested in the Planning date”.  In the row for Planning date, highlight the indicated table cell in the third column from the right and click on the dropdown icon or press F4 to show the popup menu for the selection variable.

Double-click on the line “D” for “Dynamic date calculation”.  Alternatively, click once on the line “D” and click the green check (or press F2) to continue.

Note: You will notice that another line is available with the description “Table Variable from TVARVC”.  Describing the possibilities with this selection is truly beyond the scope of this post.  Suffice it to say that you could add custom variables that could be populated via the screen variant.  I have not personally used this table for variants, but I have worked with developers who use it regularly.

You can now see a “D” in the third column from the right.  At this point, the system knows that we want this field to be dynamically determined.  However, we are not finished.  We need to tell the system how to determine the date.  In the same table row, highlight the indicated table cell in far right column and either click on the dropdown icon or press F4 to show the popup menu for the selection variable rule.

Above is the resulting popup window.  Select the desired rule from the list (double-click or select and green check/F2).  In this case, I selected “Current Date”.  It means that during the next execution of this program using this variant, the system will populate the current system date into the field.

Looking at the other options in the rules, you’ll see that SAP provides a significant amount of flexibility for date determination.  All should be self-explanatory.

You can now see that the field on the far right contains the dynamic date rule – in this case “Current Date”.

Above is the resulting screen.  Notice that the date field is grayed out?  Once you’ve defined a field to be determined dynamically, the field is no longer available for input.

What about fields with from/to dates?  Look at the example below from VL06O where we’ll define a dynamic date in the actual goods movement date using both fields.

As before, identify the selection screen variable as having a dynamic date by choosing D in the third column from the right.  Then open the dropdown on the far right column.

Compare the screenshot above to the one shown in the first example and you’ll find it looks similar, but there are two additional columns in addition to the new rules available.  These extra columns are only applicable to the rules that we saw previously.  If you recall, those rules determine single dates.  The first column allows you to specify whether the date is included or excluded; the second column allows you to specify an operator (e.g., equal to, less than, greater than or equal to, etc…).

In the example above, I selected I (include) in the first column and GE (greater than or equal to) in the second column for the rule “Current Date +/- ??? days”.  Click the green check to continue and another popup window appears where you enter the number of days (positive or negative).

I entered negative seven days.  So my expectation is that the system will return a date seven calendar days in the past (this rule does not consider the factory calendar) and will have an operator showing greater than or equal to.

Above shows how the rule appears in the variant now.  Let’s see what it looks like in the transaction:

Let’s look at another rule which populates values in both the from and to fields, like the one indicated with the arrow below.  In this case, you will be prompted to fill in values behind and ahead of the current date.  If you do not enter a value for either, the system assumes you mean zero and uses current date in the results.

I have entered seven days in the past and three days in the future.  Let’s see what it looks like in the transaction:

As you play around with the other rules and options, I think you’ll find this dynamic date calculation saves you time and effort.  I’ve found it particularly useful for reporting purposes and in background jobs that pull time-sensitive information.  FYI – for fields with time values, there is a dynamic time determination.  Obviously, it will only appear in the variant when you attempt to change a time field type.  The number of rules is significantly shorter than for dates, but depending upon your needs could be very useful.