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.
WRITE – Output to a list
1. … AT pl (position and length specification,
before the field)
2. … option (formatting option)
3. … ofmt (output format by field)
4. … AS CHECKBOX (output as checkbox)
5. … AS SYMBOL (output as symbol)
6. … AS ICON (output as icon)
7. … AS LINE (output as line)
Outputs the field f in the correct format for its type to the current list. The field f can be:
a field declared by DATA ,
a component of a structure declared by TABLES ,
a field symbol (FIELD-SYMBOLS ),
a text literal which is not language-specific
a language-specific text literal (text symbol).
DATA N TYPE I VALUE 123.
ASSIGN ‘NEW YORK’ TO
WRITE: ‘—->’, SPFLI-DISTANCE.
WRITE: TEXT-001, SPFLI-ARRTIME.
WRITE: ‘Time:’(001), SPFLI-ARRTIME.
Text symbols can be addressed in two different ways (TEXT-001 or’Time:’(001)) .
no explicit position is specified for a field on a new line, it is
output on the left (in column 1). Otherwise, output is one column
removed from the previously output field. If a field does not fit on
one line, a new line is started.
You can perform explicit
positioning with a position and length specification (see addition 1)
or with ABAP/4 statements (e.g. POSITION ). In this case, the field is
always output at the defined position, even if the line is not quite
long enough for it to fit completely.
If a field is too long to fit completely on the line, the excess characters are truncated.
field occupies a number of characters in the list. If this number is
not explicitly defined (see addition 1), the system uses a
type-specific standard length or the output length specified in the
ABAP/4 Dictionary .
Type-specific output: (len = field length)
|Type||Standard output length||Output|
|P||2*len or 2*len+1||right-justified|
fields (types P , I and F ) are always output right-justified, but all
other types are left-justified; if required, blanks are used for
padding. With number fields, leading zeros are replaced by blanks. If
there is enough space, types P and I have thousands separators. To
accommodate the decimal point, the output length of type P fields is 1
WRITE AT pl (position and length
specification before the field)
can use the position and length specification pl to define the precise
output position and length of a field. The specification consists of:
/ New line
c Output position (1-3 character number or variable)
(l) Output length (1-3 character number or variable)
Combinations are possible.
DATA: WORD(16), VALUE ’0123456789ABCDEF’,
COL TYPE I VALUE 5,
LEN TYPE I VALUE 10.
WRITE AT / WORD. “new line
WRITE AT 5 WORD. “column 5
WRITE AT (10) WORD. “output length 10
WRITE AT /5(10) WORD. “new line, column 5, length 10
WRITE AT COL WORD. “column = contents of COL
WRITE AT (LEN) WORD. “output length = contents of LEN
WRITE AT /COL(LEN) WORD. “new line, column = contents of COL
“output length = contents of LEN
position and length specification must appear before the field. If the
position and length specification contains only constants, you the
introductory AT is unnecessary. (In the first four of the above
examples, you can therefore omit AT .) Always write the position and
length specification without gaps and in the specified order. Leave at
least one space between the position and length specification and the
field name. For dynamic positioning, see also POSITION . No output
results from positioning to the right of the far right edge of the
page. With explicit column specifications, the field is output from
this column, even if it no longer completely fits on the line or
overwrites another field. If the output length is too short, number
fields (types P , I and F are prefixed with an asterisk (‘*’), while
all other types are truncated on the right. If you want the abbreviated
output of a variable, you should always use WRITE (10) T100-TEXT rather
than WRITE T100-TEXT(10) (sub-field access).
On the one hand, the
first form is always allowed and the second form can be forbidden for
certain data types (e.g. TYPE P ). On the other hand, only the first
form guarantees the identity of the variables for GET CURSOR … FIELD
and F1 help.
… option (formatting option)
You can modify the output of the field f by using one of the special formatting options .
… ofmt (output format by field)
Outputs the field with the specified output formats (color, intensity, ready for input, …).
can use the same output options as for FORMAT . If no specifications
are made, the field is output with the standard formats or with the
format set by a preceding FORMAT statement.
FORMAT INTENSIFIED OFF INPUT.
WRITE F INPUT OFF INVERSE COLOR 3.
format specifications with WRITE apply only for output of the field f .
They modify the currently valid format for this field. This means that,
in the above example, the non-highlighted output remains for the field
F . When f has been output, the system reverts to the old format.
… AS CHECKBOX (output as checkbox)
… AS SYMBOL (output as symbol)
… AS ICON (output as icon)
… AS LINE (output as line)
General notes on outputting boxes to lists
When you output a list, this is sometimes combined with vertical and horizontal lines to form closed boxes:
Vertical lines are output by the system field SY-VLINE or by a field containing ” | ” (vertical bar),
Horizontal lines are output by the system field SY-ULINE or by a field containing only ” – ” (minus sign),
Vertical and horizontal lines converge (without gaps).
- WRITE – Output to a variable ( SAP ABAP keyword)
- WRITE – Output as symbol (ABAP keyword)
- WRITE – Output formatting options ( SAP ABAP Keyword)
- WRITE – Output as icon ( SAP ABAP Keyword)
- WRITE – Output as checkbox (ABAP keyword)