You are in: RPG Cafe > Getting the best performance for a call
Short URL: http://ibm.biz/rpg_call_performance
RPG Cafe: Best call performance
Getting the best performance for a call
Avoid returning "large" values unless you add the RTNPARM keyword to your prototype and procedure interface. See https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzasd/drtnparm.htm.
There are two aspects to the performance of parameters
- The amount of data that is passed on the "parameter stack"
- The amount of data that is actually used in the procedure
To reduce the amount of data that is passed on the parameter stack
- If the parameter is small (such as numeric or date parameters, or small strings), don't worry about performance
- If the parameter is larger, pass by reference
- Code CONST when you want to be able to pass parameters that are not exactly like the prototype
- Don't code either CONST or VALUE when you want the parameter to be changed by the called procedure
- If you want to pass the parameter by value because you want the procedure to be able to change it, consider coding CONST on the prototype and procedure interface. Within the procedure, copy the parameter to a local variable inside the procedure. This involves less data-movement overall than passing the parameter by value.
- This is especially true for large varying length strings. When the parameter is passed by value, the entire maximum length of the parameter is copied to the parameter stack. When the parameter is copied to a local variable, only the current length of data is copied.
To reduce the amount of data that is used within the procedure,
- Consider using varying-length strings (this applies to strings in general, not just parameters). Even if the parameter is passed as a fixed-length string, you might improve the overall performance of your procedure by copying it to a varying-length string for use in calculations. This is especially true if you make frequent use of %TRIM for the parameter. By using a temporary varying-length variable, you can avoid by using %TRIM since it would be trimmed when you copied it to the varying length variable.
- Use %SUBARR when you are working with partially filled arrays, so you only work with the active elements in the array.
15 December 2019