PROTOTYPED PROCEDURE KEYWORDS


Several standard definition specification keywords can be used to enhance the properties of parameters passed to prototyped procedures. Table 10.1 lists the keywords that have a distinct effect on prototyped procedure parameters.

Table 10.1: Definition Specification Keywords for Prototyped Parameters

Keyword

Parameters

Used By

Description

CONST

PARM

For procedure parameters, the value being passed is constant. It is considered read-only and is not changed by the called procedure.

When a parameter is CONST, the compiler performs a small level of "type casting." If the value specified is similar to the data type and length required by the parameter, the system does some conversion to convert the value to the format required by the parameter.

This is especially apparent for numeric parameters where a length is specified for the parameter, but a numeric value of any length can be specified.

For date parameters, CONST allows the system to convert date values (of any format) to the format required by the prototype parameter.

DATFMT

Format [separator]

PARM RETURN

The date format expected for the parameter. The date format of the value passed must match this format unless the parameter is read-only (i.e., it is not changed by the called procedure), and the CONST keyword is specified for the parameter.

For return values, this is the format of the date value being returned by the called procedure.

EXTPGM

external program name

Prototype

The name of the program being prototyped. Either a quoted character literal or a named constant can be specified. This keyword is typically used for calling operating system APIs, but it can also be used to provide a prototyped interface to custom application programs.

The prototype name (specified in positions 7 to 21) does not have to match the value specified for this keyword. The prototype name is the name used within the program to evoke the subprogram.

EXTPROC

external procedure name

Prototype

The name of the procedure being prototyped. Either a quoted character literal, a named constant, or a procedure pointer can be specified.

The name of the prototype (positions 7 to 21) is used as the procedure name if neither EXTPROC nor EXTPGM is specified.

The prototype name does not have to match the value specified for this keyword. The prototype name is the name used within the program to evoke this subprocedure. This can be useful for renaming unusually named subprocedures. For example, CEEDOD can be renamed as GETOPDESC. Then GETOPDESC is used to evoke the CEEDOD procedure.

LIKEREC

based-on variable

PARM

Use this keyword to assign the attribute of the referenced variable to the new variable. Only the size, decimal positions (if any), and data type are inherited. The initial value is not inherited.

If the referenced variable is the name of a procedure prototype, the new field inherits the properties of the prototype's return value.

If the referenced variable is an array, the properties of an array element are inherited. Specify DIM(%elem(based-on VAR)) to also inherit the number of elements.

If the referenced variable is a data structure, a character field is created with a length equal to that of the data structure.

NOOP

PARM

Used when calling OPM (i.e., RPG III) programs. Most OPM programs may be called using the EXTPGM keyword without the NOOPT keyword specified. However, if problems with passing values occur, add the NOOPT key to each parameter.

OPDESC

Prototype ProcInterface

Operational descriptors are passed to the called procedure or program. All system APIs expect operation descriptors.

An operational descriptor can be useful in other procedures as well. The length and type of character fields are passed to the called procedure. This is useful for string manipulation and variable length parameters.

When this keyword is used, it must be specified on both the procedure prototype and the procedure interface definition. See also OPTIONS(*VARSIZE).

OPTIONS

[ opt1 : opt2 : opt3 ]

PARM

Parameter passing options. On a prototype, use the OPTIONS keyword on any of the parameters that require special consideration.

*NOPASS

The parameter is optional. It does not have to be specified wn the procedure is called. All subsequent parameters must also include the option OPTIONS(*NOPASS).he

*OMIT

The *OMIT option is allowed for the parameter. Use *OMIT in place of a parameter value when the procedure is called.

In other languages, the NULL value is normally passed in this situation. *OMIT is similar to passing a null value as a place holder for a parameter.

To determine whether or not a parameter is specified as *OMIT, compare the parameter's address to the *NULL built-in constant. For example:

 CSRn01..............OpCode(ex)Extended-factor2++++++ C                   If        %addr(p1) = *NULL 

Where P1 is the parameter being passed into the procedure or program.

*VARSIZE

The character, array, or graphic parameter value can be shorter than the length defined in the prototype for the parameter. If *VARSIZE is not specified, the value passed must match the length of the parameter declaration.

The *VARSIZE option allows a parameter to be passed that is of varying size. Contrast this with the CONST keyword, which allows the length to differ, but does not allow the called procedure to modify the parameter's data.

The actual length of the parameter can be determined by calling a system interface API. On the AS/400, this information is retrieved from the sixth parameter of the CEEDOD API.

See also CONST.

*STRING

Pass the value as a null terminated string. The parameter value is converted to a null terminated string automatically by the compiler.

*RIGHTADJ

The data in the character parameter is right justified

VALUE

PARM

Pass parameter argument by value. The value passed on the parameter is copied to a temporary location, and a reference to the copy is passed to the called procedure. The called program can make changes to the value, but those changes are not reflected in the calling program.

VARYING

PARM

Pass the parameter as variable length field. When used in conjunction with the CONST or the VALUE keywords, any character string expression (variable length or fixed length) may be passed as the parameter value.




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