Relative positions refer to output previously written to the list. Several relative positionings occur automatically. When you use WRITE without specifying a position, the output appears after the previous output, separated by a blank column. If there is not enough space in the current line, a line feed occurs. ULINE and SKIP statements without positioning produce a line feed.
To program relative positioning, use either the sy-colno and sy-linno system fields together with the statements described in Absolute Positioning or the statements for relative positioning described below.
Producing a Line Feed
To produce a line feed, use either the forward slash ' / ' in the AT option of WRITE or ULINE or the statement:
This statement positions output in a new line, setting sy-colno to 1 and increasing sy-linno by 1. The system only executes the statement if output was written to the screen since the last line feed. NEW-LINE does not create a blank line. To create a blank line, use the SKIP statement (see Creating Blank Lines ).
An automatic line feed occurs at the NEW-PAGE statement and at the beginning of an event.
Positioning Output Underneath Other Output
You can position a WRITE output in the same column as a previous WRITE output. Use the formatting option UNDER of the WRITE statement:
WRITE f UNDER g .
The system starts outputting f in the same column from which field g started. This statement is not limited to the current page, that is, g must not appear on the same page.
You must fix the vertical position yourself. Any existing output is overwritten.
The reference field g must be written exactly as in the corresponding WRITE statement, including all specifications such as offset (see Specifying Offset Values for Data Objects ). If g is a text symbol (see Text Symbols ), the system determines the reference field from the number of the text symbol.
Positioning Output in the First Line of a Line Block
To set the next output line to the first line of a block of lines defined with the RESERVE statement (see Programming Page Breaks ), use the BACK statement as follows:
RESERVE. ..... BACK.
If BACK follows RESERVE , the subsequent output appears in the first line written after RESERVE . You can use this statement, for example, to jump back to a specific line after writing an output from within a loop.
Examples of Relative Positioning
The first example shows how to create a column-based list by means of a self-defined page header.
REPORT demo_list_position_relative_1 NO STANDARD PAGE HEADING LINE-SIZE 80 LINE-COUNT 7. DATA: h1(10) TYPE c VALUE ' Number', h2(10) TYPE c VALUE ' Square', h3(10) TYPE c VALUE ' Cube', n1 TYPE i, n2 TYPE i, n3 TYPE i, x TYPE i. TOP-OF-PAGE. x = sy-colno + 8. POSITION x. WRITE h1. x = sy-colno + 8. POSITION x. WRITE h2. x = sy-colno + 8. POSITION x. WRITE h3. x = sy-colno + 16. POSITION x. WRITE sy-pagno. ULINE. START-OF-SELECTION. DO 10 TIMES. n1 = sy-index. n2 = sy-index ** 2. n3 = sy-index ** 3. NEW-LINE. WRITE: n1 UNDER h1, n2 UNDER h2, n3 UNDER h3. ENDDO.
This program creates a two-page list. In the self-defined page header, column headers are positioned relatively by using the sy-colno system field and the POSITION statement. The actual list output is positioned under the fields of the header line using the UNDER option of the WRITE statement. Line feeds are specified using NEW-LINE . The output appears as follows:
The different output positions of the individual fields result from the ABAP default of representing character strings as left-justified and numeric fields as right-justified. To influence justification, use the formatting options LEFT-JUSTIFIED , RIGHT-JUSTIFIED , and CENTERED of the WRITE statement (see Formatting Options ).
The second example shows the effect of the BACK statement following RESERVE .
REPORT demo_list_position_relative_2 NO STANDARD PAGE HEADING LINE-SIZE 40. DATA x TYPE i. WRITE 'Some numbers:' NO-GAP. x = sy-colno. ULINE AT /(x). RESERVE 5 LINES. DO 5 TIMES. WRITE / sy-index. ENDDO. x = sy-colno. BACK. WRITE AT x ' <- Start of Loop'.
This program creates the following output:
After the first two lines have been displayed, the RESERVE statement is used. The next five lines are defined as a block. The output following BACK is written to the first line of the block. Note how the sy-colno system field is used to underline the first line and to position the last WRITE output.