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 Listbox (dropdown) in ALV

former_member194669
Active Contributor
0 Likes
4,286

All,

I have an ALV using class CL_GUI_ALV_GRID (Editable) and have drop down in 2 different columns , using following but in display both the columns shows same drop down values as OR & AND.

Any Info?


  ls_fcat-fieldname = 'DROPDOWN_F4_1'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  append ls_fcat to pt_fieldcat.

  clear ls_fcat.

  ls_fcat-fieldname = 'DROPDOWN_F4_2'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  append ls_fcat to pt_fieldcat.


  ps_dropdown-handle = '1'.
  ps_dropdown-value = ' '.
  append ps_dropdown to pt_dropdown.

  ps_dropdown-handle = '1'.
  ps_dropdown-value = 'AND'.
  append ps_dropdown to pt_dropdown.

  ps_dropdown-handle = '1'.
  ps_dropdown-value = 'OR'.
  append ps_dropdown to pt_dropdown.

  call method g_grid->set_drop_down_table
    exporting
      it_drop_down = pt_dropdown.


  ps_dropdown-handle = '2'.
  ps_dropdown-value = ' '.
  append ps_dropdown to pt_dropdown.

  loop at i_ynetstat.
    ps_dropdown-handle = '2'.
    ps_dropdown-value = i_ynetstat-status.
    append ps_dropdown to pt_dropdown.
  endloop.

  call method g_grid->set_drop_down_table
    exporting
      it_drop_down = pt_dropdown.

a®

1 ACCEPTED SOLUTION
Read only

Former Member
2,459

Hi,

I tried your fieldcatalog and it is working correctly...The only thing I changed is the data type from INT4 to CHAR.

Try changing to CHAR data type.

DATA: ok_code     TYPE sy-ucomm,
      g_container TYPE scrfname VALUE 'CONTAINER1',
      g_grid      TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout          TYPE lvc_s_layo.

DATA: pt_dropdown TYPE lvc_t_drop,
      ps_dropdown TYPE lvc_s_drop,
      ls_fcat     TYPE lvc_s_fcat,
      pt_fieldcat TYPE lvc_t_fcat.

TYPES: BEGIN OF type_output,
         dropdown_f4_1 TYPE char10,
         dropdown_f4_2 TYPE char10,
       END OF type_output.

DATA: gt_outtab TYPE TABLE OF type_output.

START-OF-SELECTION.

  APPEND INITIAL LINE TO gt_outtab.

* Call the screen.
  CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.

  SET PF-STATUS 'TEST'.
  SET TITLEBAR 'MAIN100'.

* Create the grid.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT g_grid
      EXPORTING
        i_parent = g_custom_container.

* field catalog.
    ls_fcat-fieldname = 'DROPDOWN_F4_1'.
    ls_fcat-drdn_hndl = '1'.
    ls_fcat-datatype  = 'CHAR'.  " Changed
    ls_fcat-checktable = '!'.
    APPEND ls_fcat TO pt_fieldcat.

    CLEAR ls_fcat.

    ls_fcat-fieldname = 'DROPDOWN_F4_2'.
    ls_fcat-drdn_hndl = '2'.
    ls_fcat-datatype  = 'CHAR'.    " Changed
    ls_fcat-checktable = '!'.
    APPEND ls_fcat TO pt_fieldcat.

* Drop down box values 1
    ps_dropdown-handle = '1'.
    ps_dropdown-value = ' '.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '1'.
    ps_dropdown-value = 'AND'.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '1'.
    ps_dropdown-value = 'OR'.
    APPEND ps_dropdown TO pt_dropdown.

    CALL METHOD g_grid->set_drop_down_table
      EXPORTING
        it_drop_down = pt_dropdown.

* Drop down box values 2
    ps_dropdown-handle = '2'.
    ps_dropdown-value = ' '.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '2'.
    ps_dropdown-value = 'X'.
    APPEND ps_dropdown TO pt_dropdown.

    CALL METHOD g_grid->set_drop_down_table
      EXPORTING
        it_drop_down = pt_dropdown.


