If your procedure would work equally well with a VALUE or CONST parameter, use this rule of thumb: use VALUE for pointers and numeric values, and use CONST for arrays, structures, and strings.
For any large parameter, it's better to pass it by reference (CONST) than by value. Passing by reference requires just the 16-byte address to be copied by the system to the parameter area. Passing by value requires the entire length of the parameter to be copied to the parameter area.
Your goal should be to reduce the amount of data-copying that is required to pass your parameters.
Let's consider a few ways to handle a string parameter of 100 bytes, with a specific case of a passed value of 'abc'. There are four ways to code the prototype:
- 100A VALUE
- 100A CONST
- 100A VALUE VARYING
- 100A CONST VARYING
In the first case, the compiler must first take a 100-byte temporary, copy 'abc' to it, and then fill the rest with blanks. Then, the system will copy that 100 bytes to the parameter area.
Total data movement: 100 + 100 = 200 bytes
In the second case, the compiler will prepare the same temporary, but the system will only have to copy its address to the parameter area.
Total data movement: 100 + 16 = 116 bytes
In the third case, the compiler will take a 102-byte temporary, set the first two bytes to 3, and copy 'abc' to the next three bytes. Then the system will copy that 102 bytes to the parameter area.
Total data movement: 5 + 102 = 107 bytes
In the fourth case, the compiler will prepare the same temporary, but the system will only have to copy its address to the parameter area.
Total data movement: 5 + 16 = 21 bytes
The best solution for string parameters is CONST VARYING.
Barbara Morris is on the RPG Compiler Development team in the IBM Lab in Toronto. She can be reached at
Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online