abap - INSERT INTO itab 时抑制不可抑制的警告

标签 abap internal-tables

我正在循环内向已排序的内部表添加一个新条目。由于我所在的循环的排序顺序与排序表的排序顺序不同,因此我必须使用 INSERT INTO 语句而不是 APPEND TO ,因为后者存在违反排序顺序导致转储的风险。

但是,当我添加该代码时,我收到一条语法检查警告,其中包含内部消息代码“MESSAGE GJK”,在 EPC 中显示:

Program: ZCL_CLASS Method METHOD_NAME Row: 301
Syntax check warning.

In the table "LT_TABLE_NAME" a row was to be changed, 
deleted or inserted. It is not possible
to determine statically if a LOOP is active over "LT_TABLE_NAME"

Internal message code: MESSAGE GJK
Cannot be hidden using a pragma.

但是“无法使用编译指示隐藏”对我来说不起作用。我理解警告的原因,但我知道在构建时 100% 确定在我插入新记录的内部表上不会有任何循环处于事件状态。但我无法隐藏这个警告。除了在开发时引起无用的警告之外,在某些环境中我无法传输带有语法检查警告的代码!

有什么办法可以抑制这种不可抑制的警告吗?

如果做不到这一点,有什么方法可以避免它吗?我可能可以通过使用临时未排序表作为中间,然后将行附加到排序表中来实现这一点,但我犹豫不决创建一个无用的(百万行)内部表只是为了绕过看似明显的疏忽。

最佳答案

此消息无法隐藏,因为已经声明过 in your previous question 。 但是,我们可以消除问题的最初原因,这是这里唯一正确的方法。 此错误报告内部表上的某些操作是使用隐式索引规范执行的,如详细消息中所述:

During the program flow, the current LOOP row is used, this means INDEX sy-tabix is used. If no LOOP is active over the table at this time, the runtime error TABLE_ILLEGAL_STATEMENT occurs.

For the current case of such an implicit operation, no encompassing LOOP statement for the table can be statically found (using the syntax check).

由于某种原因,编译器看不到您的循环,因此无法找到循环索引。在这种情况下可以做什么:

  1. 使用 INSERT wa INTO TABLE 而不是简短形式的 INSERT

  2. INSERT 语句使用显式索引

    INSERT wa INTO itab INDEX loopIdx.
    

ABAP documentation for INSERT wa INTO itab 语法变体确认此语法需要 LOOP:

This variant is only possible within a LOOP across the same table and if the addition USING KEY is not specified in the LOOP. Each row to be inserted can be inserted before the current row in the LOOP.

附注可以使用 DOCU_CALL FM 传递消息代码 TRMSG_MESSAGE_GJK 获取此消息的全文。所有消息代码都存储在DOKIL表中。

关于abap - INSERT INTO itab 时抑制不可抑制的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35839716/

相关文章:

abap - 新的 ABAP 语法而不是 COLLECT

bit-manipulation - 使用 ABAP 进行位移

abap - 允许当前用户查看的 BUKRS 列表

abap - 具有多个值的字段的sql select语句

error-handling - CALL TRANSACTION MR11 未填写错误表

time-complexity - ABAP中APPEND到标准内表的时间复杂度是多少?

performance - 使用 ABAP 7.40+ 语法进行最有效的 itab 过滤

abap - 计算满足某些条件的 itab 行?

abap - 如何将内部表格行转换为列?