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.
MC Press Online