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

Former Member
0 Likes
2,864

HELLO,

I JUST WANTED TO KNOW ABOUT OK CODE.

WHEN WE ARE CREATING SCREEN.

OK CODE WILL BE AUTOMATICALLY GENERATED.

IT IS NECESSARY TO GIVE NAME TO IT.

WHY IS IT SO??

WHEN E ARE CREATING PUSHBUTTON WE HAVE TO DEFINE FCTCODE FOR IT TO USE THAT PUSHBUTTON IN OUR PROGRAM.

THEN WHAT IS NEED FOR OK CODE??

6 REPLIES 6
Read only

dhruv_shah3
Active Contributor
0 Likes
953

Hi,

Whenever we create the Screen. to use any functionality in that screen we have to use the OK Code.

If you have seen that at time of creating screen Ok Code field in attributes list is empty. So we have to write the name for the OK CODE.

Through OK CODE we are identify that which function code has been clicked and that we have to execute for desired action.

HTH

Regards,

Dhruv Shah

Read only

0 Likes
953

BUT, IF WE DOESNOT DEFINE OK CODE, AND WE HAVE DEFINED FCD CODE FOR PARTICULAR PUSHBUTTON OR ANY KEY.

THE VALUE IS STORED IN SY-UCOMM.

THEN WHAT IS THE USE OF OK CODE.

Read only

Former Member
0 Likes
953

Hi,

U r right. No need to change name if it is already created. But u have to populate it by sy-ucomm to find fncode. Then only u can write code accordingly. U can use any name or sap created name!

Regards,

Subbu

Read only

Former Member
0 Likes
953

Hi,

In each PAI event that a user triggers by choosing either a pushbutton on the screen or an element in a GUI status, the corresponding function code is placed into the system field SYST-UCOMM or SY-UCOMM and placed in the OK_CODE field (as long as the function code is not empty). Empty function codes are placed in neither the SY-UCOMM field nor the OK_CODE field.

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.

Regards

Rose

Read only

Former Member
0 Likes
953

OK_CODE must be defined in you program


DATA:
  ok_0100 LIKE sy-ucomm,
  ok_0201 LIKE sy-ucomm,
  ok_0202 LIKE sy-ucomm,
  ok_0203 LIKE sy-ucomm,
  ok_0501 LIKE sy-ucomm,
  ok_0502 LIKE sy-ucomm,
  ok_0503 LIKE sy-ucomm,
  ok_code LIKE sy-ucomm.

This is my normal practice by changing the "CODE" to the screen number it is handling.

Durring Screen Creation, you will need to do go the Element tab and add the OK_CODE where it is blank as the last field on the list.

To intercept it:


PROCESS AFTER INPUT.

.
.
.
  MODULE user_command_0100.  " <== Here

goes to here


*&---------------------------------------------------------------------*
*&      Module  user_command_0100  INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE ok_0100.
    WHEN 'EXIT'
      OR 'BACK'
      OR 'CANC'.
      PERFORM update_changed_data.
      LEAVE TO SCREEN 0.
    WHEN 'APPL'.
      IF base_appl NE prev_appl.
        IF base_appl IS INITIAL.
          base_appl = prev_appl.
          MESSAGE e803.
        ENDIF.
        IF prev_appl IS INITIAL.
          prev_appl = base_appl.
        ELSE.
          PERFORM check_data_changed.
          IF data_has_changed = 'X'.
            PERFORM ask_to_update.
            CASE popup_ans.
              WHEN '1'.     " Yes
              WHEN '2'.     " No
                CLEAR wt_dropins.
                PERFORM load_dropin_data.
              WHEN 'A'.     " Cancel
                base_appl = prev_appl.
            ENDCASE.
          ELSE.
            CLEAR wt_dropins.
            PERFORM load_dropin_data.
          ENDIF.
        ENDIF.
      ENDIF.
    WHEN 'SAVE'.
      PERFORM check_data_changed.
      CHECK data_has_changed = 'X'.
      PERFORM update_changed_data.
  ENDCASE.

Read only

Former Member
0 Likes
953

Hi Sanjay,

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 PAIevent,

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,

Chandu.