LET
The LET statement assigns values to variables.
Syntax 1: Simple assignment
LET target = expr [,...]
- target is the name of the variable to be assigned.
- expr is any valid expression supported by the language.
Syntax 2: Compound assignment
LET target oper expr [,...]
- target is the name of the variable to be assigned.
- expr is any valid expression supported by the language.
- oper a any of the following compound operators:
+=: Add the current value of target to a numeric expression. See Addition Assignment (+=).-=: Subtract the current value of target to a numeric expression. See Subtraction Assignment (-=).*=: Multiply the current value of target to a numeric expression. See Multiplication Assignment (*=)./=: Divide the current value of target to a numeric expression. See Division Assignment (/=).||=: Concat the current value of target and a character string expression. See Concatenation Assignment (||=).,=: Append the formatted form of the right operand to the current value of target . See Append Assignment (,=).
Usage
The LET target = expr instruction assigns
to the specified variable, the result of an expression, or the value of another variable. The target variable can of a primitive type,
or a complex type such as a record, dynamic array, dictionary, or reference an object of a
class.
The runtime system applies data type conversion rules, if the data type of expr does not correspond to the data type of target.
When assigning a numeric or date/time value to a character string variable, the values are formatted for display (for example, the numeric data is right-aligned).
When specifying a comma-separated list of expressions for the right operand, the
LET statement concatenates all expressions together. Unlike the || operator, if an expression in the
comma-separated list evaluates to NULL, the concatenation result will not be null,
except if all expressions to the right of the equal sign are null.
The statement LET record.* = expr-list can be a record
followed by dot- star (record.*), to reference all record members of the record. In this case, the right operand must also be a record
using this notation, and all members will be assigned individually. However, the
record.* notation to assign records is supported for backward
compatibility and should be replaced by using the new syntax without .* in new
development.
Variables defined with a complex data type (like TEXT or BYTE) can only be assigned to
NULL.
The LET statement also supports compound assignments with operators such as
+= and /=. When using this syntax, the current value of the
target variable is combined with the right-hand expression, and the result is
assigned to this target variable.
Example
SCHEMA stores
MAIN
DEFINE c1, c2 RECORD LIKE customer.*
-- Single variable assignment
LET c1.customer_num = 123
-- Complete RECORD assignment
LET c1 = c2
END MAINMAIN
DEFINE var1 INTEGER, var2 STRING
LET var1 = 500
LET var1 *= 5
LET var2 = "Value:"
LET var2 ,= var1
END MAIN