ABAP – ComboBox on Selection-Screen

SAPIn this article I’ll show you how to create a combo box as one of selection-screen parameters
I personally like OO ABAP, therefore I’ll use a helper class which will implement a method returning pairs of key-value for our combo box.

CLASS lcl_helper DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
      get_combo_items RETURNING VALUE(rt_cbx_items) TYPE vrm_values.
ENDCLASS.

…and it’s implementation

CLASS lcl_helper IMPLEMENTATION.
  METHOD get_combo_items.
    FIELD-SYMBOLS:
      <ls_vrm> LIKE LINE OF rt_cbx_items.

    APPEND INITIAL LINE TO rt_cbx_items ASSIGNING <ls_vrm>.
    <ls_vrm>-key = 'A'.
    <ls_vrm>-text = 'First Option'.

    APPEND INITIAL LINE TO rt_cbx_items ASSIGNING <ls_vrm>.
    <ls_vrm>-key = 'B'.
    <ls_vrm>-text = 'Second Option'.

    APPEND INITIAL LINE TO rt_cbx_items ASSIGNING <ls_vrm>.
    <ls_vrm>-key = 'C'.
    <ls_vrm>-text = 'Third Option'.
  ENDMETHOD.
ENDCLASS.

Now let’s define the selection screen:

SELECTION-SCREEN BEGIN OF BLOCK b01.
  PARAMETERS:
    p_combo AS LISTBOX VISIBLE LENGTH 15 OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b01.

We have to fill the combo box with values – this will be done in the INITIALIZATION part of processing.

INITIALIZATION.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = 'P_COMBO'
      values          = lcl_helper=>get_combo_items( )
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.

* We pre-select the second option
  p_combo = 'B'.

After you execute the report you’ll see the following:
ComboBox on Selection-Screen

Leave a Reply