Entering content frameFinding Out the Cursor Position Locate the document in its SAP Library structure

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 additions to the GET CURSOR statement have the following functions:

Example

Cursor position on the screen.

PROGRAM DEMO_DYNPRO_GET_CURSOR.

DATA: OK_CODE LIKE 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 itself. It has the following layout:

This graphic is explained in the accompanying text

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

 

Contents

 

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 inactive.

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_100 sets the GUI status STATUS_100 during the PBO event. In the status, the cancel icon This graphic is explained in the accompanying text (F12) is active with the function code CANCEL, and the function key F2 is active with 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.

 

 

 

 

Leaving content frame