* Display the ALV.
    gs_layout-edit = 'X'.
    CALL METHOD g_grid->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layout
      CHANGING
        it_fieldcatalog = pt_fieldcat
        it_outtab       = gt_outtab.

  ENDIF.
ENDMODULE.                    "pbo OUTPUT

Thanks

Naren

13 REPLIES 13
Read only

naimesh_patel
Active Contributor
0 Likes
2,459

Have you clear the table PT_DROPDOWN after the first set of values?

Regards,

Naimesh Patel

Read only

0 Likes
2,459

Naimesh/phani

I have cleared values , and also refresh the table. No use still it showing drop down values as OR & AND in both dropdown fields.

PS Second dropdown values are coming from custom table.

a®

Read only

0 Likes
2,459

Check if both field refers to different (or same) drop down handle in your fieldcatalog? For first field it should be 1, and for second field it should be 2.


  ls_fcat-fieldname = 'DROPDOWN_F4_1'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  ls_fcat-drdn_hndl = '1'.
  append ls_fcat to pt_fieldcat.
 
  clear ls_fcat.
 
  ls_fcat-fieldname = 'DROPDOWN_F4_2'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  ls_fcat-drdn_hndl = '2'.
  append ls_fcat to pt_fieldcat.

Regards,

Naimesh Patel

Read only

0 Likes
2,459

Hi,

Did you populated a handle value for each row in the output table?


data: begin of it OCCURS 0.
      INCLUDE STRUCTURE sflight.
dATA dd_hndl TYPE int4 .
data end of it.

select * from sflight into CORRESPONDING FIELDS OF it up to 10 rows.
  if sy-tabix le 5.
    it-dd_hndl = '1'.    "show only values with handle = '1' .
  else.
    it-dd_hndl = '2'.   "same for handle = '2'.
  endif.

  append it.
endselect.

Regards

Marcin

Read only

0 Likes
2,459

I have checked the handle 1 refers to first field and 2 refers to second field


  ls_fcat-fieldname = 'DROPDOWN_F4_1'.
  ls_fcat-drdn_hndl = '1'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  append ls_fcat to pt_fieldcat.

  clear ls_fcat.

  ls_fcat-fieldname = 'DROPDOWN_F4_2'.
  ls_fcat-drdn_hndl = '2'.
  ls_fcat-datatype  = 'INT4'.
  ls_fcat-checktable = '!'.
  ls_fcat-no_out    = c_x.
  append ls_fcat to pt_fieldcat.

Still getting wring values

a®

Read only

0 Likes
2,459

> select * from sflight into CORRESPONDING FIELDS OF it up to 10 rows.

> if sy-tabix le 5.

> it-dd_hndl = '1'. "show only values with handle = '1' .

> else.

> it-dd_hndl = '2'. "same for handle = '2'.

> endif.

I didn't get your suggestion. In my ALV in a row 2 fields a have separate dropdowns , how will we fill value dd_hndl in output table.

a®

Read only

0 Likes
2,459

It is working good for me.

I copied the program BCALV_EDIT_06 to my Z program.

I have added another Drop-Down for the field INVOICE in the form SET_DRDN_TABLE


  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
  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'NN'.
  append ls_dropdown to lt_dropdown.

  ls_dropdown-handle = '2'.
  ls_dropdown-value = 'NP'.
  append ls_dropdown to lt_dropdown.

  call method g_grid->set_drop_down_table
            exporting it_drop_down = lt_dropdown.

I changed the Field catalog in the subroutine BUILD_FIELDCAT


  loop at pt_fieldcat into ls_fcat.
    if    ls_fcat-fieldname eq 'WUNIT'.
      ls_fcat-edit = 'X'.
      ls_fcat-drdn_hndl = '1'.
      ls_fcat-outputlen = 7.
      ls_fcat-checktable = '!'.        "do not check foreign keys
    endif.

    if ls_fcat-fieldname eq 'INVOICE'.
      ls_fcat-edit = 'X'.
      ls_fcat-drdn_hndl = '2'.
      ls_fcat-outputlen = 2.
      ls_fcat-checktable = '!'.        "do not check foreign keys
    endif.
      modify pt_fieldcat from ls_fcat.
  endloop.

