Automate

 View Only
  • 1.  Tip of the Week - Where do OK Codes come from?

    Employee
    Posted 05-27-2025 13:49
    Edited by Scott Wenzel 05-27-2025 13:57

    Hello Automate Community!

    In the Automate Studio with Studio Administrator User Guide, there is a Studio Best Practices section (If you haven't read it, I would highly recommend it. It includes ideas and suggestions to streamline and improve your various scripts - Studio Best Practices). Among the recommendations is this –

    • Make the expert view work for you by understanding how to manually add/update screen and field names and descriptions, creating conditions and loops, learning where OK codes come from, and deleting unnecessary "Indicates cursor position on the screen" rows.

    So, for this week's tip, we're going to look at OK codes. Where they come from, and why its important to understand them.

    What are OK codes? 

    In the context of SAP, "OK" in OK Code does not stand for "Okay" as in approval. Instead, some sources claim it comes from the German word "Order Kommando" or "Operative Kommando", which roughly translates to "Command Code" or "Operational Command". Other sources state that it is short for "Order Keys".

    Regardless, SAP OK codes are function codes used in the SAP GUI to trigger specific actions, such as pressing a button or navigating to a different screen. They are essentially action triggers used by the SAP GUI to process specific commands within a transaction. They are usually associated with buttons, function keys, or custom logic. Developers declare this OK_CODE variable (e.g., DATA: ok_code LIKE sy-ucomm.) in their ABAP code.

    When a user triggers an action (like clicking a button), the corresponding function code is automatically placed into the SAP system field SY-UCOMM. This is a crucial system variable that holds the most recent user command. So OK codes are fundamental to how users interact with SAP applications as well as how the system processes those interactions.

    Why do OK codes matter?

    In SAP, every action you take – clicking a button, pressing Enter, selecting a menu item, saving data – is associated with a unique "function code" or "OK code." When you record a transaction in Automate Studio (i.e. using Transaction), it captures these codes automatically within the script, which not only helps track your various user actions, but also:

    ·       Ensures accurate automation by mimicking exact user interactions.

    ·       Helps in debugging scripts when errors occur due to unexpected screen flows or missing actions.

    ·       Allows for conditional logic in scripts based on the action taken.

    In other words, OK codes are the language Automate Studio uses to communicate with SAP, enabling it to precisely replicate and automate your human interactions with the SAP GUI. 

    What are some examples of OK Codes?

    OK Code

    Description

    VA01

    Create Sales Order

    /nVA01

    End current transaction and start VA01

    /oVA01 

    Open VA01 in a new session

    /nend 

    Log off

    =ENTR or /00

    Pressing the "Enter" key

    SAVE

    Saves the current document (used within a transaction)

    BACK

    Navigates to the previous screen

    EXIT

    Exits the current transaction

    CANC

    Cancels the operation

    Where do I find them?

    You can typically find the OK Code for a specific action in an SAP screen by navigating to System > Status and then double-clicking on the GUI status. You can also often find it by clicking on a field and pressing F1 for "Performance Assistant," then looking for "Technical Information". Please review this recent article - How to find OK Code in SAP

    When recording a transaction in Automate Studio, Studio captures OK Codes during the recording phase to understand what actions are being taken on each screen. These codes are used to replicate user actions like clicking buttons, navigating screens, or submitting forms.

    Most of the time, when you create your scripts, you don't need to worry about OK Codes and their values. The Mapping Expert View Tab is where the technical details of the script are exposed. Here, users (often those with a deeper understanding of SAP) can directly see and manipulate the OK codes, add or modify screen and field names, create conditions and loops, and tune the automation logic. 

    This allows for advanced customization including:  

    ·       Identifying Errors: When a script fails, understanding the OK codes can help pinpoint where the automation diverged from the intended SAP flow.

    ·       Viewing Captured OK Codes: Automate Studio's "Expert View" allows you to see the underlying details of your recorded script, including the specific OK codes associated with each step.

    ·       Debugging a script: If you see an OK code you don't recognize, you usually can view it in SAP or you can view the script in Debug mode. This can help you identify the OK codes that were captured and can help identify any issues.

    ·       Modifying a script: You can look for the OK code to navigate or perform a function you didn't capture in a script. For example:

    o   You created an Update script, and now you want to save it as a Download script, thus the last step wouldn't save but instead exit.

    o   You might have an IF condition depending on data in the script to navigate differently, such as a differing material type in a material create script.

    ·       Adding/Editing OK Codes: You can manually insert or modify OK codes in Expert View. This is important for:

    o   Handling Dynamic Screens: If an SAP screen behaves differently based on data or user input (e.g., a pop-up appears, or a different tab is active), you might need to insert specific OK codes to navigate these variations.

    o   Skipping Screens: If a screen sometimes appears and sometimes doesn't (e.g., an optional warning message), you can add conditional logic (e.g., an "IF" statement) and, if the screen appears, send an "Enter" OK code to dismiss it.

    o   Adding Conditional Logic: In advanced scenarios, you can use OK codes within conditional statements (e.g., "IF this field has a certain value, THEN click this button (OK code X) and proceed to the next screen; ELSE click this other button (OK code Y)").

    I hope you find this helpful. Have a great week!



    ------------------------------
    Scott Wenzel
    Precisely Software Inc.
    Bothell WA
    ------------------------------



  • 2.  RE: Tip of the Week - Where do OK Codes come from?

    Posted 06-05-2025 02:02

    Would like to share another OK code which I find very useful. =PB07 in MM02 on Sales Org1 view. This opens up the tax data which is especially useful for situations where there are more than two departure country settings.



    ------------------------------
    Ed Meiners
    Lead Consultant MDIM
    Wessanen Nederland Holding BV
    Amsterdam
    ------------------------------