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

Work with INTEGER and STRINGS

Former Member
0 Likes
994

Dear all,

i have the following problem. How to convert int to string and back in ABAP?

the second question, if I get a string "S1A0001" how can I check the first and the third byte, if they are equal to 'S' and 'A' then convert '0001' to integer.

And if I have int-"1080025" check, whether the first byte is equal to "1" and the third one is "8" and if so, to convert the rest "0025" to string.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
937

l_var = variable containing the value either S1A0001 or 1080025.

Please note the defn

data : l_int type i,

l_str type string.

if l_var(1) CA sy-abcde and l_var+2(1) CA sy-abcde.

l_int = l_var+3(4).

elseif l_var(1) CA '0123456789' and l_var_2(1) CA '0123456789'.

l_str = l_var+3(4).

endif.

In the above, I have given generalized checks as to 1st and 3rd char being alphabet or numeric and depending on the same do the needful, surely u can replace it with single characters if it is very specific to your requirement.

Message was edited by: Anurag Bankley

7 REPLIES 7
Read only

Former Member
0 Likes
937

data: v_value(7),

v_int type i, " integer value

v_str type string. " string value

v_value = 'S1A0001'.

if v_value+0(1) = 'S' and

v_value+2(1) = 'A'.

v_int = v_value+3(4).

endif.

v_value = '1080025'.

if v_value+0(1) = '1' and

v_value+2(1) = '8'.

v_str = v_value+3(4).

endif.

Read only

Former Member
0 Likes
937

data: v_str1 type string,

v_int type i.

if v_str0(1) = 'S' and v_str2(1) = 'A'.

v_int = v_str+3(4).

endif.

if v_str0(1) = '1' and v_str2(1) = '8'.

v_str1 = v_str+3(4).

endif.

Regards,

Ravi

Read only

Former Member
0 Likes
938

l_var = variable containing the value either S1A0001 or 1080025.

Please note the defn

data : l_int type i,

l_str type string.

if l_var(1) CA sy-abcde and l_var+2(1) CA sy-abcde.

l_int = l_var+3(4).

elseif l_var(1) CA '0123456789' and l_var_2(1) CA '0123456789'.

l_str = l_var+3(4).

endif.

In the above, I have given generalized checks as to 1st and 3rd char being alphabet or numeric and depending on the same do the needful, surely u can replace it with single characters if it is very specific to your requirement.

Message was edited by: Anurag Bankley

Read only

0 Likes
937

And if I have

p_code TYPE text8.

"S1A00005"

and want to get "S2A00006", how can I add to text 2 and 6?

The same with int, to convert "10001" to text "A10002".

Read only

0 Likes
937

l_int = 10001

l_int = l_int + 1

concatenate 'A' l_int into l_str.

is that ur requirement ?

Regards

Anurag

Read only

0 Likes
937

data: v_num(1) type n,

v_num2(5) type n.

v_num = p_code+1(1) + 1.

v_num2 = p_code+3(5) + 1.

concatenate p_code+0(1) v_num v_num2 into p_code.

Read only

0 Likes
937

Yes, this is requirements.

Thanks guys for the answers.