Back in 1984, I wrote a user-written command, but this type was different. This one required that the CPP know the length of the value specified for the parameter. I did a little research and discovered the VARY keyword.
On the PARM statement of a Command Definition source member, you can specify VARY(*YES) for the parameter. This causes the command to insert a 2-byte binary prefix that contains the length of the value specified for the parameter. This 2-byte binary prefix is passed along with the parameter value to the CPP.
Today, it is structurally similar to a variable-length field in RPG IV. A 2-byte integer, as it is called today, is appended to the front of the value.
In RPG IV, there are two ways to receive this parameter value: as a varying field or as a data structure.
To receive it as varying field, you would code the following:
C *ENTRY PLIST
C PARM CompName
To receive it as a data structure, you would code the following:
D nLen 5I 0
D Data 50A
C *ENTRY PLIST
C PARM CompName
Either method works just fine.
To declare a command parameter, as mentioned, use the VARY keyword with *YES specified, as follows:
VARY(*YES) PROMPT('Company name')
Today, the VARY keyword has two elements. Originally, it had only the *YES | *NO options, and VARY(*NO) was the default. Now, you can specify VARY(*YES) followed by the size of the integer used for the prefix. The size defaults to *INT2 (2-byte integer) or you can specify *INT4 (4-byte integer). In RPG IV, these values translate as follows:
- *INT2=5I 0
- *INT4=10I 0
Unless you're doing something unusual with the length because of the V5R3 CL enhancements, I can't ever see a need to use *INT4. So specifying VARY(*YES) is probably good enough for any work you do.
Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.
LATEST COMMENTS
MC Press Online