二维码

[Tree] Tree Control 对象与ALV Grid 对象关联

Twilight发表于 2014-01-22 18:22Twilight 最后回复于 2014-01-22 18:22 [复制链接] 3944 0

在双击 Tree 对象时,变更ALV Trid 对象的显示,实现界面如图所示。 Tree Control 对象与ALV Grid 对象关联1.jpg

Screen 设计界面如下图所示。
Tree Control 对象与ALV Grid 对象关联2.jpg


主程序:
  1. REPORT  ZDEMON_012.
  2. DATA: OK_CODE TYPE SY-UCOMM,
  3. SAVE_OK TYPE SY-UCOMM.
  4. DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'TREE1',
  5. WA_CONTAINERALV TYPE SCRFNAME VALUE 'ALV1',
  6. WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
  7. WA_CUSTOM_CONTAINERALV TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
  8. WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
  9. WA_ALV TYPE REF TO CL_GUI_ALV_GRID.
  10. DATA: NODE_TABLE LIKE TABLE OF MTREESNODE,
  11. NODE1 TYPE MTREESNODE.
  12. DATA WA_SPFLI TYPE TABLE OF SPFLI WITH HEADER LINE.
  13. DATA WA_SFLIGHT TYPE TABLE OF SFLIGHT.
  14. DATA: NODEKEY(200) VALUE 'NODE',
  15. NODETEXT(200) VALUE 'NODE'.
  16. CLASS LCL_APPLICATION DEFINITION DEFERRED.
  17. DATA EVENT_RECEIVER TYPE REF TO LCL_APPLICATION.
  18. *---------------------------------------------------------------------*
  19. * CLASS lcl_application DEFINITION
  20. *---------------------------------------------------------------------*
  21. *
  22. *---------------------------------------------------------------------*
  23. CLASS LCL_APPLICATION DEFINITION.
  24. PUBLIC SECTION.
  25. METHODS HANDLE_NODE_DOUBLE_CLICK
  26. FOR EVENT NODE_DOUBLE_CLICK
  27. OF CL_GUI_SIMPLE_TREE
  28. IMPORTING NODE_KEY.
  29. ENDCLASS. "lcl_application DEFINITION
  30. *---------------------------------------------------------------------*
  31. * CLASS lcl_application IMPLEMENTATION
  32. *---------------------------------------------------------------------*
  33. *
  34. *---------------------------------------------------------------------*
  35. CLASS LCL_APPLICATION IMPLEMENTATION.
  36. METHOD HANDLE_NODE_DOUBLE_CLICK.
  37. NODEKEY = NODE_KEY.
  38. READ TABLE NODE_TABLE WITH KEY NODE_KEY = NODE_KEY
  39. INTO NODE1.
  40. NODETEXT = NODE1-TEXT.
  41. CLEAR WA_SFLIGHT.
  42. SELECT * INTO TABLE WA_SFLIGHT FROM SFLIGHT
  43. WHERE CARRID = NODE1-NODE_KEY+2(2)
  44. AND CONNID = NODE1-NODE_KEY+4(4).
  45. * CREATE OBJECT WA_ALV
  46. * EXPORTING I_PARENT = WA_CUSTOM_CONTAINER.
  47. CALL METHOD WA_ALV->SET_TABLE_FOR_FIRST_DISPLAY
  48. EXPORTING
  49. I_STRUCTURE_NAME = 'SFLIGHT'
  50. CHANGING
  51. IT_OUTTAB = WA_SFLIGHT.
  52. ENDMETHOD. "handle_node_double_click
  53. ENDCLASS. "lcl_application IMPLEMENTATION
  54. DATA G_APPLICATION TYPE REF TO LCL_APPLICATION.
  55. START-OF-SELECTION.
  56. SELECT * INTO TABLE WA_SPFLI FROM SPFLI
  57. ORDER BY COUNTRYFR CARRID ASCENDING.
  58. CREATE OBJECT G_APPLICATION.
  59. SET SCREEN 100.
  60. *&---------------------------------------------------------------------*
  61. *& Module STATUS_0100 OUTPUT
  62. *&---------------------------------------------------------------------*
  63. * text
  64. *----------------------------------------------------------------------*
  65. MODULE STATUS_0100 OUTPUT.
  66. * SET PF-STATUS 'xxxxxxxx'.
  67. * SET TITLEBAR 'xxx'.
  68. IF WA_CUSTOM_CONTAINER IS INITIAL.
  69. PERFORM CREATE_TREE.
  70. ENDIF.
  71. ENDMODULE. " STATUS_0100 OUTPUT
  72. *&---------------------------------------------------------------------*
  73. *& Module USER_COMMAND_0100 INPUT
  74. *&---------------------------------------------------------------------*
  75. * text
  76. *----------------------------------------------------------------------*
  77. MODULE USER_COMMAND_0100 INPUT.
  78. SAVE_OK = OK_CODE.
  79. CLEAR OK_CODE.
  80. CASE SAVE_OK.
  81. WHEN 'EXIT'.
  82. LEAVE PROGRAM.
  83. ENDCASE.
  84. ENDMODULE. " USER_COMMAND_0100 INPUT
  85. *&---------------------------------------------------------------------*
  86. *& Form CREATE_TREE
  87. *&---------------------------------------------------------------------*
  88. * text
  89. *----------------------------------------------------------------------*
  90. * --> p1 text
  91. * <-- p2 text
  92. *----------------------------------------------------------------------*
  93. FORM CREATE_TREE .
  94. DATA: EVENTS TYPE CNTL_SIMPLE_EVENTS,
  95. EVENT1 TYPE CNTL_SIMPLE_EVENT.
  96. CREATE OBJECT WA_CUSTOM_CONTAINER
  97. EXPORTING
  98. CONTAINER_NAME = WA_CONTAINER.
  99. CREATE OBJECT WA_CUSTOM_CONTAINERALV
  100. EXPORTING
  101. CONTAINER_NAME = WA_CONTAINERALV.
  102. CREATE OBJECT WA_ALV
  103. EXPORTING
  104. I_PARENT = WA_CUSTOM_CONTAINERALV.
  105. CREATE OBJECT WA_TREE
  106. EXPORTING
  107. PARENT = WA_CUSTOM_CONTAINER
  108. NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE.
  109. IF SY-SUBRC <> 0.
  110. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  111. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  112. ENDIF.
  113. DATA: COUNTRYFR LIKE SPFLI-COUNTRYFR,
  114. CARRID LIKE SPFLI-CARRID.
  115. DATA: STR1(255).
  116. LOOP AT WA_SPFLI.
  117. IF COUNTRYFR NE WA_SPFLI-COUNTRYFR.
  118. CLEAR NODE1.
  119. NODE1-NODE_KEY = WA_SPFLI-COUNTRYFR.
  120. *第一层
  121. CLEAR NODE1-RELATKEY.
  122. CLEAR NODE1-RELATSHIP.
  123. *是文件夹
  124. NODE1-HIDDEN = ''.
  125. NODE1-DISABLED = ''.
  126. NODE1-ISFOLDER = 'X'.
  127. *不带ICON
  128. CLEAR NODE1-N_IMAGE.
  129. CLEAR NODE1-EXP_IMAGE.
  130. CLEAR NODE1-EXPANDER.
  131. NODE1-TEXT = WA_SPFLI-COUNTRYFR.
  132. APPEND NODE1 TO NODE_TABLE.
  133. ENDIF.
  134. IF ( COUNTRYFR NE WA_SPFLI-COUNTRYFR ) OR
  135. ( CARRID <> WA_SPFLI-CARRID ).
  136. CLEAR NODE1.
  137. CONCATENATE WA_SPFLI-COUNTRYFR WA_SPFLI-CARRID
  138. INTO NODE1-NODE_KEY.
  139. *上层关系
  140. NODE1-RELATKEY = WA_SPFLI-COUNTRYFR.
  141. NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
  142. NODE1-HIDDEN = ''.
  143. NODE1-DISABLED = ''.
  144. NODE1-ISFOLDER = 'X'.
  145. CLEAR NODE1-N_IMAGE.
  146. CLEAR NODE1-EXP_IMAGE.
  147. CLEAR NODE1-EXPANDER.
  148. *节点显示CARRID
  149. NODE1-TEXT = WA_SPFLI-CARRID.
  150. APPEND NODE1 TO NODE_TABLE.
  151. ENDIF.
  152. COUNTRYFR = WA_SPFLI-COUNTRYFR.
  153. CARRID = WA_SPFLI-CARRID.
  154. CLEAR NODE1.
  155. CONCATENATE WA_SPFLI-COUNTRYFR WA_SPFLI-CARRID
  156. WA_SPFLI-CONNID INTO NODE1-NODE_KEY.
  157. CONCATENATE WA_SPFLI-COUNTRYFR WA_SPFLI-CARRID
  158. INTO STR1.
  159. NODE1-RELATKEY = STR1.
  160. NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
  161. NODE1-HIDDEN = ''.
  162. NODE1-DISABLED = ''.
  163. NODE1-ISFOLDER = 'X'.
  164. NODE1-N_IMAGE = '@5B@'.
  165. NODE1-EXP_IMAGE = '@5B@'.
  166. CLEAR NODE1-EXPANDER.
  167. CONCATENATE WA_SPFLI-CARRID ':' WA_SPFLI-CITYFROM
  168. INTO STR1.
  169. NODE1-TEXT = STR1.
  170. APPEND NODE1 TO NODE_TABLE.
  171. ENDLOOP.
  172. CALL METHOD WA_TREE->ADD_NODES
  173. EXPORTING
  174. TABLE_STRUCTURE_NAME = 'MTREESNODE'
  175. NODE_TABLE = NODE_TABLE
  176. * EXCEPTIONS
  177. * ERROR_IN_NODE_TABLE = 1
  178. * FAILED = 2
  179. * DP_ERROF = 3
  180. * TABLE_STRUCTURE_NAME_NOT_FOUND = 4
  181. * OTHERS = 5
  182. .
  183. IF SY-SUBRC <> 0.
  184. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  185. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  186. ENDIF.
  187. *定义双击事件
  188. EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
  189. EVENT1-APPL_EVENT = 'X'.
  190. APPEND EVENT1 TO EVENTS.
  191. CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
  192. EXPORTING
  193. EVENTS = EVENTS
  194. * EXCEPTIONS
  195. * CNTL_ERROR = 1
  196. * CNTL_SYSTEM_ERROR = 2
  197. * ILLEGAL_EVENT_COMBINATION = 3
  198. * OTHERS = 4
  199. .
  200. IF SY-SUBRC <> 0.
  201. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  202. * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  203. ENDIF.
  204. *将已定义的双击事件分配至树对象
  205. SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR WA_TREE.
  206. ENDFORM. " CREATE_TREE
复制代码



回复

使用道具 举报

快速回帖

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

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