Application Development 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: 

In ALV list box

former_member188685
Active Contributor
0 Kudos

How to set the List box to the field in ALV Grid/List display.

4 REPLIES 4

Former Member
0 Kudos

Set layout's sel_mode.

See An Easy Reference for ALV Grid Control by S. Simsekler on this site.

Best!

Jim

0 Kudos

In the Out put i want for only a particular field drop down list, the user can choose the values from the list

suggest me some simple solution

0 Kudos

Please see program BCALV_EDIT_06. I think this is what you are looking for.

Regards,

Rich Heilman

0 Kudos

If you don't have a newer version, then you won't have this program. I copied it out of my 6.40 engine into my 46c system and modified it, so that you don't have to create a screen. Just copy/paste the code in SE38. It will show you what you need to do. If you don't have any flight data in your system run program SAPBC_TOOLS_GENERATOR_NEW



report zrich_0003 .

*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
* Purpose:
* ~~~~~~~~
* This example shows how to define a dropdown listbox for all cells
* of one column in an editable ALV Grid Control.
*-----------------------------------------------------------------
* To check program behavior
* ~~~~~~~~~~~~~~~~~~~~~~~~~
* Klick on the dropdown button of column 'WUNIT'. It shows
* 'KG' and 'G' as suitable units for luggage weight.
* (The standard F4-Help shows many other units that does not
* make sense in this context).
*-----------------------------------------------------------------
* Essential steps (search for '§')
* ~~~~~~~~~~~~~~~
* 1.Define a dropdown table and pass it to ALV.
* 2.Set status of column WUNIT to editable and set a dropdown handle.
*-----------------------------------------------------------------------
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

data: ok_code like sy-ucomm,
      save_ok like sy-ucomm,
      g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
      g_docking type ref to cl_gui_docking_container,
      g_grid  type ref to cl_gui_alv_grid,
      g_custom_container type ref to cl_gui_custom_container,
      gt_fieldcat type lvc_t_fcat,
      gs_layout type lvc_s_layo,
      g_max type i value 100.

data: gt_outtab type table of sbook.
data: repid type sy-repid.

parameters: p_check.


at selection-screen output.

  repid = sy-repid.

  create object g_docking
              exporting repid     = repid
                        dynnr     = sy-dynnr
                        side      = g_docking->dock_at_left
                        extension = 1700.


  if g_custom_container is initial.
    perform create_and_init_alv changing gt_outtab
                                         gt_fieldcat.
  endif.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
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.
    if    ls_fcat-fieldname eq 'WUNIT'.

*§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

      modify pt_fieldcat from ls_fcat.
    endif.
  endloop.

endform.
*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
form create_and_init_alv changing pt_outtab like gt_outtab[]
                                  pt_fieldcat type lvc_t_fcat.

  data: lt_exclude type ui_functions,
        lt_f4 type lvc_t_f4 with header line.

  create object g_grid
         exporting i_parent = g_docking.

* Build fieldcat and set column WUNIT
* edit enabled. Assign a handle for the dropdown listbox.
  perform build_fieldcat changing pt_fieldcat.

* Optionally restrict generic functions to 'change only'.
*   (The user shall not be able to add new lines).
  perform exclude_tb_functions changing lt_exclude.

* Define a drop down table.
  perform set_drdn_table.

  select * from sbook into table pt_outtab up to g_max rows.
                                                       "#EC  ci_nowhere
  if sy-subrc ne 0.
* generate own entries if database table is empty
    perform generate_entries changing pt_outtab.
  endif.

  call method g_grid->set_table_for_first_display
       exporting it_toolbar_excluding  = lt_exclude
       changing  it_fieldcatalog       = pt_fieldcat
                 it_outtab             = pt_outtab.

* Set editable cells to ready for input initially
  call method g_grid->set_ready_for_input
   exporting
    i_ready_for_input = 1.

  clear lt_f4.
  lt_f4-fieldname = 'WUNIT'.
  lt_f4-register = 'X'.
  append lt_f4.

endform.

*&---------------------------------------------------------------------*
*&      Form  EXCLUDE_TB_FUNCTIONS
*&---------------------------------------------------------------------*
form exclude_tb_functions changing pt_exclude type ui_functions.
* Only allow to change data not to create new entries (exclude
* generic functions).

  data ls_exclude type ui_func.

  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_move_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_copy.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_cut.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_paste_new_row.
  append ls_exclude to pt_exclude.
  ls_exclude = cl_gui_alv_grid=>mc_fc_loc_undo.
  append ls_exclude to pt_exclude.


endform.
*&---------------------------------------------------------------------*
*&      Form  set_drdn_table
*&---------------------------------------------------------------------*
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.

  call method g_grid->set_drop_down_table
            exporting it_drop_down = lt_dropdown.

endform.
*&---------------------------------------------------------------------*
*&      Form  generate_entries
*&---------------------------------------------------------------------*
form generate_entries changing pt_sbook type standard table.
*
* This form is only needed if database table sbook is empty.
* It generates some entries so that you may
* still try out this example program.
*
  data: ls_sbook type sbook,
        l_month(2) type c,
        l_day(2) type c,
        l_date(8) type c,
	l_prebookid type i.


  ls_sbook-carrid = 'LH'.
  ls_sbook-connid = '0400'.
  ls_sbook-forcurkey = 'DEM'.
  ls_sbook-loccurkey = 'USD'.
  ls_sbook-custtype = 'B'.

  do 110 times.
    l_prebookid = sy-index.

    ls_sbook-forcuram = sy-index * 10.
    ls_sbook-loccuram = ls_sbook-loccuram * 2.
    ls_sbook-customid = sy-index.
    ls_sbook-counter = 18.
    ls_sbook-agencynum = 11.

    l_month = sy-index / 10 + 1.
    do 2 times.
      l_day = 3 + l_month + sy-index * 2.
      l_date+0(4) = '2000'.
      l_date+4(2) = l_month.
      l_date+6(2) = l_day.
      ls_sbook-fldate = l_date.
      subtract 3 from l_day.
      ls_sbook-order_date+0(6) = l_date+0(6).
      ls_sbook-order_date+6(2) = l_day.
      ls_sbook-bookid = l_prebookid * 2 + sy-index.
      if sy-index eq 1.
        ls_sbook-smoker = 'X'.
      else.
        ls_sbook-smoker = space.
      endif.

      ls_sbook-luggweight = l_prebookid * 10.
      if ls_sbook-luggweight ge 1000.
        ls_sbook-wunit = 'G'.
        ls_sbook-class = 'C'.
      else.
        ls_sbook-wunit = 'KG'.
        ls_sbook-class = 'Y'.
      endif.

      if ls_sbook-bookid > 40 and ls_sbook-wunit eq 'KG'.
        ls_sbook-invoice = 'X'.
      endif.
      if ls_sbook-bookid eq 2.
        ls_sbook-cancelled = 'X'.
        ls_sbook-class = 'F'.
      endif.

      append ls_sbook to pt_sbook.
    enddo.
  enddo.
endform.

Please make sure to award points for helpful answers and mark your post as solved when you problem is solved. THanks.

Regards,

Rich Heilman