830 pts.
 RPG sub-procedures
What have you found to be an over-riding reason to use a sub-procedure in an RPG program instead of a sub-routine?

Software/Hardware used:
ASKED: April 18, 2009  1:53 PM
UPDATED: April 21, 2009  1:47 PM

Answer Wiki:
1. Can be used as functions - subroutine 1. loading workfields 2. call subroutine 3. move result fields to fields to be used SubProcedure - callp can return value and lists parameters in () so you can have the statement if vldDate( MyDateIn ); ... else ... endif 2. Isolation any fields that you declare in the sub procedure are local even if they have names of fields in the main. Phil
Last Wiki Answer Submitted:  April 20, 2009  1:25 pm  by  philpl1jb   44,190 pts.
All Answer Wiki Contributors:  philpl1jb   44,190 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Subprocedures are really cool. They take a little extra coding but are a great way to minimize the code in the main sections of a program.

Subroutines also have their place. Now that I’ve worked with both subroutines and subprocedures I find that subprocedures are not always the best solution.

I know some say we should dump all our subroutines and only use subprocedures. This reminds me of comments in the past that said, “If your resume does not include xxx your career is over”, which proved to be totally wrong.

Use what makes the most sense as various cases arise. The i Series provides developers a wealth of tools. Don’t limit yourself just because a particular item is trendy.

 5,525 pts.

 

I think that the best answer is simply: re-usability. Also, I think that that is the best indicator of when to use a sub-procedure. If it can be used in more than one program then use a sub-procedure. If not, generally you should use a subroutine.

 1,410 pts.

 

The ability to use local variables in subprocedures greatly faciliates writing better and easier to maintain code. Yet many long time RPG programmers still continue to create programs the way they always have and don’t take advantage of the power of subprocedures.

Having to weed through a huge, monolithic program underscores how beneficial local variables can be. Changing the value of a global variable at the wrong time can break critical business logic, as we’ve all probably encountered. Using a local variable that’s confined to the code which uses it reduces the risk that you or someone else who later comes along to modify it is going to alter behavior elsewhere in the program that they did not intend. It also reduces the time they’d have to spend analyzing the effect of their change on the whole entire program.

 4,275 pts.