gpt4 book ai didi

abap - 为什么类型不兼容?

转载 作者:行者123 更新时间:2023-12-04 18:31:06 24 4
gpt4 key购买 nike

我有一个 3 维表(带有嵌套表的表),我的目标是删除内表中 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' ) ) ) ).

编译器给出了这个语法错误:

The type of "LS_DOC_INPUT" cannot be converted to the type of "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 缩减为一行。

关于abap - 为什么类型不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56146832/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com