ABAP - Keyword Documentation →  ABAP - Reference →  ABAP Syntax →  ABAP Statements →  Operands →  Data Objects in Operand Positions → 

Substring Access

In operand positions, subareas of certain data objects can be accessed by specifying an offset/length:






A specified offset or length is directly appended to either the dobj descriptor of the data object, an <fs> field symbol, or a dereferenced data reference variable dref->*. Offsets/lengths can be specified for:

The following restrictions apply:

The segment of the data object is used that has the offset specified in off and the length (in characters or bytes) specified in len. A memory area must not be addressed outside the field boundaries, except in the case of the statement ASSIGN. In an offset specified without a length, the entire substring is addressed from off characters; for a length specified without an offset, the first len characters are addressed (different rules apply to the statement ASSIGN).

The operands off and len expect data objects of the type i. These data objects must contain positive integers, with the following exceptions.

If the prerequisites are not met or if the subarea defined by off and len is not completely contained in the data object (except in the case of ASSIGN), a syntax error occurs (if statically identifiable). Otherwise, an exception of the class CX_SY_RANGE_OUT_OF_BOUNDS is raised. If off is specified as a numeric literal, this literal cannot be prefixed with a sign.

The offset and length specified are counted in characters for character-like data objects and in bytes for all other data objects.

A substring specified by an offset or length is handled like a data object of the specified length whose data type depends on the data type of the original data object, the field symbol, or the data reference variable, as shown below:

Original Data Type Data Type of Substring
c c
n n
d n
t n
string string
x x
xstring xstring
Structure type c

If the length of the substring matches the length of the structure in a substring access to a structure exactly, the substring does not have data type c and is handled like the structure itself instead.



The following structure has both character-like and non-character-like components:

  BEGIN OF struc,
    a TYPE c LENGTH 3,    "Length 3 characters
    b TYPE n LENGTH 4,    "Length 4 characters
    c TYPE d,             "Length 8 characters
    d TYPE t,             "Length 6 characters
    e TYPE decfloat16,    "Length 8 bytes
    f TYPE c LENGTH 28,   "Length 28 characters
    g TYPE x LENGTH 2,    "Length 2 bytes
  END OF struc.

The fragment view splits the structure into five areas, F1 - F5.

[ aaa | bbbb | cccccccc | ddd | AAA | eeee | fffffffffffff | gg ]
[            F1               |  F2 |  F3  |       F4      | F5 ]

Offset/length accesses are possible on the character-like initial fragment F1 only, for example struc(21) or struc+7(14). An access such as struc+57(2), for example, is not permitted.

Executable Example


Example Substrings