Register Login

Write Statement in ABAP

Updated May 18, 2018

Write Operation

WRITE (see transaction LIBS for SAP guidelines using colors, symbols, icons etc. in lists):

WRITE [ ].
can be:

·         any data object (variable, literal, constant);

·         field symbol or formal parameter;

·         text symbol like text- or 'default text'(), where is text symbol's Id.

Type-specific output (len=field length):

Type

Standard output length

Justified

C

len

left

D

8

left

F

22

right

I

11

right

N

len

left

P

2*len[+1]

right

T

6

left

X

2*len

left

Positioning output on the screen:

WRITE AT [/][ ][()] .
can be:

·         / - new line;

·         , - numbers or variables up to 3 digits;

·         AT can be omitted if , are not variables.

If is too short, fewer characters are displayed. Numeric fields are truncated on the left and prefixed with an asterisk (*). All other fields are truncated on the right, but no indication is given that the field is shorter.

Outputting symbols and icons on the screen:

WRITE AS SYMBOL.
WRITE AS ICON.

and are system-defined constants which are specified in the include programs and ( replaces both the above). The angle brackets are part of the name.
To browse all available icons and symbols use pattern for the WRITE statement in the ABAP/4 Editor. All icons can be viewed using the ICON transaction as well.

Lines and blank lines the screen:

ULINE [AT [/][ ][()]] [NO-GAP].
this is equivalent to WRITE [AT [/][ ][()]] SY_ULINE [NO-GAP].
WRITE [AT [/][ ]] SY-VLINE.
or WRITE [AT [/][ ]] '|'.
SKIP [].
SKIP TO LINE [].

Note. WRITE / ' '. statement does not output blank line by default. To change default setting use following statement:
SET BLANK LINES ON|OFF.

Outputting field content as checkbox:

WRITE AS CHECKBOX.
If the first character of is an "X", the checkbox is displayed filled. If the first character is SPACE, the checkbox is displayed blank. The checkboxes that are created by this statement are input enabled by default.

Outputting lines on the screen:

WRITE AS LINE.
On list output, automatically links certain characters together to form continuous lines or boxes, if there is no space between them:

·         vertical lines, output with the system field SY-VLINE or using a field with the contents "|" (vertical line);

·         horizontal lines, output with the system field SY-ULINE or using a field with at least 2 consecutive minus signs "--".

Exactly how each line segment is output (e.g. whether as straight line, corner, T-piece or cross) depends on the adjoining characters.
The include (or the more comprehensive include ) contains the relevant identifiers for lines as constants, e.g. LINE_TOP_LEFT_CORNER, LINE_BOTTOM_MIDDLE_CORNER.

FORMAT:

FORMAT [ON|OFF] [ON|OFF] ... .
FORMAT = = ... .
Effective from next output (WRITE or new line) operation until next event or turning OFF. ON = default.

·         FORMAT COLOR [ON] INTENSIFIED [ON|OFF] INVERSE [ON|OFF].
Does not work for lines. If INVERSE is used, the INTENSIFIED has no effect. Has no effect on input fields.

 

 

vari

Symbol name

Color

OFF

COL_BACKGROUND

Background (GUI-specific)

1

COL_HEADING

Headers (grayish blue)

2

COL_NORMAL

List body (bright gray)

3

COL_TOTAL

Totals (yellow)

4

COL_KEY

Key columns (bluish green)

5

COL_POSITIVE

Positive threshold value (green)

6

COL_NEGATIVE

Negative threshold value (red)

7

COL_GROUP

Control levels (violet)

·         ABAP/4 colors
Call the SHOWCOLO report in any system for demonstration of colors in lists.

·         SUMMARY. this is equivalent to FORMAT INTENSIFIED ON.
DETAIL. this is equivalent to FORMAT INTENSIFIED OFF.

·         FORMAT HOTSPOT [ON|OFF].
Affects the display format of the mouse pointer and the effect of the mouse single click: If you drag the mouse pointer over list areas which are output with the format ...HOTSPOT (lines or fields), the mouse pointer switches from its standard display format (usually an arrow) to the format of a hand with an outstretched index finger. If you then click once, the effect is like double-clicking or pressing the function key F2 (AT LINE-SELECTION). Has no effect on input fields.

