二维码

[fmalv] 一个alv的刷新和双击交互实例

Twilight发表于 2014-08-12 20:03Twilight 最后回复于 2014-08-12 20:03 [复制链接] 4319 0


程序代码:
  1. *type pools for ALV declarations
  2. TYPE-POOLS: slis.
  3. *structure declaration for tstc table
  4. TYPES : BEGIN OF ty_tstc,
  5.           tcode TYPE tcode,
  6.           pgmna TYPE program_id,
  7.           dypno TYPE dynpronr,
  8.         END OF ty_tstc.
  9. * Internal table and workarea declarations for tstc
  10. DATA: it_tstc TYPE STANDARD TABLE OF ty_tstc,
  11.       wa_tstc TYPE ty_tstc.
  12. *data declarations for ALV
  13. DATA: it_layout TYPE slis_layout_alv,
  14.       wa_fieldcat TYPE slis_fieldcat_alv,
  15.       it_fieldcat TYPE slis_t_fieldcat_alv,
  16.       it_eventexit TYPE slis_t_event_exit,
  17.       wa_eventexit TYPE slis_event_exit.
  18. *initialisation event
  19. INITIALIZATION.
  20. *start of selection event
  21. START-OF-SELECTION.
  22. *subroutine to fetch data from the db table
  23.   PERFORM fetch_data.
  24. *subroutine for output display
  25.   PERFORM alv_output.
  26. *&---------------------------------------------------------------------*
  27. *&      Form  fetch_data
  28. *&---------------------------------------------------------------------*
  29. *       *subroutine to fetch data from the db table
  30. *----------------------------------------------------------------------*
  31. FORM fetch_data.
  32. *Internal table and work area declaratin for TSTC (local tables)
  33.   DATA : lt_tstc TYPE STANDARD TABLE OF ty_tstc,
  34.          ls_tstc TYPE ty_tstc.
  35. *Static field definition
  36. *Reads the last tcode and stores it in l_tstc that on refresh further data
  37. *beyond this value is fetched
  38.   STATICS l_tstc TYPE tcode.

  39. * Selection from the tstc table
  40. *we select till 25 rows and on further refresh next 25 are selected
  41. *we select transactions having screen numbers only
  42.   SELECT tcode
  43.          pgmna
  44.          dypno
  45.          FROM tstc
  46.          INTO CORRESPONDING FIELDS OF TABLE lt_tstc
  47.          UP TO 25 ROWS
  48.          WHERE tcode GT l_tstc
  49.          AND dypno NE '0000'.
  50. * Code for transferring the values of local table to output table
  51. * for 25 rows as sy-tfill is 25.
  52. *In case there are no records a message pops up.
  53.   IF sy-subrc EQ 0.
  54.     DESCRIBE TABLE it_tstc.
  55.     READ TABLE lt_tstc INTO ls_tstc INDEX sy-tfill."内部表格,当前行号
  56.     l_tstc = ls_tstc-tcode.
  57.     it_tstc[] = lt_tstc[].
  58.   ELSE.
  59.     MESSAGE 'No Records found ' TYPE 'i'.
  60.   ENDIF.
  61. ENDFORM.                    "read_data
  62. *&---------------------------------------------------------------------*
  63. *&      Form  alv_output
  64. *&---------------------------------------------------------------------*
  65. *       text
  66. *----------------------------------------------------------------------*
  67. FORM alv_output.
  68. *subroutine to refresh alv
  69.   PERFORM event_exits.
  70. *field catalogue
  71.   PERFORM build_fieldcat.
  72. *Layout for alv
  73.   PERFORM build_layout.
  74. *output display
  75.   PERFORM alv_display.
  76. ENDFORM.                    "alv_output
  77. *&---------------------------------------------------------------------*
  78. *&      Form  event_exits
  79. *&---------------------------------------------------------------------*
  80. *       text
  81. *----------------------------------------------------------------------*
  82. *subroutine to refresh alv
  83. FORM event_exits.
  84.   CLEAR wa_eventexit.
  85.   wa_eventexit-ucomm = '&REFRESH'.    " Refresh
  86.   wa_eventexit-after = 'X'.
  87.   APPEND wa_eventexit TO it_eventexit.
  88. ENDFORM.                     "event_exits
  89. *&---------------------------------------------------------------------*
  90. *&      Form  build_fieldcat
  91. *&---------------------------------------------------------------------*
  92. *       text
  93. *----------------------------------------------------------------------*
  94. *Field catalogue
  95. FORM build_fieldcat.
  96.   CLEAR wa_fieldcat.
  97.   wa_fieldcat-row_pos   = '1'.
  98.   wa_fieldcat-col_pos   = '1'.
  99.   wa_fieldcat-fieldname = 'TCODE'.
  100.   wa_fieldcat-tabname   = 'it_tstc'.
  101.   wa_fieldcat-seltext_m = 'TRANSACTION'.
  102.   APPEND wa_fieldcat TO it_fieldcat.
  103.   CLEAR wa_fieldcat.
  104.   wa_fieldcat-row_pos   = '1'.
  105.   wa_fieldcat-col_pos   = '2'.
  106.   wa_fieldcat-fieldname = 'PGMNA'.
  107.   wa_fieldcat-tabname   = 'it_tstc'.
  108.   wa_fieldcat-seltext_m = 'PROGRAM'.
  109.   APPEND wa_fieldcat TO it_fieldcat.
  110.   CLEAR wa_fieldcat.
  111.   wa_fieldcat-row_pos   = '1'.
  112.   wa_fieldcat-col_pos   = '3'.
  113.   wa_fieldcat-fieldname = 'DYPNO'.
  114.   wa_fieldcat-tabname   = 'it_tstc'.
  115.   wa_fieldcat-seltext_m = 'SCREEN'.
  116.   APPEND wa_fieldcat TO it_fieldcat.
  117. ENDFORM.                     "build_fieldcat
  118. *&---------------------------------------------------------------------*
  119. *&      Form  build_layout
  120. *&---------------------------------------------------------------------*
  121. *       text
  122. *----------------------------------------------------------------------*
  123. *Layout
  124. FORM build_layout.
  125.   it_layout-zebra = 'X'.
  126.   it_layout-colwidth_optimize = 'X'.
  127. ENDFORM.                     "build_layout
  128. *&---------------------------------------------------------------------*
  129. *&      Form  alv_display
  130. *&---------------------------------------------------------------------*
  131. *       text
  132. *----------------------------------------------------------------------*
  133. *ALV output
  134. FORM alv_display.
  135.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  136.     EXPORTING
  137.       i_callback_program       = sy-repid
  138.       i_callback_user_command  = 'USER_COMMAND'
  139.       i_callback_pf_status_set = 'PFSTATUS'
  140.       it_fieldcat              = it_fieldcat
  141.       is_layout                = it_layout
  142.       it_event_exit            = it_eventexit
  143.       i_screen_start_column    = 10
  144.       i_screen_start_line      = 20
  145.       i_screen_end_column      = 70
  146.       i_screen_end_line        = 45
  147.       i_grid_title             = 'Call Tcode Refresh ALV'
  148.     TABLES
  149.       t_outtab                 = it_tstc.
  150. ENDFORM.                    "alv_display
  151. *&---------------------------------------------------------------------*
  152. *&      Form  user_command
  153. *&---------------------------------------------------------------------*
  154. *       text
  155. *----------------------------------------------------------------------*
  156. *User actions on ALV
  157. FORM user_command USING r_ucomm TYPE sy-ucomm
  158.                         rs_selfield TYPE slis_selfield.
  159.   CASE r_ucomm.
  160. *User clicks a transaction code and that tcode is called from ALV
  161.     WHEN '&IC1'.
  162.       READ TABLE it_tstc INDEX rs_selfield-tabindex INTO wa_tstc.
  163.       IF sy-subrc = 0.
  164.         CALL TRANSACTION wa_tstc-tcode.
  165.       ENDIF.
  166. *user clicks the refresh button and the next 25 records are displayed
  167.     WHEN '&REFRESH'.
  168.       PERFORM fetch_data.
  169.       rs_selfield-refresh    = 'X'.
  170.       rs_selfield-col_stable = 'X' .
  171.       rs_selfield-row_stable = 'X' .
  172.   ENDCASE.
  173. ENDFORM.                    "user_command
  174. *---------------------------------------------------------------------*
  175. *       FORM PFSTATUS                                            *
  176. *---------------------------------------------------------------------*
  177. *Form for settings the pf status to the alv
  178. FORM pfstatus USING ut_extab TYPE slis_t_extab.
  179.   SET PF-STATUS 'STANDARD_FULLSCREEN' OF PROGRAM 'SAPLKKBL'.
  180. ENDFORM.                               " PF_STATUS_SET
复制代码

单击刷新按钮,会显示下一个25条记录,双击任何的transaction,会跳进t-code里
Call Tcode Refresh ALV.png
回复

使用道具 举报

快速回帖

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

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