Skip to Content
Author's profile photo Anup Patil

Dynamic date selection in Variants

Dear All,

While answering one of the post related to screen variant creation/setup for SAP transactions, I thought of preparing a small document on the same and sharing the same on forum. It might be possible that most of the SAP guru’s knowing this function but this blog will be helpful to new comers in SAP… 🙂

So what’s it about… It’s about creating screen variants for SAP transactions with dynamic selections as desired.

Take an example of widely used QM transaction-QA32.

1.JPG

Above QA32 screen has a field-Lot Created On, with a date range already populated on initial screen. So how these dates are appearing? And can I set my own date range here? Can I have any other fixed value on the same screen e.g. Plant ? Number of questions can come up in mind…

To answer, yes, a respective user can set his/her own variant with specific values. I’m planning to explain it below, with few screenshots.

On Tcode-QA32 screen, click on ‘SAVE’. System will display an existing variant as below, showing a variable set for a particular field, if any.

Put your own Variant Name along with meaning.

2.JPG

As seen on above screen there are few functions available as SAP standard in variant attributes. E.g.

Only for Background Processing: If you select the field Background only, the variant can only be executed in the background. Otherwise, it can be run both in the background and online.

Protect Variant: If you select this field, the variant can only be changed by the person who created it or last changed it.

Based on requirement one can select/deselect it.

Search for the field on which a dynamic/variable date needs to be setup. Go to column-Type of selection variable (Third from right hand side) and click on the dropdown icon or press F4 to show the popup menu for the selection variable.

3.JPG

Double-click on the line “D” for dynamic date calculation. Selecting ‘type of variable’ is nothing but we are declaring the field which need dynamic date calculation.

4.JPG

To mention a dynamic value, we need to select a Variable. Click on the dropdown icon or press F4 on column-Name of variable to show available selection variables.

5.JPG

You need to select a sign field which allows to enter either “I” or “E”.

  • “I” (Inclusive) means that the single value or range you specified is selected itself.
  • “E” (Exclusive) means that the single value or range you specified is excluded from the selection.

The default is “I”.

Along with the sign field, need to select ‘Option’. With the operators in this field, you specify whether the entered values are to be used as a single value, range, or search string for limiting data selection. Possible operators are: EQ- Equal: Single Value, NE- Not Equal: Everything Apart from the Specified Single Value, LE- Less or EQUAL: Everything <= Value in Field LOW, GT- Greater Than: Everything > Value in Field LOW, GE- Greater or Equal: Everything >= Value in Field LOW and LT-Less Than: Everything < Value in Field LOW.6.JPG7.JPG

Once you fill in selection variables on screen, click on ‘SAVE’.

On transaction selection screen, click on tab-Get Variant (Shift+F5) and select your own variant. Depending upon selection variables, system will populate a particular field with required values (as below).

8.JPG

Similarly, you can even choose other operators and check effect. 9.JPG

I chose option operator as ‘Less Than’ and variable as ‘Current Date +/- ??? days’. System will come up with a pop-up window and ask value for days.

10.JPG

Put value with sign ‘-‘ in order to have date in past from current date whereas sign ‘+’ for future date.11.JPG

Click on ‘SAVE’ & go back. Select your Variant to check.12.JPG

In addition to above, we can chose a variable to set a date range. For the same, choose Variable name: Current date – xxx, current date + yyy.13.JPG

System will ask for date values as below.

14.JPG

Press Enter.

15.JPG

Click on save and go back (F3). Select your variant.16.JPG

And you will see dates as per Variable selected (shown below).

17.JPG

Similar way, one can try different options of variables.

Along with it, just by adding field values on initial screen and saving the variant, system will put some fixed values. E.g. one can have his/her Plant as fixed value in his/her variant.

Hope this will help.

Thanks & Regards,

Anup

