Passing Data Automatically 

Automatic data transfer happens by means of the system fields that are filled by the system for each interactive event. For an overview of the relevant system fields, see Detail Lists.

System fields provide you with information about the list index, the position of the list in the output window, and the cursor position. The only system field that contains the contents of the selected line is SY-LISEL.

The example below demonstrates how the system fills these system fields during interactive events.

REPORT demo_list_system_fields NO STANDARD PAGE HEADING
                                LINE-COUNT 12 LINE-SIZE 40.

DATA: l TYPE i, t(1) TYPE c.

DO 100 TIMES.
  WRITE: / 'Loop Pass:', sy-index.
ENDDO.

TOP-OF-PAGE.

  WRITE: 'Basic List, Page', sy-pagno.
  ULINE.

TOP-OF-PAGE DURING LINE-SELECTION.

  WRITE 'Secondary List'.
  ULINE.

AT LINE-SELECTION.

  DESCRIBE FIELD sy-lisel LENGTH l TYPE t.

  WRITE: 'SY-LSIND:', sy-lsind,
       / 'SY-LISTI:', sy-listi,
       / 'SY-LILLI:', sy-lilli,
       / 'SY-CUROW:', sy-curow,
       / 'SY-CUCOL:', sy-cucol,
       / 'SY-CPAGE:', sy-cpage,
       / 'SY-STARO:', sy-staro,
       / 'SY-LISEL:', 'Length =', l, 'Type =', t,
       /  sy-lisel.

This program creates a list of ten pages. When you run the program, you can place the cursor within the basic list and create a detail list by choosing Choose. This displays the contents of the system fields.

SY-LSIND is the index of the current list, SY-LISTI is the index of the previous list. SY-LILLI is the number of the selected line in the list, SY-CUROW contains the line number of the selected line on the current screen. SY-CUCOL is the position of the cursor in the window. This position exceeds the corresponding unscrolled list column by one. SY-CPAGE is the currently displayed page of the list. SY-STARO is the number of the topmost actual list line displayed on the current page. This does not include the page header. SY-CPAGE and SY-STARO do not depend on the cursor position. For SY-LISEL, the program displays length, data type, and contents. The length of SY-LISEL is always 255, independent of the list's width.

Using SY-LISEL

The system field SY-LISEL is a type C field with length 255. Although it contains the selected line, it is only of limited use for passing the values of single fields, as it is a character string. To process certain parts of SY-LISEL, you must specify the corresponding offsets.

To pass data, it is therefore a better idea to use one of the methods described in Passing Data by Program Statements. SY-LISEL is, however, suitable for designing the headers of detail lists, or for checking that a selected line is not a space or an underscore.

REPORT demo_list_sy_lisel NO STANDARD PAGE HEADING.

DATA num TYPE i.

SKIP.
WRITE 'List of Quadratic Numbers between One and Hundred'.
SKIP.
WRITE 'List of Cubic Numbers between One and Hundred'.

TOP-OF-PAGE.
  WRITE 'Choose a line!'.
  ULINE.

TOP-OF-PAGE DURING LINE-SELECTION.
  WRITE sy-lisel.
  ULINE.

AT LINE-SELECTION.
  IF sy-lisel(4) = 'List'.
    CASE sy-lilli.
      WHEN 4.
        DO 100 TIMES.
          num = sy-index ** 2.
          WRITE: / sy-index, num.
        ENDDO.
      WHEN 6.
        DO 100 TIMES.
          num = sy-index ** 3.
          WRITE: / sy-index, num.
        ENDDO.
    ENDCASE.
  ENDIF.

When you start the program, a list appears on which two lines can be selected.

If the user chooses the top line, a list of square numbers is displayed. If the user selects the lower line on the basic list, the list of cubic numbers appears.

The contents of the selected line becomes the header of the detail list. The IF statement uses the first four characters of SY-LISEL to make sure that only valid lines are selected. Due to the logical conditions of the processing block following AT LINE-SELECTION, a line selection on a detail list does not produce any further output.