Q. I’ve heard you say that I can pass a data structure as a parameter, or accept it as a return value. How do I do this?
A. There are a couple of additional coding requirements when you are prototyping a data structure as a parameter or a return value.
First, you need to define the layout in a separate data structure. There’s no special requirement for this data structure; it can be program-described or externally-described.
Next, to use the data structure as a parameter or a return value, you code the LIKEDS keyword, referring to the data structure as the reference:
Dcl-pr Myproc Ind; *N Likeds(Mail); End-pr; Dcl-ds Mail; Identifier Uns(5); Name Char(35); Address1 Char(35); Address2 Char(35); City Char(21); State Char(2); Zipcode Char(10); End-ds;
D Myproc PR 1N D Parm1 Likeds(Mail) D Mail DS D Identifier 5U 0 D Name 35 D Address1 35 D Address2 35 D City 21 D State 2 D Zipcode 10
Note that in the fixed format example I named the parameter (Parm1) in the prototype. While it is not usually necessary to name parameters in a prototype, in this case, the notation in columns 7-21 serves to separate the parameter from the return value. If I had not included the Parm1 notation, the compiler would have treated the LIKEDS line as a continuation of the return value, not as a separate parameter. (This is also necessary when you code a parameter with LIKE or LIKEREC.) In the free format example, simply noting *N serves to separate the return value from the first parameter.
Of course, in the called procedure, you’ll need to include the LIKEDS keyword in the procedure interface as well. If the called procedure is a NOMAIN procedure (i.e., it’s in a separate module), you’ll need to also code the reference procedure in that module.
Although this example doesn’t show it, I also recommend that the data structure be a qualified data structure. Then you would refer to subfields by their qualified name — Mail.Identifier, Mail.Name, Mail.Address1, etc.
At V5R2, you can also use the LIKEREC keyword on a prototype and a procedure interface, to define a parameter or return value like a record format. For example, the following prototype would pass a record format to a procedure:
Dcl-f Maillist Disk Usage(*Update:*Delete) Keyed; ... Dcl-pr Myproc Ind; *N Likerec(Mailfmt:*All); End-pr;
FMaillist UF E K Disk ... D Myproc PR 1N D Parm1 Likerec(Mailfmt:*All)