AT LINE-SELECTION, AT USER-COMMAND, AT PFn

AT - Events in lists

Variants:

1. AT LINE-SELECTION.
2. AT USER-COMMAND.
3. AT PFn.


This event is processed whenever the user chooses a valid line in the list (i.e. a line generated by statements such as WRITE, ULINE or SKIP ) with the cursor and presses the function key which has the function PICK in the interface definition. This should normally be the function key F2, because it has the same effect as double-clicking the mouse, or clicking once in the case of a hotspot.
The processing for the event AT LINE-SELECTION usually generates further list output (the details list) which completely covers the current list display. If you want the current list display to remain visible (to aid user orientation), you can do this with the key word WINDOW.
In most cases, the information from the selected line is used to retrieve more comprehensive information by direct reading. When displaying the original list, you store the key terms needed for this in the HIDE area of the output line.

Note

You can choose a line and start new processing even in the details lists.
The following system fields are useful for orientation purposes, since their values change with each interactive event executed.

SY-LSIND Index of list created by current event (basic list = 0, 1st details list = 1, ...)

SY-PFKEY Status of displayed list ( SET PF-STATUS)

SY-LISEL Contents of selected line

SY-LILLI Absolute number of this line in the displayed list

SY-LISTI Index of this list - usually SY-LSIND - 1 ( READ LINE)

SY-CUROW Last cursor position: Line in window

SY-CUCOL Last cursor position: Column in window ( GET CURSOR)

SY-CPAGE 1st displayed page of displayed list

SY-STARO 1st displayed line of this page of displayed list

SY-STACO 1st displayed column of displayed list ( SCROLL LIST)

The system field SY-LSIND defines the line selection level (basic list: SY-LSIND = 0).

System field for interactive reporting are also contained in the system fields for lists documentation

Example

DATA TEXT(20). 
 
START-OF-SELECTION. 
  PERFORM WRITE_AND_HIDE USING SPACE SPACE. 
 
AT LINE-SELECTION. 
  CASE TEXT. 
	WHEN 'List index'. 
	PERFORM WRITE_AND_HIDE USING 'X' SPACE. 
	WHEN 'User command'. 
	PERFORM WRITE_AND_HIDE USING SPACE 'X'. 
	WHEN OTHERS. 
	SUBTRACT 2 FROM SY-LSIND. 
	PERFORM WRITE_AND_HIDE USING SPACE SPACE. 
  ENDCASE. 
  CLEAR TEXT. 
 
FORM WRITE_AND_HIDE USING P_FLAG_LSIND P_FLAG_UCOMM. 
  WRITE / 'SY-LSIND:'. 
  PERFORM WRITE_WITH_COLOR USING SY-LSIND P_FLAG_LSIND. 
  TEXT = 'List index'. 
  HIDE TEXT. 
  WRITE / 'SY-UCOMM:'. 
  PERFORM WRITE_WITH_COLOR USING SY-UCOMM P_FLAG_UCOMM. 
  TEXT = 'User command'. 
  HIDE TEXT. 
  IF SY-LSIND > 0. 
	WRITE / 'PICK here to go back one list level'. 
  ENDIF. 
ENDFORM. 
 
FORM WRITE_WITH_COLOR USING P_VALUE 
							P_FLAG_POSITIVE. 
  IF P_FLAG_POSITIVE = SPACE. 
	WRITE P_VALUE COLOR COL_NORMAL. 
  ELSE. 
	WRITE P_VALUE COLOR COL_POSITIVE. 
  ENDIF. 
ENDFORM.

Depending on whether you choose the line at SY-LSIND or SY-UCOMM , the next details list contains the corresponding value with the color "positive". If the line is chosen without HIDE information, the list level is reduced.


This event is executed whenever the user presses a function key in the list or makes an entry in the command field.

Some functions are executed directly by the system and thus cannot be processed by programs. These include:

PICK See variant AT LINE-SELECTION

PFn See variant AT PFn

/... System command

%... System command

PRI Print

BACK Back

RW Cancel

P... Scroll function (e.g.: P+, P-, PP+3, PS-- etc.)
Instead of this functions, you can use the SCROLL statement in programs.

Since many of these system functions begin with "P", you should avoid using this letter to start your own function codes.

Otherwise, the effect is as for AT LINE-SELECTION; also, the current function code is stored in the system field SY-UCOMM.

Example

DATA: NUMBER1 TYPE I VALUE 20, 
	NUMBER2 TYPE I VALUE  5, 
	RESULT  TYPE I. 
 
START-OF-SELECTION. 
  WRITE: / NUMBER1, '?', NUMBER2. 
 
AT USER-COMMAND. 
  CASE SY-UCOMM. 
	WHEN 'ADD'. 
	RESULT = NUMBER1 + NUMBER2. 
	WHEN 'SUBT'. 
	RESULT = NUMBER1 - NUMBER2. 
	WHEN 'MULT'. 
	RESULT = NUMBER1 * NUMBER2. 
	WHEN 'DIVI'. 
	RESULT = NUMBER1 / NUMBER2. 
	WHEN OTHERS. 
	WRITE 'Unknown function code'. 
	EXIT. 
  ENDCASE. 
  WRITE: / 'Result:', RESULT.

After entry of a function code, the appropriate processing is performed under the event AT USER-COMMAND and the result is displayed in the details list.


Here, n stands for a numeric value between 0 and 99.
This event is executed whenever the user presses a function key that contains the function code PFn in the interface definition. The default status for lists contains some of these functions.

Otherwise, the effect is as for the variant AT LINE-SELECTION. The cursor can be on any line.

To ensure that the chosen function is executed only for valid lines, you can check the current HIDE information.

Example

DATA NUMBER LIKE SY-INDEX. 
 
START-OF-SELECTION. 
  DO 9 TIMES. 
	WRITE: / 'Row', (2) SY-INDEX. 
	NUMBER = SY-INDEX. 
	HIDE NUMBER. 
  ENDDO. 
 
AT PF8. 
  CHECK NOT NUMBER IS INITIAL. 
  WRITE: / 'Cursor was in row', (2) NUMBER. 
  CLEAR NUMBER.