Simplifying environment variables

Environment variable API's can be encapsulated and simplified for use.

Environment variable API's can be encapsulated and simplified for use.
 
/TITLE Utility, Environment Variables module
(SrvPgm)   
 *PARMS                                                  
 *                                                       
H NOMAIN DATFMT(*USA)                                    
H OPTION(*NOXREF)                                        
H CVTOPT(*DATETIME) ALWNULL(*USRCTL)                     
H ENBPFRCOL(*FULL) BNDDIR('QC2LE')                       
 *                                                       
 *-- begin copy book                                     
 * * * * * * * * * * * * * * * * * * * * * * * * * * *   
 *  Standard type definitions.                           
 * * * * * * * * * * * * * * * * * * * * * * * * * * *   
D StdNulPtr       S               *                      
D StdInd          S              1n   Based( StdNulPtr ) 
D StdInt          S             10i 0 Based( StdNulPtr ) 
D StdPtr          S               *   Based( StdNulPtr ) 
D StdStr          S            256    Based( StdNulPtr ) 
 *                                                                
 *-- begin copy book                                              
 * * * * * * * * * * * * * * * * * * * * * * * * * * *            
 *  Environment prototypes.                                       
 * * * * * * * * * * * * * * * * * * * * * * * * * * *            
 * ---------------------------------------------------------      
 *                                                                
 *  Put environment variable.                                     
 *                                                                
D putenv          PR                  extproc('Qp0zPutEnvNoCCSID')
D                                     like(StdInt)                
D  i_envVar                           like(StdPtr) value          
D                                     options(*string)            
 * ---------------------------------------------------------      
 *                                                                
 *  Get environment variable.                                     
 *                                                                
D getenv          PR                  extproc('Qp0zGetEnvNoCCSID')
D                                     like(StdPtr)                
D  i_envVar                           like(StdPtr) value          
D                                     options(*string)      
 * ---------------------------------------------------------
 *                                                          
 *  Get environment variable.                               
 *                                                          
D GetEnvVar       PR         32767    varying               
D  EnvVarNam                    64    varying const         
D                                     options(*varsize)     
 * ---------------------------------------------------------
 *                                                          
 *  Get environment variable as indicator.                  
 *                                                          
D GetEnvVarInd    PR                  like(StdInd)          
D  EnvVarNam                    64    varying const         
D                                     options(*varsize)     
 * ---------------------------------------------------------
 *                                                          
 *  Delete environment variable.                            
 *                                                          
D dltenv          PR                  extproc('Qp0zDltEnv') 
D                                     like(StdPtr)          
D  i_envVar                           like(StdPtr) value             
D                                     options(*string)               
 * ---------------------------------------------------------         
 *                                                                   
 *  Environment variable workfields.                                 
 *                                                                   
D EnvVarNam       s             64                   inz             
D pEnvVar         s                   like(StdPtr)   inz             
D EnvVar          s          32767    based(pEnvVar)                 
 *                                                                   
 *-- end copy book                                                   
 * **********************************************************        
 * Get environment variable.                                         
 * **********************************************************        
P GetEnvVar       B                   Export                         
 *                                                                   
D GetEnvVar       PI         32767    varying                        
D  EnvVarNam                    64    options(*varsize) varying const
 *                                                                   
D  RtnVar         s          32767    varying inz                    
 * ---------------------------------------------------------         
 *                                                              
 *    Test for no input.                                        
 *                                                              
C                   if        EnvVarNam = *blanks               
C                   return    *blanks                           
C                   endif                                       
 * ---------------------------------------------------------    
 *                                                              
 *    Get environment variable.                                 
 *                                                              
C                   eval      pEnvVar = getenv(%trim(EnvVarNam))
 *                                                              
C                   if        pEnvVar <> *null                  
C                   eval      RtnVar   = %str(pEnvVar)          
C                   else                                        
C                   eval      RtnVar   = *blanks                
C                   endif                                       
 *                                                              
C                   return    RtnVar                            
 *                                                              
P GetEnvVar       E                            *
**********************************************************        
 * Get environment variable as indcator.                             
 * **********************************************************        
P GetEnvVarInd    B                   Export                         
 *                                                                   
D GetEnvVarInd    PI                  like(StdInd)                   
D  EnvVarNam                    64    options(*varsize) varying const
 *                                                                   
D  RtnInd         s                   like(StdInd) inz               
 * ---------------------------------------------------------         
 *                                                                   
 *    Test for no input.                                             
 *                                                                   
C                   if        EnvVarNam = *blanks                    
C                   return    *off                                   
C                   endif                                            
 * ---------------------------------------------------------         
 *                                                                   
 *    Get environment variable.                                      
 *                                                                   
C                   eval      pEnvVar = getenv(%trim(EnvVarNam))     
                  
 *                                                    
C                   if        pEnvVar <> *null        
C                   eval      RtnInd   = %str(pEnvVar)
C                   else                              
C                   eval      RtnInd   = *off         
C                   endif                             
 *                                                    
C                   return    RtnInd                  
 *                                                    
P GetEnvVarInd    E                                   


  
  


This was last published in May 2006

Dig Deeper on iSeries application development tools

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close