WRITE ( Output to a variable ) is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
WRITE - Output to a variable
Variants
1. WRITE f TO g[+off][(len)].
2. WRITE f TO itab[+off][(len)] INDEX idx.
Variant 1
WRITE f TO g[+off][(len)].
Addition
... option
Effect
Assigns the contents of the source field f to the target field g as a new value.
In
contrast to MOVE , the format of the target field g is the same as when
outputting to a list with WRITE . The field type C is always used,
regardless of the actual data type.
As with list output, the
settings in the user's master record for decimal point (period or
comma) and date format are taken into account.
Other formatting options are also possible with list output.
Instead
of specifying a static source field f , you can make a dynamic source
field specification (name) . In this case, the contents of the field
name is interpreted as the source field name at runtime and the
contents are formatted accordingly.
You can identify the target
field g more precisely by specifying the offset and/or length in the
form g+off(len) . Both the offset and the length specifications off and
len can also be dynamic.
The return code value SY-SUBRC is undefined.
Example
WRITE ... TO with dynamic source field specification and dynamic offset and length specification for the target field:
DATA: NAME(5) VALUE 'FIELD',
FIELD(5) VALUE 'Harry',
DEST(18) VALUE 'Robert James Smith',
OFF TYPE I,
LEN TYPE I.
OFF = 7.
LEN = 8.
WRITE (NAME) TO DEST+OFF(LEN).
The field DEST noew contains the value " Robert Harry ith ".
Notes
Only
values between 0 and the length of the target field g are allowed as
offset specifications. Any other offset specifications result in a
runtime error.
Only values >= 0 are allowed as length
specifications. Negative length specifications result in a runtime
error. Excessive length specifications are automatically truncated.
If
you specify the field length as the offset or the value 0 as the
length, the target field is blank. In this case, the statement has no
effect.
Addition
... option
Effect
Modifies the output format with the aid of special formatting options .
Variant 2
WRITE f TO itab[+off][(len)] INDEX idx.
Additions like variant 1.
Effect
Like variant 1, except that output is to the idx -th line of the internal table itab .
Ayn offset and/or length specifications refer to the table line used for output.
The return code value is set as follows:
SY-SUBRC = 0 Valid index specification, i.e. the internal table itab contains a line with the index idx .
SY_SUBRC = 4 Index specification is too large, i.e. the internal table itab contains fewer than idx entries.
Note
Invalid index specifications, i.e. idx <= 0, result in a runtime error.
Note
Runtime errors
WRITE_TO_LENGTH_NEGATIVE : Negative length specification in len .
WRITE_TO_OFFSET_NEGATIVE : Negative offset specification in off .
WRITE_TO_OFFSET_TOOLARGE : Offset specification in off is greater than field length.
TABLE_INVALID_INDEX : Invalid index specification <= 0 in idx (variant 2 only).
Related 10 ABAP Syntax Tutorials
Most readed SAP Tutorials
- WRITE - Output to a list ( SAP ABAP Keyword)
WRITE ( Output to a list ) is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details. - List of SAP HR TABLES and Infotypes tables
Detailed full list of tables and infotypes used in SAP HR module. - List of SAP MM Transaction codes
This documentation covers the details of SAP MM Transaction codes - SELECT-OPTIONS ( SAP ABAP Keyword)
SELECT-OPTIONS is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details. - FI Accounts Receivable and Accounts Payable | SAP FI PDF manual
The following topics are an introduction to the Accounts Receivable and Accounts Payable application components. - SAP MM Process Flow
The typical procurement cycle for a service or material consists of the following phases: - SELECT clause ( SAP ABAP Keyword)
SELECT clause is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.
Latest Added SAP documents
- 9KE9 Transaction code
Details about SAP transaction code 9KE9 - 9KE8 Transaction code
Details about SAP transaction code 9KE8 - 9KE7 Transaction code
Details about SAP transaction code 9KE7 - 9KE6 Transaction code
Details about SAP transaction code 9KE6 - 9KE5 Transaction code
Details about SAP transaction code 9KE5 - 9KE4 Transaction code
Details about SAP transaction code 9KE4 - 9KE3 Transaction code
Details about SAP transaction code 9KE3 - 9KE2 Transaction code
Details about SAP transaction code 9KE2 - 9KE1 Transaction code
Details about SAP transaction code 9KE1 - 9KE0 Transaction code
Details about SAP transaction code 9KE0