SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software SAP ABAP Programming and HANA Database Tutorials
Development resources, articles, tutorials, code samples and tools and downloads for ASP.Net, SQL Server, R Script, Windows, Windows Phone, AWS, SAP HANA and ABAP, like SAP UI5, Screen Personas, etc.

Install SAP Free

Create SAP Dynamic Variant using Date Calculation

SAP dynamic variant creation is a must for more flexible ABAP reports that are more user-friendly. For example if SAP users are using an SAP program which displays current date's orders, in order to prevent them to choose the today's date from select screen everytime they execute the report. ABAP developers can create dynamic variant in SAP for that report, so that the date select option will always display today's date (current date)

Actually a dynamic variant uses a variable and a calculation formula to set the value of the selection option variable on the screen every time the report is called.

In this ABAP tutorial, I'll try to define dynamic variable for date selection-option so that it will always display 6 months earlier than today.

Call SAP transaction SE38 just as you will run the target ABAP report.
Type the ABAP report name into the Program textbox in SAP SE38 transaction screen.
Do NOT press Enter or F8 function key. Instead on the top menu where icons and buttons are listed, you will see Variants button. Press Variants button in order to create dynamic variant for your ABAP program or to modify an existing variant.

display SAP variant for ABAP program

When you pressed Variants, the next screen will let you select the SAP variant for the ABAP report that you will configure as a dynamic variant. This screen is named as "ABAP Variants - Initial Screen" as you see in below screenshot.
You can select the possible SAP variants defined for the related SAP program by pressing the F4 for the value help screen. Or you can just type a name for your dynamic SAP variant, and press the Create button next to the Variant textbox.

I will change the SAP variant named ZTF0_Yearly and define a dynamic date for the ABAP select options. So after selecting the variant name, I selected "Value" select option and then pressed Change button to make the changes

choose variant name for ABAP report

ABAP developers are now ready to configure SAP variant select option values using the below screen. I want to configure the date field so that it will be dynamically calculated and displayed every time the ABAP report screen is called with this SAP variant. The date select option is set to a static value currently. We will change it with a dynamic calculation.

Before continue with the next step, you can provide static values that are needed for selection options

maintain variant for ABAP report

In order to modify the SAP screen select option for date field, click on the date select option on the screen.

choose selection field for dynamic variant

After the related select option field is selected by placing the cursor onto that field, press the Variant Attributes button which is on the top icons and buttons menu

SAP variant attributes button

The SAP variant configuration screen is displayed. You will see a long list of parameters and select option attributes that can be configured by just marking the checkboxes for that variant. It is also possible to define a dynamic variant calculation rule on this screen. I'll now show ABAP developers how to set the value of the date select-option field dynamically to 6 months before than the current date.

The date select option field is S_ERDAT. By configuring the Selection variable column properties, ABAP developers can create a dynamic variant for their ABAP reports.

Just click on the Selection variable column and from value help screen choose "D" as type of variable which means D: Dynamic date calculation.

I'll not continue with this ABAP tutorial with the T, variable type which means T: Table Variable from TVARVC. This is a topic of an other ABAP tutorial.

Dynamic date calculation for variant

Besides T and D a new variable type X is added on SAP systems which is as follows:
T: Table Variable from TVARVC
D: Dynamic Date Calculation (Local Date)
X: Dynamic Date Calculation (System Date)

variant types for dynamic calculations

ABAP developers can use the following Dynamic Date Calculation formulations in order to create SAP dynamic variant variables.

Dynamic Date Calculation formulations:

Current Date: Always displays the current date when the screen is called
From month start to today: Defines a range of dates between the first of month to today

Current date +/- ??? days: Calculates a date by adding or substracting a predefined amount of days. I'll use this option to set a dynamic date which is 180 days before today. That is nearly 6 months before today.

Current date +/- ??? work days: Calculate a second date by adding (or substracting) a fix amount of working days from current date
First day of current month: Displays the first day of current month
nth working day of current month: Displays the Nth working day of current month
First day of next month: Displays the first day of the next month
First day of previous month: Displays the first day of the previous month
Last day of previous month: Displays the last day of the previous month
Last Day of the Current Month: Displays the last day of the current month
First quarter ????: Displays the first quarter as a date range
Second quarter ????: Displays the second quarter as a date range
Third quarter ????: Displays the third quarter as a date range
Fourth quarter ????: Displays the fourth quarter as a date range
Current date - xxx,current date + yyy: Displays date range calculated between by substracting xxx days from today and adding yyy days to current date
Date - xxx, Date + yyy (work days): Makes the same formulation as above calculation but this time using work days
Previous month: Shows the previous month as a date range period
Current period: Shows the current month as a date range period
(Beginning of mth-xx months, end of mth+yy months):

