我有一个三维表(带有嵌套表的表),我的目标是删除内部表中FIELDNAME
等于'SCAN_ID'
的行:
TYPES : BEGIN OF ty_cell,
fieldname TYPE lvc_fname,
END OF ty_cell,
ty_celltab TYPE STANDARD TABLE OF ty_cell WITH EMPTY KEY.
TYPES : BEGIN OF ty_line,
celltab TYPE ty_celltab,
END OF ty_line,
zatool_t_doc_input TYPE STANDARD TABLE OF ty_line WITH EMPTY KEY.
DATA(it_doc_input) = VALUE zatool_t_doc_input( ( celltab = VALUE #( ( fieldname = 'SCAN_ID' ) ) ) ).
DATA(rt_doc_input) = REDUCE zatool_t_doc_input( " <=== line of syntax error
INIT lt_doc_input = VALUE zatool_t_doc_input( )
FOR ls_doc_input IN it_doc_input
NEXT lt_doc_input = VALUE #(
BASE ls_doc_input
celltab = FILTER #(
ls_doc_input-celltab
WHERE fieldname <> CONV lvc_fname( 'SCAN_ID' ) ) ) ).
编译器给出以下语法错误:
"LS_DOC_INPUT"的类型不能转换为"LT_DOC_INPUT"的类型
错误在哪里?
使用如下所示的"表推导",您可以获得带有过滤单元格选项卡的表:
TYPES:
BEGIN OF zatool_t_doc_input_s,
field1 TYPE c,
field2 TYPE c,
celltab TYPE lvc_t_styl,
END OF zatool_t_doc_input_s,
zatool_t_doc_input TYPE STANDARD TABLE OF zatool_t_doc_input_s WITH EMPTY KEY.
DATA(it_doc_input) = VALUE zatool_t_doc_input(
( field1 = 'A' field2 = 'B' celltab = VALUE #( ( fieldname = 'SCAN_ID' ) ) )
( field1 = 'C' field2 = 'D' celltab = VALUE #( ( fieldname = 'USER_ID' ) ) )
( field1 = 'C' field2 = 'D' celltab = VALUE #( ( fieldname = 'SCAN_ID' ) ) )
( field1 = 'E' field2 = 'F' celltab = VALUE #( ( fieldname = 'SYST_ID' ) ) )
).
DATA(rt_doc_input) = VALUE zatool_t_doc_input(
FOR ls_doc_input IN it_doc_input (
VALUE #( BASE ls_doc_input
celltab = FILTER #( ls_doc_input-celltab
WHERE fieldname <> CONV lvc_fname( 'SCAN_ID' ) ) ) ) ).
关于语法错误,正如@Florian指出的那样,问题在于当将BASE
与结构一起使用时(在本例中为ls_doc_input
),相应的VALUE #(
返回结构。如果 VALUE 要返回一个表,BASE 也必须使用一个表。
无论如何,即使您用这样的东西绕过 BASE 语法错误
DATA(rt_doc_input) =
REDUCE #( INIT lt_doc_input = VALUE zatool_t_doc_input( )
FOR ls_doc_input IN it_doc_input
NEXT lt_doc_input = VALUE #( ( field1 = ls_doc_input-field1
field2 = ls_doc_input-field2
celltab = FILTER #( ls_doc_input-celltab
WHERE fieldname <> CONV lvc_fname( 'SCAN_ID' ) )
) )
). "reduces the original table to a single line (albeit with celltab filtered)
甚至等效,使用 BASE 来避免单个字段分配
DATA(rt_doc_input) =
REDUCE #( INIT lt_doc_input = VALUE zatool_t_doc_input( )
FOR ls_doc_input IN it_doc_input
NEXT lt_doc_input =
VALUE #(
( VALUE #( BASE ls_doc_input
celltab = FILTER #( ls_doc_input-celltab
WHERE fieldname <> CONV lvc_fname( 'SCAN_ID' ) )
) "VALUE: table line using BASE
) " VALUE: table row
) "VALUE: table
). "reduces the original table to a single line (albeit with celltab filtered)
它仍然不会做我猜测你的目标,因为它会it_doc_input
减少到一行。