Show TOC

Finding Out the Cursor PositionLocate this document in the navigation structure

Use

After user interaction with the screen, you may need to know the position of the cursor when the action occurred. This is particularly important if the user chooses the Choose function (F2 or mouse double-click).

To find out the cursor position, use the following statement:

        


        
GET CURSOR FIELD f [OFFSET off]
        
[LINE lin]
        
[VALUE val]
        
[LENGTH len].
        


        


        


         

This statement transfers the name of the screen element on which the cursor is positioned during a user action into the variable f. If the cursor is on a field, the system sets sy-subrc to 0, otherwise to 4.

The addition:

  • OFFSET writes the cursor position within the screen element to the variable off.

  • LINE writes the line number of the table to the variable lin if the cursor is positioned in a table control. If the cursor is not in a table control, lin is set to zero.

  • VALUE writes the contents of the screen field in display format - that is, with all of its formatting characters - as a string to the variable val.

  • LENGTH writes the display length of the screen field to the variable len.

Cursor position on the screen.

        


        


        
PROGRAM demo_dynpro_get_cursor.
        
DATA: ok_code TYPE sy-ucomm,
        
save_ok LIKE ok_code.
        
DATA: input_output(20) TYPE c,
        
fld(20) TYPE c,
        
off TYPE i,
        
val(20) TYPE c,
        
len TYPE i.
        
CALL SCREEN 100.
        
MODULE init_screen_0100 OUTPUT.
        
SET PF-STATUS 'STATUS_100'.
        
ENDMODULE.
        
MODULE user_command_0100 INPUT.
        
save_ok = ok_code.
        
CLEAR ok_code.
        
CASE save_ok.
        
WHEN 'CANCEL'.
        
LEAVE PROGRAM.
        
WHEN 'SELE'.
        
GET CURSOR FIELD fld OFFSET off VALUE val LENGTH len.
        
ENDCASE.
        
ENDMODULE.
        


         

The next screen (statically defined) for screen 100 is 100. It has the following layout:

The relevant extract of the element list is as follows:

Name

Type

Format

Text

Function Code

TEXT1

Text

Input

input_output

I/O

CHAR

TEXT2

Text

Name

fld

I/O

CHAR

TEXT3

Text

Offset

off

I/O

INT4

TEXT4

Text

Content

val

I/O

CHAR

TEXT5

Text

Length

len

I/O

INT4

EXIT_BUTTTON

Push

Cancel

CANCEL

ok_code

OK

OK

The input attribute of all of the input/output fields except input_output is switched off in the Screen Painter.

The screen flow logic is as follows:

        


        


        
PROCESS BEFORE OUTPUT.
        
MODULE init_screen_0100.
        
PROCESS AFTER INPUT.
        
MODULE user_command_0100.
        


         

The module init_screen_0100 sets the GUI status STATUS_100 during the PBO event. In the status, the icon (F12) is activated by the function code CANCEL, and the function key F2 is assigned the function code SELE.

When you run the program, the user can select any screen element by double-clicking it, or use any screen element connected to the function code SELE. The output fields on the screen return the cursor position.