OO ALV网格中非DDIC类型字段F4搜索帮助失效通用解决方案问询
Hey there, I’ve run into exactly this problem when building generic ALV modules for non-DDIC tables—super frustrating when the standard F4 help bails out because of missing REF_FIELD entries. Here are three robust, generic solutions to fix this:
1. Explicitly Set Search Help Attributes in the Field Catalog
Instead of relying on DDIC references, directly populate the search help-related fields in your RTTI-generated field catalog for non-DDIC columns:
- For standard data types (like dates, currencies), map them to SAP’s built-in search helps. For example, assign
SEARCHHELP = 'H_DATE'andSHLPFIELD = 'DATUM'for date fields. - For custom logic, let users pass in search help names/parameters when calling your module, then inject those values into the field catalog.
Sample code snippet for RTTI field catalog processing:
LOOP AT lt_fcat INTO ls_fcat. IF ls_fcat-ref_field IS INITIAL. CASE ls_fcat-inttype. WHEN 'D'. " Date type ls_fcat-searchhelp = 'H_DATE'. ls_fcat-shlpfield = 'DATUM'. WHEN 'C'. " Custom char field with predefined values ls_fcat-searchhelp = 'Z_MY_CUSTOM_SH'. " Your custom search help ls_fcat-shlpfield = 'FIELD_NAME'. ENDCASE. ls_fcat-no_ddic_ref = 'X'. " Critical: tells ALV not to override your settings ENDIF. MODIFY lt_fcat FROM ls_fcat. ENDLOOP.
2. Use the ALV ONF4 Event for Custom F4 Logic
The standard ALV ONF4 event lets you intercept F4 help triggers and implement custom logic for specific fields. This is perfect for non-DDIC columns where you need dynamic or complex search help behavior:
- Register the event handler when instantiating your ALV grid:
SET HANDLER me->handle_f4_request FOR go_alv_grid. - Implement the handler method to call the appropriate F4 function module:
METHOD handle_f4_request. DATA: lv_fieldname TYPE fieldname, lt_return TYPE TABLE OF ddshretval. " Get the current field being edited CALL METHOD go_alv_grid->get_current_cell IMPORTING e_value = DATA(lv_current_value) e_fieldname = lv_fieldname. " Handle non-DDIC fields IF lv_fieldname = 'MY_NON_DDIC_FIELD'. " Populate your custom value table (e.g., from a database or internal table) DATA(lt_values) = VALUE #( ( sign = 'I' option = 'EQ' low = 'VAL1' ) ( sign = 'I' option = 'EQ' low = 'VAL2' ) ). " Call the F4 helper function CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING retfield = lv_fieldname dynpprog = sy-repid dynpnr = sy-dynnr dynprofield = lv_fieldname value_org = 'S' TABLES value_tab = lt_values return_tab = lt_return EXCEPTIONS parameter_error = 1 no_values_found = 2 OTHERS = 3. " Pass the selected value back to ALV IF sy-subrc = 0 AND lt_return IS NOT INITIAL. READ TABLE lt_return INTO DATA(ls_return) INDEX 1. CALL METHOD go_alv_grid->set_current_cell_value EXPORTING value = ls_return-fieldval. ENDIF. ENDIF. ENDMETHOD.
3. Lock Down Field Catalog with NO_DDIC_REF
As hinted earlier, setting NO_DDIC_REF = 'X' in your field catalog entries tells the standard ALV grid not to attempt fetching DDIC metadata for those fields. This prevents it from overwriting your manually set search help attributes when you call SET_TABLE_FOR_FIRST_DISPLAY.
This is a quick win that works alongside the other solutions—make sure you add this flag for all non-DDIC fields during your RTTI field catalog generation.
Bonus Tip for Generic Modules
To make your function module even more flexible, add an optional importing parameter (like IT_FIELD_SH_CONFIG) that lets users pass in search help configurations per field. This way, they can define custom F4 behavior without modifying your core module code.
内容的提问来源于stack exchange,提问作者Marcel

