midrange.com code scratchpad
Name:
Demonstrate %OCCUR being module-based value
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
10/16/2010 05:03:07 pm
IP:
Logged
Description:
Setting occurrence of variable has no impact on other modules that use the same (imported) variable

CRTMOD OCCTEST0
CRTMOD OCCTEST1
CRTMOD OCCTEST2
CRTPGM OCCTEST MODULE(OCCTEST0 OCCTEST1 OCCTEST2)
STRDBG OCCTEST
(set breakpoint at *INLR...)
CALL OCCTEST
Result shows that all modules "see" %Occur(myMODS) independently.

Code:
  1. < OCCTEST_H >
  2.  
  3.      D testOccur1      PR             3I 0 ExtProc('testOccur1')       
  4.                                                                        
  5.      D testOccur2      PR             3I 0 ExtProc('testOccur2')       
  6.                                                                        
  7.      D MAX_OCC         C                   10                          
  8.                                                                        
  9.      D myDS            DS                  based(proto_only)           
  10.      D  occnbr                        3I 0                             
  11.                                                                        
  12.      D myMODS          DS                  Occurs(MAX_OCC) LikeDS(myDS)
  13.      D/If DEFINED(p0)                                                  
  14.      D                                     Export                      
  15.      D/Else                                                            
  16.      D                                     Import                      
  17.      D/Endif                                                           
  18.  
  19.  
  20. < OCCTEST0 >
  21.  
  22.      H                                          
  23.                                                 
  24.       /Define P0                                
  25.       /Include OCCTEST_H                   
  26.                                                 
  27.      D i               S              3I 0      
  28.      D occur0a         S              3I 0      
  29.      D occur0b         S              3I 0      
  30.      D occur1          S              3I 0      
  31.      D occur2          S              3I 0      
  32.                                                 
  33.       /Free                                     
  34.                                                 
  35.        %Occur(myMODS) = 5 ;                     
  36.        occur1  = testOccur1() ;                 
  37.        occur0a = %Occur(myMODS) ;               
  38.        occur2  = testOccur2() ;                 
  39.        occur0b = %Occur(myMODS) ;               
  40.                                                 
  41.        *INLR = *On ;                            
  42.        Return ;     
  43.                     
  44.       /End-free     
  45.  
  46.  
  47. < OCCTEST1 >
  48.  
  49.      H nomain                                    
  50.                                                  
  51.       /Include OCCTEST_H                    
  52.                                                  
  53.      P testOccur1      B                   Export
  54.      D testOccur1      PI             3I 0       
  55.                                                  
  56.      D o               S              3  0       
  57.                                                  
  58.       /Free                                      
  59.        o = %Occur(myMODS) ;                      
  60.        %Occur(myMODS) = 3 ;                      
  61.        Return o ;                                
  62.       /End-free                                  
  63.                                                  
  64.      P testOccur1      E                         
  65.  
  66. < OCCTEST2 >
  67.  
  68.      H nomain                                    
  69.                                                  
  70.       /Include FTPSRC,FTEST_H                    
  71.                                                  
  72.      P testOccur2      B                   Export
  73.      D testOccur2      PI             3I 0       
  74.                                                  
  75.      D o               S              3  0       
  76.                                                  
  77.       /Free                                      
  78.        o = %Occur(myMODS) ;                      
  79.        %Occur(myMODS) = 5 ;                      
  80.        Return o ;                                
  81.       /End-free                                  
  82.                                                  
  83.      P testOccur2      E                         
  84.  
  85.  
© 2004-2019 by midrange.com generated in 0.007s valid xhtml & css