LET

The LET statement assigns values to variables.

Syntax 1: Simple assignment

LET target = expr [,...]
  1. target is the name of the variable to be assigned.
  2. expr is any valid expression supported by the language.

Syntax 2: Compound assignment

LET target oper expr [,...]
  1. target is the name of the variable to be assigned.
  2. expr is any valid expression supported by the language.
  3. oper a any of the following compound operators:

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

Record assignment:
SCHEMA stores 
MAIN
  DEFINE c1, c2 RECORD LIKE customer.*
  -- Single variable assignment
  LET c1.customer_num = 123
  -- Complete RECORD assignment
  LET c1 = c2
END MAIN
Compound assignments:
MAIN
  DEFINE var1 INTEGER, var2 STRING
  LET var1 = 500
  LET var1 *= 5
  LET var2 = "Value:"
  LET var2 ,= var1
END MAIN