SAP REGEX EXCEPTIONS

Get Example source ABAP code based on a different SAP table
  


ARTICLE

Exceptions in Regular Expressions
If a regular expression is syntactically correct but too complex, it cannot be executed by the Boost.Regex Library that is integrated in the ABAP kernel. In this case, an exception of the class
CX_SY_REGEX_TOO_COMPLEX is raised.
A regular expression is too complex if the number of transitions exceeds a certain limit. This is usually the case if there are expressions that have been programmed incorrectly or are inadequate regular expressions that would lead to extensive tracing for certain texts.

Note
The occurrence of the CX_SY_REGEX_TOO_COMPLEX exception depends on both the regular expression and the text to be checked. A regular expression that works for one text may lead to an exception in another text.

Example
If we consider the following simple search with a syntactically correct regular expression: FIND REGEX '.*X.*' IN text.
IF sy-subrc = 0.
...
ENDIF.
If the text length is several hundred characters or more, this statement always raises the exception named above. As a result of the Leftmost-longest rule and the greedy behavior of the chaining operator *, all found locations of subsequences that match the first part of the regular expression (.*) have to be saved internally until the last X has been found. A chain like .*, which matches any number of subsequences, should therefore be avoided at the start of a regular expression.
The above search is successful for every character string that contains at least one X and any number of other characters. Instead of a regular expression, in this case you can use a simple search for a subsequence or the relational operator CS : FIND SUBSTRING 'X' IN text.
IF sy-subrc = 0.
...
ENDIF.
or IF text CS 'X'.
...
ENDIF.