What does it do? A LET> expression defines variables var1>, var2>, ... or field symbols < fs1>>, < fs2>>, ... as local helper fields in an expression and assigns values to them. The helper fields can be used from their declaration in the operand positions of the expression. There is no way of accessing a helper field statically outside of its expression. The documentation of each expression lists whether and in which lines it contains a LET > expression. Any LET> expressions in an expression or subexpression are evaluated first. A helper field specified in a LET> expression is valid in the context in which the LET> expression is specified. This can be a full expression or just part of an expression. All helper fields of a full expression are in the same namespace. A previously specified helper field cannot be specified in a further LET> expression of the same expression. Furthermore, the helper fields are in the same namespace as the data objects or field symbols of the current procedure or program. Helper fields cannot be defined in a LET> expression if a data object or field symbol with the same name already exists in the procedure or program of the expression. Conversely, no data objects or field symbols with names assigned to helper fields can be declared after an expression with a LET> expression. When reusing helper fields in different expressions, the following applies:
If a helper field is defined for the first time in the current procedure or program, it is declared as with an inline declaration> and the data type is derived accordingly.
If a helper field in the current procedure or program is defined again in a LET> expression of a different expression and the derived data type matches, the helper field is bound to this expression and can be used there.
If a helper field in the current procedure or program is defined again in a LET> expression of a different expression and the derived data type does not match, the helper field cannot be used there and a syntax error occurs.
Latest notes:
LET> expressions can currently only be used in constructor expressions>. Subexpressions in which LET> expressions can be used are iteration expressions> using FOR>> and results specified after THEN> and ELSE> in the conditional expressions> COND>> and SWITCH>>.
In the assignment of a value operator VALUE> to structures> or internal tables>, values on the left side can be saved to helper fields using a LET> expression before the left side is overwritten.
A helper field defined in a LET> expression can be addressed dynamically in the entire current context. This is not recommended, however, since expressions should be free of side effects.
It is a good idea to use LET> expressions whenever helper fields are required for performance (avoiding multiple calculations) or the readability of an expression or whenever values from the left side of an assignment in a VALUE> operator are needed on the right side. NON_V5_HINTS ABAP_HINT_END
What does it do? Definition of a local helper variable var> as a helper field in a LET> expression. The value of the right side rhs> is assigned to the helper variable as an initial value. For the right side rhs> the same can be specified as in a regular assignment using the assignment operator = >>. The data type of the helper variable is determined from the right side rhs> as when an inline declaration DATA(var)>> or FINAL(var)>> is specified on the left side of an assignment operator using the assignment operator => >. It must be possible to determine the data type completely from the right side to avoid syntax errors.
Latest notes:
The helper variables declared in a LET> expression generally keep the value defined by rhs> while the expression is calculated. It is possible to change the value of a helper variable in the expression, for example by binding to a CHANGING> parameter of a method, but this would be unusual. NON_V5_HINTS
The helper variables declared in a LET> expression are a good example of where long readable names> are not necessary and can even harm readability. The helper variables can only be used in their own expression, which means that short identifiers, even single-character names, are enough. ABAP_HINT_END
ABAP_EXAMPLE_VX5 Definition of three local helper variables x>, y>, and z > in a constructor expression to construct the values of a structure. The values of the helper variables are used for the structure components. ABEXA 00379 ABAP_EXAMPLE_END
ABAP Alternative 2 ... <(><)> = wrexp ...>
What does it do? Definition of a local field symbol <(><)>> as a helper field in a LET> expression. The result of the writable expression> wrexp> is assigned to the field symbol. The same applies here as to assignments of writable expressions using ASSIGN>>, which means that only the expressions listed there can be specified. The typing of the field symbol depends on the type of wrexp> and is performed in the same way as in inline declarations of a field symbol using the statement FIELD-SYMBOL>>.
ABAP_EXAMPLE_VX5 Definition of a field symbol and a variable as helper fields in a LET> expression in a conversion expression. The lines of an internal table are assigned to the field symbol. ABEXA 00380 ABAP_EXAMPLE_END