二维码

在dialog中创建Step-loops程序

Twilight发表于 2015-01-04 16:59小懒 最后回复于 2015-04-23 10:44 [复制链接] 4525 1

Step-loops是abap中非常古老的技术,自从Table control大量使用后Step-loops就急剧减少了,但是在某种场合中除了使用step-loops而别无选择,例如Radio Frequency。

Step-loops有两种类型
  • 固定Step-loops
    显示的条数固定
  • 可变Step-loops
    根据屏幕的大小,增加step-loops的条数

1、新建标准screen 100,并定义ok_code
se51  格式布局屏幕样式
Step-loops 1.jpg
Column_1/Column_2
Step-loops 2.jpg
WA-COL1/WA-COL2
Step-loops 3.jpg
一起选中两列的input/output框,然后Edit -> Grouping -> Step Loop -> Define
Step-loops 4.jpg
调整step-loops显示的条数
Step-loops 5.jpg
RLMOB-PPGUP/RLMOB-PPGDN
程序流:
  1. PROCESS BEFORE OUTPUT.
  2.   MODULE status_0100.
  3.   MODULE pgup_down.
  4.   LOOP AT itab INTO wa CURSOR c FROM n1 TO n2.
  5.     MODULE transp_itab_out.
  6.   ENDLOOP.

  7. PROCESS AFTER INPUT.
  8.   MODULE cancel AT EXIT-COMMAND.
  9.   LOOP.
  10.     MODULE transp_itab_in.
  11.   ENDLOOP.
  12.   MODULE user_command_0100.
复制代码

