Ansicht
Dokumentation

ABENOFFSET_LENGTH - OFFSET LENGTH

ABENOFFSET_LENGTH - OFFSET LENGTH

Addresses (Business Address Services)   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.
SAP E-Book

Offset/Length Specifications for Substring Access

In operand positions, it is possible to access subareas of certain data objects by specifying an offset and a length:

dobj$[+off$]$[(len)$]

<fs>$[+off$]$[(len)$]

dref->*$[+off$]$[(len)$]

Effect

An offset off can be appended directly with the character + to the identifier dobj of a data object, <fs> of a field symbol, or to a dereferenced data reference variable dref->*. A length len can be appended to the offset specification directly in parentheses ( ) or directly to the identifier. Offsets or lengths can be specified for:

  • The structure only contains flat character-like components.

  • The first fragment of the structural fragment view is flat and character-like, and the substring addressed by specifying the offset and length is located within this fragment.

The segment of the data object is used that has the offset specified in off and the length specified in len in characters or bytes. No memory area outside the field boundaries can be addressed, except for in the statement ASSIGN. In the case of an offset specification without a length, the entire substring is addressed from off characters; in the case of a length specification 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, which must contain positive integers, with the following exceptions.

  • The length 0 can be specified for strings.
  • A negative offset, but never length 0, can be specified if an <fs> field symbol is specified in the statement ASSIGN for dobj.
  • If off is smaller than the length of dobj, an asterisk (*) can be entered for len. The upper limit of dobj then determines the upper limit of the memory area.

If the prerequisites are not met, or if the substring defined by off and len is not fully included 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, it cannot be preceded by a plus/minus sign.

The offset and length specifications are counted in characters for character-like data objects and otherwise in bytes.

A substring specified by an offset or length specification is handled like a data object of the specified length. The 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

In a substring access, if the length of the substring matches the length of the structure to a structure exactly, the substring does not have data type c but is handled like the structure itself.

The following restrictions apply:

  • At write positions, only flat data objects are allowed, that is, write access to substrings of strings is not possible.
  • Access to substrings of strings is also not possible in the following read positions:
  • Specification of dobj$[+off$]$[(len)$] as a memory area mem_area of the statement ASSIGN.

  • Specification of dobj$[+off$]$[(len)$] as an argument of the statement GET REFERENCE or of the reference operator REF.

  • Offsets and lengths cannot be specified for literals or text symbols.
  • An offset/length specification cannot be attached directly to a table expression itab[ ... ], but to a chaining whose last position is a suitable structure component after a structure component selector.
  • In case of dynamically specified operands in parentheses, no length specification can be made.
  • A dereferenced data reference variable dref->* must be typed completely.
  • For a writable expression, no offsets or lengths can be specified as memory areas of the statement ASSIGN or as arguments of the reference operator REF (table expressions only).
  • If the offset/length specification is applied to a data object that is directly assigned to the inline declaration, off and len must be literals or constants. Variables are not allowed.

  • If the offset/length specification is applied to a data object that is the result of chaining that involves a constructor expression or a table expression, the data type of the declared data object is the data type of the assigned data object in its full length and the substring is assigned according to the respective conversion rules.

Notes

  • For reads on substrings of character-like data objects, built-in substring functions that allow searches for substrings and offsets/lengths are also available. The substring functions can also be used to process arguments where offsets and lengths cannot be specified, such as data objects with an enumerated type because there is an implicit conversion to string.
  • It is recommended that always explicitly offsets with the value 0 are specified, that is, dobj+0(len) instead of dobj(len) to differentiates substring access in the source code clearly from other language constructs that also contain parentheses, such as dynamic specifications, method calls, or inline declarations.
  • A specification of dobj+0(*), dobj+0, or dobj(*) is always interpreted as dobj. In this case, dobj can also be a data object where substring access according to the rules above is not possible.
  • The above restriction regarding offset/length specifications for results of chainings involving table or constructor expressions is not valid for types that are inferred at runtime, e.g. when passing to generic parameters of procedures. Then the data type of the substring is used.
  • No substring access cnt(len), sum(len) can be performed on data objects named cnt and sum unless an offset is specified explicitly. The compiler always interprets such an entry as a number or sum of a field len in the group level processing of an extract dataset.
  • The statement MOVE PERCENTAGE represents an obsolete form of substring access.

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

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 and length accesses are only possible on the character-like initial fragment F1 only, for example struc(21) or struc+7(14). An access such as struc+57(2) is not allowed.

Substrings






SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.

Length: 13751 Date: 20240424 Time: 105749     sap01-206 ( 158 ms )