Hi David,
OPTIONS(*VARSIZE) is used to turn off the compiler's variable size checking
code. So when passing by reference you can pass a larger/smaller field than
that defined on the prototype. However, within your subprocedure you MUST
check the length actually passed, otherwise simply setting the parameter to
blanks when a smaller field was passed can corrupt data. To inform the
subprocedure of the actual length you can pass a second parameter
designating the length passed or by passing operational descriptors.
Personally I prefer the second approach as you don't have to rely on the
author of the calling code to put the length in the field. howver, if your
code may be called from other languages you can't always depend on
operational descriptors either (subject of another thread).
Your code compiles because you have specified CONST for your first
parameter. When you do this, during the call, the runtime will create a
temporary variable with the same type/length as that defined on the
prototype. The value in your field will then be copied to this temporary and
the data truncated/padded accordingly. It is the temporary variable which is
actually passed on the call.
There have been several discussions on this, one only recently.
Regarding CONST, here is a thread I started a few weeks ago:
http://archive.midrange.com/rpg400-l/200710/msg00762.html
Regarding CONST and/or OPTIONS(*VARSIZE), here is the start of a really good
thread initiated by Charles Wilt:
http://archive.midrange.com/rpg400-l/200605/msg00162.html
In this thread I wrote a program to check all of the variations of CONST
OPTIONS(*VARSIZE) and VARYING. You should follow the whole thread from
Charle's initial post. But you can take a quick peek at my findings here:
http://archive.midrange.com/rpg400-l/200605/msg00224.html Pay particular
interest to the notes at the foot of the post.
Cheers
Larry Ducie
As an Amazon Associate we earn from qualifying purchases.