·         FORMAT INPUT [ON|OFF].
Determines whether the user can enter data. See READ LINE.

·         FORMAT RESET.
The same as FORMAT COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT OFF INPUT OFF.

 

Define Structure

List Width:

REPORT LINE-SIZE .
n=0 : standard list. List cannot be wider than 255 (132 for most printers). SY-LINSZ contains the current line size.
To adapt the line size to the current window width, set to SY-SCOLS. SY-SCOLS contains the number of characters of a line of the current window.

Page Length:

REPORT LINE-COUNT [()].
n - number of reserved for footer lines. length=0 : standard list. SY-LINCT contains the current page length or 0 if standard page.
To adapt the page length to the current window length, set to SY-SROWS. SY-SROWS contains the number of lines of the current window.

Individual Page Header:

REPORT [NO STANDARD PAGE HEADING].
....
TOP-OF-PAGE [DURING LINE-SELECTION].
   WRITE... .

List processing event that is executed before the first data is output on a new page. Without the addition ... DURING LINE-SELECTION, processed only when generating basic lists, not when creating secondary lists. Only executed before outputting the first line on a new page - not triggered by a NEW-PAGE statement.
During the event TOP-OF-PAGE, you can also fill the system fields SY-TVAR0...SY-TVAR9 with values that should replace eventual placeholders &0...&9 in the standard page header.

Individual Page Footer:

REPORT LINE-COUNT ().
....
END-OF-PAGE.
   WRITE... .

END-OF-PAGE processed only if n>0. If you explicitly specify a new page with NEW-PAGE, END-OF-PAGE is ignored.

Page Break:

NEW-PAGE [PRINT ON ...].

·         ends the current page and increased SY-PAGNO by 1;

·         does not trigger the END-OF-PAGE event.

NEW-PAGE [NO-TITLE|WITH-TITLE] [NO-HEADING|WITH-HEADING].

·         used to suppress or display the standard header and/or columns headers on all pages to come. default both: WITH for basic and NO for secondary lists;

·         does not affect the display of a page header defined at the event TOP-OF-PAGE.

NEW-PAGE LINE-COUNT .

length=0 : standard list. Can be variable.

 

 

NEW-PAGE LINE-SIZE .

n=0 : standard list. Can be variable. Within a list level, that is, if the next page is not the beginning of a new list level, the system ignores the LINE-SIZE option.

RESERVE LINES.

Triggers a page break if less than free lines are left on the current list page between the last output and the page footer. can be a variable. Before starting a new page, the system processes the END-OF-PAGE event. RESERVE only takes effect if output is written to the subsequent page. No blank pages are created.

Scrolling:

common notes.

·         SCROLL works for completed lists only. If you use SCROLL before the first output statement of a list, it does not affect this list. If you use SCROLL after the first output statement of a list, it affects the entire list, that is, all subsequent output statements as well;

·         While creating a secondary list, a SCROLL statement without INDEX option always refers to the previously displayed list on which the interactive event occurred (index SY-LISTI);

·         Only when creating the basic list does the SCROLL statement refer to the currently created list;

·         You can use the INDEX option to explicitly scroll on existing list levels. To do this, the lists need not be displayed. When the user displays the list again, it is scrolled to the specified position. If the specified list level does not exist, the system sets SY-SUBRC to 8;

·         If, during an interactive event, you want to scroll through the list you are currently creating, use SY-LSIND as the index in the SCROLL statement. Note that a manipulation of SY-LSIND takes effect only at the end of the event on the created list, independent of where you place the statement in the processing block. If you want to set the list level explicitly, you must manipulate SY-LSIND in the last statement of the processing block to make sure that a SCROLL statement within the processing block accesses the correct list;

·         Another way of scrolling interactive lists from within the program is to use the SET USER-COMMAND statement in connection with the corresponding system-defined function codes;

·         SY-SUBRC = 0 : Ok; = 4 : scrolling was not possible (exit boundaries); = 8 : list level does not exist.

SCROLL LIST FORWARD|BACKWARD [INDEX ].

vertical scrolling window by window

