Cutter
Cutter

Reputation: 1820

ALV Grid columns are changed by F4 value help despite being not editable?

I have a DDIC structure containing fields BUKRS and SAKNR. A foreign key is defined for field SAKNR on check table SKB1, using keys MANDT, BUKRS, SAKNR.

enter image description here

A table of that structure is displayed in an ALV grid (CL_GUI_ALV_GRID). Field SAKNR is set to editable in the field catalog. BUKRS is not.

By using the search help on SAKNR and picking a value of SAKNR that exists only associated with a certain value of BUKRS, the value of BUKRS changes in the ALV.

I want field BUKRS to restrict the search, not change value.

How can I either:

I've tried setting all cells of other fields as "disabled" in the corresponding STYLE table, that did not work either. I would rather not create custom search helps to solve this, as this would require tremendous work given the number of standard fields that could cause this.

Sample code:

DATA: lt_fcat type lvc_t_fcat.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    i_structure_name       = 'ZTEST_SAKNR'
  CHANGING
    ct_fieldcat            = lt_fcat
  EXCEPTIONS
    inconsistent_interface = 1
    program_error          = 2
    others                 = 3.

lt_fcat[ fieldname = 'SAKNR' ]-edit = abap_true.

data(lo_alv) = new cl_gui_alv_grid(
  i_parent  = cl_gui_container=>default_screen ).

DATA: lt_test type table of ztest_saknr.

SELECT * FROM SKB1 INTO CORRESPONDING FIELDS OF TABLE @lt_test.

lo_alv->set_table_for_first_display(
  CHANGING
    it_outtab                     = lt_test
    it_fieldcatalog               = lt_fcat
  EXCEPTIONS
    invalid_parameter_combination = 1
    program_error                 = 2
    too_many_lines                = 3
    others                        = 4 ).

CALL SCREEN 1000.

Upvotes: 1

Views: 609

Answers (1)

Sandra Rossi
Sandra Rossi

Reputation: 13656

If you don't define a custom F4 (*) handling, you cannot prevent the change of non-editable fields defined in the output of the search help.

If you don't define a custom F4 handling, you cannot gray out the fields of the search help selection dialog which correspond to the non-editable fields.

So, the only solution left is to define a custom F4 handling for each concerned field (event onf4, see this example)...

  • A custom F4 handling means that you are fully responsible of displaying the value help, getting the selected value and changing the ALV table. To prevent the BUKRS value in the search help selection screen to be modified, call the function module f4if_get_shlp_descr to get the metadata information of the Search Help, call the function module f4if_start_value_request with the component interface of the parameter shlp changed this way: shlp-interface[ shlpfield = 'BUKRS' ]-dispfield = 'X'.
  • Note that in classic Dynpro programming, a display-only field passed to a Search Help leads automatically to pass disponly = 'X', but it's not handled at all by the ALV Grid control.

Of course, I cannot recommend to change the standard method F4 of class CL_GUI_ALV_GRID which handles the F4 key.

NB (*): F4 key = same as clicking the button to display the value help.

NB 2: my code for tests with less dependencies than the OP code (immediately testable in a SAP ERP or S/4HANA system):

REPORT.

PARAMETERS dummy.

DATA gt_test TYPE TABLE OF skb1.

AT SELECTION-SCREEN OUTPUT.

  DATA lt_fcat TYPE lvc_t_fcat.
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'SKB1'
    CHANGING
      ct_fieldcat      = lt_fcat
    EXCEPTIONS
      OTHERS           = 3.

  lt_fcat[ fieldname = 'ALTKT' ]-edit = abap_true.

  DATA(lo_alv) = NEW cl_gui_alv_grid(
    i_parent  = cl_gui_container=>default_screen ).

  SELECT SINGLE bukrs FROM skb1 WHERE altkt <> ' ' INTO @DATA(skb1_bukrs).
  gt_test = VALUE #( ( bukrs = skb1_bukrs ) ).

  lo_alv->set_table_for_first_display(
    CHANGING
      it_outtab       = gt_test
      it_fieldcatalog = lt_fcat
    EXCEPTIONS
      OTHERS          = 4 ).

Upvotes: 2

Related Questions