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

classical report decimals

Former Member
0 Likes
1,126

Hi,

I have a float field which when displayed via write statement shows 3 decimals by default. How can i round it and show 2 decimals. Is there any direct way. I dont want to convert it to string variable & then display.

BYe

1 ACCEPTED SOLUTION
Read only

sarbajitm
Contributor
0 Likes
1,084

data f1 type p decimals 3 value '1575.456'.

write: / f1 decimals 2.

Try the above code snippet to resolve your problem.

Thanks

10 REPLIES 10
Read only

Former Member
0 Likes
1,084

use decimals option in write statement

Read only

Former Member
0 Likes
1,084

slope it through a type p decimals 2 variable.

Read only

Former Member
0 Likes
1,084

Hi.

If you are using float type then following piece of code might be useful for you.

Suppose your value is 1.234 and you want it to be rouded of to 1.23


float f = 1.234;
f *= 100;
f = (float)Math.round(f)/100;
.... and now f==1.23


Hope it will help you

thanks

Arun

Read only

former_member203501
Active Contributor
0 Likes
1,084

do like this...

report yztest.

data: test1 type p decimals 3.

test1 = '12.332'.

write:/ test1.

write:/ test1 decimals 2.

Read only

qamar_javed
Participant
0 Likes
1,084

Hi mac,

Check this link:

http://help.sap.com/saphelp_nw04/Helpdata/EN/9f/db9e2335c111d1829f0000e829fbfe/frameset.htm

In the write statement just add the decimal option.

WRITE field DECIMALS 2.

Hope this helps.

Regards,

Qamar.

Read only

Former Member
0 Likes
1,084

Hi,

For decimals :

write w_field decimals 3.

For exponents:

use exponent option with the field.

while writing,use this.

write 😕 w_float exponent 2.

This is working.

Read only

sarbajitm
Contributor
0 Likes
1,085

data f1 type p decimals 3 value '1575.456'.

write: / f1 decimals 2.

Try the above code snippet to resolve your problem.

Thanks

Read only

Former Member
0 Likes
1,084

Hi Mac,

set the decimals_out = 2. of ur fieldcatalog.

here is a sample program for u to refer.....


REPORT  yh1308_sample2.

****TABLE WORK AREA
TABLES:vbak.

***DEFINE INTERNAL TABLE WITH HEADER LINE****

DATA:it_jtab LIKE vbak OCCURS 0 WITH HEADER LINE.

****PROVIDE TYPE GROUP***

TYPE-POOLS:slis.

***MAINTAIN REPORT ID***

DATA:repid LIKE sy-repid,

****DEFINE COLUMN HEADING****
vbak_b TYPE slis_t_fieldcat_alv ,
fs LIKE LINE OF vbak_b.

****START-OF-SELECTION EVENT***
START-OF-SELECTION.
  SET PF-STATUS 'STATUS'.
***FUNCTION MODULE COLUMN HEADINGS****

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'VBAK'
    CHANGING
      ct_fieldcat      = vbak_b.
*----------------------------------------------------------------*
*exponent

  fs-decimals_out = 5. "decimals in write statement
  fs-input = 'X'. " sets field in edit mode
  MODIFY vbak_b FROM fs
  TRANSPORTING decimals_out input
  WHERE fieldname = 'NETWR'.
*---------------------------------------------------------------------
****REPORT ID SYSTEM VARIABLE****
  repid = sy-repid.

  SELECT * FROM vbak UP TO 20 ROWS INTO TABLE it_jtab.

****FUNCTION MODULE OUTPUT DISPLAY***

  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = repid
      it_fieldcat        = vbak_b
    TABLES
      t_outtab           = it_jtab.


****END OF PROGRAM****

Regards,

Mdi.Deeba

Read only

sarbajitm
Contributor
0 Likes
1,084

Hi Mac,

If you've got your answer then please mark the thread as ANSWERED.

Thanks.

Read only

Former Member
0 Likes
1,084

thanks guys for your valuable time & inputs. You guys are amazing