二维码

[report] PERFORM封装分割代码案例

Twilight发表于 2014-02-22 19:15Twilight 最后回复于 2014-02-22 19:15 [复制链接] 3335 0

我们一定要养成一个封装分割代码的好习惯,既能提高代码的重用性,又能提高代码的可阅读性。
先阅读:用write输出带有表头和交通灯的格式化数据报表,该程序是对它的代码封装优化,执行效果相同。

程序代码:
  1. REPORT  ZLXG_HM2_PERFORM .
  2. *--------------------------------------------------------------------*
  3. *TYPES
  4. *--------------------------------------------------------------------*
  5. TYPES:BEGIN OF TP_SFLIGHT,
  6.        carrid    TYPE SFLIGHT-carrid ,
  7.        connid    TYPE SFLIGHT-connid ,
  8.        fldate    TYPE SFLIGHT-fldate ,
  9.        price     TYPE SFLIGHT-price  ,
  10.        currency  TYPE SFLIGHT-currency,
  11.        planetypE TYPE SFLIGHT-planetypE,
  12.        seatsmax  TYPE SFLIGHT-seatsmax,
  13.        seatsocc  TYPE SFLIGHT-seatsocc,
  14.        occpercent TYPE P DECIMALS 2,
  15.       END OF TP_SFLIGHT.
  16. *--------------------------------------------------------------------*
  17. *DATA
  18. *--------------------------------------------------------------------*
  19. DATA:WA_SFLIGHT TYPE TP_SFLIGHT.
  20. DATA:IT_SFLIGHT TYPE STANDARD TABLE OF TP_SFLIGHT.
  21. DATA:IT_SFLIGHT_OUT TYPE STANDARD TABLE OF TP_SFLIGHT.
  22. *--------------------------------------------------------------------*
  23. *SELECTION-SCREEN
  24. *--------------------------------------------------------------------*
  25. SELECTION-SCREEN BEGIN OF BLOCK B_P1 WITH FRAME TITLE TEXT-010.
  26. PARAMETERS:PA_CARR TYPE SFLIGHT-CARRID.
  27. SELECT-OPTIONS:SO_CONN FOR WA_SFLIGHT-CONNID,
  28.                SO_FLDA FOR WA_SFLIGHT-FLDATE.
  29. SELECTION-SCREEN END OF BLOCK B_P1.
  30. SELECTION-SCREEN BEGIN OF BLOCK B_P2 WITH FRAME TITLE TEXT-011.
  31. PARAMETERS: PA_check  AS CHECKBOX.
  32. PARAMETERS: radio1 RADIOBUTTON GROUP int,
  33.             radio2 RADIOBUTTON GROUP int,
  34.             radio3 RADIOBUTTON GROUP int.
  35. SELECTION-SCREEN END OF BLOCK B_P2.
  36. *--------------------------------------------------------------------*
  37. *LOAD-OF-PROGRAM = INITIALIZATION
  38. *--------------------------------------------------------------------*
  39. LOAD-OF-PROGRAM.
  40. PA_CARR = 'AA'.
  41. PA_check = 'X'.
  42. *--------------------------------------------------------------------*
  43. *AT SELECTION-SCREEN
  44. *--------------------------------------------------------------------*
  45. AT SELECTION-SCREEN ON PA_CHECK.
  46.   IF PA_check IS NOT INITIAL.
  47.      MESSAGE W003(ZVINO).
  48. *   Invalid operator!
  49.   ENDIF.
  50. *--------------------------------------------------------------------*
  51. *TOP-OF-PAGE.
  52. *--------------------------------------------------------------------*
  53. TOP-OF-PAGE.
  54. FORMAT COLOR COL_HEADING.
  55. IF PA_check = 'X'.
  56.   ULINE 1(131).
  57. ELSE.
  58.   ULINE /1(107).
  59. ENDIF.
  60. WRITE:/ SY-VLINE, AT 2(10) 'carrid'(001) ,
  61.         SY-VLINE, AT 14(10)'connid'(002),
  62.         SY-VLINE, AT 26(20)'fldate'(003),
  63.         SY-VLINE, AT 48(10)'price'(004),
  64.         SY-VLINE, AT 60(10)'currency'(005),
  65.         SY-VLINE, AT 72(10)'planetype'(006),
  66.         SY-VLINE, AT 84(10)'seatsmax'(007),
  67.         SY-VLINE, AT 96(10)'seatsocc'(008).
  68.         IF PA_check = 'X'.
  69.           WRITE:SY-VLINE, AT 108(10)'percent'(009),
  70.                 SY-VLINE, AT 120(10)'STATUS'(012),SY-VLINE.
  71.           ULINE /1(131).
  72.           ELSE.
  73.             WRITE:SY-VLINE.
  74.             ULINE /1(107).
  75.         ENDIF.
  76. FORMAT RESET.

  77. *--------------------------------------------------------------------*
  78. *START-OF-SELECTION.
  79. *--------------------------------------------------------------------*
  80. START-OF-SELECTION.
  81. PERFORM GET_DATA
  82.             USING
  83.                PA_CARR
  84.                RADIO1
  85.                RADIO2
  86.                RADIO3
  87.                SO_CONN[]
  88.                SO_FLDA[]
  89.             CHANGING
  90.                IT_SFLIGHT_OUT[].

  91. PERFORM OUT_DATA
  92.             USING
  93.                IT_SFLIGHT_OUT[].

  94. *&---------------------------------------------------------------------*
  95. *&      Form  GET_DATA
  96. *&---------------------------------------------------------------------*
  97. *       text
  98. *----------------------------------------------------------------------*
  99. *  -->  p1        text
  100. *  <--  p2        text
  101. *----------------------------------------------------------------------*
  102. FORM GET_DATA USING P_CARR
  103.                     rad1
  104.                     rad2
  105.                     rad3
  106.                     S_CONN TYPE TABLE
  107.                     S_FLDA TYPE TABLE
  108.               CHANGING T_SFLIGHT_OUT TYPE TABLE.

  109. DATA:W_SFLIGHT TYPE TP_SFLIGHT.
  110. DATA:T_SFLIGHT TYPE STANDARD TABLE OF TP_SFLIGHT.
  111. SELECT *
  112.   FROM SFLIGHT
  113.   INTO CORRESPONDING FIELDS OF TABLE T_SFLIGHT
  114.   WHERE CARRID = P_CARR
  115.   AND CONNID IN S_CONN
  116.   AND FLDATE IN S_FLDA.

  117. LOOP AT T_SFLIGHT INTO W_SFLIGHT.
  118. W_SFLIGHT-occpercent = W_SFLIGHT-seatsocc / W_SFLIGHT-seatsmax.
  119. MODIFY T_SFLIGHT FROM W_SFLIGHT.
  120. ENDLOOP.

  121. IF rad1 = 'X'.
  122. T_SFLIGHT_OUT = T_SFLIGHT.
  123. ENDIF.

  124. IF rad2 = 'X'.
  125.     LOOP AT T_SFLIGHT INTO W_SFLIGHT WHERE occpercent < '0.75'.
  126.        APPEND W_SFLIGHT TO T_SFLIGHT_OUT.
  127.     ENDLOOP.
  128. ENDIF.

  129. IF rad3 = 'X'.
  130.     LOOP AT T_SFLIGHT INTO W_SFLIGHT WHERE occpercent < '0.5'.
  131.        APPEND W_SFLIGHT TO T_SFLIGHT_OUT.
  132.     ENDLOOP.
  133. ENDIF.

  134. *CASE 'X'.
  135. *  WHEN radio1.
  136. *    IT_SFLIGHT_OUT = IT_SFLIGHT.
  137. *  WHEN RADIO2.
  138. *    LOOP AT IT_SFLIGHT INTO WA_SFLIGHT WHERE occpercent < '0.75'.
  139. *       APPEND WA_SFLIGHT TO IT_SFLIGHT_OUT.
  140. *    ENDLOOP.
  141. *  WHEN RADIO3.
  142. *    LOOP AT IT_SFLIGHT INTO WA_SFLIGHT WHERE occpercent < '0.5'.
  143. *       APPEND WA_SFLIGHT TO IT_SFLIGHT_OUT.
  144. *    ENDLOOP.
  145. *ENDCASE.
  146. ENDFORM.                    " GET_DATA
  147. *&---------------------------------------------------------------------*
  148. *&      Form  OUT_DATA
  149. *&---------------------------------------------------------------------*
  150. *       text
  151. *----------------------------------------------------------------------*
  152. *  -->  p1        text
  153. *  <--  p2        text
  154. *----------------------------------------------------------------------*
  155. FORM OUT_DATA USING T_SFLIGHT_OUT TYPE TABLE.
  156. DATA:W_SFLIGHT TYPE TP_SFLIGHT.
  157. LOOP AT T_SFLIGHT_OUT INTO W_SFLIGHT.
  158. WRITE:/ SY-VLINE, AT 2(10)  W_SFLIGHT-carrid COLOR COL_KEY,
  159.         SY-VLINE, AT 14(10) W_SFLIGHT-connid COLOR COL_KEY,
  160.         SY-VLINE, AT 26(20) W_SFLIGHT-fldate COLOR COL_KEY,
  161.         SY-VLINE, AT 48(10) W_SFLIGHT-price  CURRENCY W_SFLIGHT-currency,
  162.         SY-VLINE, AT 60(10) W_SFLIGHT-currency,
  163.         SY-VLINE, AT 72(10) W_SFLIGHT-planetype,
  164.         SY-VLINE, AT 84(10) W_SFLIGHT-seatsmax,
  165.         SY-VLINE, AT 96(10) W_SFLIGHT-seatsocc.
  166.         IF PA_check = 'X'.
  167.         WRITE:SY-VLINE, AT 108(10) W_SFLIGHT-occpercent.
  168.           IF W_SFLIGHT-occpercent < '0.5'.
  169.             WRITE: SY-VLINE, AT 120(10) ICON_GREEN_LIGHT AS ICON ,SY-VLINE.
  170.             ELSEIF W_SFLIGHT-occpercent < '0.75'.
  171.               WRITE: SY-VLINE, AT 120(10) ICON_YELLOW_LIGHT AS ICON ,SY-VLINE.
  172.               ELSE.
  173.               WRITE: SY-VLINE, AT 120(10) ICON_RED_LIGHT AS ICON ,SY-VLINE.
  174.           ENDIF.
  175.           ULINE /1(131).
  176.         ELSE.
  177.             WRITE:SY-VLINE.
  178.             ULINE /1(107).
  179.         ENDIF.
  180. ENDLOOP.
  181. ENDFORM.                    " OUT_DATA
复制代码
回复

使用道具 举报

快速回帖

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

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