Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error while VALUE constructing table line from literal

Tags:

abap

Here is one for you.

How come that this one does not compile

REPORT ZZY.

TYPES: my_int TYPE x LENGTH 4,
  my_int_table TYPE STANDARD TABLE OF my_int WITH EMPTY KEY.

DATA(g_tab_my_int) = VALUE my_int_table( ( 2 ) ).

and this one does?

REPORT ZZY.

TYPES: my_int TYPE x LENGTH 4,
  my_int_table TYPE STANDARD TABLE OF my_int WITH EMPTY KEY.

DATA(g_tab_my_int) = VALUE my_int_table( ( 2 * 1 ) ).
like image 836
Jagger Avatar asked Apr 03 '19 17:04

Jagger


1 Answers

The ABAP documentation for inside VALUE dtype|#( line | {LINES OF itab ...} ) says:

If a data object is specified for line, this object must be compatible with the row type.

If an expression (built-in function, functional method, calculation expression, constructor expression, or table expression) is specified for line, the result of the expression must be convertible to the row type.

In your example:

  • "2" being a numeric literal so being a data object, it's valid only if it's compatible with the type i.e. it's exactly of the same type.
  • "1 * 2" being an expression, it's valid because a conversion rule exists from the type I to the type X.

You may enter a shorter expression like "+ 2" : VALUE my_int_table( ( + 2 ) ).

like image 120
Sandra Rossi Avatar answered Sep 16 '22 17:09

Sandra Rossi