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
4,064

how to convert a char field of an internal table into a numeric field?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,260

Hi,

you can directly assign datatype c to n.

data:

w_result type n,

loop at itab into wa.

(wa-field) = w_result.

endloop.

Regards,

Anirban

7 REPLIES 7
Read only

Former Member
0 Likes
2,261

Hi,

you can directly assign datatype c to n.

data:

w_result type n,

loop at itab into wa.

(wa-field) = w_result.

endloop.

Regards,

Anirban

Read only

Former Member
2,260

hii

assign char type value in to variable of type n.

data:

w_txt(5) type c,

w_num(5) type n,

w_txt = 'gh12'.

w_num = w_txt.

regards

twinkal

Read only

Former Member
0 Likes
2,260

You can move character field to numeric field. SAP will do implicit conversion to numeric. Please make sure you handle exceptions.

Read only

Former Member
0 Likes
2,260

Hi try this,

data : var1(10) type n,

var2(10) type c value '256748'.

move var2 to var1.

write : / var1,

/ var2.

Read only

Former Member
0 Likes
2,260

Use below FMs

CHAR_NUMC_CONVERSION

MOVE_CHAR_TO_NUM

C14W_CHAR_NUMBER_CONVERSION

CHAR_NUMC_CONVERSION

See the sample code below...


codeDATA: lv_chr(4) type c,
lv_num type p.

CALL FUNCTION 'MOVE_CHAR_TO_NUM'
EXPORTING
CHR = lv_chr
IMPORTING
NUM = lv_num
EXCEPTIONS
CONVT_NO_NUMBER = 1
CONVT_OVERFLOW = 2
OTHERS = 3.
IF SY-SUBRC 0.


MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO 
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. 
ENDIF.

Also hv a look on below thread..

Hope it will solve your problem..

Thanks & Regards

ilesh 24x7

Read only

Former Member
0 Likes
2,260

Hi...

I am also facing the same issue. If You have solved this problem. I am able to convert the char into numc. but if user enters SPACE then it shuold not be valid.

How to solve that.

Regards,

Rohit

Read only

0 Likes
2,260

Rohit,

Its a answered post.

nobody will notice your prob

you post your prob in seperate post.

Regards,

Anirban