[英]How to add a new row into a nested internal table?
DATA: BEGIN OF line,
CUOBJ TYPE CUOBJ,
tab_atinn TYPE STANDARD TABLE OF ATINN WITH DEFAULT KEY,
END OF line.
DATA:
CUBOBJ_TABLE LIKE STANDARD TABLE OF line WITH DEFAULT KEY.
...
DATA(table) = CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn.
IF NOT line_exists( table[ currentatinn ] ).
INSERT currentatinn INTO table INDEX 1.
ENDIF.
I'm trying to add a new row into CUOBJ_TABLE [..]-tab_atinn.我正在尝试向 CUOBJ_TABLE [..]-tab_atinn 添加新行。 The table variable will have a new row after executing the code but the CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn table won't have it.执行代码后,表变量将有一个新行,但 CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn 表不会有它。
How can I add it directly into CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn using a reference or something?如何使用引用或其他方式将其直接添加到 CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn 中?
With a reference exactly, the issue is the assignment:确切地参考,问题是分配:
DATA(table) = CUBOBJ_TABLE[ CUOBJ = value-instance ]-tab_atinn.
This creates a new table with the sames values as the tab_atinn field.这将创建一个与 tab_atinn 字段具有相同值的新表。 Then you add the entry to this new table without affecting the deep table in CUOBJ_TABLE.然后将条目添加到这个新表中,而不会影响 CUOBJ_TABLE 中的深层表。 What you need is a reference pointing to the table you want to change so it actually updates the table and not a copy of it, something like the code below should work.您需要的是指向要更改的表的引用,以便它实际更新表而不是它的副本,类似于下面的代码应该可以工作。
TYPES: atinn_tab TYPE STANDARD TABLE OF atinn WITH DEFAULT KEY.
DATA: BEGIN OF line,
cuobj TYPE cuobj,
tab_atinn TYPE atinn_tab,
END OF line.
DATA:
cubobj_table LIKE STANDARD TABLE OF line WITH DEFAULT KEY,
value_instance TYPE cuobj,
current_atinn TYPE atinn.
...
data(table_ref) = REF atinn_tab( cubobj_table[ cuobj = value_instance ]-tab_atinn ).
IF NOT line_exists( table_ref->*[ current_atinn ] ).
INSERT current_atinn INTO table_ref->* INDEX 1.
ENDIF.
Just for checking the existence you don't need an auxiliary variable只是为了检查存在你不需要辅助变量
IF NOT line_exists( cubobj_table[ cuobj = 'VAL' ]-tab_atinn[ '0000000020' ] ).
ENDIF.
But for adding a line you need但是要添加一行,您需要
READ TABLE cubobj_table WITH KEY cuobj = 'VAL' ASSIGNING FIELD-SYMBOL(<fs_cubobj>).
INSERT atinn INTO <fs_cubobj>-tab_atinn INDEX 1.
because INSERT doesn't allow putting table expressions in the itab_position .因为 INSERT 不允许将表表达式放在itab_position 中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.