RPG/400 Help

/COPY (Positions 7-11)

The /COPY compiler directive causes records from other files to be inserted, at the point where the /COPY occurs, with the file being compiled. The inserted files may contain any valid specification except /COPY.

The /COPY statement is entered in the following way:

Positions
Entry
7-11
/COPY
12
Blank
13-44
Identifies the location of the member to be copied (merged). The format is:

libraryname/filename,membername (RPG/400 AS/400 environment)

45-49
Blank
50-80
Comments

Examples of the /COPY Compiler Directive Statement shows some examples of the /COPY directive statement.

Note:
Programs compiled under the AS/400 environment can use the extended naming convention. If extended names are used, each part of the qualified name must be enclosed in quotation marks.

For more information see How the Compiler Recognizes a Compiler /COPY, Conditions on the Members That Are Copied, Sequence Numbering of the Listing after a Compile, and Results of the /COPY during Compile.

How the Compiler Recognizes a Compiler /COPY

Use the rules for RPG/400 symbolic names, to specify the library files and member.

  1. The CRTRPGPGM command will treat any /COPY directive encountered in the source code as a compiler copy and does not accept the sorting or string replacement functions.

Examples of the /COPY Compiler Directive Statement


C/COPY MBR1 1
 
I/COPY SRCFIL,MBR2 2
 
O/COPY SRCLIB/SRCFIL,MBR3 3
 
O/COPY "SRCLIB!"/"SRC>3","MBR^3" 4

1
Copies from member MBR1 in source file QRPGSRC. The current library list is used to search for file QRPGSRC.
2
Copies from member MBR2 in file SRCFIL. The current library list is used to search for file SRCFIL. Note that the comma is used to separate the file name from the member name.
3
Copies from member MBR3 in file SRCFIL in library SRCLIB.
4
Copies from member "MBR^3" in file "SRC>3" in library "SRCLIB!"

Conditions on the Members That Are Copied

If the member being copied from is not a source type file, meaning that the file was not created with the filetype *SRC, then a message is issued. This condition does not stop compilation and the copy function is still processed.

The members being copied can contain any valid RPG/400 specifications except another /COPY directive.

The member being copied can contain a control specification (form type H), which is then processed as if it were part of the source code. Therefore, the first statement in the program can be a /COPY directive pointing to the member containing the control specification. The H specification must still follow the rules governing its use (refer to Control Specifications) and precede any other RPG/400 specification.

Results of the /COPY during Compile

During compilation, the specified file members are merged into the program at the point where the /COPY statement occurs. Any overrides defined that apply to the specified file and member are ignored.

Sequence Numbering of the Listing after a Compile

For an RPG/400 compile, the low-order 6 digits of the 8-character sequence number in the listing reflect the original source sequence number of the /COPY member. In this way you can correlate the compiler listing sequence numbers (the last 6 digits) to the source member sequence numbers (in SEU).

The high order 2 digits of the sequence number are made up of the characters A through Z and 0 through 9 in the following order: A, B, C, ..., Z, 1, 2, ..., 9, A0, AA, AB, ..., AZ, A1, A2, ..., A9, B0, BA, ..., ZZ, ..., Z9, 10, ..., 99.

This structure allows for up to 1295 different increments of the high order sequence number.

Each /COPY directive causes the high order 2 characters of the sequence number for all the code lines brought in by this /COPY to be incremented in value.

If the copied code contains specifications for externally defined files, each externally defined file may cause the high-order characters of the sequence number to be incremented in value two more times: once for input specifications, and once for output specifications.

If more than 1295 increments result from /COPY directives and/or externally defined files, a message is issued. A message is also issued if more than 50 externally defined files are specified. Remember that one externally defined file can take up two increments: for input and output specifications.

The low order 6 digits of the sequence number is incremented by one for each I specification generated for an externally defined file.

If the program is compiled by RPG/400, records that are copied into the program in this way contain a "+" adjacent to the sequence number field on the left side of the listing, between the sequence number and the form type field. If the Program Verifier is used, the lines from the copied file are identified on the listing by line numbers which start at 100001. For example, the third line in the first copied file would be 100003 and the seventh line of the fourth copied file would be 400007.

Note:
The /COPY directive is treated as a comment line. Because the compiler may have to read ahead to gather sufficient information about specifications, comments, or /COPY directives, certain lines may appear on the listing out of sequence.


[ Top of Page | Previous Page | Next Page | Table of Contents ]