Application Development and Automation 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: 
Read only

abap quest

Former Member
0 Likes
882

hi

can u plz tell me what is diffrence between GET CURSOR and OK_CODE

hi

can u plz tell me what is diffrence between GET CURSOR and OK_CODE

6 REPLIES 6
Read only

Former Member
0 Likes
843

get_cursor field var, return the name of the field where the cursor is positioned to var.

OK_CODE is the code associated with a particular action such as presing a push button etc.

Read only

Former Member
0 Likes
843

Hi,

Welcome to SDN.

GET CURSOR:

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


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. 

OK_CODE acts just as a temporary variable that stores the value of SY-UCOMM.

When user interacts with the screen elements, the function code that you have assigned is filled in the SY-UCOMM field which is turn gets reflected in OK_CODE.

Regards,

Ferry Lianto

Please reward points if helpful.

Read only

Former Member
0 Likes
843

get cursor is used to find the cursor position in the screen.

ok_code is one which we assign to the user command (sy-ucomm).

when u click a push button we get the function code using the ok_code.

Read only

Former Member
0 Likes
843

Hi,

When we use Get cursor statement, we get the contents of line (clicked by user).

Based on our requirement, we can get offset of the contents captured in sy-lisel.

EX: to get matnr on a line..

v_matnr = sy-lisel+0(18).

As we are making use of offset, we need to know the position of the field displayed on the output screen.

If we use HIDE, the field gets back into the HIDE variable.

position of the field doesnt matter.

Check the programs to understand how to make use of hide and get cursor statements.

demo_list_hide

DEMO_LIST_GET_CURSOR

see this is how u use Get Cursor command under At Line Selection Event.

**********************************************************************************************

AT LINE-SELECTION.

DATA : f(50),

v(50).

GET CURSOR FIELD f VALUE v.

CASE f.

WHEN 'F1'.

write v.

WHEN 'F2'.

write v.

endcase.

**********************************************************************************************

this code will get the name of the field that u select in the output list into variable 'f' and the contents of that field into variable' v ' which u can use for ur logical purppose as shown.

OKCODE :-

It is the UserCommand for the Module Pool Programming.

Regards,

Deepu.k

Read only

Former Member
0 Likes
843

Hi,

<u><b>Get Cursor:</b></u>

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

<u><b>OK_CODE field:</b></u>

Every screen has a twenty-character OK_CODE field (also known as the function code field), which is not displayed on the screen. User actions that trigger the PAI event also place the corresponding function code into this field, from where it is passed to the ABAP program. You can also use the command field in the standard toolbar to enter the function code. You must assign a name to the OK_CODE field to be able to use it for a particular screen.

Regards,

Bhaskar

Read only

former_member219399
Active Participant
0 Likes
843

Get cursor is to get the value.

OK code is to capture User action.

With regards,

Vamsi