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 ok_code and sy-ucomm.

Former Member
0 Likes
2,734

hi experts ,

regarding the difference between ok_code and sy-ucomm i searched and found this lines......

answer:::

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</b> in the PAI event, their contents are also assigned to the OK_CODE screen field and system field SYST-UCOMM in the PBO event.

cud u plz tell me what is the meaning of contents of corresponding screen fields...plz explain it ...and second thing can i declare another variable name instead of ok_code ..is it necessary to write ok_code....thnx in advance...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,615

Hi,

it is not obligatory that you write OK_CODE, it is just a denomination from SAP. You can declare any name for the variable in your code that is going to trap the transaction code of the button that the user pressed.

OK_CODE is used in SAP Dialog Programming, while SY-UCOMM is used all around SAP (classes, SAP Dialog Programming, ABAP, forms, and a long etc.).

<b>receive the contents of the corresponding screen fields</b> means the transaction code that you assign at development time to the objects on the screen, which should trigger an event (buttons tipically or folders in a folder control).

8 REPLIES 8
Read only

Former Member
0 Likes
1,614

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

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,

Pavan

Read only

0 Likes
1,614

dear pavan,

dnt use copy and paste dear plz try to come out with your own words...........i am already having these things ......................

Read only

Former Member
0 Likes
1,616

Hi,

it is not obligatory that you write OK_CODE, it is just a denomination from SAP. You can declare any name for the variable in your code that is going to trap the transaction code of the button that the user pressed.

OK_CODE is used in SAP Dialog Programming, while SY-UCOMM is used all around SAP (classes, SAP Dialog Programming, ABAP, forms, and a long etc.).

<b>receive the contents of the corresponding screen fields</b> means the transaction code that you assign at development time to the objects on the screen, which should trigger an event (buttons tipically or folders in a folder control).

Read only

Former Member
0 Likes
1,614

Hi Ravi

1) Here the meaning of the corresponding screen fields mean that OK code that you are setting for a particular screen push button, Application tool care or may be menu like this.

2) You need not have to declare the variable name as OK_CODE itself, you can give it any name but your name should match the OK_CODE fieldname that you are giving in the Element list of that screen.

Reward points if useful!!

~Ranganath

Read only

ashwin_bhat
Participant
0 Likes
1,614

Dear Ravi,

Please refer to the following

Regards

Ashwin

Read only

Former Member
0 Likes
1,614

OK_CODE is used to store the value of SY-UCOMM in the PBO event.

We assign SY-UCOMM to OK_CODE in SE51, i.e., MODULE POOL Programming...

Regards,

Pavan

Read only

Former Member
0 Likes
1,614

Hi Ravi

SY-UCOMM IS A system variable. It contains the latest user action triggered. Whereas ok_code is generally a variable that we declare as a type of sy-ucomm.

OK_CODE is for Batch input session to enter the key strokes that simulate actions to move from once screen to another.

SY-UCOMM - is the user input value/key pressed by user used in Interactive reporting

reward points to all helpful answers

kiran.M

Read only

Former Member
0 Likes
1,614

HI,

SY-UCOMM IS A system variable. It contains the latest user action triggered. Whereas ok_code is generally a variable that we declare as a type of sy-ucomm. Usually in ABAP programing it is a good practice not to refer to sy-ucomm directly, or sometimes we need to store a user interaction for later validation, these are the scenarios where an ok_code value comes handy.

eg.

data: ok_code type sy-ucomm.

clear ok_code.

ok_code = sy-ucomm.

case ok_code.

when 'XYZ'.

..........

..........

WHEN OTHERS.

ENDCASE.

Hope that clears the matter.

Regards

Sudheer