‎2006 Apr 24 12:54 PM
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
‎2006 Apr 24 1:03 PM
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
‎2006 Apr 24 1:03 PM
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
‎2006 Apr 24 1:04 PM
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.
‎2006 Apr 24 1:25 PM
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.
‎2006 Apr 25 9:47 AM
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