|
Variables, calculations and comparisons are needed to write complex InputScripts. You can also use them in normal GuiXT Scripts, but the InputAssistant component is required in this case as well.
It is also possible to call dll-functions or ABAP-functions (“Call“-Statement”) to perform complex logic and computations. But you will see here that most common problems can be solved without using an exit function. |
Working with variables
A variable is denoted by V[my_variable] where my_variable is the name (or identifier) of the variable. Maximum length of the name: 255 characters. All names are case sensitive, i.e. V[my_variable] and V[my_Variable] are different variables. Tip Use only a…z, A..Z, 0…9 and the special character “_” “.” “-” in the name of a variable Examples of variable names:
It is not necessary to declare a variable explicitly before working with it. Several variables are predefined by the system, including:
For a complete list, see the documentation: System variables. The variables always have a global scope, i.e. they are visible (and keep their value) in all other scripts of the same R/3 session as well. If you open a new R/3 session (e.g. with the /O command in R/3) you work with a new set of variables. Tip: If you want to use the simple notation &[name] for values of variables and of fields, you can use variable names starting with a ‘.’ in order to avoid any conflict with field names on the screen. An alternative would be to use the qualified notations &V[name] and &F[name] |
Setting values
To set a value, use the format
The value may refer to other variables, e.g.
|
Environment variables (Windows)
The value of a Windows environment variable “env” is denoted as &%[env]. For example, if you want to create a temporary file, you can use the TEMP variable to get the right folder:
|
Comparing variables
To compare a variable with a string, use the format
You can also compare two variables with the following expression (which looks a little bit complicated):
The comparison does not distinguish between upper case and lower case, and it does not distinguish between “0″, “00″, and the empty string. The reason for this behavior is that SAP entry fields are often automatically converted to upper case, and a value entered as “0″ is often shown as Space. It would be quite difficult to determine if, for example, an account number changed, if GuiXT would distinguish upper case and lower case values here. You can use the option “-strict” after a comparison if you really want to compare the values as they are. Example:
The if-expression may contain the operators “and”, “not”, “or”, “(” and “)”. Example:
|
Example 1
|
It is also possible to use the operators “<” and “>”. Please observe that in this case the variable is always considered to be a number. There is no string comparison with “<” or “>”. Example 2
|
Calculations
The Set command supports the basic operation +,-,*,/. All operands are considered to be numbers. The result is then stored in string format, up to 2 decimal places (rounded) for resulting non-integer values. The format is as follows: Set V[my_variable] value1 + value2 Please observe that at least one Space is needed before and after the operator. Example 3 The following script splits an amount field shown on the screen into 3 parts and displays the resulting amounts:
Example 4 The following script can pe performed “On Enter” in VA01 in order to enter the value 1 into the “order quantity” column for each row where the user enters a material number without specifying a quantity:
|