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: 

OK_CODE Field

Former Member
0 Kudos

Hi..

Can anyone tell me something about OK_CODE Field in screen elements.

Thanks and Regards

- Richa Verma

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi..

OK_CODE Field is a 20 Char field which is not displayed on the screen

User actions that trigger the PAI event also place the corresponding code into this field, where it is passed to the program.

Assign a name to this field and also declare it (type C ) in the top include of the ABAP program to use it for a particular screen.

reward pts. if useful.

Thanks

- Rishika bawa.

2 REPLIES 2

Former Member
0 Kudos

In simple words , OK_Code is a variable used to keep the system user command values , which is nothing but sy-comm.

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.

In your ABAP programs, you should work with the OK_CODE field instead of SY-UCOMM. There are two reasons for this: Firstly, the ABAP program has full control over fields declared within it, and secondly, you should never change the value of an ABAP system field. However, you should also always initialize the OK_CODE field in an ABAP program for the following reason:

In the same way that the OK_CODE field in the ABAP program and the system field SY-UCOMM receive the contents of the corresponding screen fields in the PAI event, their contents are also assigned to the OK_CODE screen field and system field SYST-UCOMM in the PBO event. Therefore, you must clear the OK_CODE field in the ABAP program to ensure that the function code of a screen is not already filled in the PBO event with an unwanted value. This is particularly important when the next PAI event can be triggered with an empty function code (for example, using ENTER). Empty function codes do not affect SY-UCOMM or the OK_CODE field, and consequently, the old field contents are transported.

sy-ucomm is the system variable, which is maintained by the system automatically. U need take care of that variable. U ca find the Function-Code that was pressed on a particular screen.

Ok_code is an variable which u have to maintain(means u have to declare and initialize). Usually it is used to copy the sy-ucomm in the PAI and clear the sy-ucomm. Because the value should not be processed in the next screen.

as it is general variable. it cna be 'okcode' also.

you use it like this ina screen or any operation :

eg :

data: ok_code like sy-ucomm .

in PAI at user-command event ..

ok_code = sy-ucomm.

case ok_code .

when 'SAVE'.

w3rite logic for saving .

when 'EXIT'.

write logic for exit .

when 'BACK'.

write logic for back .

endcase ,

Edited by: Richa Khosla on Mar 28, 2008 7:56 AM

Edited by: Richa Khosla on Mar 28, 2008 7:59 AM

Former Member
0 Kudos

hi..

OK_CODE Field is a 20 Char field which is not displayed on the screen

User actions that trigger the PAI event also place the corresponding code into this field, where it is passed to the program.

Assign a name to this field and also declare it (type C ) in the top include of the ABAP program to use it for a particular screen.

reward pts. if useful.

Thanks

- Rishika bawa.