Schesam
Schesam

Reputation: 764

Set Conversion Exit for dropdown values on INT4 field in SALV

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

Upvotes: 0

Views: 73

Answers (2)

Sandra Rossi
Sandra Rossi

Reputation: 13656

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( ).

Upvotes: -1

Schesam
Schesam

Reputation: 764

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

Upvotes: 1

Related Questions