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

regarding type conversion

Former Member
0 Likes
1,274

i have requirement which is like:-

data: var(30) type c.

The variable var is holding the value '44.567'.

The decimal point is set default to <b>,</b> as per my id settings.

in the production it is set to<b> .</b>.

I want to remove the decimals and store 44. How can i do this independant of the user default settings.

best regards,

Subhakar.

14 REPLIES 14
Read only

Former Member
0 Likes
1,250

Hi Subhakar,

You can use..

Write: var to var decimals 0.

Reward helpful answers.

Regards,

Siddhesh Sanghvi.

Read only

Former Member
0 Likes
1,250

DATA: I TYPE I,

P TYPE P DECIMALS 2,

M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

P = ABS( M ). " 3,5

I = P. " 4 - business rounding

I = M. " -4

I = CEIL( P ). " 4 - next largest whole number

I = CEIL( M ). " -3

I = FLOOR( P ). " 3 - next smallest whole number

I = FLOOR( M ). " -4

TRY CEIL AND FLOOR

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
1,250

Hi,

As the value is store in char variable then you can use split at <b>.</b>.

then it will be easy to remove the decimals.

I think this will be helpful for you.

Regards,

Read only

Former Member
0 Likes
1,250
report ychatest.

data : v_dec type p decimals 2,
         v_abs type i.

v_dec = '44.57'.

v_abs = trunc( v_dec ).

write : v_abs.
Read only

0 Likes
1,250

Thankyou all for your prompt reply.

Here the var is of type char. I wanna truncate the decimals of this char. Based on the user default settings the decimal may represent with , or .

Read only

0 Likes
1,250

Try this its working fine for CHAR too

DATA n(4) TYPE c.
DATA ni(4) type c.
DATA m(5) TYPE c VALUE '-5.55'.
n = ceil( m ).
ni = trunc( n ).
  WRITE: / 'VALUE: ', ni.

Read only

Former Member
0 Likes
1,250

Use this

  • numeric datatypes

DATA n TYPE p DECIMALS 2.
DATA ni type p.
DATA m TYPE p DECIMALS 2 VALUE '-5.55'.
n = ceil( m ).
ni = trunc( n ).
  WRITE: / 'VALUE: ', ni.

<b>Output:

VALUE: 5- </b>

Then use <b>trunc( n )</b>

Message was edited by:

Judith Jessie Selvi

Read only

Former Member
0 Likes
1,250
report ychatest.

data : v_dec type p decimals 2,
         v_abs type i.

v_dec = '44.57'.

v_abs = trunc( v_dec ).

write : v_abs.
Read only

Former Member
0 Likes
1,250

Hi,

If you can transfer the value to a type P variable. you can use the FLOOR command.

if you want to have only in Char, then You can write a select single query on USR01 to fetch the value of DCPFM which will tell you whether the decimal separator is '.' or ',' and use SPLIT statement to get the desired value.

regards,

Mahesh

Read only

0 Likes
1,250

I am getting rntime error when i use floor or trunc.

Read only

Former Member
0 Likes
1,250

Subhakar,

The quick solution for the same is to move the var field to a floting variable first. and then compute using arithmatic expression depending on the requirement.

See the below sample code:

DATA: char_c(30), int_i type i, p_p type p decimals 3, i type i.

char_c = '44.567'.

MOVE char_c to p_p.

int_i = ceil( p_p ). "To get the Upper value i.e 45 in this case

i = FLOOR( p_p ). "To get the Lower value i.e. 44 in this case

WRITE: / int_i, i.

Hope this helps.

Thanks

Read only

0 Likes
1,250

Hi rahul,

Tried but stilll its raising runtime error while assigning char variable to variable of type p. Pls help

Read only

0 Likes
1,250

Hi,

As the var is character type you need to use split.

the code is as follows:

data: var(30) type c value '44.567'.

data: var1(30),var2(30) type c.

split var at '.' into var1 var2 .

write 😕 var1.

i think this will helpful for you.

Read only

0 Likes
1,250

Hi Subha,

The same code is working for me.... I hope you are using the same code as posted above....

Thanks