Tuesday, January 24, 2017

Don’t forget the *return code



When we are developing in 2E we often reach the 50 file limit if we are generating for RPG.  RPG ILE (RP4) is more resilient as it allows more files to be opened.  I’ve preached before regarding proper function construction. 

Do you really need 50 or more files open for any given process? 
Can your function be better constructed or to be accurate………deconstructed?


What are the options?

1.       The easiest method to get over these limits is to change to RP4.
2.       The best is probably to re-architect your function properly and switch to RP4.
3.       The next best approach is to probably hive off a chunk of the processing into a new function to reduce the open files.
4.       The worst thing to do, is to externalise a single RTV in order to get under the limit.  As this can cause all sort of issues.
o   The 50 file limit will be breached on the next maintenance (most likely) leaving the potential for a string of EXT/RTV type functions.
o   If called in a loop or RTVOBJ then an external (if not set to Close Down ‘No’) may impact performance.

Another item to add the list of don’ts (above) is the preservation of the *Return Code.  An Execute External Function does not automatically return a *Return Code.  By default, standard processing is to pass back *Normal or an empty *Return Code.

If you are relying on a *Return Code for your now externalised RTVOBJ it will always come back as empty (*Normal)


unless you explicitly pass the return code back with the *EXIT PROGRAM built in function.

 
Another trap for young players but something that catches even seasoned developers out.  Had the RP4, re-architect or block of code to EEF option been taken the issue was likely to not have manifested.  

Good programming practice is to always be conscious of the *return code and more importantly (where required) test for it.
 
Thanks for reading.
Lee.

No comments:

Post a Comment

Thanks for considering leaving some comments about my random rants for everything software development and more.