$CHAIN Statement

The $CHAIN statement allows source code to be read in from an external file item.

Format

$CHAIN[filename] item-ID

Parameter(s)

filename

Name of the file containing the item. If filename is omitted, the current file is assumed.

item-ID

item-ID of the item containing the source code

Description

The $CHAIN statement directs the compiler to read source code from the specified file item and compile it as if it were written directly in the current program. The $CHAIN statement differs from the $INCLUDE and $INSERT statements in that the compiler does not return to the main program after compiling the source code in the specified file item; any statements appearing after the $CHAIN statement are ignored.

PC/OS versions prior to Mentor PRO 4.0 limited the size of items to 32K. Therefore, the $CHAIN statement was designed for programs with source code larger than 32K. By using $CHAIN statements, very long source code may be broken up into several file items and $CHAINed together, as long as the object code does not exceed 248K.

Example

To transfer compilation to source code in item PROG2 in file BP, the code might read:

$CHAIN BP PROG2

In the next example, a very long program is broken up into 3 different source file items, each one but the last ending with a $CHAIN statement that calls the next.

The source file item CUST.ENTRY:

EQUATE TRUE TO 1, FALSE TO 0,

   AM TO CHAR (254), VM TO CHAR (253),

   .

   .

   .

PRINT "PRINT REPORTS?"

$CHAIN CUST.ENTRY2

At the end of CUST.ENTRY, source file item CUST.ENTRY2 is called with a $CHAIN statement. CUST.ENTRY2 contains:

INPUT ANSWER

   .

   .

   .

FOUND = FALSE

FOR I = 1 TO NO.OF.ELTS UNTIL FOUND

   IF CUST.ARRAY (I) < 1, 3 > = NAME THEN

$CHAIN CUST.ENTRY3

CUST.ENTRY2, in turn, calls CUST.ENTRY3, which reads:

      FOUND = TRUE

   END

NEXT I

.

.

.

Note in the example that a FOR loop and an IF construct are broken over two file items.

See Also

Statement and Function Reference