You can see the dynamic variant configuration for the S_ERDAT select field on the below screen. The Sign is selected as I (inclusive) among I/E. E stands for exclusive.
The Option is "<=" which is for "Less than or Equal to"
And for the parametric number of days, I provided the 180 days which is approximately 6 months.

dynamic variant date calculation configuration

This is after the dynamic variant configuration is completed for date select option field in your SAP program select-options screen

dynamic date variant calculation for 6 months

I hope to answer the question "how to create dynamic variant in SAP selection screen" for date fields using a date calculation formula in this SAP tutorial.

Create Dynamic Date Range in Program Variant

What if the developer wants to create a date range for a select option dynamically using ABAP program variants. For example, I have a select option field for "Delivery creation date" and as ABAP programmer I want to see the last one year in the select option low and high values dynamically without any change in the ABAP program.

dynamic variant for high select option in ABAP program

Let's start from beginning.
On SAP SE38 tcode, after you enter the ABAP program name, click on Variants

variants of an ABAP program

Type a brief descriptive name for the report variant and press Create

create new variant for ABAP program

If there are some required fields among select options, enter valid input values and then save the variant.
The delivery creation date is a required field for my sample case.
I entered some dummy values at the moment. Later I'll let SAP system to populate the date range (low and high values for the S_ERDAT) automatically via dynamic variant.

edit variant values

To save the entered values press F3 (Back icon) and when you are asked to save the variant select option values, press Save.

When the variant attributes screen is displayed, a similar screen will be displayed. We will provide details in "Selection variable" and "Name of Variable" fields to create a dynamic variant select-option for the date range in following steps.

variant attributes for creating dynamic date range select option

Press the F4 Help icon at field "Selection variable" for the select-option fields of date type.
A list of Variable Types will be displayed.
ABAP programmers can choose D, or X for example at this step.

create default date range using dynamic variant

As the second step, at field "Name of Variable" press F4 to see possible options.
First options provide single default value for LOW option of the selection screen field.
But the options at the bottom of the list, they provide two default values; one for -LOW and one for -HIGH part of the range objects.

For example:
Current date - xxx, current date + yyy
Date - xxx, Date + yyy (work days)
(Beginning of mth-xx months, end of mth+yy months)

I will choose the option "Current date - xxx, current date + yyy" and use 365 for xxx and 0 for yyy parameters.

create dynamically calculated range for date select option

This selection will create default values for the delivery creation date since 1 year back up to current date

date calculation parameters for dynamic variant

Save the changes on the variant attributes

If the ABAP developer or SAP user executes the target report with this variant, the default values will be as assigned for the period of last year automatically by the dynamic variant.

SAP Tutorials

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table

Meetup Sunumu 1 meetup

