COBOL Manual for TNS and TNS/R Programs

Creating and Compiling HP COBOL Source
Programs
HP COBOL Manual for TNS and TNS/R Programs522555-006
22-34
Including Text From a SOURCE Library
Including Text From a SOURCE Library
Text from a SOURCE library is included in a HP COBOL source program with a
SOURCE directive. A SOURCE directive must be the last directive on its line.
When the compiler reads a SOURCE directive, it suspends reading from its primary
source file and begins reading (entire lines) from a specified section of a SOURCE
library. The SOURCE directive does not have anything like the COPY statement’s
REPLACING phrase; it cannot replace library text-words with different text-words.
The SOURCE directive’s most common uses are:
To copy File Descriptions into the Environment Division
To copy record or group descriptions into the Data Division
To copy blocks of code lines into the Procedure Division
Example 22-8. Including Text From a Source File
Library file, SRCFILE:
?SECTION NAMEREC
01 NAME-REC.
03 LAST-NAME PICTURE X(15).
03 M-I PICTURE X(1).
03 FIRST-NAME PICTURE X(15).
03 TITLE PICTURE X(5).
?SECTION ADDRREC
01 ADDR-REC.
03 NUMBER PICTURE X(5).
03 STREET PICTURE X(15).
03 APT-NUM PICTURE X(3).
03 CITY PICTURE X(15).
03 STATE PICTURE X(2).
03 ZIPCODE PICTURE X(5).
?SECTION DATEREC
01 DATE-REC.
03 MONTH PICTURE X(9).
03 DAY PICTURE X(2).
03 YEAR PICTURE X(4).
Line in HP COBOL source program:
?SOURCE SRCFILE