0

Currently I set the dropdowns of an INT4 id field as follows:

TYPES: BEGIN OF dropdown_column_ty,
         columnname_handle TYPE lvc_fname,
         columnname        TYPE lvc_fname,
         conv_exit         TYPE lvc_edtmsk,
       END OF dropdown_column_ty,
       dropdown_column_tt TYPE STANDARD TABLE OF ty_dropdown_column WITH EMPTY KEY.

DATA: i_dropdown_values  TYPE salv_t_value, " to be filled by external values
      i_dropdown_columns TYPE dropdown_column_tt,
      salv TYPE REF TO cl_salv_table.

< Stuff to initialize variables here >

LOOP AT i_dropdown_columns ASSIGNING FIELD-SYMBOL(<dropdown_columns>).
  salv->get_columns( )->set_dropdown_entry_column( <dropdown_columns>-columnname_handle ).
  FINAL(column) = CAST cl_salv_column_table( salv->get_columns( )->get_column( <dropdown_columns>-columnname ) ).
  column->set_cell_type( if_salv_c_cell_type=>dropdown ).
  column->set_dropdown_entry( 1 ).
  column->set_edit_mask( <dropdown_columns>-conv_exit ).
ENDLOOP.

salv->get_functional_settings( )->get_dropdowns( )->add_dropdown( handle   = 1
                                                                  t_values = i_dropdown_values ).

And I get the dropdown values like this:

 METHOD get_dropdown_values.
   DATA dd07 TYPE STANDARD TABLE OF dd07v WITH NON-UNIQUE DEFAULT KEY.
 
   CALL FUNCTION 'DDIF_DOMA_GET' EXPORTING  name          = 'DOMAIN_NAME'
                                            langu         = sy-langu
                                 TABLES     dd07v_tab     = dd07
                                 EXCEPTIONS illegal_input = 1
                                            OTHERS        = 2.
   LOOP AT dd07 ASSIGNING FIELD-SYMBOL(<dd07>).
     APPEND <dd07>-domvalue_l TO r_values.
   ENDLOOP.
 ENDMETHOD.

And that works for the Column itself like it should:

Column with dropdown values and used conversion exit

But the dropdown values still have their id in it:

enter image description here

Given it's an editable SALV on that column, the user must choose the id in the INT4 values, which enters the id in the field. If he presses the enter key afterwards, the conversion exit gets applied (which converts the id value to text, e.g. 0 into offen). Plus, he can look at the F4 for the corresponding number.

But is there any way, I can apply the Conversion exit to the dropdown values itself too? Because if I replace the values with the text instead of the id, it will show them, but they won't be editable anymore, because there would be text instead of numbers in it, which the SALV's automatic check wouldn't allow... The current solution is a bit ugly like this, but I can't find a way.

System: ABAP 7.58

2
  • What exact ABAP type is your numeric field please? Please create a Minimal, Reproducible Example so that the issue can be reproduced. Also, please indicate your ABAP version. Commented Feb 14 at 8:20
  • 1
    Its just plain Int4 on 7.58 Commented Feb 14 at 13:09

2 Answers 2

1

I just found the Solution by accident. I removed the explicit setting of the conversion exit:

cl_salv_column_table( r_salv-salv->get_columns( )->get_column( <dropdown_columns>-columnname ) )->set_edit_mask( <dropdown_columns>-conv_exit )

and instead, added it to the Domain itself. Then i changed the dropdown values from domvalue_l to ddtext to show the text. Now the automatic check accepts it and the texts are shown as wanted, but still uses the ID internally:

Dropdown with text values

Sign up to request clarification or add additional context in comments.

Comments

-1

A Conversion Exit is an ABAP-based object which converts a value from its database format into display format, called respectively internal and external formats. For instance, the FR internal country value could be displayed as France. A Conversion Exit is made of a 5-characters code usually assigned to a DDIC Domain (SE11) and referring to two function modules CONVERSION_EXIT_XXXXX_INPUT and CONVERSION_EXIT_XXXXX_OUTPUT where XXXXX is to be the 5-characters code.

With ALV, it's not needed to use a DDIC domain, you may display any custom dropdown values. With a conversion exit, these values must be provided as external format.

Note that the SALV framework doesn't allow fields to be editable, unless you tweak the framework. This tweak is not supported by SAP (at your own risk).

Below is a Minimal Reproducible Example to display a dropdown list for a field with a Conversion Exit. For instance, 2 is the external value and 002 is the corresponding internal value. Also, the field wasn't made editable as this wasn't the question. If you want to make a field editable with SALV, see for instance these answers.

SALV dropdown list for a field with a Conversion Exit

REPORT zdemo.
TYPES: BEGIN OF ty_dropdown_column,
         columnname_handle TYPE lvc_fname,
         columnname        TYPE lvc_fname,
         conv_exit         TYPE lvc_edtmsk,
       END OF ty_dropdown_column.
TYPES ty_dropdown_columns TYPE STANDARD TABLE OF ty_dropdown_column WITH EMPTY KEY.
TYPES ty_flights          TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.

PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  " Database tables store values in internal format ("internal values")
  DATA(flights) = VALUE ty_flights( ( carrid = '002' ) ).
  cl_salv_table=>factory( EXPORTING r_container  = cl_gui_container=>screen0
                          IMPORTING r_salv_table = DATA(salv)
                          CHANGING  t_table      = flights ).
  " ALV dropdown values must be in external format (value displayed).
  DATA(i_dropdown_values) = VALUE salv_t_value( ( '1' ) ( '2' ) ).
  DATA(carrier_id) = CAST cl_salv_column_table( salv->get_columns( )->get_column( 'CARRID' ) ).
  carrier_id->set_cell_type( if_salv_c_cell_type=>dropdown ).
  carrier_id->set_dropdown_entry( 1 ).
  " The ALPHA Conversion Exit converts between internal value 002 and external value 2.
  carrier_id->set_edit_mask( '==ALPHA' ).
  salv->get_functional_settings( )->get_dropdowns( )->add_dropdown( handle   = 1
                                                                    t_values = i_dropdown_values ).
  salv->display( ).

2 Comments

I mean.. thats exactly what i tried in the OP. I entered the Output-value (e.g. DDTEXT) as Dropdown-Values and entered the Conversion exit with the set_edit_mask. But that just results in the Error message "Entry is not numeric", at least in my case where the ID is numeric and the ouput is text. Maybe thats dependent on the release or cause i made the SALV editable (Maybe its a hack, but they added in recent releases a very convenient way to enable it... idk. The layout default to the old alv too if i set it editable..) My solution made it work
I even added a Break-Point in the INPUT Conv-Exit. It didnt get triggered at all with this attempt. Adding it to the domain did and the automatic check accepted it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.