SCROLL LIST TO {FIRST PAGE|LAST PAGE|PAGE } [INDEX ] [LINE ].
SCROLL LIST FORWARD|BACKWARD PAGES [INDEX ].

vertical scrolling by pages

SCROLL LIST LEFT|RIGHT [INDEX ].

horizontal scrolling to margins

SCROLL LIST TO COLUMN [INDEX ].
SCROLL LIST LEFT|RIGHT BY PLACES [INDEX ].

horizontal scrolling by columns

SET LEFT SCROLL-BOUNDARY [COLUMN ].

Only the part to the right from {current column|column } will be scrolled horizontally. Applies to the entire current page, and only to it. To set the same scrollable area for all pages of a list, use, for example, at the TOP-OF-PAGE event.

NEW-LINE NO-SCROLLING.

Excludes the line following the statement from horizontal scrolling (for example, title line).

NEW-LINE SCROLLING.

This statement makes sense only if after NEW-LINE NO-SCROLLING no line was output.

Displaying Lists in Dialog Windows.

WINDOW STARTING AT [ENDING AT ].
Causes the current list (index SY-LSIND) to be displayed in a dialog window. If = 0, the list appears on a fullscreen. By default, the system uses the values of the lower right corner of the window on which the event occurred. If the width of the dialog window is smaller than the width of the preceding list, the system creates a horizontal scroll bar on the dialog window. To prevent that, you must adapt the width of the secondary list to the width of the dialog window by using the following statement: NEW-PAGE LINE-SIZE .
Dialog window has not a menu bar or a standard toolbar. Standard application toolbar at the lower margin has functions PRI, %SC, %SC+, and RW.

Positioning the output

For the current output position, refer to the system fields

·         SY-COLNO - the current column;

·         SY-LINNO - the current line.

POSITION .

Sets horizontal output position. Se also WRITE AT and SKIP TO LINE for vertical output position.

BACK.

Subsequent output appears beneath the page header or to the first line of a block of lines defined with the RESERVE, if used. If you specify BACK at the TOP-OF-PAGE event, the system does not set the output position to beneath the entire page header, but only to beneath the standard page header. Any output written now overwrites the self-defined page header specified at TOP-OF-PAGE.

SET TITLEBAR:

SET TITLEBAR [WITH ... ].
Sets a screen title. A set title remains valid within a transaction until you call SET TITLEBAR again. SY-TITLE (can be up to 70 characters long) contains the current screen title. Allows you to build up to 9 parameters into the header, using the variables &1 to &9.

Retrieving List Attributes:

You should use this key word only in exceptional cases (e.g. when editing an 'anonymous' list in a program other than that which generated the list). In all other cases, you should save the relevant values when you generate the list. Take care when attempting to retrieve the list attributes being set up (...INDEX SY-LSIND), since some attributes (number of pages, number of lines, ...) may not have been updated yet.

DESCRIBE LIST NUMBER OF LINES|PAGES [INDEX ].

Returns the number of lines|pages in the list. SY-SUBRC=0 : Ok, <>0 : list does not exists.

DESCRIBE LIST LINE PAGE [INDEX ].

Returns the number of the page for the line in the list. SY-SUBRC=0 : Ok, 4 : line does not exists, 8 : list does not exists.

DESCRIBE LIST PAGE [INDEX ].

Returns the attributes of the page in the list. SY-SUBRC=0 : Ok, 4 : page does not exists, 8 : list does not exists. :

·         LINE-SIZE - page width;

·         LINE-COUNT - page length;

·         LINES - number of displayed lines;

·         FIRST-LINE - absolute number of the first line;

·         TOP-LINES - number of lines output by page header processing (i.e. standard title + column headers + TOP-OF-PAGE);

·         TITLE-LINES - number of lines output as standard title lines by page header processing (see NEW-PAGE).
Note. The value of TITLE-LINES is contained in TOP-LINES;

·         HEAD-LINES - number of lines output as column headers by page header processing (see NEW-PAGE).
Note. The value of HEAD-LINES is contained in TOP-LINES;

·         END-LINES - number of lines output by page footer processing (see END-OF-PAGE);                                                                                                            


×