‎2006 Aug 11 4:52 PM
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.
‎2006 Aug 11 5:07 PM
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
‎2006 Aug 11 5:04 PM
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.
‎2006 Aug 11 5:06 PM
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
‎2006 Aug 11 5:07 PM
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
‎2006 Aug 11 5:18 PM
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".
‎2006 Aug 11 5:22 PM
l_int = 10001
l_int = l_int + 1
concatenate 'A' l_int into l_str.
is that ur requirement ?
Regards
Anurag
‎2006 Aug 11 5:25 PM
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.
‎2006 Aug 11 5:31 PM