In addition to the procedure parameters which are generated and assigned their values when the procedure is called, an S procedure may contain so-called S variables; these may be generated anywhere within a procedure. There are three ways of generating an
S variable: explicitly by means of the DECLARE-VARIABLE command, or implicitly via the first value assignment to that variable (provided this is not prevented as a result of IMPLICIT-DECLARATION=*NO in the SET-PROCEDURE-OPTIONS command), or automatically during execution of a few special commands (such as OPEN-VARIABLE-CONTAINER or EXECUTE-CMD).
As for parameters, explicit declaration permits a type and an initial value to be defined for the variables.
The names of (simple) S variables may be up to 20 characters long; according to the rules for the SDF data type <structured-name>, these may be alphanumeric characters and hyphens. Names starting with SYS are reserved for the system software; a few other names are reserved for arithmetic operators and Boolean constants.
Value assignment
The value of a variable can be modified by various commands and also by programs. This also applies to procedure parameters since these are treated like other S variables during procedure execution.
The SET-VARIABLE command, in particular, serves to assign a variable a new value. Since the name of this command may not only be abbreviated in accordance with the general rules but even omitted altogether, the following format, which is familiar from programming languages, may be used to write assignments of new values to variables:
/ variable-name = new-value
Constants
The values assigned to the variables may be constant character strings, numerics or Boolean values (true/false).
Constant character strings (referred to as values of type STRING) are enclosed in single quotes; any single quote or & character contained in a STRING value must be doubled. Uppercase letters are distinguished from lowercase letters.
Character strings may alternatively be specified in hexadecimal format (referred to as
X strings); this permits non-printable characters to be represented. Thus, the following two commands are equivalents:
/ FILE = 'ARB.4'
/ FILE = X'C1D9C24BF4'
Integers (values of type INTEGER) may be represented as decimal constants from the value range -231 .. +231-1, where the positive sign is optional.
Boolean constants (values of type BOOLEAN) are designated by the keywords TRUE and FALSE. As an alternative, the names YES and ON or NO and OFF may be used.
Variable types
The type of a variable is determined by the type of the value assigned to it (i.e. STRING, INTEGER or BOOLEAN). To ensure early detection of incorrect value assignments and thus improve runtime security for procedures, the TYPE operand can be specified in the variable declaration to permit only values of a particular type to be accepted for a variable; all other value assignments then result in an error.
Scopes of variables
The scope of a variable is normally restricted to the procedure in which it was declared (either explicitly or implicitly). When the procedure terminates, the lifetime of the variable ends with it. If several calls of the same or different procedures within a task make use of the same variable and the variable is to retain its value, a so-called task variable can be created by explicit declaration with SCOPE=*TASK. This specification ensures that the variable can be used by various procedures.
If one procedure calls another procedure and both use variables with identical names, the variables are created and maintained separately at all times. The only exception to this rule occurs when a procedure is called via the INCLUDE-PROCEDURE command; in this case, it can access the variables of the calling procedure and create or modify variables there, provided SCOPE=*PROCEDURE has been specified in the variable declarations.
Variable containers
Variable definitions and values are normally held in the privileged memory allocated to the task and deleted at the end of the variables’ lifetime. However, there are two options that permit the use of other storage media: a variable declaration with CONTAINER=*JV causes the variable value to be stored in a job variable, enabling it to be retained for longer periods of time and making it available to other tasks for querying and modification via JV access.
If the variable declaration specifies a container in a library (via the OPEN-VARIABLE-CONTAINER command), both the variable description and its value can be stored in the library, either on request by means of the SAVE-VARIABLE-CONTAINER command or automatically at the end of the procedure or task; they will then be available in subsequent procedure runs.