Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Product and Topic Expert
Product and Topic Expert

With Release 7.40 constructor expressions NEW, VALUE and CORRESPONDING were introduced, that allow you to construct complex data objects in operand positions. Some of you might have noticed, that something was missing there.

Look at the following examples:

  BEGIN OF struct1,
    col1 TYPE i VALUE 11,
    col2 TYPE i VALUE 12,
  END OF struct1.

  BEGIN OF struct2,
    col2 TYPE i VALUE 22,
    col3 TYPE i VALUE 23,
  END OF struct2.

struct2 = CORRESPONDING #( struct1 ).

This is not the same as

MOVE-CORRESPONDING struct2 TO struct1.

Since the RHS does not know anything of the LHS, component col3 of struct2 does not keep its former value but is initialized.

Same for:


itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).

itab = VALUE #( ( 4 ) ( 5 ) ( 6 ) ).

This is not the same as

APPEND 1 TO itab.

APPEND 2 TO itab.

APPEND 3 TO itab.

APPEND 4 TO itab.

APPEND 5 TO itab.

APPEND 6 TO itab.

Again, the RHS does not know the LHS and the result of the second assignment is three lines containing 4, 5, 6.

Of course, it is a common use case to add new values to existing values. Therefore, with Release 740, SP08 there is a new addition BASE for constructor expressions NEW, VALUE and CORRESPONDING that allows you to give the expressions a start value.  Very often, this means to make the LHS known to a RHS. For the examples shown above, this simply will look as follows:

struct2 = CORRESPONDING #( BASE ( struct2 ) struct1 ).

The result of the expression is initialized with struct2 and then the evaluation takes place. Now it works like MOVE-CORRESPONDING, col3 of struct2 keeps its former value.


itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).

itab = VALUE #( BASE itab ( 4 ) ( 5 ) ( 6 ) ).

The result of the second expression is initialized with itab and then the other lines are added. After the second assignment, itab contains 1, 2, 3, 4, 5, 6.

You can als construct structures using BASE:

struct2 = VALUE #( BASE struct1  col3 = 33 ).

First, all components are taken over from struct1, then the columns specified are overwritten.

Of course, the usage of BASE is not restricted to constructor expressions in RHS-positions.

meth( VALUE #( BASE ... ( ... ) ).

Didn't you miss that?

And one mor goody for constructing internal tables:

... VALUE #( ... ( LINES OF itab ) ... ) ...

To be freely combined with other line specifications and - of course - BASE.