Code Clause
This clause can be used to prefix non-printable fields to the report records. Such information is typically of use to de-spooling software and special device handlers.
Code Clause: Coding Rules
-
The forms CODE IS and WITH CODE are synonymous.
-
The CODE clause is not permitted if the associated FD entry is followed by a record description entry. This is because it would be illogical to WRITE independently to the file if there is also a CODE. See Select and FD: Coding Rules and the rest of this section for further details.
-
The literal, if coded, must be a non-numeric literal.
-
If an identifier operand is used, it must represent a group field or a non-edited alphanumeric elementary field. The associated FD entry for the file must then have either a BLOCK CONTAINS clause with the CHARACTERS option or a RECORD CONTAINS clause, or both.
-
If a mnemonic-name operand is coded, there must be an entry in SPECIAL-NAMES of the form:
literal IS mnemonic-name
where literal is non-numeric. The value of literal is then used as the CODE value. If you require compatibility with ANS-68 report writer, one character is the norm. For ANS-85 compatibility, you should code a two-character literal.
-
If your report file description has a RECORD or BLOCK CONTAINS integer CHARACTERS clause and there is no MODE clause after SELECT, the size of the CODE, plus the maximum line width, must not be greater than the number of CHARACTERS specified.
-
Not all RD entries associated with the same report file need have a CODE clause and all the CODE clauses need not specify an operand of the same length. However, if the report file does not use a user-written file-handler that might ascribe some meaning to different lengths of CODE, it may be impossible to recognize the CODE at the front of each records and decide how long it is.
Code Clause: Operation
-
The presence of a CODE clause implicitly establishes the special register CODE-VALUE in the Report Control Area. You may alter the contents of CODE-VALUE at any time. If there are several CODE clauses in different RDs within your program, you must qualify CODE-VALUE by the report-name.
-
If you do not specify a MODE clause after the SELECT for the corresponding report file, the value of the CODE is prefixed to every record written by report writer to the report file. The CODE is placed immediately before the carriage control character:
If the length of the CODE is not the same for every report being written to the file, or if some of the reports have no CODE, then a MODE PRNT clause is assumed in default, causing the built-in PRNT file handler to be invoked.
-
If you do specify a MODE clause after the SELECT, CODE-VALUE will be passed to the Independent Report File Handler in the Report Control Area. Built-in file-handlers (PRNT, MODL, NOPF) treat the CODE in the authodox way just described, but a user-written file handler may interpret CODE-VALUE in any desired way. Hence, your own user-written file handler may use the CODE clause for the passing of any additional information that is required by the file handler but does not necessarily appear in the report line itself. See Independent Report File Handlers for more information.
-
If a literal or mnemonic-name is used, the size of CODE-VALUE is the length of literal, and CODE-VALUE is preset to the value of literal.
-
If an identifier is used, the length of CODE-VALUE is the (maximum) record length given in the RECORD CONTAINS clause, minus the LINE LIMIT. The current value of identifier is stored in CODE-VALUE at the start of the processing for each DETAIL or CONTROL HEADING for the report. This does not occur if the current group is a CONTROL FOOTING, so as to ensure that only pre-control-break values will be used. In the following example (assuming ADV is in effect) the size of CODEVALUE is 140 minus 132 = 8 bytes, and the field WC-ACCOUNT-REF is moved to CODE-VALUE at the start of each non-CF body group:
Compatibility
OS/VS and DOS/VS COBOL allow only the format: WITH CODE mnemonic-name. The corresponding literal defined in SPECIAL-NAMES must be one character.