VALUE 从文字构造 table 行时出现语法错误

Syntax error while VALUE constructing table line from literal

这是给你的。

这个怎么编译不了

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 ) ).

这个有吗?

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 ) ).

内部 VALUE dtype|#( line | {LINES OF itab ...} )ABAP documentation 说:

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.

在你的例子中:

  • “2”是一个数字文字,因此是一个数据对象,只有当它与类型兼容时才有效,即它是完全相同的类型。
  • "1 * 2"是一个表达式,它是有效的,因为存在从类型I到类型X的转换规则。

您可以输入更短的表达式,例如“+ 2”:VALUE my_int_table( ( + 2 ) ).