Skip to Content
avatar image
-3
Former Member

How to implement F4 search in a cl_salv_table

Hi everyone. I have a program that shows a list displayed by cl_salv_table. If I try to use F4 search in one of the fields, nothing happens.

I've found a solution in the forums to put F4 event on it:

DATA: P_DDIC TYPE SALV_S_DDIC_REFERENCE,
      IR_COLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE,
      IR_COLUMN TYPE REF TO CL_SALV_COLUMN_TABLE,
      EX_MSG TYPE REF TO CX_SALV_NOT_FOUND.
P_DDIC-TABLE = 'TVRO'.
P_DDIC-FIELD = 'VSART'.
TRY.
  IR_COLUMN ?= IR_COLUMNS->GET_COLUMN( P_DDIC-FIELD ).
  IR_COLUMN->SET_DDIC_REFERENCE( P_DDIC ).
  IR_COLUMN->SET_F4( IF_SALV_C_BOOL_SAP=>TRUE ).
  CATCH CX_SALV_NOT_FOUND INTO EX_MSG.
    MESSAGE EX_MSG TYPE 'I'.
ENDTRY.

But the problem with this, is that you must use this code for every field in your table and I don't like it. Does someone know a method to use F4 search in a cl_salv_table for all fields at the same time? Thanks.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Feb 20 at 08:00 AM

    If your input data has a default domain or search help defined, it should be used automatically. At least this is what I thought, and am sure it used to work like this. However on my current (7.5) system the behavior is not based on domain but on the structure.

    Example:

        SELECT * FROM t000 INTO TABLE @DATA(itab1).
        cl_salv_table=>factory(  IMPORTING r_salv_table = DATA(alv)
                                 CHANGING  t_table      = itab1 ).
        alv->display( ).  "Currency, date etc. has search helps
    
        select mtext, changedate FROM t000 into TABLE @DATA(itab2).
        cl_salv_table=>factory(  IMPORTING r_salv_table = data(alv2)
                                 CHANGING  t_table      = itab2 ).
        alv2->display( ).  "Icon but no search help
    

    The first display has a date dropdown, the second doesn't.

    Bug? At the very least, offering the dropdown icon and not providing the function is a bug. I am pretty sure this worked on 7.0/1/2, maybe someone could verify this?

    Edit: I changed the example to use change date (type D), as the currency in this table isn't based on WAERS. But you can reproduce it with any data element that has a list of domain values.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 20 at 07:06 AM

    F4 is assigned automatically if you type your fields according to the ABAP dictionary fields linked to a search help.

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 19 at 03:13 PM

    Use a class like cl_abap_structdescr (e.g. describe_by_data followed by get_ddic_field_list) to get list of fields with ddic reference in the internal table structure, then loop at this table to force F4 usage.

    Add comment
    10|10000 characters needed characters exceeded

    • Sample provided so you could understand how to use those classes provided to analyze itab/structure. (Of course it's better to correctly define the structure with ddic reference) And of course SALV as every ALV tool has a field catalog, but it's built in background. And when using the column methods, you update this field catalog...

      Hint: Method CL_SALV_CONTROLLER_METADATA=>SET_LVC_FIELDCATALOG (allows to change columns and aggregation in cl_salv_table the old way)