Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38780
  • 博文数量: 8
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 82
  • 用 户 组: 普通用户
  • 注册时间: 2013-08-03 12:08
文章分类
文章存档

2013年(8)

我的朋友

分类: AIX

2013-09-02 21:10:49

下班前,写了个简单的程序,作为例子说明参数中OPTIONS(*NOPASS)的用法,现与大家分享,共勉!

程序的作用是封装了系统API,EERAN0,用以返回4位的随机数,至于哪两四位整数之间的随机数,通过传递参数的个数和参数的值来决定,不传参返回1000-9999之间的随机四位整数。

一、程序列表如下:

二、程序源码如下:
USUSRVCDRT:
 * ------------------------------------------------------------------------         
 * MEMBER   : USUSRVCDRT                                                            
 * AUTHOR   : XIAOZL                                                                
 * DESCRIBE : US - Create Random Number                                             
 * DATE     : 2013-09-02                                                            
 * ------------------------------------------------------------------------         
 /IF DEFINED(US_USUSRVCDRT_COPYED)                                                  
 /EOF                                                                               
 /ELSE                                                                              
 /DEFINE     US_USUSRVCDRT_COPYED                                                   
 /ENDIF                                                                             
 * ------------------------------------------------------------------------         
D/IF DEFINED(USUSRVCDR)                                                             
D USUSRVCDR       PR             4S 0                                               
D  iMinNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
D  iMaxNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
D/ENDIF          
                                                                   
USUSRVCDRI:

 * ------------------------------------------------------------------------         
 * MEMBER   : USUSRVCDRP                                                            
 * AUTHOR   : XIAOZL                                                                
 * DESCRIBE : US - Create Random Number                                             
 * DATE     : 2013-09-02                                                            
 * ------------------------------------------------------------------------         
HNOMAIN DATFMT(*ISO)                                                                
 *                                                                                  
D/DEFINE USUSRVCDR                                                                  
D/COPY XXXZL2/QRPGSRC,USUSRVCDRT                                                    
 *                                                                                  
P USUSRVCDR       B                   EXPORT                                        
D USUSRVCDR       PI             4S 0                                               
D  iMinNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
D  iMaxNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
D USUSRVCDR       PR             4S 0                                               
D  iMinNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
D  iMaxNbr                       5S 0 VALUE OPTIONS(*NOPASS)                        
 *                                                                                  
D CEERAN          PR                  Extproc('CEERAN0')                            
D P_SEED                              LIKE(I_SEED)                                                     
DP_RANDOM                             LIKE(F_RANDOM)                                                   
 *                                                                                                     
DI_SEED           S             10I 0 INZ(0)                                                           
DF_RANDOM         S              8F                                                                    
 *                                                                                                     
DRNDNBR           S             10I 0                                                                  
DMINNBR           C                   CONST(1000)                                                      
DMAXNBR           C                   CONST(10000)                                                     
DoRtnNbr          S              4S 0                                                                  
 *                                                                                                     
C                   EXSR      #Init                                                                    
C                   EXSR      #Main                                                                    
C                   RETURN    oRtnNbr                                                                  
 *                                                                                                     
CSR   #Init         BEGSR                                                                              
CSR                   ENDSR                                                                              
 *                                                                                                     
CSR   #Main         BEGSR                                                                              
C                   SELECT                                                                                    
C                   WHEN      %PARMS = 0                                                                      
C                   CALLP     CEERAN(I_SEED:F_RANDOM)                                                         
C                   EVAL      RNDNBR = %DECH(F_RANDOM:30:29)                                                  
C                                      *(MAXNBR-MINNBR)+MINNBR                                                
C                   MOVE      RNDNBR        oRtnNbr                                                           
 *                                                                                                            
C                   WHEN      %PARMS = 1                                                                      
C                   CALLP     CEERAN(I_SEED:F_RANDOM)                                                         
C                   EVAL      RNDNBR = %DECH(F_RANDOM:30:29)                                                  
C                                      *(MAXNBR-iMinNbr)+iMinNbr                                              
C                   MOVE      RNDNBR        oRtnNbr                                                           
 *                                                                                                            
C                   WHEN      %PARMS = 2                                                                      
C                   CALLP     CEERAN(I_SEED:F_RANDOM)                                                         
C                   EVAL      RNDNBR = %DECH(F_RANDOM:30:29)                                                  
C                                      *(iMaxNbr-iMinNbr)+iMinNbr                                             
C                   MOVE      RNDNBR        oRtnNbr                                                           
C                   ENDSL                                                                                     
CSR                ENDSR                
P USUSRVCDR       E    

USUSRVCDRP:                                                                                   
D/DEFINE USUSRVCDR                                                                         
D/COPY XXXZL2/QRPGSRC,USUSRVCDRT                                                           
 *                                                                                         
DoDspNbr          S              4S 0                                                      
 *                                                                                         
 *    Get the Random Number Between 1000 - 10000                                           
 *                                                                                         
C                   EVAL      oDspNbr = USUSRVCDR()                                        
C     oDspNbr       DSPLY                                                                  
 *                                                                                         
 *    Get the Random Number Between 5000 - 10000                                           
 *                                                                                         
C                   EVAL      oDspNbr = USUSRVCDR(5000)                                    
C     oDspNbr       DSPLY                                                                  
 *                                                                                         
 *    Get the Random Number Between 1000 - 2000                                            
 *
C                   EVAL      oDspNbr = USUSRVCDR(1000:2000)             
C     oDspNbr       DSPLY                                                
 *                                                                       
C                   SETON                                        LR      
C                   RETURN          
四、程序编译参考:
CRTRPGMOD MODULE(MYOBJLIB/USUSRVCDRI) SRCFILE(MYSRCLIB/QRPGSRC) SRCMB(USUSRVCDRI)        
CRTRPGMOD MODULE(MYOBJLIB/USUSRVCDRP) SRCFILE(MYSRCLIB/QRPGSRC) SRCMB(USUSRVCDRP)  
CRTPGM PGM(MYOBJLIB/USUSRVCDRP) MODULE(MYOBJLIB/USUSRVCDRP MYOBJLIB/USUSRVCDRI)
五、CALL USUSRVCDRP,查看作业日志可以看到如下效果:

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