Reputation: 34119
I've got a 3-dimension table (table with nested table), and my goal is to remove the lines in the inner table which have FIELDNAME
equal to '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 compiler gives this syntax error :
The type of "LS_DOC_INPUT" cannot be converted to the type of "LT_DOC_INPUT"
Where is the error?
Upvotes: 3
Views: 1103
Reputation: 441
Using a "table comprehension" like below, you can get the table with filtered celltabs:
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' ) ) ) ) ).
Regarding the syntax error, as @Florian points out the problem is that when using BASE
with a structure (in this case ls_doc_input
), the corresponding VALUE #(
returns a structure. If VALUE is to return a table, BASE must also use a table.
Regardless, even if you bypass the BASE syntax error with something like this
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)
or even the equivalent, employing BASE to avoid individual field assignment
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 still won't do what I am guessing you are aiming for since it will reduce it_doc_input
to a single line.
Upvotes: 4