二维码

[fmalv] REUSE_ALV_HIERSEQ_LIST_DISPLAY进行简单分层序列列表显示

Twilight发表于 2014-08-13 16:27yny038 最后回复于 2015-04-15 14:46 [复制链接] 6293 1

REUSE_ALV_HIERSEQ_LIST_DISPLAY函数是输出alv用多个表得时候使用,header是一个表,item也是一个表,根据header去找相应 得item,然后输出,可以参照标准程序mb51去看看
  1. *&-----------------------------------------------------------------------------
  2. *& AS : ALV code for simple hierarchical sequential list display(single child)
  3. *& List of SAP tables and their characteristics are displayed as the header
  4. *& table ( the parent table) and the list of fields and their characteristics
  5. *& form the item table(child table)
  6. *&----------------------------------------------------------------------------
  7. REPORT  ydamon_039.
  8. * type-pools declarations for alv and icon
  9. TYPE-POOLS: slis,icon.
  10. *structure declaration for table details
  11. TYPES : BEGIN OF ty_dd02l,
  12.         icon TYPE icon_d,
  13.         tabname TYPE tabname,
  14.         tabclass TYPE tabclass,
  15.         contflag TYPE contflag,
  16.         actflag TYPE actflag,
  17.         mainflag TYPE maintflag,
  18.         buffered TYPE buffered,
  19.         as4user TYPE as4user,
  20.         as4date TYPE as4date,
  21.         as4time TYPE as4time,
  22.         expand,
  23.         END OF ty_dd02l.

  24. *internal table and wa decln for table details
  25. DATA : it_dd02l TYPE STANDARD TABLE OF ty_dd02l,
  26.        wa_dd02l TYPE ty_dd02l.

  27. *structure declarations for field details
  28. TYPES : BEGIN OF ty_dd03l,
  29.         tabname TYPE tabname,
  30.         fieldname TYPE fieldname,
  31.         keyflag TYPE keyflag,
  32.         mandatory TYPE mandatory,
  33.         checktable TYPE checktable,
  34.         rollname TYPE rollname,
  35.         END OF ty_dd03l.
  36. *Internal table and wa decln for field details
  37. DATA : it_dd03l TYPE STANDARD TABLE OF ty_dd03l,
  38.        wa_dd03l TYPE ty_dd03l.
  39. *data declarations for ALV
  40. DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
  41.        wa_fieldcat TYPE slis_fieldcat_alv,
  42.        it_layout TYPE slis_layout_alv,
  43.        key TYPE slis_keyinfo_alv.
  44. *Input the tables.User cannot enter a range but can enter any number
  45. *of tables one by one in this select-options
  46. SELECT-OPTIONS : s_table FOR wa_dd02l-tabname NO INTERVALS.
  47. *initializatin event
  48. INITIALIZATION.
  49. *start-of-selection event
  50. START-OF-SELECTION.
  51. *subroutine to fetch the data from the tables
  52.   PERFORM fetch_tabledata.
  53. *subroutine to build alv hierarchy output
  54.   PERFORM hierarchyalv_build.
  55. *&---------------------------------------------------------------------*
  56. *&      Form  hierarchyalv_build
  57. *&---------------------------------------------------------------------*
  58. *       text
  59. *----------------------------------------------------------------------*
  60. *  -->  p1        text
  61. *  <--  p2        text
  62. *----------------------------------------------------------------------*
  63. FORM hierarchyalv_build .
  64. *fieldcatalogue
  65.   PERFORM build_fieldcat.
  66. *layout
  67.   PERFORM build_layout.
  68. *key information for hierarchy
  69.   PERFORM build_key.
  70. *output
  71.   PERFORM list_display.
  72. ENDFORM.                    " hierarchyalv_build
  73. *&---------------------------------------------------------------------*
  74. *&      Form  build_fieldcat
  75. *&---------------------------------------------------------------------*
  76. *       text
  77. *----------------------------------------------------------------------*
  78. *  -->  p1        text
  79. *  <--  p2        text
  80. *----------------------------------------------------------------------*
  81. FORM build_fieldcat .
  82.   CLEAR wa_fieldcat.
  83.   wa_fieldcat-col_pos = 1.
  84.   wa_fieldcat-fieldname = 'TABNAME'.
  85.   wa_fieldcat-tabname = 'IT_DD02L'.
  86.   wa_fieldcat-seltext_m = 'Tablename'.
  87.   wa_fieldcat-key = 'X'.
  88.   wa_fieldcat-emphasize = 'C610'.
  89.   APPEND wa_fieldcat TO it_fieldcat.

  90.   CLEAR wa_fieldcat.
  91.   wa_fieldcat-col_pos = 2.
  92.   wa_fieldcat-fieldname = 'TABCLASS'.
  93.   wa_fieldcat-tabname = 'IT_DD02L'.
  94.   wa_fieldcat-seltext_m = 'Tablecategory'.
  95.   wa_fieldcat-emphasize = 'C600'.
  96.   APPEND wa_fieldcat TO it_fieldcat.
  97.   CLEAR wa_fieldcat.


  98.   CLEAR wa_fieldcat.
  99.   wa_fieldcat-col_pos = 3.
  100.   wa_fieldcat-fieldname = 'CONTFLAG'.
  101.   wa_fieldcat-tabname = 'IT_DD02L'.
  102.   wa_fieldcat-seltext_m = 'DeliveryClass'.
  103.   wa_fieldcat-emphasize = 'C510'.
  104.   APPEND wa_fieldcat TO it_fieldcat.
  105.   CLEAR wa_fieldcat.

  106.   CLEAR wa_fieldcat.
  107.   wa_fieldcat-col_pos = 4.
  108.   wa_fieldcat-fieldname = 'ACTFLAG'.
  109.   wa_fieldcat-tabname = 'IT_DD02L'.
  110.   wa_fieldcat-seltext_m = 'Activationstatus'.
  111.   wa_fieldcat-emphasize = 'C500'.
  112.   APPEND wa_fieldcat TO it_fieldcat.
  113.   CLEAR wa_fieldcat.
  114.   wa_fieldcat-col_pos = 5.
  115.   wa_fieldcat-fieldname = 'MAINFLAG'.
  116.   wa_fieldcat-tabname = 'IT_DD02L'.
  117.   wa_fieldcat-seltext_m = 'MaintainenceFlag'.
  118.   wa_fieldcat-emphasize = 'C410'.
  119.   APPEND wa_fieldcat TO it_fieldcat.

  120.   CLEAR wa_fieldcat.
  121.   wa_fieldcat-col_pos = 6.
  122.   wa_fieldcat-fieldname = 'BUFFERED'.
  123.   wa_fieldcat-tabname = 'IT_DD02L'.
  124.   wa_fieldcat-seltext_m = 'BufferFlag'.
  125.   wa_fieldcat-emphasize = 'C400'.
  126.   APPEND wa_fieldcat TO it_fieldcat.
  127.   CLEAR wa_fieldcat.

  128.   CLEAR wa_fieldcat.
  129.   wa_fieldcat-col_pos = 7.
  130.   wa_fieldcat-fieldname = 'AS4USER'.
  131.   wa_fieldcat-tabname = 'IT_DD02L'.
  132.   wa_fieldcat-seltext_m = 'User'.
  133.   wa_fieldcat-emphasize = 'C310'.
  134.   APPEND wa_fieldcat TO it_fieldcat.
  135.   CLEAR wa_fieldcat.
  136.   CLEAR wa_fieldcat.
  137.   wa_fieldcat-col_pos = 8.
  138.   wa_fieldcat-fieldname = 'AS4DATE'.
  139.   wa_fieldcat-tabname = 'IT_DD02L'.
  140.   wa_fieldcat-seltext_m = 'Date'.
  141.   wa_fieldcat-emphasize = 'C300'.
  142.   APPEND wa_fieldcat TO it_fieldcat.
  143.   CLEAR wa_fieldcat.

  144.   CLEAR wa_fieldcat.
  145.   wa_fieldcat-col_pos = 9.
  146.   wa_fieldcat-fieldname = 'AS4TIME'.
  147.   wa_fieldcat-tabname = 'IT_DD02L'.
  148.   wa_fieldcat-seltext_m = 'Time'.
  149.   wa_fieldcat-emphasize = 'C210'.
  150.   APPEND wa_fieldcat TO it_fieldcat.
  151.   CLEAR wa_fieldcat.

  152.   CLEAR wa_fieldcat.
  153.   wa_fieldcat-col_pos = 10.
  154.   wa_fieldcat-fieldname = 'ICON'.
  155.   wa_fieldcat-tabname = 'IT_DD02L'.
  156.   wa_fieldcat-seltext_m = 'ICON'.
  157.   wa_fieldcat-icon = 'X'.
  158.   APPEND wa_fieldcat TO it_fieldcat.

  159.   CLEAR wa_fieldcat.
  160.   wa_fieldcat-col_pos = 11.
  161.   wa_fieldcat-fieldname = 'FIELDNAME'.
  162.   wa_fieldcat-tabname = 'IT_DD03L'.
  163.   wa_fieldcat-key = 'X'.
  164.   wa_fieldcat-seltext_m = 'Field'.
  165.   wa_fieldcat-emphasize = 'C600'.
  166.   APPEND wa_fieldcat TO it_fieldcat.


  167.   CLEAR wa_fieldcat.
  168.   wa_fieldcat-col_pos = 12.
  169.   wa_fieldcat-fieldname = 'KEYFLAG'.
  170.   wa_fieldcat-tabname = 'IT_DD03L'.
  171.   wa_fieldcat-seltext_m = 'Key'.
  172.   wa_fieldcat-emphasize = 'C500'.
  173.   APPEND wa_fieldcat TO it_fieldcat.



  174.   CLEAR wa_fieldcat.
  175.   wa_fieldcat-col_pos = 13.
  176.   wa_fieldcat-fieldname = 'CHECKTABLE'.
  177.   wa_fieldcat-tabname = 'IT_DD03L'.
  178.   wa_fieldcat-seltext_m = 'Checktable'.
  179.   wa_fieldcat-emphasize = 'C400'.
  180.   APPEND wa_fieldcat TO it_fieldcat.


  181.   CLEAR wa_fieldcat.
  182.   wa_fieldcat-col_pos = 14.
  183.   wa_fieldcat-fieldname = 'MANDATORY'.
  184.   wa_fieldcat-tabname = 'IT_DD03L'.
  185.   wa_fieldcat-seltext_m = 'Mandatory'.
  186.   wa_fieldcat-emphasize = 'C300'.

  187.   APPEND wa_fieldcat TO it_fieldcat.

  188.   CLEAR wa_fieldcat.
  189.   wa_fieldcat-col_pos = 15.
  190.   wa_fieldcat-fieldname = 'ROLLNAME'.
  191.   wa_fieldcat-tabname = 'IT_DD03L'.
  192.   wa_fieldcat-seltext_m = 'Dataelement'.
  193.   wa_fieldcat-emphasize = 'C200'.
  194.   APPEND wa_fieldcat TO it_fieldcat.
  195. ENDFORM.                    " build_fieldcat
  196. *&---------------------------------------------------------------------*
  197. *&      Form  build_layout
  198. *&---------------------------------------------------------------------*
  199. *       text
  200. *----------------------------------------------------------------------*
  201. *  -->  p1        text
  202. *  <--  p2        text
  203. *----------------------------------------------------------------------*
  204. FORM build_layout .
  205. *to expand the header table for item details
  206.   it_layout-expand_fieldname = 'EXPAND'.
  207.   it_layout-window_titlebar = 'Hierarchical ALV list display'.
  208.   it_layout-lights_tabname = 'IT_DD03L'.
  209.   it_layout-colwidth_optimize = 'X'.


  210. ENDFORM.                    " build_layout
  211. *&---------------------------------------------------------------------*
  212. *&      Form  build_key
  213. *&---------------------------------------------------------------------*
  214. *       text
  215. *----------------------------------------------------------------------*
  216. *  -->  p1        text
  217. *  <--  p2        text
  218. *----------------------------------------------------------------------*
  219. FORM build_key .
  220. *key infomation for the header and item table
  221.   key-header01 = 'TABNAME'.
  222.   key-item01 = 'TABNAME'.
  223. ENDFORM.                    " build_key
  224. *&---------------------------------------------------------------------*
  225. *&      Form  list_display
  226. *&---------------------------------------------------------------------*
  227. *       text
  228. *----------------------------------------------------------------------*
  229. *  -->  p1        text
  230. *  <--  p2        text
  231. *----------------------------------------------------------------------*
  232. FORM list_display .
  233. *ALV output
  234.   CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
  235.     EXPORTING
  236.       i_callback_program = sy-cprog
  237.       is_layout          = it_layout
  238.       it_fieldcat        = it_fieldcat
  239.       i_tabname_header   = 'IT_DD02L'
  240.       i_tabname_item     = 'IT_DD03L'
  241.       is_keyinfo         = key
  242.     TABLES
  243.       t_outtab_header    = it_dd02l
  244.       t_outtab_item      = it_dd03l.
  245. ENDFORM.                    " list_display
  246. *&---------------------------------------------------------------------*
  247. *&      Form  fetch_tabledata
  248. *&---------------------------------------------------------------------*
  249. *       text
  250. *----------------------------------------------------------------------*
  251. *  -->  p1        text
  252. *  <--  p2        text
  253. *----------------------------------------------------------------------*
  254. FORM fetch_tabledata .
  255. *select table data
  256.   SELECT tabname
  257.           tabclass
  258.           contflag
  259.           actflag
  260.           mainflag
  261.           buffered
  262.           as4user
  263.           as4date
  264.           as4time
  265.           FROM dd02l
  266.           INTO CORRESPONDING FIELDS OF TABLE it_dd02l
  267.           WHERE tabname IN s_table.
  268. *select field data
  269.   IF it_dd02l[] IS NOT INITIAL.
  270.     SELECT tabname
  271.           fieldname
  272.           keyflag
  273.           mandatory
  274.           checktable
  275.           rollname
  276.           FROM dd03l
  277.           INTO CORRESPONDING FIELDS OF TABLE it_dd03l
  278.           FOR ALL ENTRIES IN it_dd02l
  279.           WHERE tabname EQ it_dd02l-tabname.
  280.   ENDIF.
  281. *adding icon to the header table
  282.   LOOP AT it_dd02l INTO wa_dd02l.
  283.     AT NEW tabname.
  284.       wa_dd02l-icon = '@3M@'.
  285.       MODIFY it_dd02l FROM wa_dd02l TRANSPORTING icon WHERE tabname EQ wa_dd02l-tabname.
  286.       CLEAR :  wa_dd02l.
  287.     ENDAT.
  288.   ENDLOOP.
  289. ENDFORM.                    " fetch_tabledata
复制代码


在选择屏幕填入表名,可多值
hierarchical sequential list 1.png
在相应表名前单击‘+’ ,我们就能获得这个表的全部字段的列表
hierarchical sequential list 2.png
回复

使用道具 举报

yny038
值得研究    谢谢楼主!!
回复 支持 反对

使用道具 举报

快速回帖

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

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