‎2008 Jan 16 12:56 AM
I have a string that is in the form of ##R# (# = any number from 0-9 and the quantity of numbers is dynamic). How can I split the string at the first non-numeric character? Below is an example:
String = 12R3
I need var1 = '12' and var2 = 'R3'.
Regards,
Davis
‎2008 Jan 16 1:31 AM
I know, not the most elegant solution, but a solution non-the-less.
REPORT rich_0001.
DATA: lv_str TYPE string VALUE '123456R987654321'.
DATA: lv_var1 TYPE string.
DATA: lv_var2 TYPE string.
DATA: lv_counter TYPE i.
data: lv_offset type i.
data: lv_len type i.
DO.
IF lv_str+lv_counter(1) NA '0123456789'.
lv_offset = lv_counter.
exit.
ENDIF.
lv_counter = lv_counter + 1.
ENDDO.
lv_var1 = lv_str(lv_offset).
lv_len = strlen( lv_str ).
lv_offset = lv_offset + 1. " Skip over the non-numeric
lv_var2 = lv_str+lv_offset.
write:/ lv_var1.
write:/ lv_var2.
Regards,
Rich Heilman
‎2008 Jan 16 1:31 AM
I know, not the most elegant solution, but a solution non-the-less.
REPORT rich_0001.
DATA: lv_str TYPE string VALUE '123456R987654321'.
DATA: lv_var1 TYPE string.
DATA: lv_var2 TYPE string.
DATA: lv_counter TYPE i.
data: lv_offset type i.
data: lv_len type i.
DO.
IF lv_str+lv_counter(1) NA '0123456789'.
lv_offset = lv_counter.
exit.
ENDIF.
lv_counter = lv_counter + 1.
ENDDO.
lv_var1 = lv_str(lv_offset).
lv_len = strlen( lv_str ).
lv_offset = lv_offset + 1. " Skip over the non-numeric
lv_var2 = lv_str+lv_offset.
write:/ lv_var1.
write:/ lv_var2.
Regards,
Rich Heilman
‎2008 Jan 16 1:50 AM
Rich,
Thanks a lot for that piece of code! I was hoping that I could do something like:
split string at (0 1 2 3 4 5 6 7 8 9) into var
but I guess that isn't possible.
Thanks again,
Davis
‎2008 Jan 16 1:38 AM
Check this code.
PARAMETERS : p_c(10) TYPE c.
DATA : l_pos TYPE i.
DATA : l_pos1 TYPE i.
DATA : p_c1(10) TYPE c.
DATA : p_c2(10) TYPE c.
IF p_c CA sy-abcde.
l_pos = sy-fdpos.
l_pos1 = l_pos + 1.
ENDIF.
WRITE : p_c+0(l_pos).
WRITE : p_c+l_pos1.
Regards
Gopi