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

function module to convert charcter in numeric

former_member770121
Participant
0 Likes
1,712

function module to check the string can be converted into numeric or not????? clearly explain please

7 REPLIES 7
Read only

Sandra_Rossi
Active Contributor
1,585
DATA(char) = '123'.
DATA(num) = 0.

num = char.

ASSERT num = 123.
Read only

Former Member
1,585
DATA number TYPE i.
DATA is_convertible TYPE abap_bool.

TRY.

    number = tested_string.

    is_convertible = abap_true.

  CATCH cx_sy_conversion_no_number.

    is_convertible = abap_false.

ENDTRY.
Read only

0 Likes
1,585

i need with function module ?

Read only

0 Likes
1,585

using Function module is not a best practice, FM is old school

use the the solution of gabmarian, this is how you should use ABAP today

Read only

1,585

aya12

Then you create one with the coding above.

Read only

ThorstenHoefer
Active Contributor
0 Likes
1,585

Hi Haya,

you can check if the character variable contains only numeric characters values with CO

if l_char co '0123456789'.
   ....

endif.