ABAP - Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  String Functions →  Processing Functions for Character-Like Arguments → 

substring, substring_... - Substring Functions

Syntax Forms

1. ... substring( val = text [ off = off] [len = len] ) ...

2. ... substring_from( val = text { sub = substring}|{ regex = regex}
                     [ case = case] [ occ = occ] [ len = len]  ) ...

3. ... substring_after( val = text { sub = substring}|{ regex = regex}
                      [case = case] [ occ = occ] [ len = len]  ) ...

4. ... substring_before( val = text { sub = substring}|{ regex = regex}
                       [case = case] [ occ = occ] [ len = len]  ) ...

5. ... substring_to( val = text { sub = substring}|{ regex = regex}
                   [ case = case] [ occ = occ] [ len = len]  ) ...

Effect

In the argument text, the substring functions determine a substring and return it.

The substring is determined as follows:

The return code has the type string accordingly.

Note

The performance of the substring functions is not as good as a direct substring access. They do, however, make it possible to use expressions in all operand positions.

Example

The return codes of the following function calls are: "CD", "CDEFGH"., "EFGH"., "AB"., and "ABCD".

DATA  result TYPE string.
...
result = substring( val = 'ABCDEFGH' off = 2 len = 2 ).
...
result = substring_from( val = 'ABCDEFGH' sub = 'CD' ).
...
result = substring_after( val = 'ABCDEFGH' sub = 'CD' ).
...
result = substring_before( val = 'ABCDEFGH' sub = 'CD' ).
...
result = substring_to( val = 'ABCDEFGH' sub = 'CD' ).
...

Exceptions

Handleable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

CX_SY_REGEX_TOO_COMPLEX

CX_SY_STRG_PAR_VAL