What is LET keyword in ABAP 7.4

1
22546

Dear saplearners, in this blog post we will learn about LET keyword in ABAP 7.4

LET Keyword

LET is a new syntax keyword introduced in ABAP 7.4 which is ABAP Platform version for SAP S/4HANA 1909 release. This keyword is used for local declarations in constructor expressions. It is used to define variables and field-symbols and assign values to them.

In our previous blog posts we learned about inline declarations to declare the variables with out explicit data type declaration in a program, start of sub-routine, method etc. Inline declarations will reduce the number of lines in programs.

Also Read: Inline declarations in ABAP 7.4

In the same way the LET also used to declare variables with short lifespans by getting us relieved from declaring helper variables.

Let’s see how this can make an ABAPer happier.

Where can I use LET?

LET expressions can be used in the following constructor expressions

  1. NEW
    • Single Values
    • Structures
    • Internal Tables
    • Classes
  2. VALUE
    • Structures
    • Internal Tables
  3. CONV
  4. CAST
  5. EXACT
  6. REDUCE
  7. COND
  8. SWITCH

Apart from the above constructor expressions the LET expressions can be used in all iteration expressions with FOR.

Example#1 – LET Usage in CONV Expression

In the below ABAP code snippet demonstrates the LET statement usage in constructor expression CONV.

LET Keyword in ABAP7.4

In the above example line-29, we have used LET statement to declare local variables airline_name, airline_from, airline_to and used them to built the final output string.

With out LET statement, we would have declared the helper variables before the LOOP statement and use them. Thanks to LET statement in avoiding those unwanted declaration of helper variables.

As the local variables declared using LET statement have short lifespan, after the statement is over those variables does not exists any longer.

Example#2 – LET Usage in VALUE Expression

In the below ABAP code snipper demonstrates, LET statement usage in constructor expression VALUE.

LET Keyword in ABAP7.4 2

Conclusion

Congrats..! You have successfully learned about LET keyword in ABAP 7.4. So start using the new syntax and write some good code.

Please feel free to comment and let us know your feedback. Subscribe for updates

Comments are closed.