And it is working good.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
2,459

clearing pt_dropdown may help you

Read only

MarcinPciak
Active Contributor
0 Likes
2,459

I thought you want it on cell basis. In this way you would have to fill drdn_hndl in fieldcatalog with 'DD_HNDL' and then when filling the data for output table, each row would store either values for handle 1 or 2.

But as you want it on column basis setting ls_fcat-drdn_hndl = '1' should suffice.

Regards

Marcin

Read only

Former Member
2,460

Hi,

I tried your fieldcatalog and it is working correctly...The only thing I changed is the data type from INT4 to CHAR.

Try changing to CHAR data type.

DATA: ok_code     TYPE sy-ucomm,
      g_container TYPE scrfname VALUE 'CONTAINER1',
      g_grid      TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout          TYPE lvc_s_layo.

DATA: pt_dropdown TYPE lvc_t_drop,
      ps_dropdown TYPE lvc_s_drop,
      ls_fcat     TYPE lvc_s_fcat,
      pt_fieldcat TYPE lvc_t_fcat.

TYPES: BEGIN OF type_output,
         dropdown_f4_1 TYPE char10,
         dropdown_f4_2 TYPE char10,
       END OF type_output.

DATA: gt_outtab TYPE TABLE OF type_output.

START-OF-SELECTION.

  APPEND INITIAL LINE TO gt_outtab.

* Call the screen.
  CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.

  SET PF-STATUS 'TEST'.
  SET TITLEBAR 'MAIN100'.

* Create the grid.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT g_grid
      EXPORTING
        i_parent = g_custom_container.

* field catalog.
    ls_fcat-fieldname = 'DROPDOWN_F4_1'.
    ls_fcat-drdn_hndl = '1'.
    ls_fcat-datatype  = 'CHAR'.  " Changed
    ls_fcat-checktable = '!'.
    APPEND ls_fcat TO pt_fieldcat.

    CLEAR ls_fcat.

    ls_fcat-fieldname = 'DROPDOWN_F4_2'.
    ls_fcat-drdn_hndl = '2'.
    ls_fcat-datatype  = 'CHAR'.    " Changed
    ls_fcat-checktable = '!'.
    APPEND ls_fcat TO pt_fieldcat.

* Drop down box values 1
    ps_dropdown-handle = '1'.
    ps_dropdown-value = ' '.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '1'.
    ps_dropdown-value = 'AND'.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '1'.
    ps_dropdown-value = 'OR'.
    APPEND ps_dropdown TO pt_dropdown.

    CALL METHOD g_grid->set_drop_down_table
      EXPORTING
        it_drop_down = pt_dropdown.

* Drop down box values 2
    ps_dropdown-handle = '2'.
    ps_dropdown-value = ' '.
    APPEND ps_dropdown TO pt_dropdown.

    ps_dropdown-handle = '2'.
    ps_dropdown-value = 'X'.
    APPEND ps_dropdown TO pt_dropdown.

    CALL METHOD g_grid->set_drop_down_table
      EXPORTING
        it_drop_down = pt_dropdown.


* Display the ALV.
    gs_layout-edit = 'X'.
    CALL METHOD g_grid->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layout
      CHANGING
        it_fieldcatalog = pt_fieldcat
        it_outtab       = gt_outtab.

  ENDIF.
ENDMODULE.                    "pbo OUTPUT

Thanks

Naren

Read only

0 Likes
2,459

Naren,

I changed to INT4 to CHAR , Now its working. (Strange !!!! But i could not find what will be reason) May be because of custom field values are INT4 that's why

Naimesh/Marcin

Thanks for your time replying.

a®

Read only

Former Member
0 Likes
2,459

Sorry..It works even with INT4 data type...

Thanks

Naren

Read only

Former Member
0 Likes
2,459

very good..:-)

Naren