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
segment - Segment Function
... segment( val = text index = idx [sep|space = delim] ) ...
This function returns the occurrence of a segment of the argument
index. A segment
is defined by delimiters. The beginning and ending of the string in
are the outer delimiters. Inner delimiters
delim can be passed to
space as follows:
- If the argument
sepis provided, the substring specified in
delimis searched for (case-sensitive as in
text) and used as a delimiter. If a substring specified in
delimoccurs directly one after another in
text, an empty segment is created and an empty string is returned for this segment.
- If the argument
spaceis provided, each individual character is searched for in
delim(case-sensitive) and this is used as a delimiter. If the individual characters specified in
delimoccur directly one after another in
text, no empty segment is created and no result is returned.
The delimiters are not part of the segments. If
are not specified, the argument
sep is filled implicitly a single blank. In both cases, specifying an empty string raises an exception of the class CX_SY_STRG_PAR_VAL.
index is positive, the occurrences are counted from the left; if
index is negative, the instance are counted from the right. The values 1, 2, .... indicate the
first, second, ... occurrences. The values -1, -2, .... indicate the last, last but one, ... occurrences.
If the value of
index is 0, or the specified segment does not exist, an exception of the class CX_SY_STRG_PAR_VAL is raised.
The return code has the type
If the substring specified in
delim is not found, the entire character string
forms a single segment. This segment can only be addressed by using the values 1 or -1 for
The following function calls produce "AB", "CD", "EF", "GH", respectively, and raise an exception at the end.
DATA result TYPE string. DO. TRY. result = segment( val = 'AB\brCD\brEF\brGH' index = sy-index sep = `\br` ). ... CATCH cx_sy_strg_par_val. EXIT. ENDTRY. ENDDO. DO. TRY. result = segment( val = 'AB CD - EF_GH' index = sy-index space = ` -_` ). ... CATCH cx_sy_strg_par_val. EXIT. ENDTRY. ENDDO.
Cause: Delimiter in
sepis empty or the occurrence in
indexis 0 or was not found.