SAP UNICODE OFFSET LENGTH

Get Example source ABAP code based on a different SAP table
  


Article

Offset and Length Specifications in Unicode Programs
Offset/length specifications are made by appending [+off][(len)] to the name of a data object in operand position, and the specifications are used to access subareas of a data object. This type of programming is no longer completely possible in Unicode systems because, for example when accessing structures with components of different data types, it is not possible to define whether offset and length should be specified in characters or bytes. Furthermore, restrictions have been introduced that forbid access to memory areas outside of flat data objects.

Note
Predefined substring functions can be used to perform reads on substrings of character-like data objects, instead of specifying offsets/lengths.

Offset/Length Specifications for Elementary Data Objects
Offset/length specifications are permitted for character-like data objects and byte-like data objects. The specification of offset and length is interpreted either as a number of characters or as a number of bytes. The rules that determine which data objects in Unicode programs count as character-like or byte-like objects do not allow for offset/length specifications for data objects of numeric data types.

Note
The method of using data objects of type c as containers for storing structures of different types, which are often not known until runtime, in which components are accessed using offset/length access, is no longer possible in Unicode programs. Instead of these containers, the statement CREATE DATA can be used to generate data objects of any structure. To enable access to existing containers, these can be assigned to a field symbol using the CASTING addition of the statement ASSIGN. The COMPONENT addition can then be used to access components.

Offset/Length Specifications for Structures
An offset/length specification for a structure is only permitted in Unicode systems if the structure is either
character-like (meaning it only contains flat character-like components), or it is
flat, has a character-like initial fragment according to the Unicode fragment view, and the offset/length specification accesses this initial fragment.
In both cases, the specification of offset and length is interpreted as a number of characters.

Example
The following structure has both character-like and non-character-like components: DATA:
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 Unicode 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 access is only possible for the character-like initial fragment F1. Specifications such as struc(21) or struc+7(14) are accepted and are handled as a single field of type c. An access such as struc+57(2), for example, is not permitted in Unicode systems.

Offset/Length Specifications for Actual Parameters
For actual parameters specified in PERFORM, in Unicode programs, it is not possible to specify a memory area outside of the actual parameter using offset/length specifications. In particular, it is no longer possible to specify an offset without a length, as this would implicitly set the length of the actual parameter.

Offset/Length Specification for Field Symbols
When assigning a memory area to a field symbol using the ASSIGN statement, in Unicode programs it is now only possible to use offset/length specifications to access the memory within the data object. The addition RANGE defines the data object.
Field symbols themselves are also allocated an assignable memory area. This is effective if a field symbol is used as a source in the ASSIGN statement.
In non-Unicode programs, the assignable area is defined by the data area of the current program, which can lead to references being overwritten.
If a data object is entered as a source in ASSIGN, no offset can be specified without a length unless the explicit RANGE addition is specified. Otherwise, this would implicitly set the length of the data object. If the name of a field symbol is specified, its data type in Unicode programs must be flat and elementary if an offset is specified without a length.

Note
Previously, cross-field offset/length accesses could be usefully implemented in the ASSIGN statement for editing repeating groups in structures. In order to enable this in Unicode systems, the ASSIGN statement has been enhanced with the additions RANGE and INCREMENT.