二维码

[ooalv] 在ooalv中实现下拉列表或下拉框效果

Twilight发表于 2014-08-12 17:17Twilight 最后回复于 2014-08-12 17:17 [复制链接] 7440 0

如果在ALV中修改数据,用这种下来列表的形式来实现可以保证数据的完整性和一致性,很实用。

程序代码:
  1. *Type pools declarations for ALV
  2. TYPE-POOLS : slis.
  3. *data declarations for ALV container,ALV grid, Fieldcatalogues & layout
  4. DATA: g_grid  TYPE REF TO cl_gui_alv_grid,
  5.       g_custom_container TYPE REF TO cl_gui_custom_container,
  6.       gt_fieldcat TYPE lvc_t_fcat,
  7.       gs_layout TYPE lvc_s_layo.
  8. *INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table
  9. DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0,
  10.       wa_outtab TYPE t517a.
  11. *initialisation event
  12. INITIALIZATION.
  13. *Start of selection event
  14. START-OF-SELECTION.
  15. *Call to ALV
  16.   CALL SCREEN 600.
  17. *On this statement double click  it takes you to the screen painter SE51.
  18. *Create a Custom container and name it CCONT and OK code as OK_CODE.
  19. *Save check and Activate the screen painter.
  20. *Now a normal screen with number 600 is created which holds the ALV grid.
  21. * PBO of the actual screen , Here we can give a title and customized menus
  22. * Here we also call the subroutine for ALV output.
  23. *---------------------------------------------------------------------*
  24. *       MODULE PBO OUTPUT                                             *
  25. *---------------------------------------------------------------------*
  26. MODULE pbo OUTPUT.
  27. *  set pf-status 'xxx'.
  28. *  set titlebar 'MAIN100'.
  29. * Subroutine to display the output in alv
  30.   PERFORM alv_output.
  31. ENDMODULE.                    "pbo OUTPUT
  32. * PAI module of the screen created. In case we use an interactive ALV or
  33. *for additional functionalities we can create OK codes and
  34. * based on the user command we can do the coding.
  35. *---------------------------------------------------------------------*
  36. *       MODULE PAI INPUT                                              *
  37. *---------------------------------------------------------------------*
  38. MODULE pai INPUT.
  39. ENDMODULE.                    "pai INPUT
  40. *&---------------------------------------------------------------------*
  41. *&      Form  BUILD_FIELDCAT
  42. *&---------------------------------------------------------------------*
  43. FORM build_fieldcat.
  44.   DATA ls_fcat TYPE lvc_s_fcat.
  45. *Build the field catalogue
  46.   CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  47.     EXPORTING
  48.       i_structure_name = 'T517A'
  49.     CHANGING
  50.       ct_fieldcat      = gt_fieldcat.
  51. * To assign dropdown in the fieldcataogue
  52.   LOOP AT gt_fieldcat INTO ls_fcat.
  53.     CASE ls_fcat-fieldname.
  54.       WHEN 'SLART'.
  55. *drdn-hndl = '1' is the first list box
  56.         ls_fcat-drdn_hndl = '1'.
  57.         ls_fcat-outputlen = 15.
  58.         MODIFY gt_fieldcat FROM ls_fcat.
  59. *drdn-hndl = '2' is the second list box
  60.       WHEN 'ABART'.
  61.         ls_fcat-drdn_hndl = '2'.
  62.         ls_fcat-outputlen = 15.
  63.         MODIFY gt_fieldcat FROM ls_fcat.
  64.     ENDCASE.
  65.   ENDLOOP.
  66. ENDFORM.                    "build_fieldcat
  67. *&---------------------------------------------------------------------*
  68. *&      Form  ALV_OUTPUT
  69. *&---------------------------------------------------------------------*
  70. FORM alv_output .
  71. *Create object for container
  72.   CREATE OBJECT g_custom_container
  73.          EXPORTING container_name = 'CCONT'.
  74. *create object for grid
  75.   CREATE OBJECT g_grid
  76.          EXPORTING i_parent = g_custom_container.
  77. * Build fieldcat and set column
  78. *Assign a handle for the dropdown listbox.
  79.   PERFORM build_fieldcat.
  80. *Build layout
  81.   PERFORM build_layout.
  82. * Define a drop down table.
  83.   PERFORM dropdown_table.
  84. *fetch values from the T517A table
  85.   SELECT * FROM t517a INTO TABLE gt_outtab.
  86. *Display ALV output
  87.   CALL METHOD g_grid->set_table_for_first_display
  88.     EXPORTING
  89.       is_layout       = gs_layout
  90.     CHANGING
  91.       it_fieldcatalog = gt_fieldcat
  92.       it_outtab       = gt_outtab.
  93. ENDFORM.                               "ALV_OUTPUT
  94. *&---------------------------------------------------------------------*
  95. *&      Form  dropdown_table
  96. *&---------------------------------------------------------------------*
  97. *       text
  98. *----------------------------------------------------------------------*
  99. *  -->  p1        text
  100. *  <--  p2        text
  101. *----------------------------------------------------------------------*
  102. FORM dropdown_table.
  103. *Declarations for drop down lists in ALV.
  104.   DATA: lt_dropdown TYPE lvc_t_drop,
  105.         ls_dropdown TYPE lvc_s_drop.
  106. * First SLART listbox (handle '1').
  107.   ls_dropdown-handle = '1'.
  108.   ls_dropdown-value = '01 Primary school'.
  109.   APPEND ls_dropdown TO lt_dropdown.
  110.   ls_dropdown-handle = '1'.
  111.   ls_dropdown-value = '02 Lower Secondary'.
  112.   APPEND ls_dropdown TO lt_dropdown.
  113.   ls_dropdown-handle = '1'.
  114.   ls_dropdown-value = '03 Upper Secondary'.
  115.   APPEND ls_dropdown TO lt_dropdown.

  116.   ls_dropdown-handle = '1'.
  117.   ls_dropdown-value = '04 Professional School'.
  118.   APPEND ls_dropdown TO lt_dropdown.

  119.   ls_dropdown-handle = '1'.
  120.   ls_dropdown-value = '05 College'.
  121.   APPEND ls_dropdown TO lt_dropdown.

  122.   ls_dropdown-handle = '1'.
  123.   ls_dropdown-value = '06 University'.
  124.   APPEND ls_dropdown TO lt_dropdown.

  125.   ls_dropdown-handle = '1'.
  126.   ls_dropdown-value = '09 Other Establishment'.
  127.   APPEND ls_dropdown TO lt_dropdown.
  128. * Second ABART listbox (handle '2').
  129.   ls_dropdown-handle = '2'.
  130.   ls_dropdown-value = '10 Primary School certificate'.
  131.   APPEND ls_dropdown TO lt_dropdown.

  132.   ls_dropdown-handle = '2'.
  133.   ls_dropdown-value = '20 Lower secondary/Junior high'.
  134.   APPEND ls_dropdown TO lt_dropdown.
  135.   ls_dropdown-handle = '2'.
  136.   ls_dropdown-value = '30 High school diploma(B-levels)'.
  137.   APPEND ls_dropdown TO lt_dropdown.

  138.   ls_dropdown-handle = '2'.
  139.   ls_dropdown-value = '31 Vocational'.
  140.   APPEND ls_dropdown TO lt_dropdown.
  141.   ls_dropdown-handle = '2'.
  142.   ls_dropdown-value = '32 Matriculation'.
  143.   APPEND ls_dropdown TO lt_dropdown.
  144.   ls_dropdown-handle = '2'.
  145.   ls_dropdown-value = '40 Specialist vocational certificate'.
  146.   APPEND ls_dropdown TO lt_dropdown.
  147.   ls_dropdown-handle = '2'.
  148.   ls_dropdown-value = '50 College degree Level1'.
  149.   APPEND ls_dropdown TO lt_dropdown.
  150.   ls_dropdown-handle = '2'.
  151.   ls_dropdown-value = '51 College degree Level2'.
  152.   APPEND ls_dropdown TO lt_dropdown.
  153.   ls_dropdown-handle = '2'.
  154.   ls_dropdown-value = '52 Masters degree'.
  155.   APPEND ls_dropdown TO lt_dropdown.
  156.   ls_dropdown-handle = '2'.
  157.   ls_dropdown-value = '60 Univ Degree level1'.
  158.   APPEND ls_dropdown TO lt_dropdown.
  159.   ls_dropdown-handle = '2'.
  160.   ls_dropdown-value = '61 Bachelors degree'.
  161.   APPEND ls_dropdown TO lt_dropdown.
  162.   ls_dropdown-handle = '2'.
  163.   ls_dropdown-value = '62 Masters degree'.
  164.   APPEND ls_dropdown TO lt_dropdown.
  165.   ls_dropdown-handle = '2'.
  166.   ls_dropdown-value = '63 Licenciate'.
  167.   APPEND ls_dropdown TO lt_dropdown.
  168.   ls_dropdown-handle = '2'.
  169.   ls_dropdown-value = '64 Doctors Degree Ph.D'.
  170.   APPEND ls_dropdown TO lt_dropdown.
  171.   ls_dropdown-handle = '2'.
  172.   ls_dropdown-value = '89 None'.
  173.   APPEND ls_dropdown TO lt_dropdown.
  174.   ls_dropdown-handle = '2'.
  175.   ls_dropdown-value = '90 Unknown'.
  176.   APPEND ls_dropdown TO lt_dropdown.
  177. *method to display the dropdown in ALV
  178.   CALL METHOD g_grid->set_drop_down_table
  179.     EXPORTING
  180.       it_drop_down = lt_dropdown.
  181. ENDFORM.                               " dropdown_table
  182. *&---------------------------------------------------------------------*
  183. *&      Form  build_layout
  184. *&---------------------------------------------------------------------*
  185. *       text
  186. *----------------------------------------------------------------------*
  187. *layout for ALV output
  188. FORM build_layout .
  189.   gs_layout-cwidth_opt = 'X'.
  190.   gs_layout-grid_title = 'ALV DROPDOWN LISTS'.
  191.   gs_layout-no_toolbar = 'X'.
  192. ENDFORM.                    " build_layout
复制代码


执行效果:
Dropdown list in ALV.png
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表