DATA STRUCTURES AND PROTOTYPED PROCEDURES


Prototyped procedures do not allow data structures to be declared as parameters. This is due to the syntax of the definition specification. Data structures, however, are allowed as parameter arguments (values) when the parameter is declared as a character field. Additional work must be performed within the procedure to map the incoming parameter to a data structure.

Specifically, within the subprocedure, the input parameter's address can be assigned to a pointer field. That pointer must be specified as the value of the BASED keyword for a data structure. Once the pointer is assigned the address of the input parameter, the based-on data structure overlays the input parameter in memory. At this point, the procedure's data structure can be used to access the parameter. Figure 9.22 and its related comments provide more details on this technique.

click to expand
Figure 9.22: Passing a data structure to a subprocedure.

In Figure 9.22, the data structure named MYSTRUCT is passed to the PRINTADDR subprocedure. When PRINTADDR is evoked, it copies the address of the first (and only) parameter to the PSTRUCT field. This is a pointer field that is implicitly declared by the RPG compiler. It is used on line 12 to base the THESTRUCT data structure.

The THESTRUCT data structure is based on the PSTRUCT pointer. While no explicit definition of the PSTRUCT pointer is specified, the compiler generates a declaration for it. RPG implicitly declares pointer variables when used in this manner. Once the address of INADDRESS (the input parameter) is copied into the PSTRUCT pointer (line 17), the memory of the variable passed to the procedure is accessible through the THESTRUCT data structure (lines 12 to 15).

In order to get the data from the INADDRESS input parameter (line 11) into the THESTRUCT data structure (lines 12 to 15), the address of INADDRESS is moved to the PSTRUCT field (line 17). PSTRUCT is the pointer on which THESTRUCT is based. Therefore, the data located at the memory address stored in PSTRUCT is accessible through this based-on data structure.

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.




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