2016 Sep 20 3:59 PM
Hi Experts,
Thanks in advance for you help.
i want to write a code using comparison string (CS, CA,NA,NS etc) with using case statement.
for ex- there is a filed lv_string which is having descriptions. so i want to validate some words in descriptions and want write code using CASE instead of IF- ELSE .
case lv_string.
when contains the letter 'text' or 'word'.
so how can i validate or write the code.
2016 Sep 21 5:50 AM
2016 Sep 21 6:53 AM
Hi Saransh,
Thank you for your response.
The reason behind using CASE is we can reduce no. of lines code.
please let me know if you any other efficient way to do it.
Regards
Ujjwal
2016 Sep 21 8:16 AM
Hi Ujjwal,
CASE is better then IF-ELSE if there are 5 or more conditions.
But we cannot use (CS, CA,NA,NS) with CASE. If the words you want to validate are always at the fixed offset then you can always fetch those words (lv_string+x(y)) and then use CASE on that new word.
Thanks,
Saransh Walia.
2016 Sep 21 9:58 AM
Hi,
Just to elaborate on the answer given by VenkatRamesh V.
Define ranges and get all the words that you want to compare in the low value of the range.
Loop at range.
if range-low cs lv_string.
*** Do your coding***
endif.
endloop.
Hope this helps.
2016 Sep 21 6:14 AM
2016 Sep 21 7:07 AM
Hi,
I dont think you can make use of case statement when you are comparing string as your dont know what other words will come in LV_STRING along with the words which you want to compare using case statement.
ABAP provide statements and classes for regular expression operation.
ABAP statement – REGEX ABAP statements
FIND and REPLACE support the use of regular expression with additional clause REGEX.
FIND statement searches the given text for a match with a regular expression, as shown below:
FIND REGEX 'text*word' IN LV_STRING.
FIND ALL OCCURRENCES OF REGEX pattern IN text
RESULTS match_result.
All the matching expression will be stored in match_result variables with type MATCH_RESULT_TAB.
thanks!!
2016 Sep 21 8:14 AM
Hi ujjwal,
you can not use CS , CA ... with When inside CASE statement..
forget CASE satatement instead use IF..
regards,
vinay..