20162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
SAP Tribal Knowledge
Useful Information for SAP Power Users
2011/02/01
Dynamic Dates in Screen Variants
Posted by feimster under SAP | Tags: current date, date, dynamic date, from/to, SAP, screen variant
selection screen, TVARVC, variant |
[8]_Comments
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 Ill 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.
Total Panning: Variants
Click “Create” and continue until you get to the screen below.
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 19—_——E———EE
1 Donate ct
Parte oecssing
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.
80 > =
eccooal|
coo]
aleslclelal |
Bier
loio}
iolopio|
ele
ela
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.
“ss econ
Fedrone
oie |p
100
es
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 2920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
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.
ot
[Secon vara, [Oren ame vara npn US
Blee(e
el
eel]
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.
“edo er sewer vin CSHDe aetna nees
rea ni vse
source
{ia rain net
[Laster ate Covet uo
"00 Data maeal
{00 Fara ces
"00 Userettey
00 Ose enue
ve
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.
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 3920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
‘You can now see that the field on the far right contains the dynamic date rule — in this case “Current
Date”.
‘Maintain Variant: Report RMMRPOOO, Variant 1200 MRP - RGN
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.
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 4920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
‘too
‘00
$000
“000
‘00
"0
“0
{000
“ooo
"00
‘00
000
“00
‘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...).
nan of ate pO Usa Fa)
3
[Goran ron
stay tearm
aaRREE
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 #/- ?2? days”. Click the green check to continue and
another popup window appears where you enter the number of days (positive or negative).
[ame ovate td On Osea 9)
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.
Seg tna i [Sten va [Oporto arate pd On Usa
1000 |r Oa mc
“000 |tsasna ae ® =i
"00 | anec Pna Oa BIO
“00 | as Mie iF
1000 |i Cas omrioae 5 ai fe [Eaton 7 oa
100 eter = ae
Above shows how the rule appears in the variant now. Let’s see what it looks like in the transaction:
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 5920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
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.
‘yeas scent
“00s fF
"00 |tosonn ts
00 aes
“00 |r as
“00 |i ca
1000 |oeten
000 onic | ae
700 fon i
“000 |e piaing es
“100 |areouee mbar
"100 pesca estrae
Thave entered seven days in the past and three days in the future. Let’s see what it looks like in the
transaction:
General Delivery List - Outbound Deliveries
BOOKS D @ dinaindssioand
‘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.
ntps:fsapiribalknowledge.wordpress.com/2011/02I0tidynamic-dates-r-screer-variants 6920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
Advetsoments
Report this ad
Report this ad
8 Responses to “Dynamic Dates in Screen Variants”
1. Eric Says: say
tee
2011/02/16 at 05:06 ace
I’ve been running background jobs using dynamic date variables - exactly as shown in your
screenshots, create the variant, create the variable using D and the current date. I’m running into a
problem though — I'm setting it up to run on a schedule, daily for example, but the current date
doesn’t change like it’s supposed to. It just runs it for the same date every day. Have you ran into
this problem?
Reply.
2. feimster Says:
35
SER
Ses,
2
2011/02/16 at 14:04
In the variant attributes on the line for your date field, check the box for “Save field without
values”. This should force the date calculation to be used rather than the explicit value stored in
your variant.
Repl
3. Dominik Tylezyriski Says:
nitpsisaptrbaknowledge wordpress. comy2011/020 tidynamic-dates-i-screer-varants! 7920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
2011/07/15 at 20:05 aks
‘That's a nice feature of selection variants. Useful for MM period closing - MMPV
transaction.
Reply
4, New Journey Says: ae
2011/08/10 at 12:27,
Hello Guys,
The information above is very helpful but i have a different request from my user i hope you can
help me figure it out...the date range selection for me is the first column i should have a fixed date
(First day of the Year) and the second one is Yesterday (Current day -1). Please help me setting up
this in Variant.
Thanks,
Anonymous
Reply
1. feimster Says: Seat
2011/08/10 at 17:15 SER
Unfortunately, the dynamic date selection does not have an option for beginning of a year ~ so
you may have to save that date as a fixed date in the variant. It also does not allow for multiple
dynamic selections. This prevents you from doing something where you would exclude all
dates that are less than a fixed date (first day of the year) as the first selection and exclude all
dates greater than or equal to a dynamic date (current date) as the second selection. I'll have to
look around to see if you are able to create new dynamic date selections via a user exit.
Reply.
5. nesli Says:
2014/02/11 at 14:29
You can write a report which update the variant variables
in the table TVARVC with defined and hardcoded update logic. And this program will be
scheduled to run nightly in batch before
all other batch programs run that use variant variables. Any job running a program with a variant
using a variable
updated by this program
Reply
6. mnyce@derstines.com Says: ay
2014/05/08 at 19:21.
How can use dynamic date variant to return the most recent single value from a variable date
range in the past? I am working with MEIP and want only the (single) most recent PO cost for a
range of materials. For example any given material may have been purchased one day ago or 60
days ago.
thanks,
Mark
Reply
1. feimster Says:
nitpsisaptrbaknowledge wordpress. comy2011/020 tidynamic-dates-i-screer-varants! 3920162018 Dynamic Dates in Screen Variants | SAP Tribal Knowledge
5
oe
2014/05/10 at 06:19
Mark,
Ses,
BOR,
Unfortunately, I’m not sure that dynamic date selection will work for your requirement, Using
dynamic dates will only work on the selection screen to generate a single date or range of
dates. It would appear that you would like it to act upon the results of that report. I think that
you'll simply need to sort your results first by material and then by PO document date. I
would suggest that you sort materials ascending and dates descending. In that way, you'll see
the most recent doc date (and its associated price) at the beginning of each group of POs for a
particular material. I'm not aware of a function within standard ALV layout functionality that
only shows you the first result after sorting. You could do this within an Infoset if you have the
authorization (and the time) to write one that replicates the results of MEIP. Good luck!
Reply.
Blog at WordPress.com
nitpsisaptrbaknowledge wordpress. comy2011/0210tldynamic-dates-i-screer-varants! 99