Application Development 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: 

Comma Separator for Amount when downloaded into file

Former Member
0 Kudos

Hi All,

Comma Separator for Amount when downloaded into file.

For Ex: if my input value is

data: numc(20) TYPE c VALUE '1234567.89'.

when i download this to a file, i should see it as 12,34,567.89

Thanks,

Sudheer.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

The Output should be always a comma separator with a dot decimal For Ex: 1,234,567.89. It should not depend on user settings.

Thanks,

Sudheer.

9 REPLIES 9

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

You will need to write to a character field before you before you output it.

Regards,

Rich Heilman

0 Kudos

Here is an example...



report zrich_0002 .

data: begin of itab occurs 0,
      fld1(1) type c,
      fld2(10) type p decimals 2,
      end of itab.

data: begin of iout occurs 0,
      fld1(1) type c,
      fld2(15) type c,
      end of iout.


itab-fld1 = 'A'.
itab-fld2 = '1234.54'.
append itab.

itab-fld1 = 'B'.
itab-fld2 = '1541234.54'.
append itab.

loop at itab.
  iout-fld1 = itab-fld1.
<b>  write itab-fld2 to iout-fld2.</b>
  append iout.
endloop.

call function 'GUI_DOWNLOAD'
     exporting
          filename = 'C:/test.txt'
     tables
          data_tab = iout
     exceptions
          others   = 22.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi

Use command WRITE:

data: numc(20) TYPE WRBTR VALUE '1234567.89'.

WRITE NUMC CURRENCY <CURRENCY> TO T_FILE.

Max

Former Member
0 Kudos

Hi,

The Output should be always a comma separator with a dot decimal For Ex: 1,234,567.89. It should not depend on user settings.

Thanks,

Sudheer.

0 Kudos

Hi,

USe the following WRITE statement.


data w_t(16) value '1234567890'.
write:/ w_t using edit mask '1,234,567,890'.

Regards,

Suresh Datti

for the 2nd time in the day, Pl ignore my post

Message was edited by: Suresh Datti

0 Kudos

If that is the case, you can use the CURRENCY extension, make it USD, as it will always be written in the 123,456.78 format no matter what the user settings are.

  write itab-fld2 to iout-fld2 <b>currency 'USD'</b>.

Make not, I forgot to sign off and sign back on when changing my user settings. Disregard.

Regards,

Rich Heilman

0 Kudos

Hi,

Check this code.....,it doesn't depend on any currency ...


REPORT ZTEST.

DATA: NUMC(20) TYPE C VALUE '1234567.89'.
data:: shift type i,
       i_decimals type i,
       curr type BAPICURR-BAPICURR.

 i_decimals = 0 .
 shift = 0.
 curr = numc * 10 ** ( i_decimals - shift ).

write: curr.

output <b>1,234,567.89 </b>

Message was edited by: Vijay Babu Dudla

0 Kudos

Ok, now we are going to check the user settings and translate accordingly. Here is a solution.




report zrich_0002 .

data: begin of itab occurs 0,
      fld1(1) type c,
      fld2(10) type p decimals 2,
      end of itab.

data: begin of iout occurs 0,
      fld1(1) type c,
      fld2(15) type c,
      end of iout.

data: length type i.

itab-fld1 = 'A'.
itab-fld2 = '1234.54'.
append itab.

itab-fld1 = 'B'.
itab-fld2 = '1541234.54'.
append itab.


data: xusr01 type usr01.


select single * from usr01 into xusr01
               where bname = sy-uname.

loop at itab.
  iout-fld1 = itab-fld1.
  write itab-fld2 to iout-fld2.

  shift iout-fld2 left deleting leading space.
  length = strlen( iout-fld2 ).

  case xusr01-dcpfm.
    when  'X'.
* Do nothing as it is in the write format.
    when  ' '.
      translate iout-fld2+0(length) using '.X'.
      translate iout-fld2+0(length) using ',.'.
      translate iout-fld2+0(length) using 'X,'.
    when  'Y'.

      translate iout-fld2+0(length) using ' X'.
      translate iout-fld2+0(length) using ',.'.
      translate iout-fld2+0(length) using 'X,'.
  endcase.

  shift iout-fld2 right deleting trailing space.
  write:/ iout-fld2.

  append iout.
endloop.

call function 'GUI_DOWNLOAD'
     exporting
          filename = 'C:/test.txt'
     tables
          data_tab = iout
     exceptions
          others   = 22.

Regards,

Rich Heilman

Former Member
0 Kudos

If you still didnt get what you want...try this:

DATA: amount   TYPE string VALUE '2125673.45',
      offset   TYPE i,
      value    TYPE string,
      decimal  TYPE string.

FIND '.' IN amount MATCH OFFSET offset.
value   = amount(offset).
decimal = amount+offset(3).
CLEAR amount.

WHILE offset > 3.
  offset    = offset - 3.
  CONCATENATE ',' value+offset(3) amount INTO amount.
ENDWHILE.

CONCATENATE value(offset) amount decimal INTO amount.

WRITE: / amount.