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

When a screen is displayed, the system automatically places the cursor in the first field that is ready for input. However, you can also define on which screen element the cursor should appear in your program. The screen element does not have to be an input field. Positioning the cursor can make applications more user-friendly.

You can set the cursor position either statically in the Screen Painter or dynamically in your ABAP program.

Static Cursor Position

To define the cursor position statically, enter the name of the required screen element in the Cursor position screen attribute in the Screen Painter.

Dynamic Cursor Position

To set the cursor position dynamically, use the following statement in an ABAP dialog module in the PBO event:

SET CURSOR FIELD <f> [OFFSET <off>].

<f> can be a literal or a variable containing the name of a screen element. You can use the OFFSET addition to place the cursor at a particular point within an input/output field.

Example

Setting the cursor position

REPORT DEMO_DYNPRO_SET_CURSOR.

DATA: FIELD1(14), FIELD2(14), FIELD3(14),
      NAME(10).

SELECTION-SCREEN BEGIN OF BLOCK BLOC WITH FRAME.
  PARAMETERS: DEF RADIOBUTTON GROUP RAD,
              TXT RADIOBUTTON GROUP RAD,
              F1  RADIOBUTTON GROUP RAD,
              F2  RADIOBUTTON GROUP RAD,
              F3  RADIOBUTTON GROUP RAD.
SELECTION-SCREEN END OF BLOCK BLOC.

PARAMETERS POS TYPE I.

IF TXT = 'X'.
  NAME = 'TEXT'.
ELSEIF F1 = 'X'.
  NAME = 'FIELD1'.
ELSEIF F2 = 'X'.
  NAME = 'FIELD2'.
ELSEIF F3 = 'X'.
  NAME = 'FIELD3'.
ENDIF.

CALL SCREEN 100.

MODULE CURSOR OUTPUT.
  IF DEF NE 'X'.
    SET CURSOR FIELD NAME OFFSET POS.
  ENDIF.
  SET PF-STATUS 'SCREEN_100'.
ENDMODULE.

MODULE BACK INPUT.
  LEAVE SCREEN.
ENDMODULE.

At the start of the program, a selection screen appears on which you can select a cursor position.

Screen 100 is then called. The next screen (statically defined) for screen 100 is itself, and it has the following layout:

This graphic is explained in the accompanying text

The input/output fields are assigned to the fields FIELD1 to FIELD3 in the ABAP program. The heading is the text field TEXT, and the pushbutton is the screen element PUSH.

The static cursor position in the screen attributes is set to PUSH.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.
  MODULE CURSOR.

PROCESS AFTER INPUT.
  MODULE BACK AT EXIT-COMMAND.

During the PBO event, before screen 100 is displayed, the cursor is set according to the user’s choice on the selection screen. If the user chooses the static default, the cursor is placed on the pushbutton, otherwise on the header or one of the input fields. The position POS is only taken into account for the input fields.

 

 

 

Leaving content frame