SAP WRITE- ABAP Statements



Get Example source ABAP code based on a different SAP table
  


ID WRITE
• WRITE ABAP Statement

WRITE
Short Reference

ABAP_SYNTAX
WRITE ${$[AT$] $[/$]$[pos$]$[(len$|*$|**)$]$} dobj
$[UNDER other_dobj$]
$[NO-GAP$]
$[int_format_options$]
$[ext_format_options$]
$[list_elements$]
$[QUICKINFO info$].

ABAP Addition
1 ... $[AT$] $[/$]$[pos$]$[(len$|*$|**)$]
2 ... UNDER other_dobj
3 ... NO-GAP
4 ... QUICKINFO info

What does it do?
This statement formats the content of the data object dobj and writes it to the current page of the current list. This is either a screen list in the list buffer or a spool list. dobj is a general expression position with the restriction that no arithmetic expressions and no bit expressions can be specified directly.
For dobj, those data types are allowed that are grouped under the generic type simple:
All flat data types; flat structures are handled like a data object of type c and can only contain any character-like components.
The data types string and xstring
enumerated types; the name (maximum three characters) of the enumerated constant is used in uppercase letters, which defines the current enumerated value.
Formatting the Output
The output is formatted
in accordance with the same predefined formats as in the statement WRITE ... TO or
with the additions int_format_options .
ext_format_options allows output to be formatted and the additions list_elements allow specific list elements to be displayed. By default, adjacent characters - and | in a list are joined to form continuous lines.
Output Position
The output position is either determined by the list cursor or can be specified using pos after AT or using UNDER. The list cursor itself can be adjusted using NO-GAP. At the start of every output, the output position in the list buffer is the same as the output position in the list representation. The positions of individual characters within an output field can differ between the list representation and the list buffer. In both cases, however, the output length is the same.
Output Length
The output length is determined either by the data type of dobj or can be specified after AT using len$|*$|**. len specifies an absolute length and * or ** are used to prevent unwanted truncations.
Page Break
If the last line of the current page is reached and a subsequent line is output, a new page is generated. The maximum number of lines is determined by the addition LINE-COUNT of the program-initiating statement or the statement NEW-PAGE. For the basic list, the event END-OF-PAGE is raised when the area reserved for the page footer is reached, and a new page is then created.
Line Break
Once the list cursor has been positioned with a previous output statement, if the output length is greater than the area available in the current line of the list buffer, the output goes to the next line. If this line is also not sufficient for a complete output, the output length is truncated accordingly, and the output is displayed in this line.
If the list cursor is positioned using by specifying pos or a statement BACK, NEW-LINE , NEW-PAGE, POSITION or SKIP and not with a previous output statement, the output is always displayed in the current line, and the output length is truncated, if necessary.
List Cursor
After the output is displayed, the list cursor is positioned by default in the second place after the output; the sy-colno and sy-linno system fields are set accordingly.
Field Help and Input Help
If the data object dobj is declared with reference to a data type from the ABAP Dictionary, the field and input help defined here are available in the list displayed on the window.



Latest notes:

In the default setting, the system does not place a new line that contains only blank characters in a list. A blank line is only output if the list cursor is directly positioned in an existing line, that is, not using a line break. This setting can be changed using the statement SET BLANK LINES ON.
Arithmetic expressions and bit expressions cannot be specified directly, but they can be specified in embedded expressions in string templates.
Control characters for line feeds or tabs are ignored in strings that are displayed using WRITE. These characters are displayed as #, like all other non-displayable characters.
If the start of a character string, which is output with WRITE, contains an internal ID (key or internal name) for an icon at the beginning between two characters @, this is displayed in the list as an icon, even without the addition AS ICON. This can cause unintentional output of icons and unexpected effects on the output length since the latter is determined by the length of the character string by default.
Obsolete calculations used in connection with WRITE are still possible outside of classes.
The methods of the class CL_DEMO_OUTPUT demonstrate how simple WRITE output can be replaced by using a suitable output stream.
ABAP_HINT_END



Example ABAP Coding

WRITE output for data objects, function calls, string expressions and method calls.
ABEXA 00778
ABAP_EXAMPLE_END
• / WRITE
• AT WRITE
• * WRITE
• ** WRITE

ABAP Addition

