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

Declaring a variable with a non fixed decimal.

Former Member
0 Likes
690

Hi,

There is a request to follow the number of decimal places from table TCURX depending on the country.

For example,

data: l_decimal type i.

loop at itab.

select single decimal

into l_decimal

where waers eq itab-waers.

data: X type p decimal l_decimal.

X = 5.32424 x 3.2452542 / 2.3242352

endloop.

The declaration of the variable with the decimal using another variable is not allowed.

Do you have any other suggestions on doing this?

Thanks

1 ACCEPTED SOLUTION
Read only

chaiphon
Contributor
0 Likes
537

you need to create dynamic variable.

like this


DATA lv_test TYPE REF TO data.
FIELD-SYMBOLS <X> TYPE ANY.

DATA: lv_deci TYPE i VALUE 2.
CREATE DATA lv_test TYPE p DECIMALS lv_deci.
ASSIGN lv_test->* TO <X>.
<X> = '20.333'.  "Anything.
WRITE: <fs>.

Please search CREATE DATA in F1 for more details.

Chaiphon

3 REPLIES 3
Read only

Former Member
0 Likes
537

hi

for dynamic declaration always use () brackets

That is :

data: X type p decimal l_decimal.

Replace as

data: X type p decimal (l_decimal).

Try This trick

with regards

Anand kumar

Read only

chaiphon
Contributor
0 Likes
538

you need to create dynamic variable.

like this


DATA lv_test TYPE REF TO data.
FIELD-SYMBOLS <X> TYPE ANY.

DATA: lv_deci TYPE i VALUE 2.
CREATE DATA lv_test TYPE p DECIMALS lv_deci.
ASSIGN lv_test->* TO <X>.
<X> = '20.333'.  "Anything.
WRITE: <fs>.

Please search CREATE DATA in F1 for more details.

Chaiphon

Read only

Former Member
0 Likes
537

Chaiphon,

Thanks alot your solution worked.

Anand,

Even assigning the decimal with a variable, it still displays an error of (VAR) is not numeric.