Application Development 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: 

How to convert string to integer in ABAP.

Former Member
0 Kudos
31,432

Hi All

How to convert number which is stored as string or character type into integer.

Regards

Archana.

1 ACCEPTED SOLUTION

abdul_hakim
Active Contributor
0 Kudos
5,323

Hi

check the below code which will convert character to integer..

DATA NO1(10) TYPE C VALUE '1234567890'.

DATA NO2 TYPE I.

NO2 = NO1.

WRITE NO2.

the foll code will convert the string to interger.

DATA NO1 TYPE STRING.

DATA NO2 TYPE I.

NO1 = '1234567890'.

NO2 = NO1.

WRITE NO2.

Regards,

Abdul

Reward points if ans is helpful...

Message was edited by: Abdul Hakim

5 REPLIES 5

abdul_hakim
Active Contributor
0 Kudos
5,324

Hi

check the below code which will convert character to integer..

DATA NO1(10) TYPE C VALUE '1234567890'.

DATA NO2 TYPE I.

NO2 = NO1.

WRITE NO2.

the foll code will convert the string to interger.

DATA NO1 TYPE STRING.

DATA NO2 TYPE I.

NO1 = '1234567890'.

NO2 = NO1.

WRITE NO2.

Regards,

Abdul

Reward points if ans is helpful...

Message was edited by: Abdul Hakim

Former Member
5,323

Hi Archana,

1. Just declare a new variable of type i.

and assign the character variable to i.

2. eg.

REPORT ac.

data : a(50) type c.

data :num type i.

a = '799'.

num = a.

write 😕 a.

write 😕 num.

Hope the above helps.

Regards,

Amit M.

FredericGirod
Active Contributor
0 Kudos
5,323

You must have to check if the value contain only number.

you could do that with a check: check w_value na sy-abdcd.

And if you want to prevent any problem, you could include your move with a catch. That will block the shortdump.

Rgd

Frédéric

former_member188685
Active Contributor
0 Kudos
5,323

Hi Use this Fm to do that.

<b>CONVERT_STRING_TO_INTEGER

JUST pass string variable to this you will get int value</b>regards

vijay

0 Kudos
5,323

Hi,

I don't know if it's your case, but, I guess you don't need a FM, it's is automaticly.

data: v1(8) type c ,

v2 type i .

v1 = '10' .

v2 = v1 .

att,

Alexandre Nogueira