Application Development and Automation 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: 
Read only

Declare constant dynamically

Former Member
0 Likes
2,061

Hi all

Is there any way to declare a constant ,dynamically (ie base on a condition).

Regards

Prabumanoharan

8 REPLIES 8
Read only

Former Member
0 Likes
1,433

why do you want to use a constant for this purpose....a constant would mean it will have a single value. So whatever be the condition , the value of the constant will not change.

based on your condition, you can work with a normal variable and change its value. Or, you can declare multiple constants and use the appropriate one based on your condition.

if this does not answer your question...can u pls explain the requirement in more detail in terms of what you want to do?

Read only

0 Likes
1,433

i've two fields (select-options) in the selection screen, any one of that fields will be displayed for input at a time (based on a condition), i've used a flag to identify which field is being displayed, it is the base for the data selection, this is working fine in foreground, but when scheduled in background it always considers the field A and selects data based on that.

if i could declare a constant dynamically , checking the flag , i'll declare the constant(with value 'X') . If run in background , based on the constant value, set the data selection based on the Field B.

This is for the option Program -> Execute in background ,

this will return fcode SJOB, checking that in AT SELECTION-SCREEN , i've to declare the constant.

Regards

Prabumanoharan

Read only

0 Likes
1,433

I still don't understand how a constant will help here.

if you want to do something when your program is running in background, you can check the value of system variable sy-batch. if the value of this variable is initial, means the program is in online mode, if it has X then it is being run in background....

you can do your checks accordingly. This value will be available in the at selection-screen event.

Read only

0 Likes
1,433

Hi Prabhu,

For your purpose, use a variable with default value and use it in the same manner as you are going to use it as a constant....

Regards,

Kunjal

Read only

Former Member
0 Likes
1,433

no you can not...

if you were able to set CONSTANT values dynamically then it would not make any sense of creating a constant... you can directly use a Variable

Read only

rainer_hbenthal
Active Contributor
0 Likes
1,433

A constant is a constant is a constant.

Read only

Former Member
0 Likes
1,433

Hi

You can not change the Constant's value dynamically.

Instead you define a variable, multiple constants.

And then based on your condition you can dynamically assign the value to that variable

Thnkas & Regards

Mallikharjuna Reddy

Read only

Former Member
0 Likes
1,433

dropped