Function Parameters

547 Views


Function parameters specify which fields can be passed between the calling and the called functions.

Each call can pass different values in these fields, but the definitions of the fields themselves remains the same.

You assign parameter’s roles to direct the function to use them in a particular way.

Parameters have the following four basic properties: name, usage, role, and flag error status.

A parameter’s usage definition determines how the parameter is allowed to be used. Parameters can be used in one of four ways depending on how they are received from or returned to the function.

Usage Type: Input Only, Output Only, Both (Input/Output), Neither, Flag Error Status

Input Only: A value is passed into the function when the function is called, but the function will not change this value and the same value will be returned.

Output Only: A value is returned from the function for the parameter when the function completes. Any initial value passed in this variable will be set to blank or zero at the start of the function.

Both (Input/Output): A value is passed into the function for the parameter when the function is called and a value, possibly different, is returned to the calling function when the function completes processing.

Neither: No value is passed into the function for the parameter nor is a value returned for the parameter when the function ends. Neither parameters are available for use as local variables within the function.

Flag Error Status:

Flag error status specifies whether a calling function should indicate that an error, which occurs in the called function, is associated with the parameter field.

If so, the field will be highlighted on the display of the calling function if the parameter field in the called function returns a non-blank return code.

Flag error status applies only to the following function types: · SNDERRMSG (send error message) · EXCMSG (execute message) · Any external function

Identifying the Return Code Parameter

All standard function types have an implicit parameter, the return code (other than EXCUSRPGM and EXCUSRSRC).

The return code is used to inform the calling program of the circumstances under which the called program is exited.

The return code is not shown on the Edit Function Parameters panel but is automatically declared in the generated source code as the first parameter.

Therefore, when calling your application program from a menu or a command line you must always specify a parameter for the return code.

Return Code must be the first parameter for all synon programs.

For example, when calling a function from a command line: CALL ABCDEFR ’ ’

Understanding the Role of the Parameter

The role of a parameter specifies how the parameter will be used in the function into which it is passed.

Map Parameter: This parameter is automatically moved to a corresponding field on the receiving function’s panel design.

If the field does not exist on the device design, it will be added to it.

Specifying fields as mapped Neither parameters is a way of adding fields to a panel design without the need to pass them into the function.

The Map option is ignored for reports and functions that do not have an associated device design.

Restrictor Parameter: This parameter is used to restrict the records from a database file which can be displayed, changed, or printed by the function.

Restrictor parameters must be key fields on the access path to which their function attaches and can only be used hierarchically; that is, major to minor key sequence.

A minor key can only be a restrictor parameter if all keys major to it are also restrictor parameters.

Restrictor parameters are automatically mapped and default to output on the panel.

Positioner Parameter: This parameter is used to position a function to start reading records from a database file at a particular record.

Positioner parameters can be used by themselves or in conjunction with restrictor parameters.

They must be key fields on the access path to which their function attaches and can only be used hierarchically.

For example, a minor key can only be a positioner parameter if all major keys to it are also positioner or restrictor parameters.

Positioner parameters are automatically mapped and can be either Output or Both on the panel.

The following table shows the allowed parameter roles for the standard functions.

Defining Function Parameters

To define a parameter for a function you must specify the field that will be passed to or from the function.

Parameters can either be defined as a list of specific fields or as selections of fields from a list of access paths, arrays, or files.

1. View the functions. At the Edit Database Relations panel, type F next to the selected file and press Enter. The Edit Functions Panel displays.

2. View the parameters. Type P next to the selected function and press Enter.

3. Specify the parameter. Use one of the following steps to specify the parameters.

a. Specify an individual field. Type *FIELD or *F in the File/*FIELD column.

Type the name of the field in the Access Path/Field column. By entering a ? this field can be used for prompting. The Passed As field will default to FLD.

b. Specify a set of fields from a file, access path, or array. Type the name of the file in the File/*Field column. For arrays type *ARRAY.      By entering a ? this field can be used for prompting.

A * will default to the name of the file over which the function is built.

Type the name of the access path or array name in the Access Path/Field column. By entering a ? this field can be used for prompting.

Type the value that the field is passed as.

Options are:

FLD means that each specified field is passed as an individual parameter. This must be specified for *FIELD or *NONE parameter lines. RCD means that a single parameter with the length of the specified access path is passed. The parameter contains space for all the fields associated with the access path which can individually be specified as parameters.

KEY means that a single parameter with the length of the combined keys of the specified access path is passed. The parameter contains space for all the key fields which can be individually specified as parameters.

Define the usage

Your options are: I Input, O Output, B Both, N Neither

Define the role

Type the value for the selected type of role in the Role column, next to the parameter you are defining.

Your options are: M Map, R Restrictor, P Position, V Vary

Using Arrays as Parameters

You can create elements in an array that are similar to parameter definitions. Use the following information to pass these elements as parameters.

Arrays can be defined to contain any subset of the fields in the model.

Arrays can also be specified as parameters to any function.

Using arrays allows you to define any subset of fields as parameters to any function.

Post Comments