2014 Mar 19 12:30 PM
Dear Friends,
one of my string value is "0021009010001000123NVN"
i have to split 123 ( before some alphabets )and want to store this value in another variable
other string can be like this also for eg 2225018000605010456PV
in the above string i have to split 456 and want to store this value in another variable
could anyone be pls give me some sample program
Thanks
Vijaya
2014 Mar 19 1:14 PM
Here is a one-liner way to do it using regular expressions.
For more information, you can read keyword documentation and explore DEMO_REGEX_TOY program.
See this snippet.
/.
2014 Mar 19 12:34 PM
Hi, if this parts of string have fixed value, try something like this
str = '0021009010001000123NVN'
text01 = str(16) .
text02 = str+16(3) ..
text03 = str+19.
2014 Mar 19 12:35 PM
Hi Vijaya ,
use offset
data : str(20) VALUE '0021009010001000123NVN',
var(3).
var = str+16(3).
WRITE : var.
Regards,
Yogendra
2014 Mar 19 12:45 PM
my string is not fixed , could any one pls let me know , how to remove alphabets from the string
Thanks
2014 Mar 19 1:03 PM
Hi ,
If you simply want to remove alphabets then assign the string to a numeric character variable.
It will only assign numbers to it.
data : str(20) VALUE '0021009010001000123NVN',
var(3),
num(20) TYPE n.
num = str.
WRITE : num.
Regards,
Yogendra
2014 Mar 19 12:53 PM
Hi Vijaya,
Try with this code:
DATA: l_leng TYPE i,
l_offset TYPE i,
l_string1 TYPE string VALUE '0021009010001000123NVN',
l_string2 TYPE STRING,
l_string3 TYPE string,
l_string4 TYPE string.
l_leng = strlen( l_string1 ).
do.
if l_offset = l_leng.
exit.
endif.
if l_string1+l_offset(1) co '0123456789'.
concatenate l_string2 l_string1+l_offset(1) into l_string2.
else.
* The value is a LETTER
concatenate l_string3 l_string1+l_offset(1) into l_string3.
endif.
l_offset = l_offset + 1.
enddo.
l_leng = strlen( l_string2 ).
l_offset = l_leng - 3.
l_string4 = l_string2+l_offset(3).
l_string2 = l_string2(l_offset).
The result is this:
Best Regards
2014 Mar 19 12:58 PM
Do something like thist.
DESCRIBE FIELD string LENGTH len IN CHARACTER MODE.
do.
if ofst = len1.
exit.
endif.
if str+ofst(1) co sy-abcde.
lv_alphabet_found = ofst.
endif.
ofst = ofst + 1.
enddo.
lv_alphabet = lv_alphabet_found - 4. '' This will give you the place from where you need three words
Now read like this
move STRING+lv_alphabet(3) to desired variable
2014 Mar 19 1:00 PM
Get the length of the string, (strlen);
use a index variable to loop
WHILE index < length
here you verify if the index of the string is not a number, if true, you will have when your split starts.
2014 Mar 19 1:06 PM
Hi Laxmi,
Use below code
DATA: g_str TYPE string VALUE '0021009010001000123NVN',
g_count TYPE i,
g_var TYPE char30 .
* finding the first character position in string
FIND FIRST OCCURRENCE OF REGEX '[A-Z]' IN g_str MATCH OFFSET g_count.
g_count = g_count - 3.
WRITE g_str+g_count(3).
Note: You no need to write do... enddo or while...endwhile.
It will work.
Regards,
Vineesh
2014 Mar 19 1:14 PM
Here is a one-liner way to do it using regular expressions.
For more information, you can read keyword documentation and explore DEMO_REGEX_TOY program.
See this snippet.
/.
2014 Mar 19 1:49 PM
Hi Manish,
I have never seen that expression, but It's very useful.
Despite that, I think that you solution will only work if there is at least one zero before last three numbers.
Is there any way to specify the number of bits that you want to get?
Best regards
2014 Mar 19 2:04 PM
Snippet works on 0021009010001asdf123NVN and 0021009010001asdf12345NVN too.
For second sample, you can restrict the match to only 3 digits using curly brackets. Same can be used to give upper and lower limits of length.
Try regex ([1-9]{3})[a-zA-Z]+$ on input string 0021009010001asdf12345NVN to get 345 as match.
2014 Mar 19 3:04 PM
2014 Mar 19 2:18 PM