Thursday, October 24, 2013

SAP ABAP ALV GRID drop down list box step by step part 2

Hi folks,
 in part 1 of this post i showed how to create a Dropdown list box step by step in an ALV grid.
As i pointed out in my conclusions it seemed a bit complicated to me for such a little result.

Now i realized that it is more complicated than that.

Assume you want a search help with drop down list box for a simple field like the sex of a person
There is a standard domain GESCH (Meaning Geschlecht = Sex in german ) with fixed values 1 and 2 meaning Male Female.

Now in my alv the values 1 and 2 show up.

In order to have the texts shown i have to use table type "lvc_t_dral" instead of "lvc_t_drop"
This table contains a field int_value containing the code ( 1 and 2 in my case) and the field values containing the text "Male and Female".

This yields a column with sex values of 1 and 2 ( really ugly ) with the text values "Male and Female" popping up in the drop down list box with no connection to the codes 1 and 2

In order to have the automatic conversion of the values one more step is needed:
the creation of a conversion_exit
In my case i am lucky because one exists already: it is called GESCH ( functions
CONVERSION_EXIT_GESCH_OUTPUT and CONVERSION_EXIT_GESCH_INPUT)
The conversion exit must be entered into field "CONVEXIT" of the fieldcatalogue
like this:    ps_fcat-convexit = 'GESCH'.

Then it works just fine.
HTH
Enjoy! :-)


  METHOD: set_fasex_ddlb.

    DATA :ls_dropdown TYPE lvc_s_dral.

    DATA: ls_f4 TYPE lvc_s_f4.

    ps_fcat-drdn_hndl = '1'.
    ps_fcat-outputlen = 10.
    ps_fcat-f4availabl = 'X'.
    ps_fcat-convexit = 'GESCH'.

    ls_f4-fieldname  = ps_fcat-fieldname.
    ls_f4-register   = 'X'.
    ls_f4-getbefore  = 'X'.
    ls_f4-chngeafter = 'X'.
    APPEND ls_f4 TO pt_f4.

    ls_dropdown-handle = '1'.
    ls_dropdown-value = 'Female'.
    ls_dropdown-int_value = '2'.
    APPEND ls_dropdown TO pt_dral.

    ls_dropdown-handle = '1'.
    ls_dropdown-value = 'Male'.
    ls_dropdown-int_value = '1'.
    APPEND ls_dropdown TO pt_dral.
*
  ENDMETHOD.                    "set_fasex_ddlb