子例程、功能模块

*一、宏

*data: sum type i.
*DEFINE cheng.

  • &1 = &2 * &3 * &4 * &5 * &9 * &8 * &7 * &6.
    *end-OF-DEFINITION.

*cheng sum 5 2 5 6 5 6 4.
*WRITE:sum.

*二、包含程序

*include ztext101.
*WRITE:/ MAX.

*三、子例程
*1、 用户在选择屏幕上输入两个整数,通过调用一个子程序求这两个整数之间所有被3整除的数的总和。

*PARAMETERS : M1 TYPE I,

  •         M2 TYPE I.
    

*DATA: COUNT TYPE I.
*PERFORM Z_SUM USING M1 M2 CHANGING COUNT.
*WRITE:/ COUNT.

*FORM Z_SUM USING M1 TYPE I

  •           M2 TYPE I
    
  •      CHANGING S TYPE I.
    

*DATA:T TYPE I.
*T = M1.
*WHILE T < M2.

  • T = T + 1.
  • IF T MOD 3 = 0.
  • S = S + T.
  • ENDIF.

*ENDWHILE.
*ENDFORM.

*2、 定义一个zty_score结构体类型,包含学号no、姓名name、成绩score.定义一个内表,做子例程程序,求出平均成绩。
*TYPES: BEGIN OF zty_score,

  • NO(20) TYPE C,
  • NAME(20) TYPE C,
  • SCORE TYPE I,
  • END OF zty_score.
  • DATA: GT_SCORE TYPE TABLE OF zty_score,
  •   WA_SCORE TYPE zty_score,
    
  •   SUM TYPE I,
    
  •   CISHU TYPE I,
    
  •   AVG TYPE I.
    
  • WA_SCORE-NO = 1754574555.
  • WA_SCORE-name = '谁会'.
  • WA_SCORE-SCORE = 70.
  • APPEND WA_SCORE TO GT_SCORE.
  • WA_SCORE-NO = 1754574555.
  • WA_SCORE-name = '谁会'.
  • WA_SCORE-SCORE = 80.
  • APPEND WA_SCORE TO GT_SCORE.
  • WA_SCORE-NO = 1754574555.
  • WA_SCORE-name = '谁会'.
  • WA_SCORE-SCORE = 72.
  • APPEND WA_SCORE TO GT_SCORE.

*LOOP AT GT_SCORE INTO WA_SCORE.

  • SUM = SUM + WA_SCORE-SCORE.
  • CISHU = CISHU + 1.
    *ENDLOOP.

*PERFORM H_AVG USING SUM CISHU CHANGING AVG.
*WRITE:/ avg.

  • FORM H_AVG USING X TYPE I
  •                Y TYPE I
    
  •      CHANGING AVG TYPE I.
    
  • AVG = X / Y.
  • ENDFORM.

你可能感兴趣的:(子例程、功能模块)