二维码

[fmalv] 在对话框中使用alv显示明细

Twilight发表于 2014-08-12 16:31Twilight 最后回复于 2014-08-12 16:31 [复制链接] 4365 0

使用FM:REUSE_ALV_POPUP_TO_SELECT来实现这种对话框的选中效果。有时需要用函数REUSE_ALV_POPUP_TO_SELECT来显示一些数据,例如调用BAPI创建单据时,可以把错误信息用此函数展示出来。
alv中的对话框可以过配置FM的如下参数控制
i_screen_start_column = 10
i_screen_start_line   = 20
i_screen_end_column   = 100
i_screen_end_line     = 40

程序代码:
  1. *Type pools for ALV declarations
  2. TYPE-POOLS : slis.
  3. *Internal table and wa declarations for T582A.
  4. DATA : it_t582a TYPE STANDARD TABLE OF t582a INITIAL SIZE 0,
  5.        wa_t582a TYPE t582a.
  6. *Internal table and wa declarations for T582S.
  7. DATA : it_text TYPE STANDARD TABLE OF t582s,
  8.        wa_text TYPE t582s.
  9. *Structure declaration for output
  10. TYPES : BEGIN OF ty_output,
  11.         infty TYPE infty,
  12.         zeitb TYPE dzeitb,
  13.         itext TYPE intxt,
  14.         pnnnn TYPE pnnnn_d,
  15.         dname TYPE dianm,
  16.         namst TYPE namst,
  17.         edynr TYPE edynp,
  18.         ldynr TYPE ldynp,
  19.         stypt TYPE stypt,
  20.         sytxt TYPE sytxt,
  21.         zbtab TYPE dzbtab,
  22.         checkbox(1),
  23.         END OF ty_output.
  24. *Internal table and work area declaration for output in pop up
  25. DATA : it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
  26.        wa_output TYPE ty_output.
  27. *Internal table and workarea declaration for alv Dialog display
  28. DATA : it_display TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
  29.        wa_display TYPE ty_output.
  30. *data declarations for ALV
  31. DATA:ls_fieldcat TYPE slis_fieldcat_alv,
  32.     lt_fieldcat TYPE slis_t_fieldcat_alv,
  33.     ls_fieldcatlog TYPE slis_fieldcat_alv,
  34.     lt_fieldcatlog TYPE slis_t_fieldcat_alv,
  35.     lt_layout TYPE slis_layout_alv.
  36. *Initialization event
  37. INITIALIZATION.
  38. *Start of selection event
  39. START-OF-SELECTION.
  40. *Select to fetch all the infotypes and details in sap system
  41.   SELECT *
  42.          FROM t582a
  43.          INTO CORRESPONDING FIELDS OF TABLE it_t582a.
  44. *Select to fetch the infotypes text
  45.   IF it_t582a[] IS NOT INITIAL.
  46.     SELECT * FROM t582s INTO CORRESPONDING FIELDS OF TABLE it_text
  47.     FOR ALL ENTRIES IN it_t582a WHERE infty = it_t582a-infty
  48.     AND sprsl = 'E'.
  49.   ENDIF.
  50. *Appending the selected values to the output table
  51.   LOOP AT it_t582a INTO wa_t582a.
  52.     wa_output-infty = wa_t582a-infty.
  53.     wa_output-zeitb = wa_t582a-zeitb.
  54.     wa_output-pnnnn = wa_t582a-pnnnn.
  55.     wa_output-dname = wa_t582a-dname.
  56.     wa_output-namst = wa_t582a-namst.
  57.     wa_output-edynr = wa_t582a-edynr.
  58.     wa_output-ldynr = wa_t582a-ldynr.
  59.     wa_output-stypt = wa_t582a-stypt.
  60.     wa_output-sytxt = wa_t582a-sytxt.
  61.     wa_output-zbtab = wa_t582a-zbtab.
  62.     READ TABLE it_text INTO wa_text WITH KEY infty = wa_t582a-infty.
  63.     wa_output-itext = wa_text-itext.
  64.     APPEND wa_output TO it_output.
  65.     CLEAR wa_output.
  66.   ENDLOOP.
  67. *Subroutine to display the pop up values.
  68.   PERFORM popup_display.
  69. *Subroutine to display the ALV dialog display
  70.   PERFORM alv_output.
  71. *----------------------------------------------------------------*
  72. *      Form  popup_display
  73. *------------------------------------------------------------*
  74. FORM popup_display.
  75. *field catalogue for pop up
  76.   CLEAR ls_fieldcat.
  77.   ls_fieldcat-row_pos   = '1'.
  78.   ls_fieldcat-col_pos   = '1'.
  79.   ls_fieldcat-fieldname = 'CHECKBOX'.
  80.   ls_fieldcat-tabname   = 'IT_OUTPUT'.
  81.   ls_fieldcat-seltext_m = 'SELECT'.
  82.   APPEND ls_fieldcat TO lt_fieldcat.
  83.   CLEAR ls_fieldcat.
  84.   ls_fieldcat-row_pos   = '1'.
  85.   ls_fieldcat-col_pos   = '2'.
  86.   ls_fieldcat-fieldname = 'INFTY'.
  87.   ls_fieldcat-tabname   = 'IT_OUTPUT'.
  88.   ls_fieldcat-seltext_m = 'information type'.
  89.   ls_fieldcat-outputlen = 10.
  90.   APPEND ls_fieldcat TO lt_fieldcat.
  91.   CLEAR ls_fieldcat.
  92.   ls_fieldcat-row_pos   = '1'.
  93.   ls_fieldcat-col_pos   = '3'.
  94.   ls_fieldcat-fieldname = 'ITEXT'.
  95.   ls_fieldcat-tabname   = 'IT_OUTPUT'.
  96.   ls_fieldcat-seltext_m = 'DESCRIPTION'.
  97.   ls_fieldcat-outputlen = 50.
  98.   APPEND ls_fieldcat TO lt_fieldcat.
  99. * Display data in a POPUP
  100.   CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
  101.     EXPORTING
  102.       i_zebra              = 'X'
  103.       it_fieldcat          = lt_fieldcat
  104.       i_tabname            = 'IT_OUTPUT'
  105.       i_checkbox_fieldname = 'CHECKBOX'
  106.     TABLES
  107.       t_outtab             = it_output.
  108. *Appending the selected infotypes only to internal table
  109.   LOOP AT it_output INTO wa_output WHERE checkbox = 'X'.
  110.     wa_display-itext = wa_output-itext.
  111.     wa_display-infty = wa_output-infty.
  112.     wa_display-zeitb = wa_output-zeitb.
  113.     wa_display-pnnnn = wa_output-pnnnn.
  114.     wa_display-dname = wa_output-dname.
  115.     wa_display-namst = wa_output-namst.
  116.     wa_display-edynr = wa_output-edynr.
  117.     wa_display-ldynr = wa_output-ldynr.
  118.     wa_display-sytxt = wa_output-sytxt.
  119.     wa_display-stypt = wa_output-stypt.
  120.     wa_display-zbtab = wa_output-zbtab.
  121.     APPEND wa_display TO it_display.
  122.     CLEAR wa_display.
  123.   ENDLOOP.
  124. ENDFORM.                               " popup_display
  125. *&-------------------------------------------------------------*
  126. *&      Form  alv_output
  127. *&-------------------------------------------------------------*
  128. FORM alv_output .
  129. *fieldcatalogue for ALV dialog
  130.   PERFORM build_fieldcat.
  131. *Layout for ALV dialog
  132.   PERFORM build_layout.
  133. **ALV dialog output
  134.   PERFORM alv.
  135. ENDFORM.                    " alv_output
  136. *&------------------------------------------------------------*
  137. *&      Form  build_fieldcat
  138. *&------------------------------------------------------------*
  139. FORM build_fieldcat .
  140. *fieldcatalogue for alv dialog
  141.   CLEAR ls_fieldcatlog.
  142.   ls_fieldcatlog-row_pos   = '1'.
  143.   ls_fieldcatlog-col_pos   = '1'.
  144.   ls_fieldcatlog-fieldname = 'INFTY'.
  145.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  146.   ls_fieldcatlog-seltext_m = 'Infotype'.
  147.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  148.   CLEAR ls_fieldcatlog.
  149.   ls_fieldcatlog-row_pos   = '1'.
  150.   ls_fieldcatlog-col_pos   = '2'.
  151.   ls_fieldcatlog-fieldname = 'ITEXT'.
  152.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  153.   ls_fieldcatlog-seltext_m = 'Description'.
  154.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  155.   CLEAR ls_fieldcatlog.
  156.   ls_fieldcatlog-row_pos   = '1'.
  157.   ls_fieldcatlog-col_pos   = '3'.
  158.   ls_fieldcatlog-fieldname = 'ZEITB'.
  159.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  160.   ls_fieldcatlog-seltext_m = 'TimeConstraint'.
  161.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  162.   CLEAR ls_fieldcatlog.
  163.   ls_fieldcatlog-row_pos   = '1'.
  164.   ls_fieldcatlog-col_pos   = '4'.
  165.   ls_fieldcatlog-fieldname = 'PNNNN'.
  166.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  167.   ls_fieldcatlog-seltext_m = 'Structure'.
  168.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  169.   CLEAR ls_fieldcatlog.
  170.   ls_fieldcatlog-row_pos   = '1'.
  171.   ls_fieldcatlog-col_pos   = '5'.
  172.   ls_fieldcatlog-fieldname = 'DNAME'.
  173.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  174.   ls_fieldcatlog-seltext_m = 'DialogModule'.
  175.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  176.   CLEAR ls_fieldcatlog.
  177.   ls_fieldcatlog-row_pos   = '1'.
  178.   ls_fieldcatlog-col_pos   = '6'.
  179.   ls_fieldcatlog-fieldname = 'NAMST'.
  180.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  181.   ls_fieldcatlog-seltext_m = 'Subtypefield'.
  182.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  183.   CLEAR ls_fieldcatlog.
  184.   ls_fieldcatlog-row_pos   = '1'.
  185.   ls_fieldcatlog-col_pos   = '7'.
  186.   ls_fieldcatlog-fieldname = 'EDYNR'.
  187.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  188.   ls_fieldcatlog-seltext_m = 'Singlescreenno'.
  189.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  190.   CLEAR ls_fieldcatlog.
  191.   ls_fieldcatlog-row_pos   = '1'.
  192.   ls_fieldcatlog-col_pos   = '8'.
  193.   ls_fieldcatlog-fieldname = 'LDYNR'.
  194.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  195.   ls_fieldcatlog-seltext_m = 'Listscreenno'.
  196.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  197.   CLEAR ls_fieldcatlog.
  198.   ls_fieldcatlog-row_pos   = '1'.
  199.   ls_fieldcatlog-col_pos   = '9'.
  200.   ls_fieldcatlog-fieldname = 'STYPT'.
  201.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  202.   ls_fieldcatlog-seltext_m = 'SubtypTable'.
  203.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  204.   CLEAR ls_fieldcatlog.
  205.   ls_fieldcatlog-row_pos   = '1'.
  206.   ls_fieldcatlog-col_pos   = '10'.
  207.   ls_fieldcatlog-fieldname = 'SYTXT'.
  208.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  209.   ls_fieldcatlog-seltext_m = 'Subtyptexttable'.
  210.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  211.   CLEAR ls_fieldcatlog.
  212.   ls_fieldcatlog-row_pos   = '1'.
  213.   ls_fieldcatlog-col_pos   = '11'.
  214.   ls_fieldcatlog-fieldname = 'ZBTAB'.
  215.   ls_fieldcatlog-tabname   = 'IT_DISPLAY'.
  216.   ls_fieldcatlog-seltext_m = 'SubtypeTCTable'.
  217.   APPEND ls_fieldcatlog TO lt_fieldcatlog.
  218. ENDFORM.                    " build_fieldcat
  219. *&----------------------------------------------------------*
  220. *&      Form  build_layout
  221. *&----------------------------------------------------------*
  222. *Layout for ALV dialog
  223. FORM build_layout .
  224.   lt_layout-zebra = 'X'.
  225.   lt_layout-colwidth_optimize = 'X'.
  226. ENDFORM.                    " build_layout
  227. *&---------------------------------------------------------------*
  228. *&      Form  alv
  229. *&---------------------------------------------------------------*
  230. *Alv dialog output.
  231. FORM alv .
  232.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  233.     EXPORTING
  234.       i_callback_program    = sy-repid
  235.       i_grid_title          = 'INFOTYPE DETAILS'
  236.       is_layout             = lt_layout
  237.       it_fieldcat           = lt_fieldcatlog
  238.       i_screen_start_column = 10
  239.       i_screen_start_line   = 20
  240.       i_screen_end_column   = 100
  241.       i_screen_end_line     = 40
  242.     TABLES
  243.       t_outtab              = it_display
  244.     EXCEPTIONS
  245.       program_error         = 1
  246.       OTHERS                = 2.
  247.   IF sy-subrc <> 0.
  248. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  249. *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  250.   ENDIF.
  251. ENDFORM.                    " alv
复制代码


在对话框中选择infotype
Pop up ALV 1.png
把alv作为dialog box用来显示 infotype details
Pop up ALV 2.png
回复

使用道具 举报

快速回帖

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

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