ABAP – Problems with combo box in ALV

SAPIn this article I’ll show you how to implement a “combo box” with key-value structure as one of ALV columns. It can be considered as an easy task but you would be facing an unexpected problem in ALV which will display KEYS instead of VALUES of the combo box. If you select a value from the list, it will be displayed correctly until you press enter (in case you have the Enter event handled) or you refresh the grid. After refresh keys will be displayed again instead of values.

Keys are displayed instead of values

I’m not sure if this is a bug or a “feature” in SAP,  but in my task I needed to have KEYS hidden in the combo control and display the VALUE (understandable text) to the user. This was necessary because I had to display “Short text” description of selected DDIC domain value.

Domain definition

One solution of this “issue” can be described in the following steps:

  1. The required ALV column is marked with dropdown handle ID in field catalog
    "There might be more than one handle defined,
    because you can have more than one combo columns in your ALV
    So we have to specify which one will this field use
    <ls_fcat>-drdn_hndl = 1.
  2. The required ALV column is marked with dopdown alias in field catalog
    <ls_fcat>-drdn_alias = abap_true.
  3. The required ALV column might be set as editable (in case you want it)
    <ls_fcat>-edit = abap_true.
  4. Prepare an itab structure holding dropdown key-value items
    METHOD get_combo_items.
      DATA:
        lt_dd07v TYPE TABLE OF dd07v.
    
      FIELD-SYMBOLS:
        <ls_dral> TYPE lvc_s_dral,
        <ls_dd07> TYPE dd07v.
    
    * Get values and their short texts for given domain 
      CALL FUNCTION 'DDIF_DOMA_GET'
        EXPORTING
          name      = 'ZDOM_TEST'
          langu     = sy-langu
        TABLES
          dd07v_tab = lt_dd07v.
    
      LOOP AT lt_dd07v ASSIGNING <ls_dd07>.
        APPEND INITIAL LINE TO rt_dral ASSIGNING <ls_dral>.
        <ls_dral>-handle    = 1.
        <ls_dral>-int_value = <ls_dd07>-domvalue_l.
        <ls_dral>-value     = <ls_dd07>-ddtext.
      ENDLOOP.
    ENDMETHOD.
  5. Attach the itab with items to the ALV grid
    me->mo_grid->set_drop_down_table(
      it_drop_down_alias = me->get_combo_items( )
    ).
  6. Create standard INPUT (VALUE -> KEY) conversion exit
    FUNCTION conversion_exit_zprio_input.
    *"---------------------------------------------------------
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(INPUT)
    *"  EXPORTING
    *"     VALUE(OUTPUT)
    *"---------------------------------------------------------
      DATA:
        lt_dd07v TYPE TABLE OF dd07v.
      FIELD-SYMBOLS:
        <ls_dd07> TYPE dd07v.
    
      CALL FUNCTION 'DDIF_DOMA_GET'
        EXPORTING
          name      = 'ZDOM_TEST'
          langu     = sy-langu
        TABLES
          dd07v_tab = lt_dd07v.
    
      READ TABLE lt_dd07v ASSIGNING <ls_dd07>
        WITH KEY ddtext = input.
      CHECK sy-subrc = 0.
    
      output = <ls_dd07>-domvalue_l.
    ENDFUNCTION.
  7. Create standard OUTPUT (KEY-> VALUE) conversion exit
    FUNCTION CONVERSION_EXIT_ZPRIO_OUTPUT.
    *"----------------------------------------------------------
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(INPUT)
    *"  EXPORTING
    *"     VALUE(OUTPUT)
    *"----------------------------------------------------------
      DATA:
        lt_dd07v TYPE TABLE OF dd07v.
      FIELD-SYMBOLS:
        <ls_dd07> TYPE dd07v.
    
      CALL FUNCTION 'DDIF_DOMA_GET'
        EXPORTING
          name      = 'ZDOM_TEST'
          langu     = sy-langu
        TABLES
          dd07v_tab = lt_dd07v.
    
      READ TABLE lt_dd07v ASSIGNING <ls_dd07>
        WITH KEY domvalue_l = input.
      CHECK sy-subrc = 0.
    
      output = <ls_dd07>-ddtext.
    ENDFUNCTION.
  8. Assign your conversion exit to the ALV field with dropdown in field catalog
    <ls_fcat>-convexit = 'ZPRIO'.

The result should now be like this:

ALV Dropdown with correct key-value assignment

You can donwload complete source code of Z_ALV_DROPDOWN right here.

2 thoughts on “ABAP – Problems with combo box in ALV

  1. Hi,

    I’ve tried your solution and it’s working fine, the problem is that if I put a button in my dynpro to save the data in DB after using method CHECK_CHANGED_DATA the values in the drop down lists are geting cleared…

    only if you has changed the initial value, or if you add a new line. The values in this list are clered.

    Do you know what can be the problem?

    Thanks

Leave a Reply to Erik GrantCancel reply