Dropdown list in ALV

By Swarna S, Tata Consultancy Services

****************************************************************************
*Simple code for creating dropdown lists for columns in ALV grid output
*Author : Swarna.S.
* Published at SAPTechnical.COM
****************************************************************************
REPORT zalv_dropdowns.
*Type pools declarations for ALV
TYPE-POOLS : slis.
*data declarations for ALV container,ALV grid, Fieldcatalogues & layout
DATA: 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.
*INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table
DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0,
      wa_outtab TYPE t517a.
*initialisation event
INITIALIZATION.
*Start of selection event
START-OF-SELECTION.
*Call to ALV
  CALL SCREEN 600.
*On this statement double click  it takes you to the screen painter SE51.
*Create a Custom container and name it CCONT and OK code as OK_CODE.
*Save check and Activate the screen painter.
*Now a normal screen with number 600 is created which holds the ALV grid.
* PBO of the actual screen , Here we can give a title and customized menus
* Here we also call the subroutine for ALV output.
*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.
*  set pf-status 'xxx'.
*  set titlebar 'MAIN100'.
* Subroutine to display the output in alv
  PERFORM alv_output.
ENDMODULE.                    "pbo OUTPUT
* PAI module of the screen created. In case we use an interactive ALV or
*for additional functionalities we can create OK codes and
* based on the user command we can do the coding.
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
ENDMODULE.                    "pai INPUT
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
FORM build_fieldcat.
  DATA ls_fcat TYPE lvc_s_fcat.
*Build the field catalogue
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      i_structure_name = 'T517A'
    CHANGING
      ct_fieldcat      = gt_fieldcat.
* To assign dropdown in the fieldcataogue
  LOOP AT gt_fieldcat INTO ls_fcat.
    CASE ls_fcat-fieldname.
      WHEN 'SLART'.
*drdn-hndl = '1' is the first list box
        ls_fcat-drdn_hndl = '1'.
        ls_fcat-outputlen = 15.
        MODIFY gt_fieldcat FROM ls_fcat.
*drdn-hndl = '2' is the second list box
      WHEN 'ABART'.
        ls_fcat-drdn_hndl = '2'.
        ls_fcat-outputlen = 15.
        MODIFY gt_fieldcat FROM ls_fcat.
    ENDCASE.
  ENDLOOP.
ENDFORM.                    "build_fieldcat
*&---------------------------------------------------------------------*
*&      Form  ALV_OUTPUT
*&---------------------------------------------------------------------*
FORM alv_output .
*Create object for container
  CREATE OBJECT g_custom_container
         EXPORTING container_name = 'CCONT'.
*create object for grid
  CREATE OBJECT g_grid
         EXPORTING i_parent = g_custom_container.
* Build fieldcat and set column
*Assign a handle for the dropdown listbox.
  PERFORM build_fieldcat.
*Build layout
  PERFORM build_layout.
* Define a drop down table.
  PERFORM dropdown_table.
*fetch values from the T517A table
  SELECT * FROM t517a INTO TABLE gt_outtab.
*Display ALV output
  CALL METHOD g_grid->set_table_for_first_display
    EXPORTING
      is_layout       = gs_layout
    CHANGING
      it_fieldcatalog = gt_fieldcat
      it_outtab       = gt_outtab.
ENDFORM.                               "ALV_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  dropdown_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM dropdown_table.
*Declarations for drop down lists in ALV.
  DATA: lt_dropdown TYPE lvc_t_drop,
        ls_dropdown TYPE lvc_s_drop.
* First SLART listbox (handle '1').
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '01 Primary school'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '02 Lower Secondary'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '03 Upper Secondary'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '04 Professional School'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '05 College'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '06 University'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '1'.
  ls_dropdown-value = '09 Other Establishment'.
  APPEND ls_dropdown TO lt_dropdown.
* Second ABART listbox (handle '2').
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '10 Primary School certificate'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '20 Lower secondary/Junior high'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '30 High school diploma(B-levels)'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '31 Vocational'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '32 Matriculation'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '40 Specialist vocational certificate'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '50 College degree Level1'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '51 College degree Level2'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '52 Masters degree'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '60 Univ Degree level1'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '61 Bachelors degree'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '62 Masters degree'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '63 Licenciate'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '64 Doctors Degree Ph.D'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '89 None'.
  APPEND ls_dropdown TO lt_dropdown.
  ls_dropdown-handle = '2'.
  ls_dropdown-value = '90 Unknown'.
  APPEND ls_dropdown TO lt_dropdown.
*method to display the dropdown in ALV
  CALL METHOD g_grid->set_drop_down_table
    EXPORTING
      it_drop_down = lt_dropdown.
ENDFORM.                               " dropdown_table
*&---------------------------------------------------------------------*
*&      Form  build_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*layout for ALV output
FORM build_layout .
  gs_layout-cwidth_opt = 'X'.
  gs_layout-grid_title = 'ALV DROPDOWN LISTS'.
  gs_layout-no_toolbar = 'X'.
ENDFORM.                    " build_layout

ALV Dropdown lists output<?XML:NAMESPACE PREFIX = O />

<?XML:NAMESPACE PREFIX = V /><shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"></path><lock v:ext="edit" aspectratio="t"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 292.5pt; HEIGHT: 203.25pt" type="#_x0000_t75"><imagedata src="file:///C:/DOCUME~1/PARVAT~1/LOCALS~1/Temp/msoclip1/01/clip_image001.png" o:title=""></imagedata></shape>

Drop down List 1 for field SLART (educational establishment)

Dropdown list in ALV

Drop down List 2 for field ABART(certificate)

Dropdown list in ALV<!-- google_ad_client = "pub-1086451200925480"; google_alternate_color = "0000FF"; google_ad_width = 336; google_ad_height = 280; google_ad_format = "336x280_as"; google_ad_type = "text"; //2007-04-05: 336 x 280 google_ad_channel = "5227776827"; google_color_border = "FFFFFF"; google_color_bg = "FFFFFF"; google_color_link = "000000"; google_color_text = "000000"; google_color_url = "008000"; //-->window.google_render_ad();

你可能感兴趣的:(xml,ext,F#,Google)