INFER

Stacks are array variables containing rows and columns. When defining a stack and its structure, provide a name for the stack and a name, format, and order for each of the columns in the stack.

Stacks can be defined in two ways:

  • Performing actual data retrieval with the NEXT command, the stack is defined and populated at the same time. The stack is defined with all the segments that are retrieved. This is convenient when the procedure is processing on the same physical platform as the data source.
  • If the procedure referring to a stack does not retrieve data, you must issue the INFER command to define the structure of the stack. When you issue the command, you specify a data source path. INFER defines the stack with columns corresponding to each field in the specified path. The Master File provides the names and formats of the columns. INFER may only be used to define stack columns that correspond to data source fields. To define user-defined variables, use the COMPUTE command.

    A procedure that includes an INFER command must specify the name of the corresponding Master File in the MAINTAIN command, and must have access to the Master File.

Use the INFER Command

The syntax of the INFER command is

INFER path_spec INTO stackname [;]

where:

path_spec

Identifies the path to be defined for the data source. To identify a path, specify its anchor and target segments. If the path contains only one segment, the anchor and target are identical. Simply specify the segment once. For paths with multiple segments, to make the code clearer to readers, you can also specify segments between the anchor and target.

To specify a segment, provide the name of the segment or of a field within the segment.

stackname

Is the name of the stack.

;

Terminates the command. Although the semicolon is optional, you should include it to allow for flexible syntax and better processing. For more information about the benefits of including the semicolon, see Terminating Command Syntax.

Inferring Two Stacks

In the following called procedure, two INFER commands define the EmpClasses and ClassCredits stacks:

MAINTAIN FROM EmpClasses INTO ClassCredits
INFER Emp_ID Ed_Hrs Date_Attend Course_Code INTO EmpClasses;
INFER Emp_ID Course_Code Grade Credits INTO ClassCredits;
.
.
.
END

Commands Related to INFER

  • CALL. Can be used to call one Maintain Data procedure from another.
  • COPY. Can be used to copy data from one stack to another.
  • COMPUTE. Can be used to define the contents of a stack for non-data source fields.

Defining Non-Data Source Columns

To define stack columns in a procedure for non-data source fields (fields created with the COMPUTE command), you do not need to provide a value for the column. The syntax is:

COMPUTE stackname.target_variable/format = ;

Note that the equal sign is optional when the COMPUTE is issued solely to establish the format.

In the following example, the stack column TempEmp was passed to the called procedure. The COMPUTE is issued in the called procedure to define the variable prior to use:

COMPUTE EmpClasses.TempEmp_ID/A9 ;