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

Converting character type to integer

Former Member
0 Likes
4,162

Hi,

My requirement is like this.

I read transfer in units into a character field.

Now i need to check whether it is Less Than 0 or contains any alphabet.

Please tell me how to move this char field to an integer field.

Thanks & regards,

Neeraja

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,073

HI,

You can directly move it.

DATA : LV_CHAR(4) TYPE C.

LV_CHAR = '10'.

DATA : LV_INT TYPE I.

check lv_char ca 'abcdefgh....z'. " To check if it conains any alphabets

LV_INT = LV_CHAR.

WRITE LV_INT.

Thanks,

Mahesh

6 REPLIES 6
Read only

Former Member
0 Likes
4,074

HI,

You can directly move it.

DATA : LV_CHAR(4) TYPE C.

LV_CHAR = '10'.

DATA : LV_INT TYPE I.

check lv_char ca 'abcdefgh....z'. " To check if it conains any alphabets

LV_INT = LV_CHAR.

WRITE LV_INT.

Thanks,

Mahesh

Read only

0 Likes
4,073

Hi mahesh,

i tried this way, but i am getting run time error .

Can please clearify.

Thanks ,

Neeraja

Read only

0 Likes
4,073

Use this code.

data: lv_char(10), lv_int type i.

if lv_char co '0123456789'.
  lv_int = lv_char.
endif.

Please mark points if the solution was useful.

Regards,

Manoj

Read only

Former Member
0 Likes
4,073

HI Neeraja,

You can try using the function module NUMERIC_CHECK for checking that ur char field contains an alphabet or not.

IF htype = 'NUMC'.

then the field doesn't have any alphabets.

elseif htype = 'CHAR'

then the field is containing alphabets.

if the field didn't have any alphabets u can then move it directly to int field.

Regards,

kasinath.

Read only

Former Member
0 Likes
4,073

Move the field inside a TRY ENDTRY block with a CATCH for CONVERSION_ERRORS. If no error occurs, then check if less than zero. If an exception occurs, the code in the CATCH can issue relevant message.

Andrew

Read only

Former Member
0 Likes
4,073

Hi Neeraja

data: a(10) type c,

b(10) type n.

a = '123'.

b = a.

write:/ b.

b = 0000000123.

reward points if helpful,

Use the standard function module MOVE_CHAR_TO_NUM