PROCEDURE DEFINITION


A procedure definition is made up of three parts:

  • Procedure prototype — Specified with the definition specification.

  • Procedure identification — Specified with the procedure specification.

  • Procedure interface — Specified with the definition specification.

With only two exceptions, the procedure prototype and the procedure interface are similar interfaces. First, the type of definition specification is PR (for the procedure prototype) and PI (for the procedure interface). Second, the parameter names specified on the procedure interface are accessible by the procedure. The names specified on the procedure prototype, however, are optional and are used for documentation purposes only. They are not accessible by the calling procedure.

A procedure prototype is required within any program that calls the subprocedure and by the subprocedure itself. Procedure prototypes can be stored in a separate source file and are included at compile time through the /COPY compiler directive. This allows the prototype to be inserted into any source file that requires it.

Figure 10.6 shows a simple procedure prototype. The definition type is PR (positions 24 and 25). The procedure name is TOUPPER and it accepts one parameter named INSTR that is a read-only character string of up to 1.024 bytes in length. The INSTR field is only for documentation and is not inserted into the program. The procedure has a return value that is a character string of up to 1,024 bytes in length.

start figure

 .....DName+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++++      D ToUpper         PR          1024A      D   InStr                     1024A   Const 

end figure

Figure 10.6: Simple procedure prototype.

To evoke a prototyped procedure, the CALLP operation is used. If the procedure returns a value, the procedure can be used in an expression just like a built-in function. In Figure 10.7, the three basic forms of evoking a procedure are illustrated on lines 5, 6, and 7.

click to expand
Figure 10.7: Example use of prototyped procedure.

In Figure 10.7, lines 1 and 2 are the prototype for the TOUPPER procedure. The length and data type attributes on line 1 indicate that this procedure returns a value. Lines 3 and 4 are the prototype for the MAKEUPPER procedure. Because there is no length or data-type attribute for this procedure, it doesn't return a value. This type of procedure can be called through the CALLP or CALLB operations. It cannot, however, be used within an expression of a conditional or assignment statement.

The first (and only) parameter of the MAKEUPPER procedure contains the OPTIONS (*VARSIZE) keyword. This indicates that the length of the parameter represents the longest argument length accepted by the procedure. Arguments of shorter length are accepted, but longer-length arguments are not. This option allows variable-length parameters to be passed to subprocedures.

There is no RPG interface to access the attributes of variable-length parameters. However, there are several system interface APIs that provide this support.

If the *VARSIZE option is not specified, and the CONST keyword also is not specified, the length of the argument being passed must exactly match that of the parameter definition.




The Modern RPG IV Language
The Modern RPG IV Language
ISBN: 1583470646
EAN: 2147483647
Year: 2003
Pages: 156
Authors: Robert Cozzi

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net