Table Expressions
A table expression consists of an internal table itab, followed directly by a row (itab_line) specified in square brackets [ ]. The expression finds the specified row in the internal table and returns it as the result of the corresponding row type, which can be used as follows:
The VALUE Expression for Internal Tables
The VALUE( ) operator allows you to assign values to a simple variable, structure, or internal table. The left-hand side of the expression can be a formal parameter as shown here, but also a variable. This example shows how you can use the VALUE( ) operator to pass a single-line internal table to a method without first having to create an internal table and corresponding work area. In total, it saves 7 lines of code. The disadvantage is that the data that you use is anonymous and cannot be accessed at any other point in the program.
Note: To create a variable with its initial value, use VALUE with empty parentheses.
VALUE Expression to Append to an Internal Table
By using the option BASE within the VALUE expression, you can build the result on top of an existing internal table. The figure shows an example. The expression on the right hand side of the value assignment takes the content of internal table gt_carriers and adds (inserts) an additional line.
The VALUE Expression With a Built-In LOOP
Addition FOR also builds the result based on an existing internal table. But instead of simply copying the complete table, it defines a loop — with an optional selection — and constructs one new line in the result for every line in the source.
In the example, the runtime environment performs a loop over internal table gt_scarr and for each carrier with currcode = ‘EUR’ it creates a new line in target table gt_range. Data object line serves as a kind of “work area” for this loop. It only exists within the VALUE expression.
Internal Tables: Built-in Functions
The descriptive table function line_index() returns the number of the row found for the table expression specified. The return value has the type i.
The predicate function line_exists() checks whether the row of an internal table specified in the table expression exists and returns the appropriate logical value.