abapalvsap-data-dictionary

ALV Grid cells are changed by 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.

Solution

  • 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)...

    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 ).