Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1061766
  • 博文数量: 106
  • 博客积分: 9093
  • 博客等级: 中将
  • 技术积分: 2770
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-01 17:22
文章分类

全部博文(106)

文章存档

2014年(1)

2012年(29)

2011年(32)

2010年(20)

2008年(24)

分类: 系统运维

2012-07-27 17:30:03

子程序(Subroutine)是一组多次被调用的程序片段(但只能是calculation specifications)。子程序是以操作符号BEGSR开始,以ENDSR结束。更多关于Subroutine的操作符可以查看IBM i信息中心:

Subroutine里的变量都是全局的,没有局部的。

EX9

0001.00 D Name            S             10A   Inz('Terry')                    

0002.00 D Message         S             52A   Inz                             

0003.00 D Wait            S              1A                                   

0004.00 C*                                                                     

0005.00 C                   Eval      Message = 'Hello World!'                

0006.00 C                   Exsr      SrDisplay                               

0007.00 C*                                                                     

0008.00 C                   Eval      Message = 'Hello ' + Name               

0009.00 C                   Exsr      SrDisplay                               

0010.00 C*                                                                     

0011.00 C     'Complete'    Dsply                   Wait                      

0012.00 C*                                                                    

0013.00 C                   Eval      *inlr = *on                              

0014.00 C                   Return                                            

0015.00 C*=========================================================*          

0016.00 C* Subroutine name: SrDisplay                              *          

0017.00 C* Description    : Display a messge on terminal           *          

0018.00 C*=========================================================*          

0019.00 C     SrDisplay     BegSr                                             

0020.00 C*                                                                     

0021.00 C     Message       Dsply                                             

0022.00 C*                                                                    

0023.00 C                   EndSr        


EX9F

0001.00 D Name            S             10A   Inz('Terry')                    

0002.00 D Message         S             52A   Inz                             

0003.00 D Wait            S              1A                                   

0004.00  /free                                                                 

0005.00    Message = 'Hello World!';                                          

0006.00    Exsr      SrDisplay;                                               

0007.00                                                                        

0008.00    Message = 'Hello ' + Name;                                         

0009.00    Exsr      SrDisplay;                                               

0010.00                                                                        

0011.00    Dsply 'Complete' '' Wait;                                          

0012.00                                                                       

0013.00    *inlr = *on;                                                        

0014.00    return;                                                            

0015.00                                                                       

0016.00    //=========================================================*       

0017.00    // Subroutine name: SrDisplay                              *       

0018.00    // Description    : Display a messge on terminal           *       

0019.00    //=========================================================*       

0020.00    BegSr SrDisplay;                                                   

0021.00                                                                       

0022.00      Dsply  Message;                                                  

0023.00                                                                        

0024.00    EndSr;                                                         

0025.00  /end-free

         

你应该看到的内容
加分练习

1.      尝试一下关于Subroutine的各种操作符

2.      验证一下Subroutine里变量是全局的还是局部的

 

阅读(1057) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~