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: 

Difference between sy-ucomm and ok_code

Former Member
0 Kudos
681

what is the Difference between sy-ucomm and ok_code. both r used for user command. then where we can use this sy-ucomm and where we can use ok_code

5 REPLIES 5

Former Member
0 Kudos
195

Hi Josh,

SAP recommends that in dialog program always use OK_Code instead of sy-ucomm. Here is what the help says

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.

Hope this resolves your query.

Reward all the helpful answers.

Regards

Former Member
0 Kudos
195

Hi,

sy-ucomm is for doing the functions what the user wishes to do at that particular event. You use it in menus and other place . this mainly in using <pfstatus>

ok_code is generally used in screen as of I have used. You will define the function in the screen. and you can use it in the main program.

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.

Regards,

Priyanka.

Former Member
0 Kudos
195

hi

<b>sy-ucomm conatins the function code of the button pressed <b>automatically</b></b>

whereas <b>ok-code is used to store the value of sy-ucomm</b> and to perform action based on the button pressed even after user has performed some other action.

regards

ravish

<b>reward points if helpful</b>

Former Member
0 Kudos
195

hi josh,

SY-UCOMM is a system field in SYST structure which holds Function Codes.

OK_CODE is a variable. It Generally using for to be a copy of SY-UCOMM in screens. sometimes there are some problems in screens.

thats y, OK_CODE is used instead of SY-UCOMM in screens.

<b>sy-ucomm</b> is for doing the functions what the user wishes to do at that particular event. You use it in menus and other place . this mainly in using <pfstatus>

<b>ok_code</b> is generally used in screen as of I have used. You will define the function in the screen. and you can use it in the main program.

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.

******reward points if useful.

all the best

Former Member
0 Kudos
195

Hiii

There is no need to explicitly define the sy-ucomm it takes the value of the button which we have pressed in our dialog program..

Whereas ok-code must be of type sy-ucomm which contians the value of sy-ucomm

Pls reward if helpful

Regards

hitesh