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

Changing figure display.

Former Member
0 Likes
1,847

hi,

I would like to change 1500.000 -> 1500, is there any function for that in the system?

Thanks.

hi,

I would like to change 1500.000 -> 1500, is there any function for that in the system?

Thanks.

13 REPLIES 13
Read only

Former Member
0 Likes
1,800

write <variable> no decimals.

Read only

Former Member
0 Likes
1,800

Ong,

You can aslo do this

WRITE: <Variable> DECIMALS 0

Cheers

Raghava

Read only

Former Member
0 Likes
1,800

Hi,

If I use no decimals for it, will my result come out like this 150020 if my value is 1500.20?

Read only

0 Likes
1,800

No , It would be 1500

Cheers

Raghava

Read only

0 Likes
1,800

Ong,

In case if you want more info on Decimals option

Option ... DECIMALS d

Effect d specifies the number of decimal places for a number field

(type I, P or F) in d. If this value is smaller than the

number of decimal places in the number, the number is rounded.

If the value is greater, the number is padded with zeros.

Since accuracy with floating point arithmetic is up to about

15 decimal places (see ABAP number types), up to 17 digits are

output with floating point numbers (type F). (In some

circumstances, 17 digits are needed to differentiate between

two neighboring floating point numbers.) If the output length

is not sufficient, as many decimal places as possible are

output. Negative DECIMALS specifications are treated as

DECIMALS 0.

Example Effect of different DECIMALS specifications:

DATA: X TYPE P DECIMALS 3 VALUE '1.267',

Y TYPE F VALUE '125.456E2'.

WRITE: /X DECIMALS 0, "output: 1

/X DECIMALS 2, "output: 1.27

/X DECIMALS 5, "output: 1.26700

/Y DECIMALS 1, "output: 1.3E+04

/Y DECIMALS 5, "output: 1.25456E+04

/Y DECIMALS 20. "output: 1.25456000000000E+04

Read only

Former Member
0 Likes
1,800

I see.

How about if when the figures is 1500.00, I want to keep it as 1500 and figure is 1500.20, I want to keep it as 1500.2?

Read only

0 Likes
1,800

Ong ,

Variable1 = 1500.00

WRITE: <Variable1> DECIMALS 0.

That would give you 1500.

Variable2 = 1500.20

WRITE: <Variable2> DECIMALS 1.

That would give you 1500.2

Message was edited by: Raghava M

Message was edited by: Raghava M

Read only

0 Likes
1,800

Can you tell how many maximum decimal places you can have? Is it one or two or any number?

Srinivas

Read only

Former Member
0 Likes
1,800

Ong,

I think I got your issue now. I checked for standard SAP function module, but I could not find much help .However, I have one possible solution to your issue, if you are considering only two decimal places. Complexity might increase as you increase the number of decimals.

Let us say

A = 1500. XY

If Y is a non zero .

WRITE: A DECIMALS 2.

Else.

If X is a non zero.

WRITE: A DECIMALS 1.

Else.

WRITE: A DECIMALS 0.

Endif.

Endif.

Hope it helps.

Cheers

Raghava

Read only

Former Member
0 Likes
1,800

Hi Raghava,

I able to solve my problem now.

I am using code as below:

WRITE <variable1> NO-GROUPING UNIT 'ST' TO <variable2>.

So whatever figure come with 1500.00 will bcome 1500.00 and figure come with 1500.20 will maintain as 1500.20.

Thanks for your help!

Read only

Former Member
0 Likes
1,800

Hi Raghava,

Sorry for making mistake for previous post.

The result will be 1500.00 will bcome 1500 and 1500.20 will maintain as 1500.20

Thanks.

Read only

Former Member
0 Likes
1,800

Hi,

Refer following code. It will surely solve ur problem.

data rs type p decimals 2 value '1500.50'.

data in type i.

  • if u want rounded figure, uncomment the below code (exa. 1500.50 as 1501)

*in = rs.

  • if u do not want rounded figure (exa. 1500.50 as 1500)

in = trunc( rs ).

write in.

Regards,

Digesh Panchal

Read only

Former Member
0 Likes
1,800

Hi,

According to your last post u have to Define ur variable in folloing way:

parameters rs type p decimals 2.

write rs.

Regards,

Digesh