Showing posts with label REGEX Statement in SAP ABAP. Show all posts
Showing posts with label REGEX Statement in SAP ABAP. Show all posts

ABAP REGEX Statement usage in STRING


ABAP REGEX statement to remove special characters from a STRING

ABAP Tips and Tricks

To remove the special characters from the string, use replace all and regex statement to do so.
Let's see the process with an example.
The replace all occurrences is added having the regular expression [^\d].




Enter the value for the string with special characters




Press F8 to execute the program.
After executing the program, you will get the output without special characters.













REGEX Statement instead of IF statement in SAP ABAP



Usage of REGEX Statement instead of IF statement with multiple Conditions

Tips and Tricks:

Code a program with if statement that will check if the value of a parameter variable field has the value equal to ABC, DEF, or CDE. In case the value is equal to any of the three, the message Field Value is Valid is displayed. We will then see the equivalent regex.




Instead of IF statement, write a find REGEX statement along with the regex '[ABC|CDE|DEF]'.


We have used an OR (|) operator within the find statement. A match is found if the value of the three-character field is equal to any of the three values specified. In this case, sy-subrc is equal to zero, and the success message is then displayed.
In case, you need to ignore the CASE, add IGNORING CASE in the FIND REGEX statement.