abapdynpro

Cannot select values via VRM_SET_VALUES?


I made Listbox on screen using function VRM_SET_VALUES. It works normal, but I can't choose field from the list.

SAP GUI dropdown listbox

Have I forgotten something?

DATA: BEGIN OF gs_screen1100,
        db_flight(40) TYPE c,
      END OF gs_screen1100.

MODULE init_listbox OUTPUT.
  DATA:
    ls_value  TYPE vrm_value,
    lt_values TYPE vrm_values.

  SELECT carrid, connid
    FROM sflight
    WHERE carrid = 'LH'
    INTO TABLE @DATA(lt_sflight).

  CLEAR lt_values.
  LOOP AT lt_sflight ASSIGNING FIELD-SYMBOL(<fs_sflight>).
    ls_value-key = <fs_sflight>-carrid.
    ls_value-text = <fs_sflight>-connid.
    APPEND ls_value TO lt_values.
  ENDLOOP.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id     = 'GS_SCREEN1100-DB_FLIGHT'
      values = lt_values.
ENDMODULE.

Solution

  • I got the answer on answer.sap.com. The error is due to how you fill the list of values, KEY should be unique.

    ls_value-key = <fs_sflight>-carrid is not a unique. It will store "LH" in the screen field and "LH" represents many entries, the first one is shown. The code below is one of the solutions.

    LOOP AT lt_sflight ASSIGNING FIELD-SYMBOL(<fs_sflight>).
        ls_value-key = <fs_sflight>-carrid && <fs_sflight>-connid.
        ls_value-text = <fs_sflight>-carrid && ` ` && <fs_sflight>-connid.
        APPEND ls_value TO lt_values.
      ENDLOOP.