NEW Operator – Single Value for All Data Types


In the previous post, we showed that NEW Operator is one of the enhanced features in EhP7. In this post, we would see the usage of NEW Operator for Single Value for All Data Types.


For NEW Operator:

i) An expression specified for data object can itself be a constructor expression or contain a constructor expression.

ii) When a constructor expression is assigned to a reference variable using NEW, this variable points to the initial object from the start. This means that the original reference is no longer available using the target variable in the expression.

NEW operator constructs an anonymous data object of the type string, whose value is determined using a string expression.
Note: The chaining operator && concatenates two operands in a string expression as a character string.

The above statement APPEND wa_marc to d_ref would give syntax error:  “WA_MARC” cannot be converted to the line type of “D_REF”.

Instead if we use the NEW Operator as shown below, the content of the work area can be assigned to the data object d_ref.

For row selected, a structured anonymous data object is created after the SELECT . The content of the row is assigned to this data object. The object is created in the general expression position of the statement APPEND and the NEW data reference is appended directly to an internal table with the appropriate row type. The result is a table that references all new anonymous data objects.

Already mentioned in previous post, when “#” succeeds NEW, it means the object ref in the Left Hand Side determines the type.

These are simple examples. In subsequent posts, we would try to explore more complex and real project scenarios. Please check the next post on structures and internal tables in NEW Operator.

If you want to get notification about the newest posts, please subscribe. Your email is safe with us.
If you liked it, please share it! Thanks!


Image source: via Free Stock Photos


Please enter your comment!
Please enter your name here