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.
Setting the cursor position
REPORT demo_dynpro_set_cursor. DATA: field1(14) TYPE c, field2(14) TYPE c, field3(14) TYPE c, name(10) TYPE c. 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:
The input/output fields are assigned to the fields field 1 to field 3 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.