F4 / search help, filter results dynamically
When you want to filter the results dynamically based on some criteria, you can do it in search help exits. The example below demonstrates how to create your own exit.
If you need it in a standard search help, then hopefully you have the possibility to create a post exit/implicit enhancement and apply this logic. The most common problem is the conversion of the result set structure, which is a long character variable. Hopefully there are standard functions to support this. We’ll aplly these functions together with the definition of a structure type having the same fields in the same order, as the parameters are definded in the serach help. So first create the structure type ty_shlp_str containing the same components with the same types in the same order as the search help parameters. Based on that structure, create the standard table type ty_shlp_tab. After converting the search hep results to structured format with function F4UT_PARAMETER_VALUE_GET into lt_result, you can do filtering based on the components. If you removed the unnecessary entries, just convert back with help of F4UT_RESULTS_MAP.
Attention: Set max results restrcton different than the default 500 (in our case 30.000) and manage maxexceed property at the end manually. This is required to prevent problems receiving only the first 500 entries in the exit from the db/view assigned to the search help matching user selection criteria. After you’ll filter to less, and the message generated and displayed in search help dialog would be wrong displaying that max hits 500 reached. Maybe you removed all the entries and nothing is displayed in the result list.
DATA: ls_field_descr TYPE dfies, lt_result TYPE ty_shlp_tab, lr_result TYPE REF TO ty_shlp_str. IF callcontrol-step NE 'SELECT' AND callcontrol-step NE 'DISP'. RETURN. ENDIF. callcontrol-maxrecords = 30000. IF lines( record_tab ) EQ 0."Table with header RETURN. ENDIF. "Conversion by component metadata to structured format LOOP AT shlp-fielddescr INTO ls_field_descr. CALL FUNCTION 'F4UT_PARAMETER_VALUE_GET' EXPORTING parameter = ls_field_descr-fieldname fieldname = CONV fnam_____4( ls_field_descr-fieldname ) TABLES shlp_tab = shlp_tab record_tab = record_tab results_tab = lt_result CHANGING shlp = shlp callcontrol = callcontrol EXCEPTIONS parameter_unknown = 1 OTHERS = 2. IF sy-subrc NE 0. CONTINUE. ENDIF. ENDLOOP. * Remove unnecessary entries from lt_result here "Convert data back to search help result list format CLEAR: record_tab, record_tab. CALL FUNCTION 'F4UT_RESULTS_MAP' TABLES shlp_tab = shlp_tab record_tab = record_tab source_tab = lt_result CHANGING shlp = shlp callcontrol = callcontrol EXCEPTIONS illegal_structure = 1 OTHERS = 2. IF sy-subrc NE 0. RETURN. ENDIF.
Remark: CONV fnam_____4( ls_field_descr-fieldname ). This statement not available in older releases. Instead of CONV move ls_field_descr-fieldname to a variable expected by the function first, and pass it, that’s it.
Share this content: