在 INSERT INTO itab 时抑制无法抑制的警告
Suppressing an insuppressible warning while INSERT INTO itab
我正在向循环内已排序的内部 table 添加一个新条目。由于我所在的循环的排序顺序与排序后的 table 不同,我必须使用 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% 确定在我插入新记录的内部 table 上不会激活任何循环。然而我无法隐藏这个警告。除了在开发时引起无用的警告之外,在某些环境中我将无法传输带有语法检查警告的代码!
有什么办法可以抑制这种无法抑制的警告吗?
做不到这一点,有什么办法可以避免吗? 我可能可以通过使用临时未排序的 table 作为中间体然后附加行来做到这一点进入已排序的 table,但我不愿创建一个无用的(百万行)内部 table 只是为了绕过似乎是明显的疏忽。
收到此警告的最可能原因实际上是语法错误!只要您有如下语句,它就会发生:
INSERT [work area] INTO [internal table].
插入 itab 的实际语法需要 INTO TABLE
:
INSERT [work area] INTO TABLE [internal table].
警告的描述似乎与此处实际发生的情况不符。据推测,它正在考虑 table 可能有一个 header 区域(事实并非如此)。如果您 运行 此代码,您将得到一个 TABLE_ILLEGAL_STATEMENT
转储,其中包含更具描述性的错误消息:
An attempt was made to change, delete or add a row in internal table "[internal table]". There is no valid cursor for this table however.
这实际上是我第二次遇到这种情况,但它是如此令人困惑的消息,以至于我不记得解决方案了。当我发布这个时我并没有打算 self-answer 但当我得到转储时我意识到我的错误。我猜主要问题是当我使用不正确的语法时依靠语法错误来告诉我:语法检查显然不认为这是一个彻底的错误,即使它可能应该如此。
无法隐藏此消息,因为它已经声明 in your previous question。
但是,我们可以摆脱问题的最初原因,这是这里唯一正确的做法。
此错误报告内部 table 上的某些操作是使用隐式索引规范执行的,如详细消息中所述:
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).
出于某种原因,编译器看不到您的循环,因此无法找到循环索引。在那种情况下可以做什么:
使用INSERT wa INTO TABLE
代替INSERT
的缩写形式。
为你使用显式索引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.
P.S。可以使用 DOCU_CALL
FM 传递消息代码 TRMSG_MESSAGE_GJK 获取此消息的全文。所有消息代码都存储在 DOKIL
table.
我正在向循环内已排序的内部 table 添加一个新条目。由于我所在的循环的排序顺序与排序后的 table 不同,我必须使用 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% 确定在我插入新记录的内部 table 上不会激活任何循环。然而我无法隐藏这个警告。除了在开发时引起无用的警告之外,在某些环境中我将无法传输带有语法检查警告的代码!
有什么办法可以抑制这种无法抑制的警告吗?
做不到这一点,有什么办法可以避免吗? 我可能可以通过使用临时未排序的 table 作为中间体然后附加行来做到这一点进入已排序的 table,但我不愿创建一个无用的(百万行)内部 table 只是为了绕过似乎是明显的疏忽。
收到此警告的最可能原因实际上是语法错误!只要您有如下语句,它就会发生:
INSERT [work area] INTO [internal table].
插入 itab 的实际语法需要 INTO TABLE
:
INSERT [work area] INTO TABLE [internal table].
警告的描述似乎与此处实际发生的情况不符。据推测,它正在考虑 table 可能有一个 header 区域(事实并非如此)。如果您 运行 此代码,您将得到一个 TABLE_ILLEGAL_STATEMENT
转储,其中包含更具描述性的错误消息:
An attempt was made to change, delete or add a row in internal table "[internal table]". There is no valid cursor for this table however.
这实际上是我第二次遇到这种情况,但它是如此令人困惑的消息,以至于我不记得解决方案了。当我发布这个时我并没有打算 self-answer 但当我得到转储时我意识到我的错误。我猜主要问题是当我使用不正确的语法时依靠语法错误来告诉我:语法检查显然不认为这是一个彻底的错误,即使它可能应该如此。
无法隐藏此消息,因为它已经声明 in your previous question。 但是,我们可以摆脱问题的最初原因,这是这里唯一正确的做法。 此错误报告内部 table 上的某些操作是使用隐式索引规范执行的,如详细消息中所述:
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).
出于某种原因,编译器看不到您的循环,因此无法找到循环索引。在那种情况下可以做什么:
使用
INSERT wa INTO TABLE
代替INSERT
的缩写形式。为你使用显式索引
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.
P.S。可以使用 DOCU_CALL
FM 传递消息代码 TRMSG_MESSAGE_GJK 获取此消息的全文。所有消息代码都存储在 DOKIL
table.