String Parameters of Various Lengths
May 29, 2002 Timothy Prickett Morgan
I have an RPG IV subprocedure that I call from several different programs. I use what I call the QCMDEXC method to pass a character string to it. That is, I pass two parameters–the character string and the length of the character string. I would like to eliminate the second parameter.
The subprocedure would have to determine the length of the character string that is passed to it. Is that possible?
Yes, it’s possible. Your subprocedure needs the operational descriptor of the parameter. Here’s what you need to do.
Add the OPDESC keyword to the parameter definition in the prototype, as follows:
D MyProc PR Opdesc D String 32767 Const Options(*Varsize)
I recommend you put the prototype in a source member of its own in a source physical file for copybooks. In this example, I’ll call the subprocedure MYPROC and assume prototypes are in a file called COPYSRC.
The subprocedure must call the CEEDOD API to retrieve the operational descriptor. Here’s the prototype for CEEDOD:
* Retrieve Operational Descriptors API D CEEDOD PR D ParmNum 10I 0 Const D DescType 10I 0 D DataType 10I 0 D DescInfo1 10I 0 D DescInfo2 10I 0 D DataLen 10I 0 D Feedback 12A Options(*Omit)
Here are the essentials of the subprocedure:
H nomain /copy copysrc,myproc /copy copysrc,ceedod P MyProc B Export * Procedure Interface D PI Opdesc D String 32767 Const Options(*Varsize) * Variables for the CEEDOD API D DescType s 10I 0 D DataType s 10I 0 D DescInfo1 s 10I 0 D DescInfo2 s 10I 0 D DataLen s 10I 0 * Retrieve the length of the string parameter C Callp CEEDOD(1: DescType: C DataType : DescInfo1: C DescInfo2 : DataLen : C *OMIT) * DataLen now contains the length of the input string * Do whatever needs to be done C Return P e
The first parameter of CEEDOD is the number of the positional parameter whose descriptor is to be retrieved. In this example, the constant 1 indicates that I want the operational descriptor of the first parameter.
The length of the string variable is returned in binary format in the sixth parameter (DataLen).
ADVANCED SYSTEMS CONCEPTS
SEQUEL meets all your iSeries and AS/400 data access needs in a single, integrated solution:
Take 6 minutes to
For more information or a FREE trial of SEQUEL,