‎2011 Jul 02 4:29 PM
Hi
If in a report the input is a string which contains alphabets ,special characters and numbers . If we want to filter the different data types into different variables of their respective types , how can we do it . Is there a function module to do this .
Eg : parameters a type string value 'abc12*3d& .
data : alphab type char ,
numbers type num,
special type cahr .
How can we get alphabets = abcd
numbers = 123
specialchar = *&
<removed by moderator> .
Thanks in advance
MSR
Edited by: Thomas Zloch on Jul 2, 2011 7:25 PM
‎2011 Jul 02 4:59 PM
hello,
use regular expressions. for example:
data: lv_regex type ref to cl_abap_regex,
lv_text type string value 'aaa1b',
lt_result type match_result_tab,
create object lv_regex
exporting
pattern = '\d+'. "only digits
find all occurrences of regex lv_regex in lv_text results lt_result.the result will be length and offset (identifies the position of valid character or set of characters).
‎2011 Jul 02 4:59 PM
hello,
use regular expressions. for example:
data: lv_regex type ref to cl_abap_regex,
lv_text type string value 'aaa1b',
lt_result type match_result_tab,
create object lv_regex
exporting
pattern = '\d+'. "only digits
find all occurrences of regex lv_regex in lv_text results lt_result.the result will be length and offset (identifies the position of valid character or set of characters).
‎2011 Jul 03 12:05 PM
Hi
I did not understand the answer ,can you please elaborate . Can't this be done in 5 to 10 lines of code .
Thanks N Regards
MSR
‎2011 Jul 03 2:04 PM
Hi msr,
it is nopt easy to five an answer without knowing your level of knowledge.
I think the idea is to find the alphabets ,special characters and numbers using regular expressions (well known in may programming languagesm available in ABAP since ECC600) to find all occurences of the patterns and store the offset and length of the data in table lt_result.
For testing Regex without coding you can use the ABAP program DEMO_REGEX_TOY. Basically it can be done in 5-10 lines of code:
For each pattern, FIND ALL OCCURENCES OF <pattern> IN <yourstring> RESULTS lt_result. Then loop at lt_result and concatenate every <yourstring>+<result-offset(<result>-length) into respective pattern subgroup.
Please try to convert this into ABAP code, feel free to come back when you are struck.
Regards,
Clemens