midrange.com code scratchpad
Name:
Dennis Lovelady
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
03/02/2010 06:16:21 pm
IP:
Logged
Description:
// This routine is a shell to demonstrate alternative
// methods of leaving a procedure early. It expoits
// the RPG opcode LEAVE, which will exit a loop
// prematurely without breaking structured programming
// protocol

// This approach doesn't add unnecessary condition tests
// to the flow - that is as clean as any alternative. It
// also adheres to the "one entry / one exit" standard of
// programming.
Code:
  1.  /Free                                                 
  2.                                                        
  3. P myProc          B                                    
  4. D                 PI            10I 0                  
  5. D  parm1                         8    Const            
  6.                                                        
  7. D once            S              3U 0                  
  8. D rtnValue        S                   Like(myProc)
  9.                                                        
  10.  /Free     
  11.  
  12.   // This routine is a shell to demonstrate alternative
  13.   // methods of leaving a procedure early.  It expoits
  14.   // the RPG opcode LEAVE, which will exit a loop
  15.   // prematurely without breaking structured programming
  16.   // protocol 
  17.  
  18.   // This approach doesn't add unnecessary condition tests
  19.   // to the flow - that is as clean as any alternative.  It
  20.   // also adheres to the "one entry / one exit" standard of
  21.   // programming.
  22.  
  23.   rtnValue = -9999 ;
  24.   For once = 1 to 1 ;                                  
  25.      // Stuff                                          
  26.      // Oops - an error is found.  We gotta get out.   
  27.      If oops ;                                         
  28.         // do stuff                                    
  29.         rtnValue = -1 ;                                
  30.         Leave ;                                        
  31.      EndIF ;                                           
  32.      // More stuff
  33.      // More stuff                                    
  34.      If oopsToo ;                                      
  35.         // do stuff                                    
  36.         rtnValue = -2 ;      
  37.         Leave ;              
  38.      EndIF ;                 
  39.      rtnValue = *Zero ;      
  40.   EndDO ;                    
  41.   // Cleanup                 
  42.   Return rtnValue ;          
  43.                              
  44.  /End-free                   
  45.                              
  46. P myProc          B          
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css