LET statement Syntax: [LET] string-variable = string-expression
[LET] numeric-variable = numeric-expression
Discussion: The LET statement assigns a value to a string variable or a numeric variable. There are two forms of the LET statement: one for string variables and another for numeric variables. In both cases, the word "LET" itself is optional. In the first format, the string-variable is a single-element string variable or a string array element. The string-expression is a string constant, single-element string variable, string array element, string function or string expression. The result of the string-expression is moved into the string-variable (sometimes referred to as the "receiving variable").
If the string-expression results in more characters than are defined for the receiving string, the value will be truncated on the right side.
Note: Only one SUB function is permitted in a string-expression that is to be concatenated and stored as the value of the string variable.
In the second format shown above, the numeric-variable is a single-element numeric variable or a numeric array element. The numeric-expression may be a numeric constant, a single-element numeric variable, a numeric array element, a numeric function or a numeric expression. The result of the numeric-expression is moved into the numeric-variable (which is also referred to as the "receiving variable").
The result of the numeric-expression is truncated or expanded (on the right or left) to match the length and precision of the receiving variable. However, if the receiving variable has been defined for rounding (see ROUND), the value of the numeric-argument will be rounded to the precision of the receiving variable.
Example 1: LENGTH 40 & LOCAL NAME$ LENGTH 25 & LOCAL FIRST$, LAST$ . . . LET NAME$ = FIRST$ + LAST$
In the above example, the string variables named FIRST$ and LAST$ are concatenated (combined) and the resulting string is stored in the string variable named NAME$. Notice that NAME$ is defined with a length of 40 while FIRST$ and LAST$ are each defined with a length of 25 characters. This means that truncation could result if the combined total number of characters of FIRST$ and LAST$ is greater than 50. Note: The assignment statement could also have been written without the word "LET". In this case it would appear as:
NAME$ = FIRST$ + LAST$
Example 2: LENGTH 8.2 & LOCAL CRLIMIT, ARTOTAL, CREDIT . . . LET CREDIT = CRLIMIT - ARTOTAL
In this example, a new value is assigned to the numeric variable named CREDIT. The value will equal the difference between the values in CRLIMIT and ARTOTAL. Since all of these variables are defined with a length and precision of 8.2, and the numeric expression is a subtraction operation, there is no concern about truncation of the result. However, see the next example for a possible truncation situation. Note: The assignment statement could also have been written without the word "LET". In this case it would appear as:
CREDIT = CRLIMIT - ARTOTAL
Example 3: LENGTH 8.2 & LOCAL TOTAL, CURRENT, AR30, AR60, AR90, AR120 . . . TOTAL = CURRENT + AR30 + AR60 + AR90 + AR120
In this example, the values contained in five numeric variables are added together and the result is stored in the variable named TOTAL. Since all of the variables in this example are defined with a length and precision of 8.2 -- including the receiving variable TOTAL -- there could be possible truncation of the result. For example, if the sum of the five values exceeded 999,999.99 (the maximum value storable in an 8.2 field), the result would be truncated on the left-hand side without warning of any kind. Example 4: LENGTH 30 & LOCAL COMPANY$ LENGTH 5 & LOCAL VALUE$ . . . VALUE$ = SUB(COMPANY$,1,5)
This example shows a string function used as the string-expression. The function in this case is the SUB function -- one that derives a substring from a string value. In this example, the SUB function returns the first five characters of the value stored in COMPANY$ and stores the result in the variable named VALUE$.