二维码

[ooalv] 使用oops方式在alv里实现双击交互功能

Twilight发表于 2014-08-20 11:52Twilight 最后回复于 2014-08-20 11:52 [复制链接] 4619 0

程序代码:
  1. *Class definition for handling double click
  2. CLASS event_class DEFINITION DEFERRED.
  3. *Internal table and work area declarations for dd02l and dd03l
  4. DATA : it_dd02l TYPE TABLE OF dd02l,
  5.        wa_dd02l TYPE dd02l,
  6.        it_dd03l TYPE TABLE OF dd03l,
  7.        wa_dd03l TYPE dd03l.
  8. *data declarations for ALV Main list
  9. DATA : ty_lay1 TYPE lvc_s_layo,
  10.        it_fieldcat TYPE lvc_t_fcat ,
  11.        ty_fieldcat TYPE lvc_s_fcat ,
  12.        c_alv1 TYPE REF TO cl_gui_alv_grid,
  13.        c_cont1 TYPE REF TO cl_gui_custom_container,
  14.        event_receiver TYPE REF TO event_class.
  15. *data declarations for ALV Interactive list
  16. DATA : ty_lay2 TYPE lvc_s_layo,
  17.        it_fcat TYPE lvc_t_fcat ,
  18.        ty_fcat TYPE lvc_s_fcat ,
  19.        c_alv2 TYPE REF TO cl_gui_alv_grid,
  20.        c_cont2 TYPE REF TO cl_gui_custom_container.

  21. **Select options for multiple values and NOT ranges
  22. SELECT-OPTIONS : s_table FOR wa_dd02l-tabname NO INTERVALS.

  23. * Initialization event
  24. INITIALIZATION.
  25. *Start of selection event
  26. START-OF-SELECTION.
  27. *fetch data into table and field characteristics
  28.   PERFORM fetch_data.
  29. *ALV display for output
  30.   PERFORM alv_output.
  31. *&---------------------------------------------------------------------*
  32. *&      Form  FETCH_DATA
  33. *&---------------------------------------------------------------------*
  34. *       text
  35. *----------------------------------------------------------------------*
  36. *  -->  p1        text
  37. *  <--  p2        text
  38. *----------------------------------------------------------------------*
  39. FORM fetch_data .
  40. *Select the table details
  41.   SELECT * FROM dd02l
  42.   INTO CORRESPONDING FIELDS OF TABLE it_dd02l
  43.   WHERE tabname IN s_table
  44.     AND tabclass = 'TRANSP'.
  45. ENDFORM.                    " FETCH_DATA
  46. *----------------------------------------------------------------------*
  47. * CLASS lcl_event_receiver DEFINITION
  48. *----------------------------------------------------------------------*
  49. CLASS event_class DEFINITION.
  50. *Handling double click
  51.   PUBLIC SECTION.
  52.     METHODS:
  53.     handle_double_click
  54.     FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row .
  55. ENDCLASS. "lcl_event_receiver DEFINITION
  56. *----------------------------------------------------------------------*
  57. * CLASS lcl_event_receiver IMPLEMENTATION
  58. *----------------------------------------------------------------------*
  59. CLASS event_class IMPLEMENTATION.
  60.   METHOD handle_double_click.
  61.     DATA : ls_dd02l LIKE LINE OF it_dd02l.
  62. *Reading the selected data into a variable
  63.     READ TABLE it_dd02l INDEX e_row-index INTO ls_dd02l.
  64. *  *Select the field details of the selected table
  65.     SELECT * FROM dd03l INTO CORRESPONDING FIELDS OF TABLE it_dd03l
  66.     WHERE tabname EQ ls_dd02l-tabname.

  67. *calling the ALV containing the field values
  68.     CALL SCREEN 101.
  69.   ENDMETHOD. "handle_double_click
  70. ENDCLASS. "lcl_event_receiver IMPLEMENTATION
  71. *&---------------------------------------------------------------------*
  72. *& Module pbo_100 OUTPUT
  73. *&---------------------------------------------------------------------*
  74. MODULE pbo_100 OUTPUT.
  75. *set pf-status 'XXX'.
  76. *set titlebar 'XXX'.
  77. ENDMODULE. " PBO_100 OUTPUT

  78. *&---------------------------------------------------------------------*
  79. *& Module alv_100 OUTPUT
  80. *&---------------------------------------------------------------------*
  81. MODULE alv_100 OUTPUT.
  82. *Check if there is no custom container in screen 100
  83.   IF c_cont1 IS INITIAL.
  84. *Creating object of container
  85.     CREATE OBJECT c_cont1
  86.      EXPORTING
  87.        container_name = 'CCONT'.
  88.     IF sy-subrc <> 0.
  89. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  90. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  91.     ENDIF.
  92. *Creating object of alv
  93.     CREATE OBJECT c_alv1
  94.        EXPORTING
  95.         i_parent = c_cont1.
  96.     IF sy-subrc <> 0.
  97. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  98. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  99.     ENDIF.
  100. *alv layout
  101.     PERFORM alv_100_layout.
  102. *alv field catalogue
  103.     PERFORM alv_100_fieldcat.
  104. *Displaying the ALV grid
  105.     CALL METHOD c_alv1->set_table_for_first_display
  106.       EXPORTING
  107.         is_layout       = ty_lay1
  108.       CHANGING
  109.         it_outtab       = it_dd02l[]
  110.         it_fieldcatalog = it_fieldcat.
  111.     IF sy-subrc <> 0.
  112. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  113. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  114.     ENDIF.
  115. *Create object of the event class and setting handler for double click
  116.     CREATE OBJECT event_receiver.
  117.     SET HANDLER event_receiver->handle_double_click FOR c_alv1.
  118.   ENDIF.
  119. ENDMODULE. " ALV_100 OUTPUT
  120. *&---------------------------------------------------------------------*
  121. *& Module pai_100 INPUT
  122. *&---------------------------------------------------------------------*
  123. MODULE pai_100 INPUT.
  124. ENDMODULE. " pai_100 INPUT
  125. *----------------------------------------------------------------------*
  126. * MODULE PBO_101 OUTPUT
  127. *----------------------------------------------------------------------*
  128. MODULE pbo_101 OUTPUT.
  129. *  SET PF-STATUS 'XXX'.
  130. *  SET TITLEBAR 'XXX'.
  131. ENDMODULE. " PBO_101 INPUT
  132. *----------------------------------------------------------------------*
  133. * MODULE ALV_101 OUTPUT
  134. *----------------------------------------------------------------------*
  135. MODULE alv_101 OUTPUT.

  136. *Check if the Custom container exists.
  137.   IF c_cont2 IS INITIAL.
  138. *Creating container object
  139.     CREATE OBJECT c_cont2
  140.       EXPORTING
  141.         container_name = 'CDCONT'.
  142.     IF sy-subrc <> 0.
  143. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  144. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  145.     ENDIF.
  146. *creating ALV grid for interactive list
  147.     CREATE OBJECT c_alv2
  148.       EXPORTING
  149.        i_parent = c_cont2.
  150.     IF sy-subrc <> 0.
  151. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  152. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  153.     ENDIF.
  154. *ALV layout
  155.     PERFORM alv_101_layout.
  156. *ALV fieldcatalogue
  157.     PERFORM alv_101_fieldcat.
  158. *Sorting the output by field position
  159.     SORT it_dd03l BY position.
  160. *ALV for display field details
  161.     CALL METHOD c_alv2->set_table_for_first_display
  162.       EXPORTING
  163.         is_layout       = ty_lay2
  164.       CHANGING
  165.         it_outtab       = it_dd03l[]
  166.         it_fieldcatalog = it_fcat.
  167.     IF sy-subrc <> 0.
  168. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  169. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  170.     ENDIF.
  171.   ENDIF.
  172. ENDMODULE. " ALV_101 OUTPUT

  173. *&---------------------------------------------------------------------*
  174. *& Module PAI_101 INPUT
  175. *&---------------------------------------------------------------------*
  176. MODULE pai_101 INPUT.
  177. ENDMODULE. " PAI_101 INPUT
  178. *&---------------------------------------------------------------------*
  179. *&      Form  ALV_OUTPUT
  180. *&---------------------------------------------------------------------*
  181. *       text
  182. *----------------------------------------------------------------------*
  183. *  -->  p1        text
  184. *  <--  p2        text
  185. *----------------------------------------------------------------------*
  186. FORM alv_output .
  187.   CALL SCREEN 100.
  188. ENDFORM.                    " ALV_OUTPUT
  189. *&---------------------------------------------------------------------*
  190. *&      Form  ALV_100_LAYOUT
  191. *&---------------------------------------------------------------------*
  192. *       text
  193. *----------------------------------------------------------------------*
  194. *  -->  p1        text
  195. *  <--  p2        text
  196. *----------------------------------------------------------------------*
  197. FORM alv_100_layout .
  198.   ty_lay1-grid_title = 'TABLES'.
  199.   ty_lay1-zebra = 'X'.
  200.   ty_lay1-no_toolbar = 'X'.
  201. ENDFORM.                    " ALV_100_LAYOUT
  202. *&---------------------------------------------------------------------*
  203. *&      Form  ALV_100_FIELDCAT
  204. *&---------------------------------------------------------------------*
  205. *       text
  206. *----------------------------------------------------------------------*
  207. *  -->  p1        text
  208. *  <--  p2        text
  209. *----------------------------------------------------------------------*
  210. FORM alv_100_fieldcat .
  211.   CLEAR ty_fieldcat.
  212.   ty_fieldcat-row_pos = 1.
  213.   ty_fieldcat-col_pos = 1.
  214.   ty_fieldcat-fieldname = 'TABNAME'.
  215.   ty_fieldcat-tabname = 'GT_DD02L'.
  216.   ty_fieldcat-coltext = 'TableName'.
  217.   ty_fieldcat-outputlen = 10.
  218.   APPEND ty_fieldcat TO it_fieldcat.
  219.   CLEAR ty_fieldcat.
  220.   ty_fieldcat-row_pos = 1.
  221.   ty_fieldcat-col_pos = 2.
  222.   ty_fieldcat-fieldname = 'TABCLASS'.
  223.   ty_fieldcat-tabname = 'GT_DD02L'.
  224.   ty_fieldcat-coltext = 'CATEGORY'.
  225.   ty_fieldcat-outputlen = 10.
  226.   APPEND ty_fieldcat TO it_fieldcat.
  227.   CLEAR ty_fieldcat.
  228.   ty_fieldcat-row_pos = 1.
  229.   ty_fieldcat-col_pos = 3.
  230.   ty_fieldcat-fieldname = 'AS4USER'.
  231.   ty_fieldcat-tabname = 'GT_DD02L'.
  232.   ty_fieldcat-coltext = 'CREATED'.
  233.   ty_fieldcat-outputlen = 10.
  234.   APPEND ty_fieldcat TO it_fieldcat.
  235.   CLEAR ty_fieldcat.
  236.   ty_fieldcat-row_pos = 1.
  237.   ty_fieldcat-col_pos = 4.
  238.   ty_fieldcat-fieldname = 'AS4DATE'.
  239.   ty_fieldcat-tabname = 'GT_DD02L'.
  240.   ty_fieldcat-coltext = 'DATE'.
  241.   ty_fieldcat-outputlen = 10.
  242.   APPEND ty_fieldcat TO it_fieldcat.
  243.   CLEAR ty_fieldcat.

  244.   ty_fieldcat-row_pos = 1.
  245.   ty_fieldcat-col_pos = 5.
  246.   ty_fieldcat-fieldname = 'AS4TIME'.
  247.   ty_fieldcat-tabname = 'GT_DD02L'.
  248.   ty_fieldcat-coltext = 'TIME'.
  249.   ty_fieldcat-outputlen = 10.
  250.   APPEND ty_fieldcat TO it_fieldcat.
  251.   CLEAR ty_fieldcat.
  252.   ty_fieldcat-row_pos = 1.
  253.   ty_fieldcat-col_pos = 6.
  254.   ty_fieldcat-fieldname = 'CONTFLAG'.
  255.   ty_fieldcat-tabname = 'GT_DD02L'.
  256.   ty_fieldcat-coltext = 'Delivery Class'.
  257.   ty_fieldcat-outputlen = 15.
  258.   APPEND ty_fieldcat TO it_fieldcat.
  259.   CLEAR ty_fieldcat.
  260. ENDFORM.                    " ALV_100_FIELDCAT
  261. *&---------------------------------------------------------------------*
  262. *&      Form  ALV_101_LAYOUT
  263. *&---------------------------------------------------------------------*
  264. *       text
  265. *----------------------------------------------------------------------*
  266. *  -->  p1        text
  267. *  <--  p2        text
  268. *----------------------------------------------------------------------*
  269. FORM alv_101_layout .
  270.   ty_lay2-grid_title = 'FIELDS'.
  271.   ty_lay2-zebra = 'X'.
  272.   ty_lay2-no_toolbar = 'X'.
  273. ENDFORM.                    " ALV_101_LAYOUT
  274. *&---------------------------------------------------------------------*
  275. *&      Form  ALV_101_FIELDCAT
  276. *&---------------------------------------------------------------------*
  277. *       text
  278. *----------------------------------------------------------------------*
  279. *  -->  p1        text
  280. *  <--  p2        text
  281. *----------------------------------------------------------------------*
  282. FORM alv_101_fieldcat .
  283.   REFRESH it_fieldcat.
  284.   REFRESH it_fcat.
  285.   CLEAR ty_fcat.
  286.   ty_fcat-row_pos = 1.
  287.   ty_fcat-col_pos = 1.
  288.   ty_fcat-fieldname = 'FIELDNAME'.
  289.   ty_fcat-tabname = 'GT_DD03L'.
  290.   ty_fcat-coltext = 'Fieldname'.
  291.   ty_fcat-outputlen = 10.
  292.   APPEND ty_fcat TO it_fcat.

  293.   ty_fcat-row_pos = 1.
  294.   ty_fcat-col_pos = 2.
  295.   ty_fcat-fieldname = 'CHECKTABLE'.
  296.   ty_fcat-tabname = 'GT_DD03L'.
  297.   ty_fcat-coltext = 'CHECKTABLE'.
  298.   ty_fcat-outputlen = 10.
  299.   APPEND ty_fcat TO it_fcat.
  300.   ty_fcat-row_pos = 1.
  301.   ty_fcat-col_pos = 3.
  302.   ty_fcat-fieldname = 'KEYFLAG'.
  303.   ty_fcat-tabname = 'GT_DD03L'.
  304.   ty_fcat-coltext = 'Key Flag'.
  305.   ty_fcat-outputlen = 10.
  306.   APPEND ty_fcat TO it_fcat.
  307. ENDFORM.                    " ALV_101_FIELDCAT
复制代码

程序执行效果:
选择屏幕可输入多表
ooalv double click 1.png
双击任意一行
ooalv double click 2.png
回复

使用道具 举报

快速回帖

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

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