Skip to Content
-3

How to implement F4 search in a cl_salv_table

Feb 19 at 10:24 AM

124

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Mike Pokraka Feb 20 at 08:00 AM
1

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.

Share
10 |10000 characters needed characters left characters exceeded
Sandra Rossi Feb 20 at 07:06 AM
0

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

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

SALV does not make it automatically, basically because it can't. If you want the F4 search in a cl_salv_table you must put it yourself somehow.

0

You're just wrong. cf Mike's answer.

1
Raymond Giuseppi
Feb 19 at 03:13 PM
0

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.

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Raymond. I've never used a cl_abap_structdescr class. Could you show me an example of what you are trying to explain me? I don't have much experience with SAP/ABAP.

0

Look for some samples in wiki like ALV fieldcatalog - create for ANY table using RTTS.

0
Former Member
Raymond Giuseppi

SALV hasn't fieldcat.

0

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)

0