Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Set the default value for a date parameter with a variable

Former Member

Hey everyone,

I want to set a default value for a parameter with a variable, but that doesn't work.

DATA: start_date TYPE sy-datum.
start_date = '20170510'.
PARAMETER: p_sdate TYPE sy-datum OBLIGATORY DEFAULT start_date.

This is just an example, normally the variable 'start_date' is automatically generated depending on the week you select.

The above code sample leaves the paramter field empty when I run my report. I don't understand this, because those two examples work fine:

PARAMETER: p_sdate TYPE sy-datum OBLIGATORY DEFAULT '20170510.
*or
PARAMETER: p_sdate TYPE sy-datum OBLIGATORY DEFAULT sy-datum.

Anyone knows what I'm doing wrong here?

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

"Anyone knows what I'm doing wrong here?"

Yes, of course. You miss one of the most basic features of ABAP, namely that you cannot expect a program to simply process the statements sequentially. First, you must understand the difference between declarations and operational statements. Second, you must know the implicit modularization of any ABAP program and how it is executed by the runtime environment.

Look up how a program is executed after SUBMIT and you'll see, that your assignment is not carried out before sending the selection screen. Debugging also shows that.

Implement the assignment during the INITIALIZATION or the AT SELECTION-SCREEN OUTPUT event and not implicitly during START-OF-SELECTION as you do.

2 REPLIES 2

horst_keller
Product and Topic Expert
Product and Topic Expert

"Anyone knows what I'm doing wrong here?"

Yes, of course. You miss one of the most basic features of ABAP, namely that you cannot expect a program to simply process the statements sequentially. First, you must understand the difference between declarations and operational statements. Second, you must know the implicit modularization of any ABAP program and how it is executed by the runtime environment.

Look up how a program is executed after SUBMIT and you'll see, that your assignment is not carried out before sending the selection screen. Debugging also shows that.

Implement the assignment during the INITIALIZATION or the AT SELECTION-SCREEN OUTPUT event and not implicitly during START-OF-SELECTION as you do.

0 Kudos

Thank you for your quick reply! You're completely right, I really did miss the understanding of this. I looked it up and now everything works fine and just like planned.

Thanks for your help!