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

char to numeric conversion

Former Member
0 Likes
10,368

Hi all.

I want to convert character value into numeric value

amount = (numeric type)

in_var-value = 4,000.00 (char type)

Iam getting error with below mentioned statement

amount = in_var-value.

because there is ',' in 4,000.00 .

How to remove this came ',' from this 4,000.00. is there any function module

Thanks in advance

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
5,421

Hi Ranjith,

You can use the following code:

data a type p decimals 3.
data b(4) type c.
b = '4,000'.
replace ',' in b with space .
condense b.
a = b.
write : / b.

This will remove the ',' from the numeric value.

As for any function module that does the same, I'm not aware of it.

Regards

Anil Madhavan

Hi all.

I want to convert character value into numeric value

amount = (numeric type)

in_var-value = 4,000.00 (char type)

Iam getting error with below mentioned statement

amount = in_var-value.

because there is ',' in 4,000.00 .

How to remove this came ',' from this 4,000.00. is there any function module

Thanks in advance

10 REPLIES 10
Read only

Former Member
0 Likes
5,421

Hello,

Use


write: lv_num to lv_char.
write: lv_char.

Vasanth

Read only

0 Likes
5,421

hi,

I want to convert char to numeric but not from numeric to char.

Read only

0 Likes
5,421

hI,

data: char(10) type c value '12345.00'.

data: p type p decimals 2.

if char co '1234567890. '.

p = char.

else.

  • Give message

endif.

write:/

<b>*Reward points</b>

REGARDS

Read only

0 Likes
5,421

data : var1(10) type c,

var2(10) type n.

var1 = 'ABC123'.

var2 = var1.

write 😕 var2.

this way the non-numeric characters will be removed. See how you can modify this to suit your requirement.

Read only

Former Member
0 Likes
5,421

Hi,

Try this:

&----


*& Form convert-string-to-number (type f, i, p)

&----


FORM convert-string-to-number

USING

value(p_string) TYPE string

CHANGING

p_number TYPE any "-- f, i, p --

p_error TYPE i.

TRY.

CLEAR p_error.

p_number = p_string. "Convert string to number.

CATCH cx_sy_conversion_no_number.

p_error = 1.

CATCH cx_sy_conversion_overflow.

p_error = 2.

ENDTRY.

ENDFORM. "convert-string-to-number

Regards,

Padmam.

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
5,421

Hi,

Use NUMC and then assign the NUMC to an I or P

Like this

DATA: num1(10) type n,

number(10) type p decimals 2.

num1 = in_var-value.

number = num1.

Regards,

Sesh

Read only

Former Member
0 Likes
5,421

replace all occurrences of ',' in in_var-value with space.

condense in_var-value no-gaps.

amount = in_var-value.

regards

shiba dutta

Read only

Former Member
0 Likes
5,422

Hi Ranjith,

You can use the following code:

data a type p decimals 3.
data b(4) type c.
b = '4,000'.
replace ',' in b with space .
condense b.
a = b.
write : / b.

This will remove the ',' from the numeric value.

As for any function module that does the same, I'm not aware of it.

Regards

Anil Madhavan

Read only

0 Likes
5,421

Hi anil,

Thanks for your answer, it looks good, but I have found another solution as follows

REPLACE ALL OCCURRENCES OF ',' IN IN_VAR-VALUE WITH ''.

VAL5 = IN_VAR-VALUE.

it is working fine.

Read only

Former Member
0 Likes
5,421

Hi,

You can use this function module

'C14W_CHAR_NUMBER_CONVERSION'

Pass your in_var-value in the FM and you can get the amount in numeric type.

Regards,

Sangeeta.