NotationA script variable is denoted by V[varname] where varname is the name (or identifier) of the variable.
Tip: Observe a consistent name convention. For example, only lower case letters and the underscore as delimiter, such as V[previous_account]. Or with upper case and lower case letters, without underscore: V[PreviousAccount]. It often makes sense to let all variable names start with a common identifier denoting the transaction or transaction group, e.g. V[VA01_PreviousAccount] or [VA_PreviousAccount]. ValueA variable represents a string, the value of the variable. Each expression &V[varname] in a script line is replaced by the value of the given variable V[varname] before the script line is executed.System variablesSome variables are already predefined by the system. Their names start with an underscore, followed by lower case letters. Examples:
For a detailed list of all system variables please see the section system variables. ScopeThe variables always have a global scope, i.e. they are visible (and keep their value) in all other scripts of the same SAP GUI session. If you open a new session (e.g. with the /O command in SAP GUI) you will work with a new set of variables.If you need to pass values from one session to another you can use the "toSharedText" and "fromSharedText" options of the CopyText command. If you start an InputScript that runs in a new session, using a "/O..." function code, the parameters are automatically passed to the new mode. To return parameters from the called session to the calling session, use the "ReturnValues" statement. Additionally, Process can be used to make scripts more modular and structured. It is important to note that variables within Process scripts exist in a local namespace. When leaving the script, these variables are released, so that, for example, the calling script can no longer access them. It is therefore recommended to use local variables whenever possible, as this reduces the risk of unintentionally overwriting other variables.Setting valuesTo set a value, use the formatGuiXT
Example: GuiXT
Use the "&V[...]" notation if the new string value is to be taken from another variable. Example: GuiXT
Please avoid a notation without quotation marks, e.g. GuiXT
since this will not work as desired if the variable value contains blank characters: The statement is executed after replacing the variables and this results in using the first word of the given string without the rest, which GuiXT interprets as additional options of the Set command. The only case where quotation marks are not needed is when you work with numbers (represented as string values). Example: GuiXT
Querying a variable valueTo compare a variable with a string, use the formatGuiXT
Please observe: The comparison does not distinguish between upper case and lower case, and it does not distinguish between "0", "00", and an empty string. The reason for this behaviour is that SAP entry fields are often automatically converted to upper case, and a value entered as "0" is often shown as Space. If GuiXT distinguished between upper and lower case values here, it would be difficult to determine if an account number changed. You can use the option "-strict" after a comparison if you really want to compare the values exactly as they are. Example: GuiXT
The if-expression may contain the operators "and", "not", "or", "(" and ")". Example: GuiXT
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:GuiXT
Short notation to ensure that a variable is not emptyUse the notationGuiXT
Comparing two variablesInstead of a fixed string you can compare the variable with another variable using the notation &V[varname]. Example:GuiXT
Please observe: two ending brackets and no inverted commas Generic reset of numerous variablesIf you specify a variable name with an ending *, all variables the names of which start with the given string will be set to this value. This is handy to reset numerous variables that belong to the same transaction or transaction group. You can use the system variable V[_transactionid] in order to decide whether a new transaction has started. Example:GuiXT
Concatenating variablesIn the "Set" command, like in all other commands, you can use several variables one after the other which are then concatenated. Example:GuiXT
Constant strings can be interspersed. Example: GuiXT
Partial stringsTo extract a partial string, denote its first and last position after the variable, enclosed with round brackets and separated by a hyphen or a comma. Example:GuiXT
No V[y] has the value "31". Similarly with comma: GuiXT
There is a difference in meaning between the two notations that is only significant in Unicode systems. Internally GuiXT uses the UTF-8 character code and some characters (e.g. Umlauts such as ä,ö) are stored in two bytes, not in one byte as in ANSI. With the hyphen notation e.g. (4-6) you will obtain bytes 4 to 6, whereas you obtain the characters 4 to 6 with the comma notation (4,6). Example: GuiXT
Now V[y] has the value "nch". Whereas GuiXT
sets y to the value "che". Since variables can contain structures with binary or decimal packed components, GuiXT cannot generally use the character semantics in Unicode systems. Length of a string in bytes or charactersThe option -stringLength of the Set command returns the length of a string in bytes, whereas -charCount returns the number of characters. In a Unicode system this can be different. Example:GuiXT
GuiXT
V[leng] is 7 in a non-Unicode system and 8 in a Unicode system, since 'ü' needs two bytes in UTF-8. The value of V[count] on the other hand is 7 for all systems. Tip: Use -stringLength in conjunction with the hyphen substring notation (i-k) and -charCount with the comma notation (i,k); see also the example in the next section. Partial strings with variable positionsThe positions in the substring notation can be variables, for example (&V[i],&V[k]) instead of (5,8), where V[i] and V[k] contain the desired positions as digits. In the following example we delete all dot characters in a given string. In the example we make use of calculations as explained in a section below.The string V[in] is searched for a dot, one character after the other, and simultaneously we build up the output string V[out]. GuiXT
Extracting components of SAP structuressOften SAP function modules return an SAP data dictionary structure where you need to extract individual components. You can use fixed positions for this purpose, but instead it is better to use a symbolic notation that refers to the SAP data dictionary. You name the dictionary structure in round brackets, followed by a hyphen and the name of the component. As an example we read the address data for a given customer number and extract the city:GuiXT
Explanation: The function module "BAPI_CUSTOMER_GETDETAIL2" defines an export parameter "CUSTOMERADDRESS" that we receive in our variable V[addr]. As defined in the SAP function library the parameter possesses the structure "BAPICUSTOMER_04" where the city is stored in component "CITY". Often function modules return table parameters where each row is a SAP dictionary structure that we can handle with this symbolic notation. If you use VersionNumber the text will be stored in the GuiXT cache (local files) and taken from there instead of relative complex reading of the text from the SAP Repository unless VersionNumber changed. Alternatively, the OpenCall interface can also be used. Conversions are performed automatically for external and internal formats in both directions, making the steps mentioned above as well as those in section 15 no longer necessary. Setting components in SAP structuresAnalogously we can set substrings in a variable, using fixed positions or using symbolic names according to the SAP data dictionary. As an example we read all customers with numbers between 1 and 50 using the function module BAPI_CUSTOMER_GETLIST. As input this function expects a table where each row contains a customer number interval:GuiXT
CalculationsThe 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. A different number of decimal places and further options may be specified in the Set command; see documentation.
The format
is as follows:
GuiXT uses double precision floating point numbers for all calculations. Example: GuiXT
Result: 0,66667 Date calculationsWhen GuiXT converts strings into numbers, it recognizes the normal standard date formats such as "01.06.2014" and calculates the days since a fixed date. In this way you can subtract dates from each other, or add and subtract a number of days from a given date. In this latter case the result is returned as date as well, using the same format as the input date.Example 1: GuiXT
Result: "31.05.2014" Example 2: GuiXT
Result: "151" Example 3: We use a couple of date calculations in order to decide whether a given date "V[date]" falls on a Sunday. For this purpose, we subtract a fixed Sunday, e.g. the 31.12.2000, from the given date and then check whether the result is a multiple of 7: GuiXT
Using variables within a variable nameIt is possible to use variable values within a variable name. Example:GuiXT
Now V[x] has the value "10". This feature is often used for indexed variables, as shown in the following example. We read the "Material" column of all currently displayed rows in table "All items" and set the variables VA_material_1, VA_material_2, ...: GuiXT
Field texts from the SAP Data DictionaryWith the notation &ddic[xxx] you get the text of the SAP field xxx in the language of connection of the user. If you specify a length, you will get a corresponding short text from Data Dictionary. Examples:
"&ddic[BSEG-BSCHL]" Buchungsschlüssel If you use VersionNumber the text will be stored in the GuiXT cache (local files) and taken from there instead of relative complex reading of the text from the SAP Repository unless VersionNumber changed. 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: GuiXT
Structure / Table VariablesStructure variables are used to store related data in a fixed, clear format. They consist of predefined fields (components) that can be accessed directly. This makes them especially suitable for individual datasets with a clear structure.GuiXT
Table variables are used to manage multiple datasets in the form of rows and columns. Each row represents a separate dataset. They are particularly useful when processing recurring or list-like data. GuiXT
A more detailed explanation can be found here. |