$INCLUDE/$INSERT Statement

$INCLUDE and $INSERT statements allow source code to be read in from an external file item.

Format

$INCLUDE[filename] item-ID

$INSERT[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 $INCLUDE and $INSERT statements direct the compiler to read in source code from the specified file item and compile it as if it were written directly in the current program. The $INSERT statement is identical to the $INCLUDE statement.

The $INCLUDE statement differs from the $CHAIN statement in that the compiler returns to the main program and continues compiling with the statement following the $INCLUDE.

The $INCLUDE and $INSERT statements are particularly useful to read in file items containing COMMON and EQUATE statements, or any statements which a programmer might want to be consistent between several different programs. Be careful, however, of naming conflicts between file items.

$INCLUDE statements may be nested; that is, a program may $INCLUDE a file item which $INCLUDEs another file item, up to 40 levels. However, the total object code when compiled may not exceed 248K bytes.

If the source code read in through an $INCLUDE statement generates a run-time error message, the error message displays only the number of the line which contains the $INCLUDE statement. The line numbers from the external file item are not kept in the object code.

Examples

To read in the source code written in item SETUP in file BP, the code might read:

$INCLUDE BP SETUP

In the next application, the $INCLUDE statement is used at the beginning of a program to read in common variables, equated variables, and the part of the program which opens the file.

$INCLUDE STARTUP

PRINT "ENTER THE CUSTOMER ID : ":

INPUT ID

MATREAD PHONE.ARRAY FROM CUSTFILE, ID ELSE

   PRINT "CANNOT READ RECORD!"

   STOP

END

The file item STARTUP contains the text:

COMMON PHONE.ARRAY(10), PHONEREC

EQUATE TRUE TO 1, FALSE TO 0, AM TO CHAR(254)

PROMPT " "

OPEN "CUSTOMERS" TO CUSTFILE ELSE

   ABORT 201, "CUSTOMERS"

END

See Also

Statement and Function Reference