What does it do?
The output position and length for the current statement WRITE can be defined after AT. The output position of existing outputs in the list buffer is overwritten with the output length of the new output. Once an existing output has been overwritten, the list cursor is placed at the next position and not the position after next.
The components of the specified position and length /,pos and len or * or ** must be specified with no blanks and in the given order. If position and length are only specified as numeric literals, the addition AT can be omitted.
BEGIN_SECTION SAP_INTERNAL_HINT
This is an euphemism. It is unexplainable when AT can be left away and what kind of literals can be used.
END_SECTION SAP_INTERNAL_HINT
/ is used to display the output in the next line after the current line. If no position pos is specified, the output is written from the first column onward. If specified immediately after the position of the list cursor in a list line that is not the result of a previous output statement, / is ignored. This is the case during initial writing to a list page, and after explicit positioning with the statements SKIP , NEW-LINE, NEW-PAGE and BACK.
The output position is determined by specifying pos. pos expects a data object of type i that contains a value within the current list width. If the value in pos is less than 1, it is ignored. If it is greater than the current list width, there is no output.
The output length is determined by specifying len, *, or ** in parentheses. len can be used to specify an absolute value. len expects a data object of type i which contains a value greater than zero and which is within the current list width. If is len specified, the number of characters displayed in the list can differ from the number of characters stored in the list buffer. By specifying * or ** , the output length depends on the data type of the data object dobj, as shown in the following table. Data Type*** cNumber of columns needed in the list to display the entire content. Trailing blanks are ignored. This length can be greater than the implicit length.Doubled length of the data object. stringimplicit length Doubled length of contained characters. n, x, xstring, utclong Implicit length implicit length d1010 t8 for 24-hour format, 11 for 12-hour format8 without using the addition ENVIRONMENT TIME FORMAT , 11 using this addition (b, s), f, i, int8, pLength required to output the current value including thousands separators. The value used here is the value after the application of the possible additions CURRENCY, DECIMALS, NO-SIGN, ROUND, or UNIT. Length required to output the maximum possible values, including signs and thousands separators. The value used here is the value after the application of the possible additions CURRENCY, DECIMALS, NO-SIGN, ROUND or UNIT. decfloat16, decfloat34The same as for ** applies here. However, leading and trailing blanks are removed.24 or 26. These are the predefined output lengths that can also include thousands separators. If the values are too large, exceptions may be raised if the format O_SIGN_AS_POSTFIX from class CL_ABAP_FORMAT is specified after STYLE.
If a conversion routine is executed in relation to a data type in the ABAP Dictionary, this routine is performed for the relevant specified length when len is specified, and if * or ** is specified, the routine is performed for the output length specified in the ABAP Dictionary. If * or ** is specified, the output length is then determined according to the rules explained above from the conversion routine. The specification of * or ** when using formatting templates (USING EDIT MASK , DD/MM/YYYY ...), follows special rules. * or ** cannot be specified together with the option TIME ZONE.



Latest notes:

Specifying the output length len after AT should always be preferred over specifying a length for the data object dobj (substring access). In contrast to substring accesses, specifying the output length is not restricted to byte-like and character-like data objects. Furthermore, the assignment of the list output to the data object is lost during substring access, which means that it can no longer be addressed in the list.
The specification of * or ** for the output length ensures that, regardless of data type, all characters from dobj are displayed, even when more columns are needed in the list than positions in the list buffer. With *, the minimum possible length is used, and with **, the maximum possible length is used.
When an output position is specified within an existing output, the position should always refer to the characters stored in the list buffer. If characters that require more than one column in the list are displayed, the displayed output position can differ from the specified output position. In addition, the displayed content of a partially overwritten output can be shifted, depending on the characters that overwrote the output.
ABAP_HINT_END



Example ABAP Coding

Displays a text field text at different positions, with different output lengths.
ABEXA 00779
ABAP_EXAMPLE_END
• UNDER WRITE

ABAP Addition

What does it do?
The output is made in the current line at the position where the data object other_dobj was the output of a previous WRITE statement. The data object other_dobj must be written exactly as in the corresponding WRITE statement, including all possible specified offset/lengths and so on. If the data object other_dobj was not specified before, the addition is ignored. If it was specified more than once, the horizontal output position of the last WRITE statement is used.
The addition UNDER cannot be used together with a position pos specified after AT. For other_dobj, a boxed component or component of a boxed component cannot be specified.



Latest notes:

Vertical positioning must be carried out by the user. If the list cursor is positioned underneath the output of other_dobj, the output also appears underneath. If the list cursor is positioned in the same line in which other_dobj is displayed, this output is overwritten. If the list cursor is positioned above the output of other_dobj, the output also appears above.
The data object other_dobj should be defined globally in the current program. Using local data objects in procedures may lead to unwanted results, for example, if the components of the same structures are used in different procedures.
The data object other_dobj can also be specified as a field symbol or as a dereferenced data reference. In this case, the field symbol or data reference must not point to a line of an internal table.
ABAP_HINT_END



Example ABAP Coding

Tabular output of flight connections.
ABEXA 00780
ABAP_EXAMPLE_END
• NO-GAP WRITE

ABAP Addition

What does it do?
The list cursor is positioned directly after the output and not in the place after the next place in the list buffer.



Example ABAP Coding

The output of the two WRITE statements is NoGap.
ABEXA 00781
ABAP_EXAMPLE_END
• QUICKINFO WRITE

ABAP Addition

What does it do?
A tooltip is assigned to the output. If the mouse cursor is placed on the output area of dobj, the content of info appears in a colored rectangle. info expects a character-like data object with length 80. Character strings that exceed this length are truncated after position 80.
The addition QUICKINFO is ignored by fields that are ready for input and line elements. If a list output is overwritten by another output, no tooltip for the overwritten field appears at or after the position where overwriting starts.



Latest notes:

The character @ is represented internally in the tooltip text by and it occupies two places rather than just one. This means that for every @ character, there is one less character available to display it.
ABAP_HINT_END



Example ABAP Coding

Additional information on the output of date and time.
ABEXA 00782
ABAP_EXAMPLE_END



Runtime Exceptions

See WRITE - TO

Return to menu