Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Filtering field value from table return by class method

pgotze
Newcomer
0 Likes
1,161

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

2 REPLIES 2
Read only

rameez_khan
Active Participant
737

Hello Pavel,

Please see the documentation for table expression.

It's mentioned in documentation:

  • The internal table itab must be specified directly using its name, a field symbol, or a dereferenced data reference as described under Reading Positions.

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

Read only

DoanManhQuynh
Active Contributor
737

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