Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Creating Objects and Values 

VALUE - Value Operator

Other versions: 7.31 | 7.40 | 7.54

Syntax


... VALUE type( ... ) ...

Effect

A constructor expression with the value operator VALUE creates a result of a data type specified using type. The following can be specified for type:

  • A non-generic data type dtype.
  • The # character as a symbol for the operand type. Can be specified only if the data type required in an operand position is unique and fully identifiable. The following exceptions apply:
  • When an initial value VALUE #( ) is passed to a generically typed formal parameter, the type is derived from the generic type.

The operator does the following:

  • It creates initial values for any non-generic data types.
  • It constructs the content of the following:
  • Structured types
  • Table types
  • It controls the type of the result of table expressions and so enables a default value to be specified for any rows not found.

The content of the result is determined by the parameters specified in parentheses. The syntax used in pass by parameter depends on the type used when the value was constructed. There are specialized categories of pass by parameter for each possible type.

  • Pass by parameter when constructing values:
  • If a single table expression is specified as a parameter, VALUE does not construct a value and controls the type of the result instead.

In assignments of constructor expressions to a data object using VALUE, the data object is used directly. It is overwritten in full by an initial value or start value before being assigned the values specified in the parentheses.


Notes

  • The value operator VALUE can also be used to construct the content of existing complex data objects (structures and internal tables). This goes beyond what is possible using the VALUE addition.

  • The value operator VALUE uses mainly the same syntax as in the instance operator NEW to create values.

  • When using the operator VALUE to construct values, elementary data types and reference types cannot be specified explicitly, except when an initial value is created. Unlike when using the instance operator NEW, the correct result can be achieved by using direct assignments. For this reason, it is not necessary to specify unnamed arguments as single values when using NEW (and also not allowed). The use of VALUE to control table expressions is not affected by this, since any valid data type can be specified here.

  • Arithmetic calculations with the results of VALUE for constructing values are not possible (except when creating an initial value). This means that constructor expressions of this type cannot be specified directly in the operand positions of arithmetic expressions. Any constructor expressions with VALUE used to control table expressions are not affected by this (if the table expressions can be used for calculations using valid results).

  • The conversion operator CONV closes the gap where no elementary data objects can be constructed in operand positions using VALUE.

  • If a constructor expression with VALUE is not used as the source of an assignment to a data object, the value operator VALUE creates a new temporary data object whose data type is determined by the specified type and whose content is determined by the parameters passed. This data object is used as the operand of a statement and then deleted. It is deleted either when the current statement is closed or when a relational expression is evaluated after the truth value is determined.

  • In assignments to a data object, the target variable is used directly and no temporary data object is created. This variable is initialized or overwritten in full before the assignment of the values specified in the parentheses. Its original value, however, is still available in an optional LET expression. This is the difference between VALUE and the instance operator NEW.

Example

Constructs the values of a structure of type T100 declared inline.

DATA(wa) = VALUE t100( sprsl = 'E' 
                       arbgb = 'DEMO' 
                       msgnr = '111' 
                       text =  '...' ).

Continue

VALUE - Initial Value for All Types

VALUE - Structures

VALUE - Internal Tables