The WRITE statement is one of the most fundamental statements in ABAP for outputting data. Its main purpose is to write values (variable contents, literals, system fields, etc.) to the current output list (also known as “classic list” or “spool list”). This list is typically displayed when an executable program (report) runs in dialog mode, or it is saved as a spool job when the program runs in the background.
Syntax
The simplest form of the syntax is:
WRITE <output> [formatting_options].<output>: This is the value to be output. It can be:
- A data object (variable, constant)
- A text literal (e.g.,
'Hello World') - A field symbol
- A system field (e.g.,
sy-datum,sy-uzeit) - A component of a structure (e.g.,
structure-fieldname) - An expression
[formatting_options]: Optional additions to control the position and appearance of the output.
Positioning on the List
By default, each WRITE statement continues directly after the previous output in the current line (with a space in between). However, you can precisely control the position:
-
New line (
/):WRITE / <output>.Starts the output on a new line in the first column (column 1).
-
Absolute position (
AT <column>):WRITE AT <column> <output>.WRITE AT /<column> <output>. " Combined: New line and columnStarts the output in the current line (or a new line with
AT /) at the specified column number<column>. -
Position with length specification (
AT <column>(<length>)):WRITE AT <column>(<length>) <output>.WRITE AT /<column>(<length>) <output>.Outputs
<output>starting at column<column>, but reserves exactly<length>characters for it. The content is truncated or padded as needed (default: right-justified for numbers, left-justified for text).
Important Formatting Options
There are numerous options to influence the appearance of the output:
Alignment:
LEFT-JUSTIFIED: Left-alignedCENTERED: CenteredRIGHT-JUSTIFIED: Right-aligned (default for numeric types)
No gap:
NO-GAP: Suppresses the automatic space between directly consecutiveWRITEoutputs in the same line.
Formatting masks:
USING EDIT MASK <mask>: Applies a mask.<mask>is a literal or variable, e.g.,'__:__'for time,'RR__,___,___.__'for numbers,'DD.MM.YYYY'for date.USING NO EDIT MASK: Suppresses the application of standard conversion routines (e.g., for date formats).
Number formats:
CURRENCY <currency_field>: Formats an amount according to the currency key in<currency_field>. Considers the number of decimal places and thousand separator of the currency.DECIMALS <count>: Outputs the value with<count>decimal places.NO-ZERO: Outputs nothing if the value is zero or the initial value of the data type.NO-SIGN: Suppresses the output of the sign (+/-).EXPONENT <exp>: For floating point numbers (typef), output with exponent<exp>.
Appearance (colors, etc.):
COLOR <color> | COL_<key> | <n>: Sets the color.<color>can be1-7,<key>can be e.g.,HEADING,NORMAL,TOTAL,POSITIVE,NEGATIVE.INTENSIFIED [ON|OFF]: Intensified (bright) display.INVERSE [ON|OFF]: Inverse display (background/foreground color swapped).INPUT [ON|OFF]: Makes the field input-ready (only meaningful in lists used for input).
Special outputs:
AS CHECKBOX: Outputs the field as a checkbox (value ‘X’ = checked, ’ ’ = unchecked).AS SYMBOL: Outputs a predefined symbol (e.g.,SYM_BULLET,SYM_PHONE; see type groupSYM).AS ICON: Outputs an icon (e.g.,ICON_OKAY,ICON_CANCEL; see type groupICON).AS LINE: Draws lines (used withULINE,VLINE).
Examples
1. Simple Outputs and Line Breaks
DATA: text1 TYPE string VALUE 'Hello', text2 TYPE string VALUE 'ABAP World!', count TYPE i VALUE 10, today TYPE d.
today = sy-datum. " Today's date (e.g., 20250420)
WRITE text1. " Output: HelloWRITE text2. " Output: ABAP World! (with space)WRITE / 'New paragraph.'. " Output: New paragraph. (on new line)WRITE / 'Count:'.WRITE count. " Output: 10 (right-justified in default length)WRITE / 'Date:'.WRITE today. " Output: 20.04.2025 (default format from user master)2. Positioning
WRITE: / AT 5 'Text in column 5', / AT 10(20) 'Limited text from column 10 to 20 characters', sy-vline, " Vertical line at current position AT 40 'After the line'.3. Formatting Options
DATA: price TYPE p DECIMALS 2 VALUE '1234.99', currency_code TYPE waers VALUE 'EUR', date TYPE d VALUE '20250420', time TYPE t VALUE '103000'.
WRITE: / 'Price (Standard):', price.WRITE: / 'Price (Currency):', price CURRENCY currency_code.WRITE: / 'Price (Centered):', price CENTERED.WRITE: / 'Price (No zeros):' NO-ZERO price.
WRITE: / 'Date (Mask):', date USING EDIT MASK '____/__/__'. " Output: 2025/04/20WRITE: / 'Time (Mask):', time USING EDIT MASK '__:__:__'. " Output: 10:30:00
WRITE: / 'Important message' COLOR COL_NEGATIVE INTENSIFIED.WRITE ' here' COLOR COL_NEGATIVE INTENSIFIED NO-GAP. " Directly attached, without space4. Special Outputs
DATA: checkbox_val TYPE c LENGTH 1 VALUE 'X'.
WRITE: / 'Status:' AS ICON, icon_led_green AS ICON NO-GAP.WRITE: / 'Option A:' AS CHECKBOX, checkbox_val AS CHECKBOX INPUT. " Input-readyWRITE: / 'Bullet Point:' AS SYMBOL, sym_bullet AS SYMBOL NO-GAP, ' Text'.ULINE AT /1(30). " Horizontal line over 30 columns on new lineImportant Notes
- The
WRITEstatement is fundamental for classic ABAP list processing. - The width of the list is usually determined by the
LINE-SIZEaddition of theREPORTstatement. - In modern ABAP applications (e.g., with ALV = ABAP List Viewer, or Fiori Apps), data display is usually handled by the UI frameworks. There,
WRITEis less commonly used for primary data display, but it remains useful for simple logs, debugging, or generating simple spool lists in the background.