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

Dynamically changing variables

Former Member
0 Likes
778

Is it possible to contain a DATA statement within an IF statement, or similarly define variables according to existing data?

I am attempting to fix a problem with a program for calculating index values. Some systems use indexes with two decimals, others use indexes with four decimals. I don't want to make the calculations using four decimals all of the time, but I also don't want to write IF statements wherever the index is used, to check whether it is a two or four decimals index. Is there a way to check the number of decimals and define the variable according to the result?

If changing the DATA definition is not possible, perhaps it is possible to accomplish that using constants in some way?

Kind regards,

Itay Horev

SAP Israel Localization Team

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
705

Hi,

You can create a variable of a specifc type at runtime.

DATA : var type ref to data

CREATE DATA VAR TYPE (DYNAMIC VARIABLE NAME).

DYNAMIC VARIABLE NAME could refer to any data type.

Is this what you were looking for.

Regards,

Ravi

Note : Please mark the helpful answers

4 REPLIES 4
Read only

Former Member
0 Likes
706

Hi,

You can create a variable of a specifc type at runtime.

DATA : var type ref to data

CREATE DATA VAR TYPE (DYNAMIC VARIABLE NAME).

DYNAMIC VARIABLE NAME could refer to any data type.

Is this what you were looking for.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

Former Member
0 Likes
705

Hi itay,

1. we cannot write data in IF condition.

2. possibly u can use two variables,

and depending upon the condition,

use either of them.

regards,

amit m.

Read only

Former Member
0 Likes
705

Hi Itay,

If dynamic declaration is not allowed, you can use the following logic. Just try it.

***************************************

If index is 4.

perform calculateindex2 using ind.

else .

perform calculate index4 using ind.

endif.

Form calculateindex2 using ind typ i.

data : index type i decimals 2.

  • Logic for calculation of index

  • you can cast any value to the index.

Endform.

Form calculateindex4 using ind typ i.

data : index type i decimals 4.

  • Logic for calculation

Endform.

Read only

Former Member
0 Likes
705

Thanks to all the repliers.

Using a different logic or two variables is impossible, since there are many many places and many ways in which the variable is used, and making such a repair would take a long time and make the program cumbersome.

The problem has been solved by making a specific repair to the variable type in the customer's system.

Itay