‎2019 Jun 19 5:17 PM
Hi,
if i have class method, returning table, is it possible to directly filter table result to get field value from exact line?
This standard 2-rows operation works (but local temporary variable lt_tab is necessary )
DATA(lt_tab) = cl_myclass->get_myobject( obj_id )->get_mytable( ).
DATA(lv_field_value) = lt_tab[ line_id = 'A' ]-field_1.
How to reach something like this
DATA(lv_field_value) = cl_myclass->get_myobject( obj_id )->get_mytable( )[ line_id = 'A' ]-field_1.
This construction does not work, i tried also via FILTER #( ), but also not work.
Any ideas?
Thanks.
Pavel
‎2019 Jun 19 10:01 PM
Hello Pavel,
Please see the documentation for table expression.
It's mentioned in documentation:
So to conclude we cannot use table expression for itab returning from method since it's not specified directly as mentioned above.
Also see this thread. Although bit old but still holds true.
Best Regards
‎2019 Jun 20 1:47 AM
direct access like class->method( ) [ value ] is not possible but you can loop or read.
and filter is working (table must be hashed or sorted), idk how did you filter:
CLASS test DEFINITION.
PUBLIC SECTION.
CLASS-METHODS get RETURNING VALUE(return_tab) TYPE flighttab.
ENDCLASS.
CLASS test IMPLEMENTATION.
METHOD get.
SELECT * FROM sflight INTO TABLE return_tab.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
LOOP AT test=>get( ) INTO DATA(ls_data) WHERE carrid = 'AA'.
WRITE: / ls_data-carrid, ls_data-connid.
ENDLOOP.
READ TABLE test=>get( ) INTO ls_data WITH KEY carrid = 'AA'.
DATA(filter_tab) = FILTER flighttab( test=>get( ) WHERE carrid = conv #( 'AA' ) ).
"this syntax error because flighttab is not hashed or sorted