Related Articles and Tutorials(http://www.kodyaz.com/sap-abap/create-sap-dynamic-variant-using-date-calculation.aspx)
Check Existence using ABAP SELECT
ABAP LOOP Statement with At New and At End
Complete List of SAP Modules
Free Adobe LiveCycle Designer Download
Convert Smartform to PDF in Print Preview Mode
Create Business Object in SAP
Delete All Data from SAP Database Table
How to Debug Popup Screen in ABAP
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
ABAP Tutorial - ABAP String Split Example Code
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
Email Spool Request using SAPOffice - Spool to PDF
How to Create SAPScript Text using SO10 Transaction Code
How to Set Start Transaction in SAP GUI
How to Display SAP Graphics using SE78 Transaction Code
ALV Grid Color - Table Row Background Color in ALV List
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
SAP Smartforms - How to Call Smartform within ABAP Program
ABAP Tutorial - SAP Split and ABAP Split String Function
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
Set Default Single Values List for SAP Selection Screen Parameter
ABAP Debugging using Log Point and Break Point
ABAP RegEx for ABAP Regular Expression to fetch Date from String
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
ABAP Shared Memory Objects Tutorial with Sample ABAP Code
ABAP Try Catch for exception is neither caught Code Inspector Error
Add Year, Month or Day to Date Variable in ABAP using RP_CALC_DATE_IN_INTERVAL
Add Web Dynpro Applications to SAP Favorites Menu
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
ABAP Authority-Check Object For User Other Than Current
SAP Code Inspector for ABAP Break-Point Statement
Call Function Module using RFC Destination in ABAP
Change Fields for Selection in SE11 ABAP Data Browser
Compare Code in ABAP using SE39 SplitScreen Editor
Connect SAP from Eclipse using ABAP Project
How to Spell Numbers using ABAP Spell_Amount Function Module
Convert the table using the Database Utility (SE14)
Convert Sales Unit into Text using Function Module in Target Language
ABAP Code Inspector Check Variants for HANA Migration Optimization
Create SAP Dynamic Variant using Date Calculation
Create Scheduled Job using SAP SM36 Transaction
Create Search Help in ABAP for Web Dynpro Component
Create Transaction Code for Web Dynpro Application
Create SAP Transaction to Maintain ABAP Table using SM30
Create Transport Request for Text Translations using RS_LXE_RECORD_TORDER
Database Hint Pseudo-Comment for SAP Code Inspector
Delete Entries in NAST Table using RSCLNAST ABAP Program
List Locks in SAP system using SM12 Transaction Code
Dynamic Programming using Field Symbols in ABAP Reports
Prevent DYNPRO_SEND_IN_BACKGROUND Error in Background Process
Enable Remote Debugging in ABAP using RSRDEBUG
Execute ABAP Program Automatically After Transport Request Import
How to Execute SAP Program in Background Task
Export Graphics from SE78 SAP Form Graphics Administration using ABAP program
How to Export IDOC as Excel and Save as Local File from WE02 Transaction
Export SAP Spool Requests as PDF using SP01 Transaction
How to Find Internal Table Row Count in ABAP
How to Find SAP Role Users Assigned for Transaction Code
Export SAP Data to Fixed Length Text File
Get Fullname of SAP user using Function Module in ABAP Program
How to Delete Standard Text using SO10 SAP Transaction
How to Find User Exits in ABAP Codes of SAP Transaction
Read Integer and Decimals of a Numeric Value in ABAP Programming
How to Transport SAP Graphics using SE78 Transaction
Import and Export SO10 Standard Text using RSTXSCRP ABAP Program
Main program for include RV61Bxxx not found
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Primary key change not permitted for value table
Business Document Service Error: Error when accessing graphic (BDS), RC = 5
Read Pricing Condition Text using ABAP in SAP Sales Document Output
Read Text Symbols in Specific Language using ABAP RS_TEXTPOOL_READ
Get SAP Document Flow using SD_DOCUMENT_FLOW_GET ABAP Function Module
SAP Purchase Order Tables, Transaction Codes and Output
Graphics White Background Displayed Grey on SAP Smartform Output
Export Table Contents into Text File and Download File
SE63 Smartform Translation and Export using SLXT Program
Search and Find SAP Transaction Code using SE93 or SEARCH_SAP_MENU
SAP Code Inspector Error: Select For Cluster Table Without Order By
ABAP Select Statement using Space instead of Null or Initial
SAP Code Inspector: Select-Statement can be Transformed
ABAP Tutorial for SET and GET PARAMETER ID Command
ABAP CONVT_NO_NUMBER Error on SP01 due SP01_WARN Parameter
How to find string length using STRLEN ABAP string function
ABAP Submit Report to Run Another ABAP Program within Code
Unicode Character Problem in IFS File Interface
Web Dynpro Text Translation using Assistance Class
Transport Variants of an ABAP Program into Workbench Request
TVAP Item Category and SAP Table TVAPT for Text Translations
Unlock Objects Locked in Request or Task using Transport Organizer Tools
Code Inspector: Unsecure use of FOR ALL ENTRIES
Update Multiple Variables in ABAP Select Single Statement
Update Database Table Data using ABAP SE16N_INTERFACE
VF31 SAP Transaction to Reprocess Billing Output Messages
Function module is not released for the Internet
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement
Activate Fixed Point Arithmetic Flag for Open SQL Statement

Copyright © 2004 - 2020 Eralper YILMAZ. All rights reserved.
Community Server by Telligent Systems