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

Convert char format to decimal format

Former Member
0 Likes
1,264

Hi,

How can i convert a char number in char format to decimal format?.

For example:

Data: char_format(10) type c value '12,345.56'.

Data: decimal_format(10) type p decimals 2.

How should i assign it?

Thanks,

Sandeep

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,133

Try:


REPORT ztest MESSAGE-ID 00.

DATA: char_format(10) TYPE c VALUE '12,345.56'.
DATA: decimal_format(10) TYPE p DECIMALS 2.

REPLACE ALL OCCURRENCES OF ',' IN char_format WITH space.
CONDENSE char_format NO-GAPS.
decimal_format = char_format.

Rob

This just gets rid of the comma. If you have any other non-numerics in the field ($, etc.), you have to remove them as well.

Message was edited by: Rob Burbank

Try:


REPORT ztest MESSAGE-ID 00.

DATA: char_format(10) TYPE c VALUE '12,345.56'.
DATA: decimal_format(10) TYPE p DECIMALS 2.

REPLACE ALL OCCURRENCES OF ',' IN char_format WITH space.
CONDENSE char_format NO-GAPS.
decimal_format = char_format.

Rob

This just gets rid of the comma. If you have any other non-numerics in the field ($, etc.), you have to remove them as well.

Message was edited by: Rob Burbank

6 REPLIES 6
Read only

Former Member
0 Likes
1,133

nevermind don't listen to me. I need some sleep.

Message was edited by: Matt Nagel

Message was edited by: Matt Nagel

Read only

0 Likes
1,133

Rob is right here, you need to get rid of the commas, you can also do this using the TRANSLATE statement.



DATA: char_format(10) TYPE c VALUE '12,345.56'.
DATA: decimal_format(10) TYPE p DECIMALS 2.
 
<b>translate char_format using ', '.
CONDENSE char_format NO-GAPS.</b>
decimal_format = char_format.


Regards,

Rich Heilman

Read only

0 Likes
1,133

hi rich,

here i have one more doubt...

suppose if the amount is comming in country specific format then how we are going to handle it

like in us --> 123.123,00

in india --> 123,123.00

then how can we convert this to num?

Read only

0 Likes
1,133

Really we should be checking the user specific formatting from table USR01, field DCPFM, and handle accordingly.

Regards,

Rich Heilman

Read only

0 Likes
1,133

For example..........



report  zrich_0005.

data: char_format(10) type c value '12,345.56'.
data: decimal_format(10) type p decimals 2.
data: xusr01 type usr01.

*   1.234.567,89
*X  1,234,567.89
*Y  1 234 567,89

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

case xusr01-dcpfm.
  when space.
    translate char_format using '. '.
    translate char_format using ',.'.
  when 'X'.
    translate char_format using ', '.
  when 'Y'.
    translate char_format using ',.'.
endcase.

condense char_format no-gaps.
decimal_format = char_format.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
1,134

Try:


REPORT ztest MESSAGE-ID 00.

DATA: char_format(10) TYPE c VALUE '12,345.56'.
DATA: decimal_format(10) TYPE p DECIMALS 2.

REPLACE ALL OCCURRENCES OF ',' IN char_format WITH space.
CONDENSE char_format NO-GAPS.
decimal_format = char_format.

Rob

This just gets rid of the comma. If you have any other non-numerics in the field ($, etc.), you have to remove them as well.

Message was edited by: Rob Burbank