Liquid UI - Documentation - 8.20 onTcodeTerminate()

8.20 onTcodeTerminate()


Purpose

The OnCodeTerminate command in Liquid UI is used to clear runtime memory and reset console variables when a script ends, whether it completes normally or terminates unexpectedly. This ensures the next script execution starts from a clean, predictable state.

When placed in a script, OnCodeTerminate performs the following actions when the script ends:

  • Clears all temporary console variables.
  • Resets any memory values stored during runtime.
  • Ensures that no residual data from the current session affects the next.

 

This is especially useful in multi-screen scripts, shared scripts, or workflows involving conditional logic based on user roles, previous steps, or input values.


Why it matters

When scripts rely on temporary variables to control logic, such as:

  • User role-based customization
  • Navigation between steps
  • Flags that track input or validation states


If the script ends abruptly, due to navigation, screen change, or error, and you don’t use OnCodeTerminate, those temporary values can persist. This can lead to:

  • Fields showing or hiding incorrectly
  • Logic running based on old values
  • Users see inconsistent or buggy behavior

 

Syntax

onTCodeTerminate[_transaction] = function(){
-----------------;
-----------------;
}


Options

The OnTCodeTerminate command does not take any options.


Example

In the following example, we will use the OnTCodeTerminate command to initiate an action from the Create Sales Order: Initial screen to execute a function before exiting from the transaction.


Customization

In this section, we will explain how the WS commands and script are used in customizing the SAP transaction (VA01) to run a process on performing an exit operation using the onTcodeTerminate command.

Create this file inside your script folder for customizing the Create Sales Order screen SAPMV45A.E0101.sjs
//Now, let's start adding the content to the above file.

  1. On the Create Sales Order Initial screen, we are assigning values into variables namely, z_variable1 and z_variable2, and then assigning their values into Sales Organization and Distribution Channel fields respectively using the set command, as shown below:
     
    //Initializing the variables 
    set("V[z_variable1]" , "1000"); 
    set("V[z_variable2]" , "01");
    set("F[Sales Organization]" , "&V[z_variable1]"); 
    set("F[Distribution Channel]" , "&V[z_variable2]");
    
     
  2. To display the Sales Organization and Distribution Channel field values before performing exit operation in the console window, we used println statements, as shown below:
     
    //Initializing the variables 
    println ("-----------Value of Sales Organization before clicking Exit Button is : " +z_variable1);
    println ("-----------Value of Distribution Channel before clicking Exit Button is : " +z_variable2);
    
     
  3. Here, we used the onTcodeTerminate command to execute a function that will reset the fields with null values and display a message on the status bar on performing exit operation.
     
    //Initializing the variables 
    //onTCodeTerminate executing function
    onTCodeTerminate[_transaction] = function (){
       //Resetting the Variables
        set("V[z_*]"," ");
       message ("S: Successfully reset the field values on exitVariables are resetted");
       println ("-----------Value of Sales Organization after clicking Exit Button is: " +z_variable1);
       println ("-----------Value of Distribution Channel after clicking Exit Button is: " +z_variable2);
    }
    
     


SAP Process

In this section, we will explain how the SAP process is simplified after customizing the Create Sales Order transaction screen using Liquid UI WS.

  1. Navigate to Create Sales Order Initial screen and enter the Order Type value in the input field. Here, Sales Organization and Distribution Channel field values are automatically updated and also show the same in the Cornelius window.
     
     
  2. Click the exit button present on the toolbar as shown below. Then the Sales Organization and Distribution Channel field values. The cleared values are printed as blanks, as shown below:
     
     
  3. You will also see the status message displaying, “Successfully reset the variables on exit”.
     
     

Can't find the answers you're looking for?