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

regarding sy-ucomm and ok_code

Former Member
0 Likes
2,784

hi experts,

gud morning,

i got something for sy-ucomm and ok_code....

<b>answer:::</b>

In the same way that the OK_CODE field in the ABAP program and the system field SY-UCOMM <b>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.</b> 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 ENTERS). Empty function codes do not affect SY-UCOMM or the OK_CODE field, and consequently, the old field contents are transported.

cud u plz explain the meaning of the bold part how can we see that the contents are also copied in the pbo side as done in pai.......

null

3 REPLIES 3
Read only

Former Member
0 Likes
1,206

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.

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dba99935c111d1829f0000e829fbfe/content.htm

This is a long standing issue dating back many years. The general answer is that you control the OK_CODE field while SAP controls the SY-UCOMM field. You assign field OK_CODE to the OK code field in the screen painter and SAP copies SY-UCOMM to your OK_CODE field. Now you have control over the value. If you start invoking other code, like SAP utilities that display screens, you can be guaranteed that the value in OK_CODE will still be there, while you have no idea what SAP might be doing with SY-UCOMM.

This is a design decision that was probably made about 20 years ago when screen processing was introduced. In most cases, you can probably use SY-UCOMM and not have any problems but there are probably cases out there where SAP has done something tricky and you will have a problem.

Because there are unknowns out there, I always define an OK_CODE and do not use SY-UCOMM for standard screen processing. For me this is a long standing habit.

OK_Codes are like function code for each button or for any action on the screen.

When you press SAVE or when you Press some Button on the screen, your every action is recorded by using the OK_COde.

for example for ENTER button it is '/00'.

While you record BDC's using SHDB you will come to know all these OK codes.

Read only

varma_narayana
Active Contributor
0 Likes
1,206

Hi..

SY-UCOMM is a System field which stores the Function code of a GUI Function during the PAI event.

OK_CODE is a Special SCREEN ELEMENT which stores the Function code of a GUI Function during the PAI event just like SY-UCOMM.

They will never store field values.

In every PAI Event:

We will check the Value of OK_CODE to find out which GUI Function is selected by the user.

But when user selects ENTER Function system will not transfer the Function code to either SY-UCOMM or OK_CODE.

Bcoz ENTER Will have EMPTY function code.

But if we check the OK_Code in PAI it will have the Previous Function code.

To avoid this problem

We have to always use the following statement in PBO to clear the OK_Code.

CLEAR OK_CODE.

This is to ensure that the Previous Function code is not used in PAI.

<b>Reward if Helpful</b>

Read only

former_member194669
Active Contributor
0 Likes
1,206

Hi,

For triggering user command , usually sy-ucomm will move OK_code variable. and then on the basis of ok_code corresponding function codes will get triggered. like

Module user_command input.

clear ok_code.

ok_code = sy-ucomm

if ok_code eq 'SAVE'

Do the perform for SAVE

endif.

if ok_code = 'BACk'

Do the perform for BACK functionality

endif.

endmodule

it is not mandatory that you have to always use ok_code you can do it this way also

Module user_command input.

if sy-ucomm eq 'SAVE'

Do the perform for SAVE

endif.

if sy-ucomm = 'BACk'

Do the perform for BACK functionality

endif.

endmodule

aRs