Purpose
With the OnTCodeTerminate command, you can trigger a function to perform the required actions before exiting from the transaction.
In the function, you can add operations like adding/removing fields, assigning/clearing field values, and more before exiting from a transaction.
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 exit operation using the onTcodeTerminate command.
Create this file inside your script folder for customizing Create Sales Order screen SAPMV45A.E0101.sjs
//Now, let's start adding the content to the above file.
- 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]");
- 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);
- 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.
- 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.
- Click the exit button present on the toolbar as shown below. Then the Sales Organization and Distribution Channel field values will reset and display in the console window, as shown below:
- You will also see the status message displaying, “Successfully reset the variables on exit”.