简体   繁体   English

如何在动态内部表中循环?

[英]How to loop at a dynamic internal table?

I'm working on an Enhancement Implantation on ZXMBCU10 which is called in a custom program couple of levels down the execution path.我正在 ZXMBCU10 上进行增强植入,它在执行路径下几个级别的自定义程序中调用。 Inside ZXMBCU10 I want to access the a table in the parent program, which I do in the following method;在 ZXMBCU10 内部,我想访问父程序中的表,我通过以下方法进行;

  1. Declare the parent program name;声明父程序名;

    DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.

  2. Getting the value through field symbol assignment.通过字段符号分配获取值。

    FIELD-SYMBOLS: <fs> TYPE any.

    ASSIGN (ex_tbl_name) TO <fs>.

Then I check for successful assignment (which is true).然后我检查分配是否成功(这是真的)。

IF <fs> IS ASSIGNED.

访问父表

Problem I have is how to read the data in the <fs> field symbol.我的问题是如何读取<fs>字段符号中的数据。

I've tried LOOP and READ TABLE, but getting the following;我试过 LOOP 和 READ TABLE,但得到以下结果;

循环和读取表示例

Both Read Table and Loop is added here just to get the syntax checks这里添加了读取表和循环只是为了进行语法检查

LOOP;环形;

Internal table " <FS> " has no header line - one of the additions "INTO wa", "ASSIGNING", "REFERENCE INTO", "TRANSPORTING NO FIELDS" required.内部表“ <FS> ”没有标题行 - 需要添加“INTO wa”、“ASSIGNING”、“REFERENCE INTO”、“TRANSPORTING NO FIELDS”之一。 required.必需的。

READ TABLE;读表;

You cannot use explicit or implicit index operations on tables with types "HASHED TABLE" or "ANY TABLE".不能对类型为“HASHED TABLE”或“ANY TABLE”的表使用显式或隐式索引操作。 " <FS> " has the type "ANY TABLE". <FS> ”的类型为“ANY TABLE”。 It is possible that the "TABLE" addition was not specified before " <FS> ".可能在“ <FS> ”之前没有指定“TABLE”添加。

LOOP AT循环

The error about LOOP AT ( Internal table " <FS> " has no header line - one of the additions "INTO wa", "ASSIGNING", "REFERENCE INTO", "TRANSPORTING NO FIELDS" required ), is that you don't indicate the "result" part of LOOP AT ie ASSIGNING, REFERENCE INTO... (as said in the message).关于LOOP AT的错误(内部表“ <FS> ”没有标题行 - 需要添加“INTO wa”、“ASSIGNING”、“REFERENCE INTO”、“TRANSPORTING NO FIELDS”之一),是你没有指示LOOP AT IE ASSIGNING, REFERENCE INTO... 的“结果”部分(如消息中所述)。

For a field symbol, LOOP AT alone is always invalid, and if it's a variable instead of a field symbol it's obsolete because that would imply the use of a header line.对于字段符号,单独的LOOP AT 总是无效的,如果它是变量而不是字段符号,则它已过时,因为这意味着使用标题行。

LOOP AT <fs>. " always invalid !

A valid syntax could be as follows: you must declare the field symbol as being an internal table (with at least the word TABLE , or refer to a "Table Type"), any category of internal table is supported for LOOP AT (hashed, sorted, standard), so you can use TYPE ANY TABLE :有效的语法如下:您必须将字段符号声明为内部表(至少使用单词TABLE ,或引用“表类型”), LOOP AT 支持任何类别的内部表(散列,排序,标准),因此您可以使用TYPE ANY TABLE

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE.

ASSIGN (ex_tbl_name) TO <fs>.
LOOP AT <fs> ASSIGNING FIELD-SYMBOL(<line>).
ENDLOOP.

READ TABLE读表

The error about READ TABLE ( You cannot use explicit or implicit index operations on tables with types "HASHED TABLE" or "ANY TABLE". " <FS> " has the type "ANY TABLE". It is possible that the "TABLE" addition was not specified before " <FS> " ) is that you used READ TABLE ... INDEX ... whose INDEX means that it can only be used with an internal table with category SORTED or STANDARD .关于READ TABLE的错误(您不能对类型为“HASHED TABLE”或“ANY TABLE”的表使用显式或隐式索引操作。“ <FS> ”具有“ANY TABLE”类型。可能是“TABLE”添加在“ <FS> ”之前未指定)是您使用了READ TABLE ... INDEX ...其 INDEX 意味着它只能与类别为SORTEDSTANDARD的内部表一起使用。

The next code is invalid because of the combination of ANY TABLE and READ TABLE INDEX, because <FS> could eventually be a hashed internal table (who knows), then READ TABLE INDEX would fail, hence the compiler error:由于 ANY TABLE 和 READ TABLE INDEX 的组合,下一个代码无效,因为<FS>最终可能是一个散列内部表(谁知道),然后 READ TABLE INDEX 将失败,因此编译器错误:

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE ANY TABLE. " <=== impossible with READ TABLE INDEX !

ASSIGN (ex_tbl_name) TO <fs>.
READ TABLE <fs> ASSIGNING FIELD-SYMBOL(<line>) INDEX 1. " <=== impossible with ANY TABLE !

Solution: to use READ TABLE <fs> INDEX ... you may declare the field-symbol as SORTED, STANDARD, or INDEX (the latter is a generic name corresponding to SORTED and STANDARD).解决方案:要使用READ TABLE <fs> INDEX ...您可以将字段符号声明为 SORTED、STANDARD 或 INDEX(后者是对应于 SORTED 和 STANDARD 的通用名称)。

This code is valid:此代码有效:

DATA: ex_tbl_name TYPE char100 VALUE '(ZPROGRAM)G_TAB'.
FIELD-SYMBOLS: <fs> TYPE INDEX TABLE.

ASSIGN (ex_tbl_name) TO <fs>.
READ TABLE <fs> ASSIGNING FIELD-SYMBOL(<line>) INDEX 1.

Of course, it's assumed that G_TAB is an "index" table, not a hashed table!当然,假设 G_TAB 是一个“索引”表,而不是一个哈希表!

PS: in your code you used INTO DATA(lv_fs) but usually if you have a generic internal table ASSIGNING is preferred. PS:在你的代码中你使用了INTO DATA(lv_fs)但通常如果你有一个通用的内部表ASSIGNING是首选。

change field symbol type to将字段符号类型更改为

any table.

instead of:代替:

any.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM