Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Multiple Drop Down boxes in ALV

Former Member
0 Likes
4,113

Hi all

I seem to have a problem in trying to create several drop down boxes. It's easy enough to create a drop down box for a cell in a column but if I want drop down boxes in multiple columns it doesn't seem to work.

I build the table with the following structure for example

TYPES: BEGIN OF s_elements,

tabname TYPE dd02l-tabname,

tabclass TYPE dd02l-tabclass,

as4user TYPE dd02l-as4user,

as4date TYPE dd02l-as4date,

as4time TYPE dd02l-as4time,

viewed(1) TYPE c,

drop_down_handle type int4.

TYPES: END OF s_elements.

I create and adust the field catalog

  • Here before displaying you can change the field catalog to

  • adjust your own column names.

*col_name col-nr 'your name' output length.

col_name 1 'Table name' 30.

col_name 2 'Table class' 12.

col_name 3 'Changed By' 12.

col_name 4 ' On' 12.

col_name 5 ' At' 8.

col_name 6 'Act' 3.

  • Make any other changes to the field catalog

  • for example colour cells or drop down box

  • set some colours

loop at it_fldcat into wa_it_fldcat.

if wa_it_fldcat-fieldname = 'TABNAME'.

wa_it_fldcat-emphasize = 'C210'.

modify it_fldcat from wa_it_fldcat. " index sy-tabix.

endif.

if wa_it_fldcat-fieldname = 'AS4USER'.

wa_it_fldcat-emphasize = 'C710'.

modify it_fldcat from wa_it_fldcat. " index sy-tabix.

endif.

  • set a drop down box as test

if wa_it_fldcat-fieldname = 'VIEWED'.

wa_it_fldcat-edit = 'X'.

wa_it_fldcat-drdn_field = 'DROP_DOWN_HANDLE'.

wa_it_fldcat-checktable = '!'.

modify it_fldcat from wa_it_fldcat. " index sy-tabix.

endif.

  • I don't need the actual handle value to be displyed in the grid so I define it as a Technical Field

if wa_it_fldcat-fieldname = 'DROP_DOWN_HANDLE'.

wa_it_fldcat-tech = 'X'.

modify it_fldcat from wa_it_fldcat.

endif.

clear wa_it_fldcat.

endloop.

  • Insert values for the drop down box

ls_dropdown-handle = '1'.

ls_dropdown-value = 'V'.

append ls_dropdown to lt_dropdown.

ls_dropdown-handle = '1'.

ls_dropdown-value = 'X'.

append ls_dropdown to lt_dropdown.

ls_dropdown-handle = '1'.

ls_dropdown-value = ' '.

append ls_dropdown to lt_dropdown.

  • now set the drop down table

call method z_object->set_drop_down_table

exporting

it_drop_down = lt_dropdown.

endform.

(the method set_drop_drop_down_table is the same as in cl_gui_alv_grid).

So the question is how to I relate a 2nd or 3rd drop down table to the display for different columns.

Thanks

Jimbo

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
2,598

Hello James

The solution is provided by sample report

BCALV_EDIT_06

. I copied this report and made the following changes:

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.

  DATA ls_fcat TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'SBOOK'
    CHANGING
      ct_fieldcat      = pt_fieldcat.

  LOOP AT pt_fieldcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'WUNIT'.  " first dropdown column
*§2.Set status of column WUNIT to editable and set a dropdown handle.
        ls_fcat-edit = 'X'.
        ls_fcat-drdn_hndl = '1'.
        ls_fcat-outputlen = 7.
* Field 'checktable' is set to avoid shortdumps that are caused
* by inconsistend data in check tables. You may comment this out
* when the test data of the flight model is consistent in your system.
        ls_fcat-checktable = '!'.        "do not check foreign keys

      WHEN 'CLASS'.  " second dropdown column
        ls_fcat-edit = 'X'.
        ls_fcat-drdn_hndl = '2'.         " handle in fieldcatalog, not output itab !!!
        ls_fcat-outputlen = 20. 
        ls_fcat-checktable = '!'.        "do not check foreign keys

      WHEN OTHERS.
        CONTINUE.
    ENDCASE.

    MODIFY pt_fieldcat FROM ls_fcat.

  ENDLOOP.

ENDFORM.                    "build_fieldcat

*&---------------------------------------------------------------------*
*&      Form  set_drdn_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_drdn_table.
*§1.Define a dropdown table and pass it to ALV.
*   One listbox is referenced by a handle, e.g., '1'.
*   For each entry that shall appear in this listbox
*   you have to append a line to the dropdown table
*   with handle '1'.
*   This handle can be assigned to several columns
*   of the output table using the field catalog.
*
  DATA: lt_dropdown TYPE lvc_t_drop,
        ls_dropdown TYPE lvc_s_drop.

* First listbox (handle '1').
  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'KG'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'G'.
  APPEND ls_dropdown TO lt_dropdown.


* Second listbox (handle = '2' ).
  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'Economy'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'Business'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'First Class'.
  APPEND ls_dropdown TO lt_dropdown.



  CALL METHOD g_grid->set_drop_down_table
    EXPORTING
      it_drop_down = lt_dropdown.

ENDFORM.                               " set_drdn_table

Note

: The dropdown handle is defined at the level of the fieldcatalog and not as additional field within the output itab.

Regards,

Uwe

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
2,599

Hello James

The solution is provided by sample report

BCALV_EDIT_06

. I copied this report and made the following changes:

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      <--P_GT_FIELDCAT  text
*----------------------------------------------------------------------*
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.

  DATA ls_fcat TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'SBOOK'
    CHANGING
      ct_fieldcat      = pt_fieldcat.

  LOOP AT pt_fieldcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'WUNIT'.  " first dropdown column
*§2.Set status of column WUNIT to editable and set a dropdown handle.
        ls_fcat-edit = 'X'.
        ls_fcat-drdn_hndl = '1'.
        ls_fcat-outputlen = 7.
* Field 'checktable' is set to avoid shortdumps that are caused
* by inconsistend data in check tables. You may comment this out
* when the test data of the flight model is consistent in your system.
        ls_fcat-checktable = '!'.        "do not check foreign keys

      WHEN 'CLASS'.  " second dropdown column
        ls_fcat-edit = 'X'.
        ls_fcat-drdn_hndl = '2'.         " handle in fieldcatalog, not output itab !!!
        ls_fcat-outputlen = 20. 
        ls_fcat-checktable = '!'.        "do not check foreign keys

      WHEN OTHERS.
        CONTINUE.
    ENDCASE.

    MODIFY pt_fieldcat FROM ls_fcat.

  ENDLOOP.

ENDFORM.                    "build_fieldcat

*&---------------------------------------------------------------------*
*&      Form  set_drdn_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM set_drdn_table.
*§1.Define a dropdown table and pass it to ALV.
*   One listbox is referenced by a handle, e.g., '1'.
*   For each entry that shall appear in this listbox
*   you have to append a line to the dropdown table
*   with handle '1'.
*   This handle can be assigned to several columns
*   of the output table using the field catalog.
*
  DATA: lt_dropdown TYPE lvc_t_drop,
        ls_dropdown TYPE lvc_s_drop.

* First listbox (handle '1').
  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'KG'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '1'.
  ls_dropdown-value = 'G'.
  APPEND ls_dropdown TO lt_dropdown.


* Second listbox (handle = '2' ).
  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'Economy'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'Business'.
  APPEND ls_dropdown TO lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'First Class'.
  APPEND ls_dropdown TO lt_dropdown.



  CALL METHOD g_grid->set_drop_down_table
    EXPORTING
      it_drop_down = lt_dropdown.

ENDFORM.                               " set_drdn_table

Note

: The dropdown handle is defined at the level of the fieldcatalog and not as additional field within the output itab.

Regards,

Uwe

Read only

Former Member
0 Likes
2,598

Thanks Uwe -- solution was fine. Points awarded.

I was referred to that program before but someone on the system I'm currently working on deleted all the programs BCALV* higher than BCALV_EDIT_04 and I don't currently have my "minisap" system available.

Thanks

Jimbo