Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

. set cursor

Former Member
0 Kudos
2,098

hi to all sdn people

HOW TO USE SET CURSOR , GETCURSOR PLS GIVE ONE EXAMPLE PROGRAM FOR THIS.

TELL ME ABOUT THE CONCEPT OF SET CURSOR HOW DO WE USE THIS ACTUALLY WHERE IS THE CURSOR POSITION IN ANY SCREEN

4 REPLIES 4

Former Member
0 Kudos
242

SET CURSOR { { FIELD field [LINE line] [[DISPLAY] OFFSET off] }

| { col lin } }.

Alternatives:

1. ... FIELD field [LINE line] [[DISPLAY] OFFSET off]

2. ... col lin

Effect:

During PBO processing, this statement sets the cursor in the screen layout of the current screen. The cursor can be positioned by entering a screen element after FIELD or by entering a specific position using col and lin. Outside of PBO processing, the cursor is positioned in the next list displayed on the screen.

If the SET CURSOR statement is not specified, depending on the definition of the screen, the cursor is set according to the following hierarchy:

On the cursor position determined statically in the screen properties,

On the first input field of the screen,

On the first screen element of the screen,

On the input field in the system toolbar.

Alternative 1

... FIELD field [LINE line] [[DISPLAY] OFFSET off]

Effect

: The cursor is positioned on the screen element whose name is contained in upper case in field. The data object field must be character-type and flat. The screen layout or a table control is scrolled in the display so that the screen element on which the cursor is positioned is visible. If the specified screen element is not found, the statement is ignored.

If the specified screen element is part of a table control or a step loop, the line of the table control or group of the step loop in which the cursor is positioned on the specified screen element must be specified using the addition LINE. For the data object line, the type i is expected. If there is no line or group for the value of line, or the addition LINE is not specified, the statement is ignored. The statement is also ignored if the addition LINE is specified and the screen element is not part of a table control or step loop.

If the addition OFFSET is not specified, the cursor is set to the first position of the screen element. Using the addition OFFSET, the cursor can be set to the position in a screen element entered in off. In this case, the counting begins at 0. The position of the cursor is only visible in input/output fields. In other screen elements, the whole element is selected. For the data object off, the type i is expected. If the value of off is greater than the length of the screen element, the addition is ignored. If the value of off is negative, the cursor is positioned at the end of the screen element. As of release 6.20, the addition DISPLAY is standard and can be omitted.

Alternative 2

... col lin

Effect:

The cursor is positioned in the column specified in col and the line specified in lin in the screen layout, if a screen element is available in this position that is not part of a table control or tabstrip control. For col and lin, data objects of type i are expected. The counting of the columns starts at 2. If the screen element is not an input/output field, the whole element is selected. If no screen element is available at the specified positions, or if the cursor is positioned in a table control or tabstrip control, or if negative values are entered in col or lin, the statement is ignored.

Former Member
0 Kudos
242

Hello,


SET CURSOR 

Variants: 

1. SET CURSOR FIELD f. 
2. SET CURSOR LINE line. 
3. SET CURSOR col line. 



Effect 
Sets the cursor dynamically in display (screen program or list). 



Variant 1 
SET CURSOR FIELD f. 



Additions: 

1. ... OFFSET off 
2. ... LINE lin 



Effect 
Places the cursor dynamically at the start of the field g which is specified in the field f. You must specify the name of the field in uppercase letters. 



Note 
With step loops and in list processing, you also need the addition ... LINE lin. 



Addition 1 
... OFFSET off 


Effect 
Offsets the cursor position by off columns from the start of the field g which is specified in the field f (1st column = 0). 


Addition 2 
... LINE lin 

Effect 
Places the cursor in the field g (specified in the field f) of the loop line lin with step loops, or of the absolute list line lin (SY-LILLI) in the case of list processing. 


Notes 
Specifying LINE lin is possible only with step loops and in list processing. In these cases, it is necessary. 

The name specified in the field f must be a global field. For field symbols and reference parameters, you must use the name of the global field which is assigned to the field symbol or parameter at the time of output (i.e. with "WRITE"). 



Examples 
1. Place the cursor on a screen field. 


DATA F(5) VALUE 'MODUS'. 
DATA MODUS(10) VALUE '1234567890'. 
... 
MODULE set_cursor OUTPUT. 
... 
  SET CURSOR FIELD  F. 


or 


  SET CURSOR FIELD 'MODUS'. 


Both statements place the cursor at the beginning of the field MODUS. 

SET CURSOR FIELD F OFFSET 2. 


or 


  SET CURSOR FIELD 'MODUS' OFFSET 2. 


Both statements place the cursor on the third character (in this case the digit "3") of the field MODUS. 

... 

ENDMODULE. 


2. Place the cursor at the beginning of a field when selecting a line in list processing. 


MOVE 'MODUS' TO F. 
MOVE '1234567890' TO MODUS. 

DO 10 TIMES. 
  NEW-LINE.   POSITION SY-INDEX   WRITE MODUS. 
ENDDO. 

AT LINE-SELECTION. 
  SET CURSOR FIELD F LINE SY-LILLI. 


or 


  SET CURSOR FIELD 'MODUS' LINE SY-LILLI. 


Both statements place the cursor at the beginning of the field MODUS on this line when the user double-clicks. 

SET CURSOR FIELD F LINE SY-LILLI OFFSET 2. 


or 


  SET CURSOR FIELD 'MODUS' LINE SY-LILLI OFFSET 2. 


Both statements place the cursor on the third character (in this case the digit "3") of the field MODUS on this line when the user double-clicks. 


Variant 2 
SET CURSOR LINE line. 

Additions: 

1. ... OFFSET off 


