ABAP HANA 7.51: VALUE expressions/Chaining/DEFAULT
VALUE expression – This provides a powerful mechanism to declare as well as initialize internal tables. Syntax also facilitates to set a type of internal table.
This is a very useful utility for ABAPers where they can enjoy to do more with minimal coding. Earlier, to achieve similar functionality, the programmer used to fill up the work area and then append it to the internal table which was a cumbersome work. SAP finally recognized made this easy.
VALUE expression has two types:
- Non-generic data type e.g. type can be defined before using it with VALUE keyword. The Type created using this mechanism is Structured or Table type.
- Using # character for type where operand position is fixed and identifiable
VALUE chaining – Newly created CONV and LET operators can be used with the combination of VALUE keyword. It is also possible to fill multiple rows with same data by writing it only once in syntax. An example can be checked to below video where RANGE table is filled with sample data on the fly.
DEFAULT addition – When content inside VALUE refers to information that doesn’t exist, DEFAULT keyword comes handy and defaults to that reference to the defaulted value.
Sample Source Code: Variant 1
Output: Variant 1
Sample Source Code: Variant 2
Notice extra parentheses around values(Line 17-18). This may produce unexpected results if this is not intended for what is actually does.
Output: Variant 2
Four lines are created… each for one parenthesis set!
Sample Source Code: Variant 3
A sample code for how easily a range table can be filled.
Output: Variant 3
Sample Source Code: Variant 4
Check that how intelligently provision is given that same field need not be addressed again and again in case of repetition. In this example, SIGN and OPTION in line 11 and 12 are written once however creates two lines in output with values I and EQ.
Output: Variant 4
Sample Source Code: Variant 5
Output: Variant 5
Check the video for Code and Execution:
Find the code on GitHub: