CHAIN Statement

Allows a DataBasic program to exit and pass values to any TCL command or separately compiled program. See also the COMMON and ENTER statements.

Syntax

CHAIN command

Syntax elements

command A string expression that evaluates to a valid TCL command, cataloged DataBasic program or Proc in the user's MD.

Operation

The CHAIN statement allows values to be passed to chained program via the COMMON statement, provided the I option is used. Consider the following two programs:

Program ABC in file BP

Program XYZ in file BP

COMMON A,B(2)
A=500
B(1)=1;B(2)=2
CHAIN "RUN BP XYZ (I)"
END
COMMON J(2),K
PRINT J(1),J(2),K
END

Program ABC causes program XYZ to be executed. The I option in the RUN command specifies that the COMMON variables are not to be reinitialized, allowing program ABC to pass the values 500, 1 and 2 to program XYZ. Program XYZ prints the values 500, 1 and 2.

Note

  • Control is never returned to the program executing the CHAIN statement.

  • You can CHAIN to a program that calls a subroutine or external function, but it is not advisable to CHAIN from a subroutine or external function because the subroutine or function will never return.

Passing data in COMMON variables

You can use COMMON variables to pass data from a CHAINing program to a CHAINed program. However, workspace used for COMMON variables is also used by other system software. The only way to pass COMMON variables using the CHAIN statement is to use the RUN command, or to specify the name of a cataloged program, with the I option. This preserves the COMMON variables from the CHAINing program to the CHAINed program.

The following does not work: CHAINing to a Proc that invokes a DataBasic program with the RUN command and the I option.

All COMMON variables form a long vector in row major order, and, on a CHAIN, are assigned left to right to the CHAINed program's COMMON variables.

Passing data by means of the DATA Statement

You can use the DATA statement in a chaining program to specify arguments that are to be passed to a CHAINed statement or command. The arguments are specified as an ordered list, separated by commas. Individual arguments must be less than 140 bytes long.

A CHAINed DataBasic program can retrieve data specified in a DATA statement by means of the INPUT statement.

The CHAIN statement can also be used to execute a Proc. Stacked data specified by DATA statements in the CHAINing program appears to the Proc as data in the secondary output buffer. Proc input commands ignore stacked data. However, the data can be copied.

Passing data to the Proc primary input buffer

When CHAINing to a Proc, the primary input buffer is initialized to contain the value of the CHAIN expression. Thus in the statement:

CHAIN "PROCNAME PARAM1 PARAM2"

the Proc primary input buffer would contain 3 parameters with 'PROCNAME' being the first parameter.

Examples

CHAIN "RUN FN1 LAX (I)"

Executes program LAX in file FN1. The I option specifies that COMMON variables are not reinitialized and the program executing the CHAIN statement can pass COMMON variables to program LAX.

CHAIN "LISTU"

Executes the LISTU PROC.

X = "LIST INV"
CHAIN X

Executes the English command LIST.