2、新建程序se38
  1. * Number of records to be displayed
  2. PARAMETERS : p_num TYPE i.
  3. * Types to declare the internal table for records
  4. TYPES: BEGIN OF t_itab,
  5.          col1 TYPE i,
  6.          col2 TYPE i,
  7.        END OF t_itab.
  8. * Internal table for the records
  9. DATA: itab TYPE STANDARD TABLE OF t_itab,
  10. * Work area for the records
  11.       wa   LIKE LINE OF itab.
  12. DATA:
  13. * Index of the row of step-loop
  14.       idx   TYPE i,
  15. * Current Line to be displayed
  16.       line  TYPE i,
  17. * Total Rows of step-loop to be displayed on single page
  18.       lines TYPE i,
  19. * Final Limit of step loop rows that can be displayed
  20.       limit TYPE i,
  21. * Cursor position
  22.       c     TYPE i,
  23. * Lower limit of the record index to be displayed on a page
  24.       n1    TYPE i VALUE 1,
  25. * Upper limit of the record index to be displayed on a page
  26.       n2    TYPE i,
  27. * Variable to handle next page navigation
  28.       y_v_next           TYPE    i,
  29. * Variable to handle previous page navigation
  30.       y_v_prev           TYPE    i,
  31.       y_v_limit TYPE i.
  32. DATA:  ok_code TYPE sy-ucomm,
  33.        save_ok TYPE sy-ucomm.

  34. START-OF-SELECTION.
  35. * Building the records to be displayed as per the selection screen entry
  36.   DO p_num TIMES.
  37.     wa-col1 = sy-index.
  38.     wa-col2 = sy-index ** 2.
  39.     APPEND wa TO itab.
  40.   ENDDO.
  41.   IF p_num < 0.
  42.     n2 = p_num.
  43.   ELSE.
  44.     n2 = 5.
  45.   ENDIF.
  46.   CALL SCREEN 100.
  47. *----------------------------------------------------------------------*
  48. *  MODULE status_0100 OUTPUT
  49. *----------------------------------------------------------------------*
  50. *
  51. *----------------------------------------------------------------------*
  52. MODULE status_0100 OUTPUT.
  53.   SET PF-STATUS 'STATUS_100'.
  54. ENDMODULE.                    "status_0100 OUTPUT
  55. *----------------------------------------------------------------------*
  56. *  MODULE transp_itab_out OUTPUT
  57. *----------------------------------------------------------------------*
  58. *
  59. *----------------------------------------------------------------------*
  60. MODULE transp_itab_out OUTPUT.
  61.   idx = sy-stepl + line.
  62.   READ TABLE itab INTO wa INDEX idx.
  63. ENDMODULE.                    "transp_itab_out OUTPUT
  64. *----------------------------------------------------------------------*
  65. *  MODULE transp_itab_in INPUT
  66. *----------------------------------------------------------------------*
  67. *
  68. *----------------------------------------------------------------------*
  69. MODULE transp_itab_in INPUT.
  70.   lines = sy-loopc.
  71.   idx = sy-stepl + line.
  72.   MODIFY itab FROM wa INDEX idx.
  73. ENDMODULE.                    "transp_itab_in INPUT
  74. *----------------------------------------------------------------------*
  75. *  MODULE user_command_0100 INPUT
  76. *----------------------------------------------------------------------*
  77. *
  78. *----------------------------------------------------------------------*
  79. MODULE user_command_0100 INPUT.
  80.   DATA : y_v_index TYPE sy-index.
  81.   DATA : y_lv_d   TYPE f,
  82.          y_lv_div TYPE i,
  83.          y_curr_p_num TYPE i.
  84.   save_ok = ok_code.
  85.   CLEAR ok_code.
  86.   CASE save_ok.
  87.     WHEN 'BACK'.
  88.       LEAVE TO SCREEN 0.
  89. * When Page Down is Hit
  90.     WHEN 'PGDN'.
  91. * Number of screens required for output if 5 records per screen
  92.       y_lv_d = p_num / 5.
  93.       y_lv_div = CEIL( y_lv_d ).
  94.       y_curr_p_num = y_lv_div * 5.
  95.       y_v_index = y_v_next + 1.
  96.       IF y_v_next < y_lv_div.
  97.         y_v_next = y_v_next + 1.
  98.       ELSE.
  99.         y_v_next = y_lv_div.
  100.       ENDIF.
  101.       y_v_prev = y_v_next.
  102.       IF y_v_next <> y_lv_div.
  103.         n2 = p_num - 5 *  y_v_next.
  104.         IF n2 > 5.
  105.           n2 = 5 * y_v_next.
  106.         ENDIF.
  107.         n1 = 1.
  108.         line = line + lines.
  109.         limit = y_curr_p_num - lines.
  110.         IF line > limit.
  111.           line = limit.
  112.         ENDIF.
  113.       ELSE.
  114.         y_v_next = y_v_next - 1.
  115.       ENDIF.
  116. * When Page Up is Hit
  117.     WHEN 'PGUP'.
  118.       n2 = 5 * y_v_next.
  119.       IF n1 < 0.
  120.         n1 = 1.
  121.       ENDIF.
  122.       IF y_v_next > 0.
  123.         y_v_next = y_v_next - 1.
  124.       ELSE.
  125.         y_v_next = 0.
  126.       ENDIF.
  127.       y_v_prev = y_v_next.
  128.       IF line NE 0 AND y_curr_p_num GT 5.
  129.         line = y_v_next * 5.
  130.       ELSE.
  131.         line = 0.
  132.         y_v_index = y_v_next - 1.
  133.       ENDIF.
  134.       IF line < 0.
  135.         line = 0.
  136.       ENDIF.

  137.   ENDCASE.
  138. ENDMODULE.                    "user_command_0100 INPUT
  139. *----------------------------------------------------------------------*
  140. *  MODULE cancel INPUT
  141. *----------------------------------------------------------------------*
  142. *
  143. *----------------------------------------------------------------------*
  144. MODULE cancel INPUT.
  145.   LEAVE PROGRAM.
  146. ENDMODULE.                    "cancel INPUT
  147. *&---------------------------------------------------------------------*
  148. *&      Module  PGUP_DOWN  OUTPUT
  149. *&---------------------------------------------------------------------*
  150. *       text
  151. *----------------------------------------------------------------------*
  152. MODULE pgup_down OUTPUT.
  153.   DATA : y_v_div TYPE i,
  154.          y_v_d TYPE f,
  155.          y_v_temp TYPE i.

  156.   DESCRIBE TABLE itab[] LINES p_num.
  157.   y_v_d = p_num / 5.
  158.   y_v_limit = CEIL( y_v_d ).
  159.   y_v_temp = y_v_limit - 1.
  160.   IF p_num LE 5.
  161.     PERFORM y_f_hide_field USING 'RLMOB-PPGDN'.
  162.     PERFORM y_f_hide_field USING 'RLMOB-PPGUP'.
  163.   ELSEIF y_v_next  = y_v_limit .
  164.     PERFORM y_f_hide_field USING 'RLMOB-PPGDN'.
  165.     PERFORM y_f_show_field USING 'RLMOB-PPGUP'.
  166.   ELSEIF y_v_prev IS INITIAL.
  167.     PERFORM y_f_hide_field USING 'RLMOB-PPGUP'.
  168.   ELSEIF y_v_next GT y_v_limit.
  169.     PERFORM y_f_hide_field USING 'RLMOB-PPGDN'.
  170.   ELSEIF y_v_temp = y_v_next.
  171.     PERFORM y_f_hide_field USING 'RLMOB-PPGDN'.
  172.   ENDIF.
  173. ENDMODULE.                 " PGUP_DOWN  OUTPUT
  174. *&---------------------------------------------------------------------*
  175. *&      Form  Y_F_HIDE_FIELD
  176. *&---------------------------------------------------------------------*
  177. *       text
  178. *----------------------------------------------------------------------*
  179. *      -->P_0372   text
  180. *----------------------------------------------------------------------*
  181. FORM y_f_hide_field  USING    value(p_name).
  182.   LOOP AT SCREEN.
  183.     IF screen-name = p_name.
  184.       screen-active    = '0'.
  185.       screen-invisible = '1'.
  186.       MODIFY SCREEN.
  187.       EXIT.
  188.     ENDIF.
  189.   ENDLOOP.
  190. ENDFORM.                    " Y_F_HIDE_FIELD
  191. *&---------------------------------------------------------------------*
  192. *&      Form  Y_F_SHOW_FIELD
  193. *&---------------------------------------------------------------------*
  194. *       text
  195. *----------------------------------------------------------------------*
  196. *      -->P_0388   text
  197. *----------------------------------------------------------------------*
  198. FORM y_f_show_field  USING    value(p_name).
  199.   LOOP AT SCREEN.
  200.     IF screen-name = p_name.
  201.       screen-active = '1'.
  202.       MODIFY SCREEN.
  203.       EXIT.
  204.     ENDIF.
  205.   ENDLOOP.
  206. ENDFORM.                    " Y_F_SHOW_FIELD
复制代码

3、GUI状态
Step-loops 6.jpg
4、程序执行效果
Step-loops 7.jpg
输入总共的数据条数
Step-loops 8.jpg
Step-loops 9.jpg
Step-loops 10.jpg
回复

使用道具 举报

小懒
Radio Frequency是什么?
回复 支持 反对

使用道具 举报

快速回帖

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

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