Effect 
Places the cursor dynamically in the loop line lin with step loops or in the absolute list line lin (SY-LILLI) in list processing. This variant is only possible with step loops and in list processing. 


Addition 1 
... OFFSET off 

Effect 
Places the cursor off columns from the beginning of the line. 


Example 
Place the cursor at the beginning of the line when selecting a line in list processing. 



DATA MODUS(10) VALUE '1234567890'. 

DO 10 TIMES. 
  NEW-LINE. WRITE MODUS. 
ENDDO. 

AT LINE-SELECTION. 
  SET CURSOR LINE SY-LILLI. 


This statement sets the cursor at the beginning of the line when the user double-clicks. 


  SET CURSOR LINE SY-LILLI OFFSET 2. 


This statement sets the cursor on the third column (in this case the digit "3" of the field MODUS) on this line when the user double-clicks. 


Variant 3 
SET CURSOR col line. 

Effect 
Places the cursor dynamically on the column col and the line lin of the current screen. 


Example
SET CURSOR 60 5. 


Positions the cursor on line 5, column 60. 


Related 
GET CURSOR 


Additional help 
Setting the Cursor Position 

Setting the Cursor Position From a Program 
***
GET 


Basic form 2 GET CURSOR. ... 



Variants: 

1. GET CURSOR FIELD f. 
2. GET CURSOR LINE line. 



Variant 1 
GET CURSOR FIELD f. 


Additions: 

1. ... OFFSET off 
2. ... LINE line 
3. ... VALUE g 
4. ... LENGTH len 
5. ... AREA 



Effect 
Transfers the name of the field at the cursor position to the field f. 

The return code is set as follows: 



SY-SUBRC = 0: 
Cursor was positioned on a field. 
SY-SUBRC = 4: 
Cursor was not positioned on a field. 


Note 
Unlike screen processing, list processing allows you to output literals, field symbols, parameters and local variables of subroutines. Literals, local variables and VALUE parameters of subroutines are treated like fields without names (field name SPACE, return value 0). 
Otherwise, GET CURSOR FIELD returns only names of global fields, regardless of whether they are addressed directly (i.e. by "WRITE"), by field symbols or by reference parameters. 



Example
DATA: CURSORFIELD(20), 
      GLOB_FIELD(20)    VALUE 'global field', 
      REF_PARAMETER(30) VALUE 'parameter by reference', 
      VAL_PARAMETER(30) VALUE 'parameter by value', 
      FIELD_SYMBOL(20)  VALUE 'field symbol'. 
FIELD-SYMBOLS: <F> TYPE ANY. 
PERFORM WRITE_LIST USING REF_PARAMETER VAL_PARAMETER. 
ASSIGN GLOB_FIELD TO <F>. 

AT LINE-SELECTION. 
  GET CURSOR FIELD CURSORFIELD. 
  WRITE: /   CURSORFIELD, SY-SUBRC. 

FORM WRITE_LIST USING RP VALUE(VP). 
  DATA: LOK_FIELD(20)  VALUE 'local field'. 
  ASSIGN FIELD_SYMBOL TO <F>. 
  WRITE: /  GLOB_FIELD,  /  LOC_FIELD, 
         /  RP,          /  VP, 
         /  'literal',   /  FIELD_SYMBOL. 
ENDFORM. 



When you double-click the word " global field", CURSORFIELD contains the field name GLOB_FIELD, on "parameter by reference" the field name REF_PARAMETER, on " field symbol" the field name FIELD_SYMBOL, and on "local field", "parameter by value" and "literal" the value SPACE. 



Addition 1 
... OFFSET off 



Effect 
Copies the position of the cursor within the field to the field off (1st column = 0). 
If the cursor is not somewhere within a field (SY-SUBRC = 4), the offset value is set to 0. 



Addition 2 
... LINE line 

Effect 
With step loops, lin contains the number of the loop line where the cursor stands. In list processing, this is the absolute line number (as stored in the system field SY-LILLI). 



Addition 3 
... VALUE g 

Effect 
g contains the value of the field where the cursor stands, always in output format (character display). 



Addition 4 
... LENGTH len 

Effect 
len contains the output length of the field where the cursor stands. 



Addition 5 
... AREA a 


Effect 
If the cursor is positioned on the field of a table view control, the name of the control is placed in the field a. 



Variant 2 
GET CURSOR LINE line. 

Additions: 

1. ... OFFSET off 
2. ... VALUE  g 
3. ... LENGTH len 



Effect 
As for variant 1 with addition LINE, except that there are differences with the return code and the effect of the additions. 

The return code is set as follows: 



SY-SUBRC = 0: 
The cursor is on one of the list lines (list processing) or on a loop line (step loop). 
SY-SUBRC = 4: 
The cursor is not on one of the list or loop lines. 


Addition 1 
... OFFSET off 


Effect 
Applies to list processing only. The field off contains the position of the cursor relative to the beginning of the list line (1st column = 0). With horizontally shifted lists, the offset value can thus be greater than 0, even if the cursor is positioned on the extreme left of the window. 



Addition 2 
... VALUE g 


Effect 
List processing only. The field g contains the list line where the cursor is positioned. 



Addition 3 
... LENGTH len 


Effect 
List processing only. len contains the length of the line (LINE-SIZE). 



Related 
SET CURSOR 


Additional help 
Setting the Cursor Position 

Reading Lists at the Cursor Position 

***

REgards,

Vasanth

Former Member
0 Kudos
242

also check this programs

<b>demo_dynpro_get_cursor</b>

<b>demo_dynpro_set_cursor</b>

Former Member
0 Kudos
242

Hi,

Set Cursor:

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.

Ex:

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.

Get Cursor:

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:

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

Ex:

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.

Regards,

Bhaskar