ABAP Keyword Documentation → ABAP - Reference → ABAP Syntax → ABAP Statements → Operands → Data Objects in Operand Positions → Substring Access
Subfields
This example demonstrates how subfields can be accessed.
Other versions: 7.31 | 7.40 | 7.54
Source Code
DATA time TYPE t VALUE '172545'.
DATA: f1(8) TYPE c VALUE 'ABCDEFGH',
f2(20) TYPE c VALUE '12345678901234567890'.
DATA: f3(8) TYPE c VALUE 'ABCDEFGH',
f4(8) TYPE c.
DATA: o TYPE i VALUE 2,
l TYPE i VALUE 4.
DATA: string(20) TYPE c,
number(8) TYPE c VALUE '123456',
offset TYPE i VALUE 8,
length TYPE i VALUE 12.
WRITE time.
WRITE / time+2(2).
CLEAR time+2(4).
WRITE / time.
ULINE.
f2+6(5) = f1+3(5).
WRITE / f1.
WRITE / f2.
ULINE.
MOVE f3 TO f4. WRITE f4.
MOVE f3+o(l) TO f4. WRITE / f4.
MOVE f3 TO f4+o(l). WRITE / f4.
CLEAR f4.
MOVE f3 TO f4+o(l). WRITE / f4.
MOVE f3+o(l) TO f4+o(l). WRITE / f4.
ULINE.
WRITE number(6) TO string+offset(length) LEFT-JUSTIFIED.
WRITE: / string.
CLEAR string.
WRITE number(6) TO string+offset(length) CENTERED.
WRITE: / string.
CLEAR string.
WRITE number TO string+offset(length) RIGHT-JUSTIFIED.
WRITE: / string.
CLEAR string.
Description
In the first part, the minutes are selected by specifying an offset in the WRITE
statement. Then the minutes and seconds are set to their initial values by specifying an offset in the CLEAR
statement.
In the second part, the five character sequence 78901 from the field f2
is replaced with DEFGH from f1
using offset and length specifications.
In the third part, the MOVE
statement is used. First, the content of
f1 is assigned to f2
without offsets. This is repeated with offsets
and length specification for f1
. The next three MOVE
statements overwrite the contents of f2
with an offset of 2. Note,
f2 is filled on the right with empty spaces, according to the conversion rules for source type c
.
In part four, the WRITE TO
statement is used. The first six positions of
the field number
are written left-justified, centered, and right-justified into the last 12 positions of the string
field.