Assigned Tags

      48 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Anup Patil
      Anup Patil
      Blog Post Author

      Forgot to mention but comments will be appreciated... Thanks.

      Author's profile photo Former Member
      Former Member

      Good job

      Author's profile photo Andrea Fuschetto
      Andrea Fuschetto

      Hello Anup:

       

      I'm changing my Planning area in both DP and SNP from 2 years to 5 years in monthly buckets.  I need to release my forecast from DP into SNP for all buckets.  In the variant, I see the choice for "Current day +/- days".  When I try to enter any value over 1000 days, I get an error saying it can't accept it (too long).

      Entry too long (enter in the format __~V)

       

      It appears that only 3 characters are accepted, so 999 is my limit.  But this is only 33 months instead of 60 months.

       

      Do you know how I can get an option to enter "Current month +/- months"?  Then I could say "60 months"

       

      I'm using /n/sapapo/mc90 to release the fcst from DP to SNP.

       

      Thanks.

      Andrea

      Author's profile photo Thomas Zloch
      Thomas Zloch

      At the bottom of the choices for dynamic date calculation, I can see

       

      "(Beginning of mth-xx months, end of mth+yy months)"

       

      Try this for your scenario.

      Thomas

      Author's profile photo Andrea Fuschetto
      Andrea Fuschetto

      Hi Thomas:

       

      I wish I had that option.  In APO (mc90 and also in lcout), these are my choices.  (I'm selecting from Current Date row, which is about 7 or 8 down in the list):

       

      Current Date

      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

       

      Do you know how I can get the "Beginning of mth-xx-months, end of mth+yy months" option to show?  That would be perfect and exactly what I need.

       

      Thanks.

      Andrea

      Author's profile photo Thomas Zloch
      Thomas Zloch

      I don't know in what way APO is special in this regard. For "normal" selection variants there is a function module RS_VARI_V_INIT which collects the available options for dynamic date calculation.

       

      I have SAP_BASIS 700 to 731 systems here, and all have the option I quoted above. What is your SAP_BASIS level?

       

      I once had the idea to enhance this function module to include a new option at the end (driven by a new Z-function module that would contain the calculation logic), but enhancements there are forbidden by SAP with a hint to "central basis" component.

       

      Thomas

      Author's profile photo Andrea Fuschetto
      Andrea Fuschetto

      They must have used different programmers for APO because it is very different than ECC.  I see tons of other choices in ECC, but only the ones I listed above in APO. 

       

      I'm going to post in an APO forum and see what suggestions I get.

       

      Thanks for the response, though.

      Andrea

      Author's profile photo Jason Duncan
      Jason Duncan

      Great post here. I wish I had this the first time I had to setup a variant. It would have made it much easier.

      Author's profile photo Anup Patil
      Anup Patil
      Blog Post Author

      Thanks Jason for your appreciation and apologies for posting this a bit late... 🙂

      But still you can go-in and change/overwrite your existing variants in SAP.

      Thanks again.

      Author's profile photo Former Member
      Former Member

      How do I get all the dynamic date variables.  For instance, I do not have any that say "quarter".   I only have these:

      Current Date

      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

      Author's profile photo Jeevan Sagar
      Jeevan Sagar

      What version of SAP are you on?

      Author's profile photo Former Member
      Former Member

      Actually its in APO.  But I am asking how to create new ones in general.  What if I wanted a new dynamic variable for end of the year.   I know I can use TVARV variables.  But is it possible to create new dynamic date variables.

      Author's profile photo Sven Ringling
      Sven Ringling

      Hi Ken,

       

      I happened upon this post only now, but maybe it's still interesting for you:

      if you need any additional variables, you can define them yourself in table TVARVC.

      I the popup "choose selection variables" shown above you select T rather than D to access those variables.

      However, you now need to take care of them being updated yourself. Could be manually in transaction STVARVC or SM31, but usually you'd have a custom ABAP running in Batch every night (or whatever frequency is needed) to update the values.

      In older versions (R/3 4.5, if I remember correctly, not sure about APO), it was TVARV rather than TVARVC. The old table was not client dependant.

      Author's profile photo Former Member
      Former Member

      Dear,

       

              Very informative !!

      Author's profile photo Pawan Kesari
      Pawan Kesari

      Good document.

      Author's profile photo Samy Magdy
      Samy Magdy

      Nice one.

      Author's profile photo Thanga Prakash
      Thanga Prakash

      How can I create a dynamic variant for date only in TO, like below.

       

      Date  <BLANK>  TO  <Current date - 365 days>

      Author's profile photo Thomas Zloch
      Thomas Zloch

      You would rather do it like "Date LE <Current date - 365 days>" using only the FROM date.

       

      Thomas

      Author's profile photo Thanga Prakash
      Thanga Prakash

      If I do like that I will end up like below.

       

      Created on 19.03.2013 TO <blank>.

       

      My requirement is like FROM should be the initial date and TO should be current date - 365 days like.

       

      Created on <blank> TO 19.03.2013.

      Author's profile photo Thomas Zloch
      Thomas Zloch

      But this means you want everything up to 19.03.2013. You can set "LE" (less or equal) as "option" for the dynamic date variant "current date +/- ??? days" and that should do it.

      Thomas

      Author's profile photo Former Member
      Former Member

      Thanks, great post. I have a report which requires a date range including a working day and a non-working day. I need the 'date from' to be working day - 1 and the 'date to' being yesterday.

       

      This is so that on a Monday, document postings from Friday to Sunday are picked up. Does anyone know if this is possible via SQ02 if not in the variant?

       

      Thanks

      Author's profile photo Narayana N
      Narayana N

      Dear Anup,

       

      Good effort keep it up

       

      Regards,

      Narayan N

      Author's profile photo Douglas Lin
      Douglas Lin

      Thanks Anup , this is really helping me to understand the dynamic data .

      Author's profile photo Former Member
      Former Member

      I knew about this before, but it's great to have it written down. Great post!

      Author's profile photo sreehari tokala
      sreehari tokala

      nice document but i need Segment field where i can get his field.

      Author's profile photo Former Member
      Former Member

      Thank you.  Learned something new today.

      Author's profile photo Poonam Chawla
      Poonam Chawla

      Hi,

      I have a requirement for date range where the first date is fixed (01/23/2013) and last date is current date which varies depending on sy-datum.

      Which option will help me to get this resolved.is it possible with dynamic selection screen?

      Kindly reply.

      Author's profile photo Anup Patil
      Anup Patil
      Blog Post Author

      Hi Poonam,

      You can simply put in date value as 'greater than or equal to 01/23/2013 (your fixed date)' in date field and I think it should work.

      So whenever you run your report/program, system will take documents from that date (01/23/2013) to current date on which you're executing it.

       

      Hope it helps.

      Thanks.

       

      Kind Regards,

      Anup

      Author's profile photo Poonam Chawla
      Poonam Chawla

      Thank you Anup

      Author's profile photo Kashi Yadaram
      Kashi Yadaram

      Excellent...wish I know this before.

       

      Kashi

      Author's profile photo Former Member
      Former Member

      Exactly what I needed Thank you 🙂

      Author's profile photo Former Member
      Former Member

      Hello All,

       

      My requirement is to select the variant "Current date + 0 , Current date + 50" in working days but when i select the variant Date - xxx, Date + yyy(work days), it doesn't work.

      Could anyone help or give any suggestion regarding this?

       

      Thanks,

      Shashank

      Author's profile photo Anup Patil
      Anup Patil
      Blog Post Author

      Hi Shashank,

      I've given printscreen of the requirement same as yours & definitely it would work.

      Could you please check again in my blog about this & try?

       

      Thanks.

      Author's profile photo John McKee
      John McKee

      Hi

      This is excellent material here.

      However, I would like to know how we can use this with the updated data browser SE16N?
      I have a requirement to run an extract for some HR data from table PA0001.
      I want to extract all records where End Date is greater than the current date -1 and Start Date is less than Current date +1, effectively status as at today, eg ENDDA > 09.07.2015 and BEGDA <11.07.2015 meaning status as at 10.07.2015 - but to have this update dynamically at run time.

       

      I know how to do this in SE16 and save as a variant using Dynamic Date Calculation.

       

      But how do you do this with and SE16N variant and schedule with SE16N_BATCH.  I can't find where to store these parameters with SE16N?

       

      Can this be done?

       

      John McKee

      Author's profile photo Anup Patil
      Anup Patil
      Blog Post Author

      Hi John,

      Thanks for your comments above. Also to mention, I never tried this function in SE16N but shall check. Thanks.

      Author's profile photo Swati Kaushal
      Swati Kaushal

      Really good stuff.. thanks

      Author's profile photo Former Member
      Former Member

      Very Useful

      Author's profile photo Timothy Bondy
      Timothy Bondy

      Thank you this was very helpful

      Author's profile photo Former Member
      Former Member

      Hello,

       

      Need your suggestions to understand what am I doing wrong here.

      I use a ZZ T-code which provide me a list with Purchase Orders, then I created a Variant to display only the last working day PO's created, and it is working well as your guidance above.

       

      The problem appeared when I created a daily basis Job on SM36, to run this Variant with the dynamic date, the result list of the Job display always the same day as the Job creation date, instead of getting updated after the days past by.

       

      If someone can help me with this, it will be of great assistance.

       

      Best regards

      Author's profile photo Nimbl AMS Nimbl AMS
      Nimbl AMS Nimbl AMS

      Hi,

      What if we want these dates in "Exclude" selection column? How can we do that?

       

      Thanks,

      Author's profile photo Former Member
      Former Member

      Very useful article but it is possible to set first and last date of current week? I can't see any mention about it.

      Author's profile photo Subhadeep Kar
      Subhadeep Kar

      Helpful Anup.

      Author's profile photo karan kothari
      karan kothari

      Hi

      I am having requirement to create screen variant for a transaction that is executed based on fiscal year parameter. I want to make it dynamic.

      For eg. if I run the transaction today then it should executed for current fiscal year "-2".

      How we can do the same? Please Guide!!

      Thanks
      Karan 

      Author's profile photo Former Member
      Former Member

      many thanks for share this Anup

      Author's profile photo Former Member
      Former Member

      Very helpful. Thanks for Sharing.

      Author's profile photo Former Member
      Former Member

      Dear Anup.

      Many thanks for this useful document !

      JF

      Author's profile photo purna sabbineni
      purna sabbineni

      Hi there,

      I have a report, which contains a date field (type: Parameter), in this field, I want to save the variant as "the last date of next month" dynamically.

      Could anyone help or give any suggestions regarding this?

       

      Regards,

      Purna Sabbineni

      Author's profile photo Mohamed Chamlal
      Mohamed Chamlal

      Thank you for this great article

      it certainly makes life easier