HP COBOL II/XL Reference Manual Series 900 HP 3000 Computer Systems ABCDE HP Part No. 31500-90001 Printed in U.S.A.
Notice The information contained in this document is subject to change without notice. HEWLETT-PACKARD MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Hewlett-Packard shall not be liable for errors contained herein or for incidental or consequential damages in connection with the furnishing, performance or use of this material.
Printing History New editions are complete revisions of the manual. Update packages, which are issued between editions, contain additional and replacement pages to be merged into the manual by the customer. The dates on the title page change only when a new edition or a new update is published. No information is incorporated into a reprinting unless it appears as a prior update; the edition does not change when an update is incorporated.
iv
Preface This reference manual documents the HP COBOL II language for programming on Hewlett-Packard computer systems. HP COBOL II is based on the 1974 and ANSI COBOL'1985 Standard X3.23-1985. This manual is a reference text for programmers who have a working knowledge of COBOL. The objective of the HP COBOL II Reference Manual is to guide you in writing source programs in HP COBOL II, compiling them into object programs, preparing and executing them.
Preface Appendix F Appendix G Appendix H Lists COBOL reserved words. Describes the COBEDIT program and COPY libraries. Describes machine-dependent information for MPE XL systems.
Preface What's New in This Release This section brie y describes what is new in this release of HP COBOL II/XL and where to nd more information.
Addendum toANSI ANSICOBOL'85: COBOL'85:Built-In Built-In COBOL Functions Addendum to COBOL Functions This version of the HP COBOL II/XL compiler introduces the 42 built-in COBOL functions recently de ned by Addendum 1 of the ANSI COBOL'85 standard. Chapter 10, \COBOL Functions," describes all the functions.
Compatibility and the $CONTROL POST85 Option Compatibility and the $CONTROL POST85 Option To use the new COBOL functions, you must use the $CONTROL option POST85. This option was added because the COBOL functions introduce a new reserved word, FUNCTION. If your existing COBOL programs use the word FUNCTION as an identi er, those programs will continue to compile without $CONTROL POST85.
The TZEnvironment EnvironmentVariable Variable The TZ Use the TZ environment variable to set the time zone. The COBOL functions CURRENT-DATE and WHEN-COMPILED use the value of this variable and the value of the hardware clock when reporting their results. For more information, see Chapter 10, \COBOL Functions.
HP COBOL II/XL Reference Manual Supplement HP COBOL II/XL Reference Manual Supplement The HP COBOL II/XL Reference Manual Supplement (31500-90005) is no longer a separate manual. It has been moved into Appendix H of this manual.
Previous HP COBOL COBOLII/XL II/XL Documents Previous HP Documents Information from the HP COBOL II/XL Technical Addendum , published in April, 1990 for MPE XL Release 2.1 and the HP Communicator article, published for MPE XL Release 3.0 have been incorporated into this manual. These documented the following features: The $CONTROL NLS option. See Appendix H, \MPE XL System Dependencies," for more information. Dynamic le assignment with the USING phrase of the ASSIGN clause.
Acknowledgement At the request of the American National Standards Institute (ANSI), the following acknowledgement is reproduced in its entirety: Any organization interested in reproducing the COBOL standard and speci cations in whole or in part, using ideas from this document as the basis for an instruction manual or for any other purpose, is free to do so.
Conventions Notation UPPERCASE and UNDERLINING Description Change bars in the margin show where substantial changes have been made to this manual since the last edition. (Chapter 10 and Appendix H are new to this manual, but are not marked with change bars.) Within syntax statements, characters in uppercase must be entered in exactly the order shown. Uppercase words that are underlined are keywords that are always required when the clause or statement in which they appear is used in your program.
[ ] Within syntax statements, brackets enclose optional elements. In the following example, brackets around ,TEMP indicate that the parameter and its delimiter are not required: PURGE lename[,TEMP] When several elements within brackets are stacked, you can select any one of the elements or none.
<, >, =, <=, >=, <> ; , . ^ NNNNNNNNNNNNNNNNNNNNNNN Shading LG200026 198 xvi These symbols are used in conditional statements to represent the keywords LESS THAN, GREATER THAN, EQUAL TO, LESS THAN OR EQUAL TO, GREATER THAN OR EQUAL TO, and NOT EQUAL TO, respectively. Although these symbols represent keywords, they are not underlined. The semicolon is used only to improve readability and is always optional. The comma is used only to improve readability, and is always optional.
Contents 1. Introduction ANSI Standard Compliance . . . . . . . . . . . . . . . . ANSI COBOL'85 Features in HP COBOL II . . . . . . . . . ANSI Features Added Since ANSI COBOL'85 . . . . . . . Compatibility Considerations . . . . . . . . . . . . . . . . Compatibility between ANSI COBOL'74 and ANSI COBOL'85 Compatibility of COBOL Functions . . . . . . . . . . . . HP Extensions . . . . . . . . . . . . . . . . . . . . . Portability to HP from Other Vendors . . . . . . . . . . .
Embedded Quotation Marks in Nonnumeric Literals PICTURE Character Strings . . . . . . . . . . . Comment Entries . . . . . . . . . . . . . . . . Comment Lines . . . . . . . . . . . . . . . . Separators . . . . . . . . . . . . . . . . . . . . Character Set . . . . . . . . . . . . . . . . . . Coding Rules . . . . . . . . . . . . . . . . . . . Sequence Number (Columns 1 through 6) . . . . . Program Text (Columns 8 through 72) . . . . . . Continuation Lines . . . . . . . . . . . . . . . Debugging Lines . . . . .
6. ENVIRONMENT DIVISION ENVIRONMENT DIVISION Format . . . . . . . . . . . . . . . . . ENVIRONMENT DIVISION Syntax Rules . . . . . . . . . . . . . . . CONFIGURATION SECTION . . . . . . . . . . . . . . . . . . . . SOURCE-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . OBJECT-COMPUTER Paragraph . . . . . . . . . . . . . . . . . . MEMORY-SIZE Clause . . . . . . . . . . . . . . . . . . . . . . PROGRAM COLLATING SEQUENCE Clause . . . . . . . . . . . . SEGMENT-LIMIT Clause . . . . . . . . . . . . . . . . .
RECORD KEY Clause . . . . . . . . . . . . . . . . . . . DUPLICATES Phrase . . . . . . . . . . . . . . . . . . . RESERVE Clause . . . . . . . . . . . . . . . . . . . . . . I-O-CONTROL Paragraph . . . . . . . . . . . . . . . . . . . SAME Clause . . . . . . . . . . . . . . . . . . . . . . . SAME AREA Clause . . . . . . . . . . . . . . . . . . . SAME RECORD AREA Clause . . . . . . . . . . . . . . SAME SORT AREA and SAME SORT-MERGE AREA Clauses MULTIPLE FILE Clause . . . . . . . . . . . . . . . . . . 7.
Size of Elementary Data Items . . . . . . . . . . . . . Editing Rules . . . . . . . . . . . . . . . . . . . . . Simple Insertion Editing . . . . . . . . . . . . . . . Special Insertion Editing . . . . . . . . . . . . . . . Fixed Insertion Editing . . . . . . . . . . . . . . . Floating Insertion Editing . . . . . . . . . . . . . . Zero Suppression Editing . . . . . . . . . . . . . . Precedence Rules . . . . . . . . . . . . . . . . . . REDEFINES Clause . . . . . . . . . . . . . . . . . . SIGN Clause . . . . .
ANSI Standard Relation Conditions . . . . . . . . . Comparison of Numeric Operands. . . . . . . . . . Comparisons Using Index Names and Index Data Items. Comparison of Nonnumeric Operands. . . . . . . . . Condition Name Conditions . . . . . . . . . . . . . Intrinsic Relation Conditions . . . . . . . . . . . . . Correct Example . . . . . . . . . . . . . . . . . Incorrect Examples . . . . . . . . . . . . . . . . Complex Conditions . . . . . . . . . . . . . . . . . . Combined Conditions . . . . . . . . . . . .
EVALUATE Statement . . . . . . . . . . . . . . . . . . . Subjects and Objects . . . . . . . . . . . . . . . . . . . Correspondence Between Subjects and Objects . . . . . . . Evaluation of Subjects and Objects . . . . . . . . . . . . Comparison Operation of EVALUATE . . . . . . . . . . . . Execution of EVALUATE . . . . . . . . . . . . . . . . . EXAMINE Statement . . . . . . . . . . . . . . . . . . . . TALLYING Phrase . . . . . . . . . . . . . . . . . . . . REPLACING Phrase . . . . . . . . . . . . . . . . . .
READ Statement - Format 1 . READ Statement - Format 2 . READ Statement - Format 3 . RELEASE Statement . . . . . RETURN Statement . . . . . REWRITE Statement . . . . . FROM Phrase . . . . . . . SEARCH Statement . . . . . . SEARCH Statement - Format 1 VARYING Phrase . . . . . . SEARCH Statement - Format 2 SEEK Statement . . . . . . . SET Statement . . . . . . . . SET Statement - Format 1 . . SET Statement - Format 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10. COBOL Functions The $CONTROL POST85 Option . . ANSI85 Entry Point . . . . . . . . . Function Types . . . . . . . . . . . Function Parameters . . . . . . . . Using ALL as a Table Subscript . . Precision of Numeric Functions . . . Calling COBOL Functions . . . . . . Examples . . . . . . . . . . . . ACOS Function . . . . . . . . . . . ANNUITY Function . . . . . . . . ASIN Function . . . . . . . . . . . ATAN Function . . . . . . . . . . . CHAR Function . . . . . . . . . . COS Function . . . . . . . . . . .
WHEN-COMPILED Function . . . . . . . . . . . . . . . . . . . . . Setting the TZ Environment Variable . . . . . . . . . . . . . . . . . 10-61 10-62 11. Interprogram Communication Transfer of Control . . . . . . . . . . . . . . . . . . . . Reference to Common Data and Files . . . . . . . . . . . . Reference to Common Data through Parameter Passing . . . . Reference to Common Data and Files through External Objects PROGRAM-ID Paragraph . . . . . . . . . . . . . . . . COMMON Clause . . . . . . . . . . . . . .
Segmentation Considerations . . . . . . . . . . . . . . . . . . . . . 13. Debug Module WITH DEBUGGING MODE Clause . . USE FOR DEBUGGING statement . . . Debugging Lines . . . . . . . . . . . The ANSI Debug Module Example . . Using the ANSI Debug Module Example . . . . . 13-2 13-3 13-6 13-7 13-8 14. Source Text Manipulation COPY Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . REPLACING Phrase . . . . . . . . . . . . . . . . . . . . . . . . REPLACE Statement . . . . . . . . . . . . . . . . .
NOSEQ Parameter . . . . . . . . . . INC Parameter . . . . . . . . . . . . Compiler-Dependent Options . . . . . . . . $COPYRIGHT Command . . . . . . . . $PAGE Command . . . . . . . . . . . $TITLE Command . . . . . . . . . . . $VERSION Command . . . . . . . . . . $CONTROL Command . . . . . . . . . ANSISORT . . . . . . . . . . . . . ANSISUB . . . . . . . . . . . . . . BOUNDS . . . . . . . . . . . . . . CHECKSYNTAX . . . . . . . . . . . CODE . . . . . . . . . . . . . . . . NOCODE . . . . . . . . . . . . . .
C. Di erences Between ANSI COBOL'74 and ANSI COBOL'85 ANSI74 Entry Point Di erences . . . . . . . . . . . . . . . Incompatibilities between ANSI COBOL'74 and ANSI COBOL'85 Syntax Incompatibilities . . . . . . . . . . . . . . . . . . Run-time Incompatibilities . . . . . . . . . . . . . . . . . Obsolete Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C-1 C-3 C-3 C-3 C-6 D. ASCII and EBCDIC Character Sets How to Use This Table . . . . . . . . . . .
SYMDEBUG=XDB . . . . . . . . . . . . . . VALIDATE and NOVALIDATE . . . . . . . . Control Options that Work Di erently . . . . . . . ANSISUB . . . . . . . . . . . . . . . . . . BOUNDS . . . . . . . . . . . . . . . . . . CODE . . . . . . . . . . . . . . . . . . . . USLINIT . . . . . . . . . . . . . . . . . . Obsolete Control Options . . . . . . . . . . . . Data Alignment and Limits on MPE XL . . . . . . . Alignment . . . . . . . . . . . . . . . . . . . Limits on Data Items . . . . . . . . . . . . . .
Figures 2-1. 2-2. 4-1. 7-1. 8-1. 8-2. 8-3. 8-4. 8-5. 9-1. 9-2. 9-3. 9-4. 9-5. 9-6. 9-7. 12-1. H-1. H-2. H-3. COBOL Structure Hierarchy . . . . . . . . . . . . . . . . . . . . . 2-2 Program Structure Example . . . . . . . . . . . . . . . . . . . . . 2-3 Record Desctiption Entry . . . . . . . . . . . . . . . . . . . . . . 4-3 Example of the LINAGE Clause and its Logical Representation . . . . . . 7-18 Evaluation of the hierarchical level condition-1 and condition-2 and . . . condition-n . . . . . . . . . . .
Tables 1-1. 1-2. 1-3. 3-1. 3-2. 3-3. 3-4. 3-5. 3-6. 4-1. 4-2. 4-3. 4-4. 6-1. 6-2. 6-3. 7-1. 7-2. 7-3. 7-4. 7-5. 7-6. 7-7. 7-8. 7-9. 8-1. 8-2. 8-3. 8-4. 8-5. 8-6. 9-1. 9-2. 9-3. 9-4. 9-5. 9-6. 9-7. 10-1. 10-2. 10-3. ANSI COBOL'85 Organization . . . . . . . . . . . . . . . . . . . . 1-2 HP COBOL II Compiler Conformity Levels . . . . . . . . . . . . . . 1-3 Terms Used in This Manual . . . . . . . . . . . . . . . . . . . . . 1-4 Special Register Words . . . . . . . . . . . . . . . . . . . . . . .
10-4. 10-5. 10-6. 10-7. 11-1. 11-2. A-1. B-1. B-2. B-3. C-1. D-1. F-1. G-1. H-1. H-2. H-3. H-4. H-5. H-6. H-7. Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . Financial and Statistical Functions . . . . . . . . . . . . . . . Trigonometric Functions . . . . . . . . . . . . . . . . . . . . Time Zones and TZ Environment Variable Values . . . . . . . . . Types of Subprograms and How to Specify Them . . . . . . . . . Relationship Between EXIT PROGRAM, STOP RUN and GOBACK Statements . . . . . . .
1 Introduction COBOL (Common Business Oriented Language) is the most widely used programming language for commercial applications. Hewlett-Packard's COBOL II is based on ANSI COBOL as speci ed in the American National Standard Programming Language COBOL (ANSI X3.23a-1989). It o ers the following important features: Compatibility with American National Standards Institute (ANSI) COBOL at the highest level of all the required COBOL modules.
Introduction Table 1-1. ANSI COBOL'85 Organization Module Function Nucleus Contains language elements necessary for internal processing. Sequential I/O Module Provides language elements for de nition and access of sequentially organized external les. Relative I/O Module Provides capability for de ning and accessing mass storage les in which records are identi ed by relative record number.
Introduction Hewlett-Packard's COBOL II compiler conforms to the high level of the ANSI COBOL X3.23-1974 speci cation and to the high level of the ANSI COBOL X3.23a-1989 speci cation. It meets the corresponding level of the United States Government Federal Information Processing Standard as described in FIPS PUB 21-3. Some of the individual modules meet the high level requirements as described in Table 1-2. Table 1-2.
Introduction Table 1-3 lists the terms used in this manual. Table 1-3. Terms Used in This Manual This Term Refers To ANSI COBOL'74 The 1974 ANSI COBOL standard. ANSI COBOL'85 The 1985 ANSI COBOL standard. ANSI74 The compiler entry point used to invoke COBOL features of ANSI COBOL'74 plus HP extensions. ANSI85 The compiler entry point used to invoke COBOL features of ANSI COBOL'85 plus COBOL functions and HP extensions.
Introduction ANSI COBOL'85 Features in HP COBOL II Features in the X3.23a-1989 American National Standard Programming Language COBOL that are in HP COBOL II are shown below. These features provide structured programming capabilities to make coding and maintenance easier. They also provide capabilities to enhance the manipulation of data initialization and extend I/O status codes for reporting I/O errors. EVALUATE statement. In-line PERFORM. Scope-delimited statements. CONTINUE statement.
Introduction Compatibility Considerations There are several compatibility issues to consider when using the HP COBOL II compiler. Compatibility between ANSI COBOL'74 and ANSI COBOL'85 The HP COBOL II compiler is compatible with the ANSI COBOL'74 standard. Through the use of entry points to the compiler you can choose which standard to execute, thereby avoiding any conversion issues between the two standards.
Introduction Portability to HP from Other Vendors If you are transferring COBOL source programs and data to an HP computer system from another system, ANSI standard features are compatible. Any extension to accommodate vendor operating systems and le systems need to be examined for conversion e orts. Consult your HP representative for assistance and advice.
2 Program Structure COBOL is similar to the English language in both structure and content. Structurally, for example, COBOL programs are made up of such familiar constructs as paragraphs, sentences, statements, and clauses. These constructs, in turn, contain such elements as words, names, verbs, and symbols. Program constructs are described in this chapter of the manual; program elements are described in Chapter 3. Within the context of COBOL, constructs and elements all have very speci c meanings.
Program Structure Figure 2-1.
Program Structure: Divisions Figure 2-2 is an example of the COBOL program structure. The numbers indicate speci c parts of the program. They are described in more detail later in this chapter as \item". For example, under the section \Division Header Format", the phrase \items 1 through 4" refers to the circled numbers 1 through 4. Figure 2-2. Program Structure Example The items shown in Figure 2-2 are: 1. Identi cation Division. 2. Environment Division. 3. Data Division. 4. Procedure Division. 5.
Program Structure: Divisions Divisions A division is the rst level (highest) construct in a COBOL program. COBOL programs are partitioned into the following four divisions, which appear in the order listed: IDENTIFICATION DIVISION: Speci es the program name and other items used to uniquely identify the program. This division is required in every COBOL program. ENVIRONMENT DIVISION: Describes the computer and peripheral devices used to compile and execute the program, and the data les used by the program.
Program Structure: Sections Sections A section is the second level construct in a COBOL program. In the source program, sections allow you to group logically related items together within a division. In the PROCEDURE DIVISION, you can organize logically related functions into the same sections in such a way that often used routines reside in main memory for longer periods of time than routines used infrequently.
Program Structure: Sections In the PROCEDURE DIVISION, the section header consists of a user-de ned section name that identi es the section, followed by the word \SECTION", followed by an optional segment number, followed by a period and a space. In the PROCEDURE DIVISION, unlike the ENVIRONMENT and DATA DIVISIONs, names are not restricted to speci c words, so you can supply any section names you desire.
Program Structure: Paragraphs Paragraphs A paragraph is the third level construct in a COBOL program. Paragraphs allow you to break your program into even more elementary units. One paragraph (the PROGRAM-ID paragraph) is required in the IDENTIFICATION DIVISION. Paragraphs are optional in the ENVIRONMENT and PROCEDURE DIVISIONs. They are not used in the DATA DIVISION.
Program Structure: Paragraphs Paragraph Header and Name Format The paragraph header, used in the IDENTIFICATION and ENVIRONMENT DIVISIONs, consists of a COBOL reserved word identifying the paragraph, followed by a period and a space. In the IDENTIFICATION DIVISION, only the following headers are permitted: PROGRAM-ID. AUTHOR. INSTALLATION. DATE-WRITTEN. DATE-COMPILED. SECURITY. REMARKS. (This is an HP extension to the ANSI COBOL standard.
Program Structure: Sentences, Statements, Clauses Sentences, Statements, and Clauses Within a paragraph, sentences (in the PROCEDURE DIVISION) and entries (in the IDENTIFICATION, ENVIRONMENT, and DATA DIVISIONs) may appear. Within a sentence, in turn, one or more statements can be written. These items provide a further syntactic breakdown of your program. In structure, they closely resemble their English language counterparts.
3 Program Elements All COBOL language constructs are made up of basic elements comprised of character strings and separators. A character string is a character or sequence of characters that forms a COBOL word, literal, PICTURE character string, or comment entry (as de ned later in this chapter). Every character string is enclosed by a separator that is either a single special character (such as a period, comma, semicolon, or blank) or a sequence of special characters.
Program Elements Character Strings Character strings may form: Words. Literals. PICTURE character strings. Comment entries. Words In COBOL, a word is generally the name of some entity such as a function, paragraph, register, section, data item, constant, or other syntactical term used in a format description. There are four types: Reserved words. User-de ned words. System names. Function-Names. Each word is limited to a maximum length of 30 characters.
Program Elements Keywords. A keyword is a reserved word that is required in a statement or clause. You must enter the keywords where they are used. In the division header below, the words PROCEDURE, DIVISION, and USING are keywords. (In the format descriptions in this manual, all keywords are denoted by underlined upper case letters.) The USING clause is optional, as indicated by the brackets. But if you use this clause in your program, you must include the keyword USING.
Program Elements Table 3-2 lists the HP COBOL II special register words that are an HP extension to the ANSI COBOL standard. Table 3-2. Extensions to Special Register Words Word Contents TALLY A 5-digit unsigned integer typically used to store information produced by the EXAMINE statement in the PROCEDURE DIVISION. (This statement counts the occurrences of a particular character within a data item and optionally replaces all instances of that character with another character.
Program Elements Table 3-2. Extensions to Special Register Words (continued) Word Contents RETURN-CODE A prede ned numeric data name in the PROCEDURE DIVISION of a subprogram, RETURN-CODE is used to pass a value back to the calling program. For complete information, see \GIVING Phrase (COBOL Subprograms)" in Chapter 11. TIME-OF-DAY A six-character numeric item accessed only as the transmitting eld of a MOVE or DISPLAY statement in the PROCEDURE DIVISION to access the time of day.
Program Elements Figurative Constants. Figurative constants are values that have been used so often that they have been assigned xed data names within the COBOL language. For example, the gurative constant consisting of a string of zeros is the gurative constant ZERO. The values for gurative constants are generated automatically by the compiler. The gurative constants that you can use are shown in Table 3-3. Singular and plural forms of these words are identical. Table 3-3.
Program Elements Figurative constants are not enclosed in quotation marks or apostrophes. The number of characters for a gurative constant is determined by the size of the eld to which the constant is moved or with which it is associated, as follows. 1. When the constant is associated with another data item, as in a VALUE clause or when the constant is moved to or compared with another item, the constant assumes the same length as the associated item.
Program Elements Special Character Words. A special character word is a reserved word, grouping of reserved words, or character that represents an arithmetic or relational operator. These words are listed in Table 3-5. Table 3-5. Special Character Words Arithmetic Operators Relational Operators IS [NOT] GREATER THAN IS [NOT] > IS [NOT] LESS THAN IS [NOT] < IS [NOT] EQUAL TO IS [NOT] = IS <> (<> is an HP extension to the ANSI COBOL standard.
Program Elements In ANSI COBOL'85, 15 types of user-de ned words are permitted. These are de ned in Table 3-6. Fourteen of these word types are implemented in HP COBOL II. routine-name is not, but it is accepted by the compiler and treated as a comment. Table 3-6. User-Defined Word Types Word Type De nition Alphabet-name Word that identi es (names) a speci c character set or collating sequence to be used by the program.
Program Elements Table 3-6. User-Defined Word Types (continued) Word Type De nition Level-number Word that indicates the position of a data item in the hierarchical structure of a logical record, or that indicates special properties of a data description entry. Level numbers 1 through 49 indicate the position in a record structure; level numbers 66, 77, and 88 identify special properties. In the example that appears in the condition-name description above, level numbers 02 and 88 are used.
Program Elements All user-de ned words within the same program, except segment numbers and level numbers, can belong to only one of the following disjoint sets. Alphabet names. Condition names, data names, and record names. File names. Index names. Library names. Mnemonic names. Paragraph names. Program names. Section names. Text names. For example, if the word TEST-1 is used as a program name, it cannot also be used as a routine name.
Program Elements Function-Names A function-name is a word that names a function you can call from your COBOL source program. Except for CURRENT-DATE, LENGTH, RANDOM, and WHEN-COMPILED, which are already reserved words, you can use function-names in a di erent context as user-de ned words or system-names. See Chapter 10, \COBOL Functions," for more information about the COBOL functions. Literals A literal is a character string that de nes itself, rather than representing some other value.
Program Elements Numeric Literals A numeric literal is essentially a number (numeric value) that is speci ed directly in a program. It is comprised of characters selected from the digits 0 through 9, the plus sign (+), the minus sign (-), and a decimal point (.). As an example, the literal 1 appears in the ADD statement below: ADD 1 TO PAGE-NUMBER. The speci c value of the literal is the algebraic quantity represented by the characters that compose the literal.
Program Elements Tip Try using the SYMBOLIC CHARACTERS clause to de ne constants instead of using octal literals. Caution For octal literals used in VALUE clauses, it is recommended that you only use nonnumeric items or items with USAGE BINARY. For other types that are used in level 88 values, the octal literal is converted to decimal before it is used. Otherwise, no conversion is done for octal literals. When no conversion is done, the octal literal is right-justi ed with NULL ll.
Program Elements Nonnumeric Literals A nonnumeric literal is a character string containing letters, digits, or special characters that is coded directly into a program. It is formed by entering: A quotation mark or apostrophe that denotes the beginning of the literal. The character string that comprises the literal. A matching quotation mark or apostrophe that delimits the end of the literal.
Program Elements Embedded Quotation Marks in Nonnumeric Literals You can use two consecutive quotation marks, or two consecutive apostrophes, within the characters of a nonnumeric literal to represent a single quotation mark or apostrophe.
Program Elements PICTURE Character Strings The PICTURE character string appears in the PICTURE clause of the DATA DIVISION. This clause describes the characteristics and editing requirements of data that is typically destined for some external output device such as a terminal or line printer. Speci cally, the PICTURE clause determines the appearance of the eld that is actually output by specifying: The size of the eld.
Program Elements Comment Entries This is an obsolete feature of the 1985 ANSI COBOL standard. You should use comment lines instead of comment entries. A comment entry is used in the IDENTIFICATION DIVISION to include comments or remarks in the program. These comments appear on the source program listing but do not a ect program compilation or execution. They denote such items as program author, installation name, date written, date compiled, security requirements, and other general remarks.
Program Elements Separators A separator is a punctuation character that delimits a character string. Separators include: Spaces (one or more). A comma or semicolon immediately followed by a space, except when the comma is used in a PICTURE character string. A period that is followed by a space. The period must be used only to indicate the end of a sentence, or as shown in formats. Left and right parentheses.
Program Elements Character Set Most character strings and all delimiters in a COBOL program are formed from characters selected from the COBOL character set. This character set includes upper case letters A through Z, lower case letters a through z, digits 0 through 9, and certain special characters: Special Character + * / = $ , ; : .
Program Elements Note When lower case letters appear outside of literals, the HP COBOL II compiler automatically converts them to upper case letters. Each character in the ASCII Character Set has a unique value that establishes its order in the collating sequence of this character set. In Appendix D, the characters are listed in order of ascending value.
Program Elements Coding Rules The following paragraphs state the standards that you should follow when coding COBOL source programs. These coding rules are known in COBOL as the reference format . Sequence Number (Columns 1 through 6) Sequence numbers appear in columns 1 through 6 of the source record. They identify the order of the record with respect to other records in your program. When you enter a program through EDIT/3000, the sequence numbers are supplied automatically by that subsystem.
Program Elements Continuation Lines Any sentence or entry that requires more than one line, must be continued in Area B of the next line. Your program can contain any number of continuation lines. When a word or numeric literal is broken from one line to the next, you must enter a hyphen (-) in column 7 of the continuation line. This hyphen indicates that the rst nonspace character in Area B is part of the word or literal broken on the previous line.
Program Elements The following example shows that all characters of the rst line are used in the nonumeric literal: Columns 68 through 72 are blank and considered part of the literal. - " # # MOVE "Name 1A Number 1A Name 2A Number 2A Name 3A Number "3A Name 4A Number 4A" TO RECORD-ITEM. " " Column 72. Columns 7 and 12.
4 Describing and Referencing Data The data used by a COBOL program is de ned and described in the DATA DIVISION, and referenced and operated upon in the PROCEDURE DIVISION. This data is stored in, read from, and written to les (collections of information) that reside on various peripheral devices.
Describing and Referencing Data Logical Versus Physical Records A physical record is one or more logical records and is commonly called a block. A block is the physical unit used by the operating system to read data from a le, or write data to it; it is the basic unit transferred between the device on which the le resides and main memory each time a program executes an input or output operation.
Describing and Referencing Data Within the record description entry, each group includes all following group and elementary items until an item with a level number greater than or equal to the level number of that group is encountered. A record is considered a single elementary item if it is not subdivided; otherwise, it is regarded as a sequence of elementary items that may or may not be organized into groups.
Describing and Referencing Data Level 66, 77, and 88 Items Programs can contain special level numbers that do not actually apply to hierarchical levels. Instead, they indicate special properties of entries in the DATA DIVISION. These level numbers are described below: Level Number Purpose 66 speci es group or elementary items introduced by a RENAMES clause. This clause permits the regrouping of data.
Describing and Referencing Data Categories of Data Items The three classes of data items are subdivided into ve categories: Alphabetic, which is synonymous with the alphabetic class. Numeric, which is synonymous with the numeric class. Alphanumeric, which can contain any characters from the ASCII character set in any combination, not edited by a PICTURE clause.
Describing and Referencing Data Algebraic Signs Numeric data can have two types of algebraic signs: operational signs and editing signs. Operational Signs These signs are associated with signed numeric data items and signed numeric literals, to indicate their algebraic properties. In regular (default) internal format, they are represented in storage as noted in the description of the USAGE clause of the DATA DIVISION (see Chapter 7).
Describing and Referencing Data Data Alignment In a COBOL program, data is moved from one area of storage (sending data item) to another (receiving data item) through use of the MOVE, ACCEPT, STRING, UNSTRING, arithmetic, or other statements in the PROCEDURE DIVISION. When aligning data within the receiving item, the compiler follows speci c rules. These rules depend upon the category of that item, as noted below. Table 4-2 contains some examples.
Describing and Referencing Data Level-01 (record) and level-77 data items are always aligned on word boundaries unless they are in the LINKAGE SECTION. Refer to \System Dependencies" in Appendix H for more information. In Table 4-2, a space character is represented by the symbol , and an assumed decimal point position is represented by the symbol . The receiving data items for alphabetic and alphanumeric data items are each 11 positions long.
Describing and Referencing Data Identifiers NNNNNNNNNNNNNNNNNNNNNNNNNNNNN Data names that are uniquely identi ed by quali ers, subscripts, indexes, or reference modifiers are known collectively as identi ers . Function-identi ers are also identi ers . NNNNNNNNNNNNNNNNNNNNNNNNNNNNN The syntax for identi ers is summarized in the general format: The syntax for a function-identi er is: FUNCTION function-name-1 [({parameter-1} ...
Describing and Referencing Data Uniqueness of Reference To ensure that the basic elements de ned in the various program divisions can be properly referenced in the PROCEDURE DIVISION, the compiler places several restrictions on some of these elements. These restrictions cover quali ers, subscripts, indexes, and identi ers as they apply to data names, condition names, paragraph names, and text names.
Describing and Referencing Data Note In these format descriptions, the keywords OF and IN are logically equivalent and can be used interchangeably. In all cases, you must use su cient quali ers to make the name unique. It is not always necessary, however, to mention all levels in a particular hierarchy. Within the DATA DIVISION, all data names used as quali ers must be associated with a level indicator or level number.
Describing and Referencing Data In the PROCEDURE DIVISION, two identical paragraph names must not appear in the same section. A section name is the highest and only quali er for a paragraph name. Note The most signi cant name in any hierarchy must be unique and cannot be quali ed. Subscripted or indexed data names and conditional variables can be made unique through quali cation. The name of a conditional variable can be used as a quali er for any of its condition names.
Describing and Referencing Data For data names: You cannot subscript a data name that is used as a quali er. You cannot specify, as the complete set of quali ers for one data name, a partial set of quali ers used for another data name. You must qualify data names if more than one le contains a LINAGE clause. For paragraph names: You cannot duplicate a paragraph name within a section.
Describing and Referencing Data Tables Quite frequently in business applications, data is arranged in the form of tables. This is because of the logical arrangement of data and because it is easier to both describe and select elements of a table than it is to write all the components of the table as one record. Tables composed of contiguous data items are de ned in COBOL by using the OCCURS clause in a record description entry.
Describing and Referencing Data De ning a three dimensional table is analogous to de ning a two dimensional table. Simply extend the table elements of the two dimensional table to include an element that uses the OCCURS clause. For example: 01 SALES-ORGANIZATION-TABLE. 11 REGION-TABLE OCCURS 4 TIMES. 22 SALES-REGION 22 STATE-TABLE OCCURS 13 TIMES. 33 STATE 33 REP-TABLE OCCURS 4 TIMES. 34 REP-INFO. 35 REPRESENTATIVE 35 LOCATION-INFO PIC X(05). PIC X(20). PIC X(20). PIC X(60).
Describing and Referencing Data The subscript can be represented by the reserved word ALL, a numeric literal, a data name, or an index name. The subscript ALL can be used only when the subscripted identi er is a parameter to a COBOL function. ALL cannot be used with condition-name-1 . ALL speci es that each table element associated with that subscript position is a parameter to the function. See Chapter 10, \COBOL Functions", for more information on calling COBOL functions.
Describing and Referencing Data The compiler determines the sequential location of the element in the table by incrementing (for the plus sign) or decrementing (for the minus sign) the value in the index or data item by the value of the literal. The following illustrates direct subscripted data items. DAY (1) DATE (1 2) BENCHMARK (ALPHA BETA GAMMA) CANDY (20 FILEZ-01 +3) The following illustrates relative subscripting.
Describing and Referencing Data Referencing Table Items with Indexing Indexing requires more coding in the OCCURS clause, since you must specify at least one name to be used for the indexing. To illustrate, the SALES-ORGANIZATION-TABLE has been modi ed for indexing: 01 SALES-ORGANIZATION-TABLE. 11 REGION-TABLE OCCURS 4 TIMES. 22 SALES-REGION PIC 22 STATE-TABLE OCCURS 13 TIMES. 33 STATE PIC 33 REP-TABLE OCCURS 4 TIMES INDEXED BY RPINDX. 34 REP-INFO. 35 REPRESENTATIVE PIC 35 LOCATION-INFO PIC X(05). X(20).
Describing and Referencing Data Note In the format descriptions appearing throughout this manual, condition-name refers to a condition name that can be quali ed, indexed, or subscripted as necessary. Function-Identifiers A function-identi er is a syntactically correct combination of character strings and separators that references a function. Syntax The format of a function-identi er is: FUNCTION function-name-1 [({parameter-1} ...
Describing and Referencing Data Reference Modification NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Reference modification is a feature of the 1985 ANSI COBOL standard. Reference modi cation is a method of referencing data by specifying a leftmost character and length for the data item. Syntax The format of a reference modi er is: (leftmost-character-position: [length]) You use a reference modi er with a data item or a function identi er.
Describing and Referencing Data Reference Modification Rules The following rules apply when using reference modi cation: Each character of a data item referenced by data-name-1 or by function-name-1 and its parameters, if any, is assigned an ordinal number according to its position. The leftmost position is assigned the number one and the number of each successive position to the right is incremented by one.
Describing and Referencing Data Examples Based upon the following example, Table 4-3 shows the result of reference modi cation upon four statements: 01 TAB. 05 ELEMENT 01 X PIC X(5) OCCURS 5 TIMES VALUE "12345". PIC X(3). Table 4-3. Reference Modification Results Statement Result MOVE "ABC" TO ELEMENT (3) (2:) Changes the third element of ELEMENT table to 1ABCt. MOVE "ABC" TO ELEMENT (2) (4:) Changes the second element of ELEMENT table to 123AB.
Describing and Referencing Data The following program shows reference modi cation on function calls: 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 $CONTROL POST85 IDENTIFICATION DIVISION. PROGRAM-ID. FUNC-EXAMPLE. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 TAB. 05 ELEMENT PIC X(5) USAGE DISPLAY OCCURS 5 TIMES VALUE "12345". PROCEDURE DIVISION. FIRST-PARA.
5 IDENTIFICATION DIVISION Every HP COBOL II program begins with the IDENTIFICATION DIVISION. This division speci es information that identi es both the source program and related listings produced by the HP COBOL II compiler. Among this information, you must always include the name of your program. In addition, you may optionally identify: The author of the program. The installation where the program is compiled. The date that the program is written. The date that the program is compiled.
IDENTIFICATION DIVISION The IDENTIFICATION DIVISION can not be abbreviated to ID DIVISION in the contained programs within a nested program. Only the outermost containing program can abbreviate IDENTIFICATION to ID. IDENTIFICATION DIVISION Syntax Rules The PROGRAM-ID paragraph is always required, but all other paragraphs are optional. When any optional paragraphs are included, they must always appear in the order shown in the format description. Begin the division header in Area A of the rst line.
IDENTIFICATION DIVISION Example The following example shows parts of several programs. Only the IDENTIFICATION DIVISION, PROGRAM-ID, and END PROGRAM are shown for each program. For clarity, the lines are appropriately indented. However, in practice, IDENTIFICATION DIVISION, PROGRAM-ID, and END PROGRAM must start in margin A. Program Structure IDENTIFICATION DIVISION. PROGRAM-ID. A. . . . IDENTIFICATION DIVISION. PROGRAM-ID. B. . . . END PROGRAM B. IDENTIFICATION DIVISION. PROGRAM-ID. C COMMON. . . .
IDENTIFICATION DIVISION DATE-COMPILED Paragraph The DATE-COMPILED paragraph is an obsolete feature of the 1985 ANSI COBOL standard. When you enter the DATE-COMPILED paragraph in your source program, the compiler prints the current date and time on the rst line of this paragraph as it appears on the source program listing. Generally, you include only the paragraph header (and do not specify a body) when you enter the source program.
IDENTIFICATION DIVISION Other Paragraphs The remaining paragraphs of the IDENTIFICATION DIVISION, AUTHOR, INSTALLATION, DATE-WRITTEN, and SECURITY, are obsolete features of the 1985 ANSI COBOL standard. In the other paragraphs of the IDENTIFICATION DIVISION, which are optional, the paragraph bodies are treated as comments. Thus, you may enter any information you wish in any of them. For example, you may use the AUTHOR paragraph for data other than someone's name.
6 ENVIRONMENT DIVISION The ENVIRONMENT DIVISION allows you to de ne those aspects of a data processing application that depend on the physical characteristics of the processing environment. The ENVIRONMENT DIVISION is optional. It always follows the IDENTIFICATION DIVISION.
CONFIGURATION SECTION ENVIRONMENT DIVISION Syntax Rules The CONFIGURATION and INPUT-OUTPUT SECTIONs are optional. In nested programs, the CONFIGURATION SECTION is not allowed, because the information in the containing program is global across the contained programs. In separate programs, or in concatenated programs when included, they must appear in the order shown in the format description.
CONFIGURATION SECTION ENVIRONMENT DIVISION 6-3
CONFIGURATION SECTION SOURCE-COMPUTER Paragraph SOURCE-COMPUTER Paragraph The SOURCE-COMPUTER paragraph denotes the computer system on which you plan to compile your source program, and whether or not to set the debugging mode switch on at compile time. Syntax This paragraph has the following format: [SOURCE-COMPUTER. [computer-name [WITH DEBUGGING MODE].]] where computer-name is any valid user-de ned COBOL word.
CONFIGURATION SECTION OBJECT-COMPUTER Paragraph OBJECT-COMPUTER Paragraph The OBJECT-COMPUTER paragraph denotes the computer system on which the object program is executed. HP COBOL II assumes that all COBOL programs are executed on an HP computer system. The only clause in the OBJECT-COMPUTER paragraph that is not treated as a comment is the PROGRAM COLLATING SEQUENCE clause.
CONFIGURATION SECTION OBJECT-COMPUTER Paragraph PROGRAM COLLATING SEQUENCE Clause On an HP computing system, the following operations are performed on the basis of the ASCII collating sequence: Determining the truth value of nonnumeric comparisons explicit in relation or condition name conditions.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph SPECIAL-NAMES Paragraph The SPECIAL-NAMES paragraph allows you to relate certain COBOL-supplied feature, switch, or device names to mnemonic names. By specifying these mnemonic names in your program, you can invoke these functions. It allows you to relate the alphabet name speci ed in the PROGRAM COLLATING SEQUENCE clause to a particular collating sequence or character set, and to de ne other collating sequences with di erent alphabet names.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph Parameters feature-name-1 switch-name-1 device-name-1 mnemonic-name-1 and mnemonic-name-2 condition-name-1 and condition-name-2 alphabet-name-1 literal-1 through literal-5 a COBOL reserved word having a speci c meaning. Table 6-1 lists these feature names and describes their meanings. a COBOL reserved word having a speci c meaning. Table 6-1 lists these switch names and describes their meanings. a COBOL reserved word having a speci c meaning.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph literal-6 THROUGH and THRU symbolic- character-1 integer-1 alphabet-name-2 class-name-1 a single character, chosen from a speci c set. This set is shown later in this chapter, when the CURRENCY SIGN clause is described. are equivalent and may be used interchangeably. a name you choose to represent the user-de ned constant within your program. This name can be any valid user-de ned COBOL word.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph Feature-name, Switch-name, or Device-name Clause Feature-name, Switch-name, or Device-name Clause In the Feature-name, Switch-name, or Device-name clause, you relate various COBOL functions to mnemonic names used in your program. You do this by equating the speci c function name to the desired mnemonic name.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph Feature-name, Switch-name, or Device-name Clause Table 6-1. HP COBOL II Feature, Switch, and Device Names Feature Name Function CONDITION-CODE Refers to condition codes returned by operating system intrinsics when they have been called through the CALL statement. NO SPACE CONTROL When included in the ADVANCING clause of the WRITE statement, this prevents the line printer from advancing vertically or horizontally.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph Feature-name, Switch-name, or Device-name Clause Software Switches The software switches are external switches known to COBOL, the status of which is available to each object program functioning within the entire run unit. Each of the 16 software switches (SW0 through SW15) used in a given program has at least one condition name associated with it. A condition name and the SET statement are the means by which you can reference one of these switches.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph Feature-name, Switch-name, or Device-name Clause Line Printer Features The TOP, NO SPACE CONTROL, and C01 through C16 switches are all related to line printer control. Since there is no way for a COBOL II program to explicitly check for the condition of a line printer, you cannot use condition names with these functions. You must, however, specify mnemonic names for these functions if you intend to reference them later in your program.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph ALPHABET Clause ALPHABET Clause The ALPHABET clause has three functions: 1. To de ne a program collating sequence to be used in sort and merge operations, and nonnumeric comparisons. 2. To de ne an alphabet name and relate this name to either the ASCII, EBCDIK, or the EBCDIC collating sequence. This alphabet name can later be used in the CODE-SET clause of the DATA DIVISION to specify whether records of a sequential le are written in ASCII or EBCDIC code. 3.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph ALPHABET Clause EBCDIK THROUGH and THRU (for example) sorted or merged according to the EBCDIC collating sequence. speci es the Japanese version of the EBCDIC collating sequence. equivalent and may be used interchangeably.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph ALPHABET Clause Defining Your Own Collating Sequence To de ne your own collating sequence, you must follow the rules listed below. 1. If you specify a nonnumeric literal, it represents the equivalent character in the ASCII collating sequence. For instance, the literal \A" represents an ASCII A.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph ALPHABET Clause 6. If you use the ALSO phrase, the ASCII characters speci ed by literal-1 and literal-3 are assigned to the same relative positions in the new collating sequence. If you use a nonnumeric literal in an ALSO phrase, it must be only one character long. 7. The character with the highest ordinal position in the new collating sequence may be referenced by the gurative constant, HIGH-VALUE.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph ALPHABET Clause THEN DISPLAY "ERROR IN SORTED RECORD " DISPLAY CHK-REC ELSE MOVE CHK-REC TO EBCDOUT. GO GET-NEXT-REC. END-OUT. In the above example, the program collating sequence is speci ed as STANDARD-1. Because this is the default, the PROGRAM COLLATING SEQUENCE clause and the ASCII IS STANDARD-1 phrase serve only as documentation.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph SYMBOLIC CHARACTERS Clause SYMBOLIC CHARACTERS Clause NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN The SYMBOLIC CHARACTERS clause is a feature of the 1985 ANSI COBOL standard. A symbolic character is a user-de ned word that speci es a user-de ned gurative constant. This feature is useful for unprintable characters. For example, a symbolic character can be used to produce audible output from the terminal.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph SYMBOLIC CHARACTERS Clause For example, the following SYMBOLIC CHARACTERS clause declares the words BELL, CARRIAGE-RETURN, and ESCAPE: SYMBOLIC CHARACTERS BELL IS 8, CARRIAGE-RETURN IS 14, ESCAPE IS 28. With the above declaration you can use the following DISPLAY statements. The rst DISPLAY makes a sound on the terminal before displaying the message. The second displays the message in inverse video on certain terminals: DISPLAY BELL " JOB COMPLETED ".
CONFIGURATION SECTION SPECIAL-NAMES Paragraph CLASS Clause CLASS Clause NNNNNNNNNNNNNNNNN The CLASS clause is a feature of the 1985 ANSI COBOL standard. The CLASS clause is used to create a user-de ned class and provides a means for relating a name to the speci ed set of characters it lists. Syntax Parameters can only be referenced in a class condition. (Refer to Chapter 8 for more information about class conditions.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph CURRENCY SIGN IS Clause CURRENCY SIGN IS Clause The CURRENCY SIGN IS clause is used to specify a literal whose value is later referenced in the PICTURE clause of the DATA DIVISION to denote a currency symbol. Syntax Parameters literal-6 Note a single character, chosen from a speci c set. The literal cannot be any of the following characters: The digits 0 through 9.
CONFIGURATION SECTION SPECIAL-NAMES Paragraph DECIMAL POINT IS COMMA Clause DECIMAL POINT IS COMMA Clause The DECIMAL POINT IS COMMA clause allows you to request the exchange of the function of the comma and decimal point (or period) in numeric literals or PICTURE-CLAUSE character strings. Syntax [DECIMAL-POINT IS COMMA]. Description This clause has some e ect on pictures for edited data items. Refer to Chapter 7, under \PICTURE-CLAUSE," for details.
INPUT-OUTPUT SECTION INPUT-OUTPUT SECTION The INPUT-OUTPUT SECTION allows you to specify information needed to control the transmission and handling of data between the object program and various input-output devices. Speci cally, it permits you to de ne the names of data les, and the devices on which they reside, and special control techniques to be used in the object program.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE-CONTROL Paragraph The FILE-CONTROL paragraph is used to name les to be used in your program, and to de ne certain properties of these les that are necessary for their use by your program. Each le named in the FILE-CONTROL paragraph must be described in the DATA DIVISION of your program. Conversely, each le described in the DATA DIVISION must be named once in the FILE-CONTROL paragraph.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph SYNCHRONIZED. However, any numeric data item of a su cient size for the records in a le can be used. The ACTUAL KEY data item is used by placing a number into it that corresponds to the logical record number in the le. Logical records in a random access le begin with record zero. Thus, to access the tenth record in a random access le, your program must move the integer 9 into the ACTUAL KEY data item, and then execute the input-output statement.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph Sequential Access Sequential WRITE statements for a relative le release data to the le, starting with the rst record on the le, and proceeding to the second, third, and so forth in turn. If the RELATIVE KEY data item has been speci ed, it is updated each time a sequential WRITE statement is executed. Note Even though you may already have data on these records, a sequential WRITE statement will cause the new data to replace it.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph Indexed Files Indexed les use data items that are integral parts of the records to control accessing of the records. For a given indexed le, each record contains a single prime record key, and zero or more alternate record keys. Each key must be described as alphanumeric within the record description entry of the associated indexed le.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph Dynamic Access When dynamic access is used for indexed les, you can use either the READ NEXT or the READ . . . KEY IS form of the READ statement. The READ NEXT form is used when you wish to read records in a sequential manner. This statement allows you to access the records of the le starting with the record pointed to by the current record pointer (if valid). If the record is invalid, the next valid record in the le is read.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph File Status Every type of le described above (except sort-merge les) may have a le status data item associated with it. This data item can be used to check on the success or failure of an input-output operation involving the le with which it is associated. File status data items are described in more detail later in this chapter. Fixed Length Records Fixed length records must contain the same number of character positions for all the records in the le.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph SELECT clause File Control Clauses The various clauses of the FILE-CONTROL paragraph can be speci ed in ve separate formats, depending upon the type of le being described.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph SELECT clause 6-32 ENVIRONMENT DIVISION
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph SELECT clause In the FILE-CONTROL paragraph body, the SELECT clause must be speci ed rst. The remaining clauses may appear in any order. Each of the clauses of the FILE-CONTROL paragraph are described on the following pages in alphabetical order, except the SELECT and ASSIGN clauses. Since these clauses must be speci ed rst for any le type, they are discussed rst.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph SELECT clause SELECT Clause The SELECT clause is used to identify a le to be used in your program. Syntax The SELECT clause has two formats: Parameters le-name-1 any valid user-de ned COBOL word. File-name-1 is the name you use later in OPEN, CLOSE, USE, and other statements in the PROCEDURE DIVISION. It must also be used in an FD or an SD entry in the DATA DIVISION.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ASSIGN clause ASSIGN Clause The ASSIGN clause associates a le with the storage medium on which the le resides. With the USING phrase, you can assign logical les to physical les dynamically (that is, at run time). Syntax ASSIGN f [TO le-info-1 ] [USING data-name-1 ] g Parameters le-info-1 a nonnumeric literal of the form: name [,[class] [,[recording mode] [, [device [(CCTL)] ] [,[ le-size] [, [formsmessage.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ASSIGN clause for a listing device, a request for the operator to provide special forms, such as blank checks or inventory report forms, on the printer. For any other device, this parameter is ignored. This entry may contain a maximum of 49 characters and must be terminated with a period. L enables your program to dynamically lock and unlock a disk le. However, this feature is provided only to assist in the conversion of COBOL'68 programs to COBOL II.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ACCESS MODE clause ACCESS MODE Clause The ACCESS MODE clause speci es the way in which your program is to access the associated le. Syntax There are four formats of this clause, depending upon the type of le being described. This clause cannot be used for sort-merge les. The four formats are shown below. Parameters data-name-1 a data item that must not be de ned in the record description entry for the relative le being described.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ACCESS MODE clause Note The ANSI standard de nes the relative key value as an unsigned integer data item; however, HP COBOL II extends the standard and allows the use of signed integers for e ciency of code. Because a 32-bit integer is used for relative record numbers, a de nition of \USAGE COMPUTATIONAL SYNCHRONIZED PIC S9(9)" would allow for maximum code e ciency and record access.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ACTUAL KEY clause ACTUAL KEY Clause (an HP extension to the ANSI COBOL standard) The ACTUAL KEY clause names the data item to be used in accessing records of a random access le and applies only to random access les. Syntax This clause has the following format: ACTUAL KEY IS data-name-1 Parameters data-name-1 an integer item of one to nine digits.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ALTERNATE RECORD KEY clause ALTERNATE RECORD KEY Clause Each use of the ALTERNATE RECORD KEY clause names an alternate record key for an indexed le. The number of alternate keys for a le must be the same as the number used when the le was created. Syntax This clause has the following format: [ALTERNATE RECORD KEY IS data-name-2 [WITH DUPLICATES]] . . .
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE STATUS clause FILE STATUS Clause The FILE STATUS clause allows you to name a data item to be used in obtaining information about the success or failure of input-output operations performed using the le being described. This clause is optional, and may be used for all types of les except sort-merge les. Syntax The FILE STATUS clause has the following format: [FILE STATUS IS stat-item ].
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE STATUS clause FIXED FILE ATTRIBUTE Information about a le that is established when a le is created and cannot subsequently be changed during the le's existence. These attributes include the following: Organization of the le (sequential, relative, or indexed). Prime record key. Alternate record keys. Code-set. Minimum and maximum record size. Record type ( xed or variable). Collating sequence of the keys for indexed les. Blocking factor. Padding character.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE STATUS clause Table 6-2. ANSI COBOL'85 File Status Codes SEQUENTIAL RANDOM ACCESS or RELATIVE INDEXED S U C C E S S F U L 00-Successful. No more information available. 04-READ length of record doesn't match file. 05-OPEN. Optional file not present, created. 07-File is not a tape as the OPEN/ CLOSE phrase implies. 00-Successful. No more information available. 04-READ length of record doesn't match file. 05-OPEN. Optional file not present, created.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE STATUS clause Table 6-2. ANSI COBOL'85 File Status Codes (continued) SEQUENTIAL P E R M A N E N T E R R O R L O G I C E R R O R RANDOM ACCESS or RELATIVE INDEXED 30-No more information available. 31-OPEN, SORT, or MERGE of dynamic file failed due to file attribute conflict. 34-Boundary violation. 35-Nonoptional file not present for OPEN. 37-EXTEND or OUTPUT on unwritable file. -I-O for file that does not support it. -INPUT on invalid device for input.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph FILE STATUS clause Table 6-3. ANSI COBOL'74 File Status Codes SEQUENTIAL RANDOM ACCESS or RELATIVE INDEXED S U C C E S S F U L 00-Successful. NO more information available. 00-Successful. No more information available. 00-Successful. No more information available. 02-READ current key = next key value. -WRITE or REWRITE creates duplicate key for alternate key in which duplicates are allowed. A T 10-EOF or optional file not present.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph ORGANIZATION clause ORGANIZATION Clause The ORGANIZATION clause speci es the logical structure of the le being described. It can be used in sequential, relative, and indexed les. Syntax The three formats of the ORGANIZATION clause are shown below. [ORGANIZATION IS] SEQUENTIAL [ORGANIZATION IS] RELATIVE [ORGANIZATION IS] INDEXED Description The ORGANIZATION clause is required for relative and indexed les. It is optional for sequential les.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph RECORD KEY clause RECORD KEY Clause The RECORD KEY clause is used for indexed les only. It is required, because it provides the means (data-name-1 ) by which the associated indexed le is accessed. Syntax RECORD KEY IS data-name-1 [WITH DUPLICATES] The WITH DUPLICATES phrase in the record key clause is an HP extension to the ANSI COBOL standard.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph RESERVE clause RESERVE Clause The RESERVE clause allows you to indicate the number of input-output bu ers to be allocated for the le being described. Its use is optional. If you do not specify it, the number of bu ers allocated is the operating system default. This clause may be used for sequential, relative, indexed, and random access les. It may not be used for sort-merge les. Syntax The format of the RESERVE clause is shown below.
INPUT-OUTPUT SECTION FILE-CONTROL Paragraph RESERVE clause Example The following example shows a FILE-CONTROL paragraph for an indexed le and a sequential le, as well as important data items associated with the les. ENVIRONMENT DIVISION. . . . INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT INDXFILE ASSIGN TO "KFILE,DA,A,DISC,5000,,L" RESERVE 3 AREAS ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS FIRST-CHARS ALTERNATE RECORD KEY IS SECOND-CHARS WITH DUPLICATES FILE STATUS IS CHECK-KFILE.
INPUT-OUTPUT SECTION IO-CONTROL Paragraph I-O-CONTROL Paragraph The I-O-CONTROL paragraph is an optional paragraph that speci es the areas of memory (bu ers) to be shared by di erent les and the locations of les on a multi- le tape reel.
INPUT-OUTPUT SECTION IO-CONTROL Paragraph SAME Clause SAME Clause The SAME clause has three formats, whose meanings and restrictions are described below. Syntax SAME AREA Clause The SAME AREA clause allows you to conserve main memory space by permitting two or more non-sort or non-merge les to use the same area of main memory for processing the le. Because the area shared includes all storage areas assigned to the les speci ed, only one le can be open at any given time.
INPUT-OUTPUT SECTION IO-CONTROL Paragraph SAME Clause If any le appears in the SAME RECORD AREA clause and in the SAME AREA clause, then all other les appearing in the SAME AREA clause must also appear in the SAME RECORD AREA clause. Of course, les not named in the SAME AREA clause can also appear in the SAME RECORD clause.
INPUT-OUTPUT SECTION IO-CONTROL Paragraph MULTIPLE FILE Clause MULTIPLE FILE Clause The MULTIPLE FILE clause is an obsolete feature of the 1985 ANSI COBOL standard. The MULTIPLE FILE clause speci es the location of les on a multiple le reel. Syntax [MULTIPLE FILE TAPE CONTAINS f le-name-5 [POSITION integer-3 ] g . . . ] . . . Description When the le referenced by your program shares a labeled tape with other les, you must enter the MULTIPLE FILE clause.
7 DATA DIVISION The DATA DIVISION describes all data that your program is to use. That is, it describes any data to be read from or written to a le, data developed internally and held in temporary or working storage, and any constants that are used. The DATA DIVISION is optional. When included, however, it must follow the ENVIRONMENT DIVISION.
DATA DIVISION DATA DIVISION Format The DATA DIVISION has the following general format; The format of each section is described separately on the following pages, followed by an explanation of record description entries. DATA DIVISION Syntax Rules All sections within the DATA DIVISION are optional. When included, however, they must appear in the order shown in the format description.
DATA DIVISION FILE SECTION FILE SECTION The FILE SECTION de nes the structure of any sequential, indexed, relative, random access, or sort-merge le appearing in your program. Each le is de ned by a le description entry and one or more record descriptions. A le description entry always begins with the letters SD (for sort-merge les), or FD (for any other type of le as mentioned above) in Area A.
DATA DIVISION FILE SECTION 7-4 DATA DIVISION
DATA DIVISION WORKING-STORAGE SECTION WORKING-STORAGE SECTION The WORKING-STORAGE SECTION consists of a section header, \WORKING-STORAGE SECTION", and one or more data description entries for noncontiguous data items, as well as record description entries. The general format of the WORKING-STORAGE SECTION is: Each data description entry within WORKING-STORAGE allocates memory space for the data item and associates a data name with the item.
DATA DIVISION LINKAGE SECTION LINKAGE SECTION The LINKAGE SECTION consists of the header, \LINKAGE SECTION", and one or more data description entries for noncontiguous data items, as well as record description entries. The LINKAGE SECTION in a program is meaningful only if the object program is to be called from another object program through a CALL statement, and the CALL statement in the calling program contains a USING phrase.
FILE SECTION File Description (FD, SD) Clauses DATA DIVISION Clauses There are two distinct sets of clauses in the DATA DIVISION: le description clauses and data description clauses. File description clauses apply only to data les (FD level entries) and sort-merge les (SD level entries). Data description clauses can be used in any of the three sections allowed by HP COBOL II within the DATA DIVISION. They must be used in conjunction with each le description entry.
FILE SECTION File Description (FD, SD) Clauses 7-8 DATA DIVISION
FILE SECTION File Description (FD, SD) Clauses FD Level Indicator - For Data File Descriptions The FD level indicator names the data le being described. It must be the rst clause in a data le description entry. Syntax The data le description clause has the following format: FD le-name-1 Parameters FD le-name-1 indicates that the clauses that follow are data le description clauses. the name of the data le being described. Description The characters FD must begin in Area A.
FILE SECTION File Description (FD, SD) Clauses BLOCK CONTAINS Clause BLOCK CONTAINS Clause The BLOCK CONTAINS clause allows you to specify the blocking factor of the le being described. This clause should be used if the actual blocking factor of the le being described cannot be determined by the operating system.
FILE SECTION File Description (FD, SD) Clauses BLOCK CONTAINS Clause Random and relative les require xed length records. To illustrate the use of the BLOCK CONTAINS clause: A magnetic tape le contains variable length logical records with a maximum of 120 characters, blocked with a minimum of four logical records per physical record. There is a maximum of 480 characters (bytes) per physical record, and a minimum of 60 bytes per physical record. In this case, you can use either: BLOCK CONTAINS 4 RECORDS.
FILE SECTION File Description (FD, SD) Clauses CODE-SET Clause CODE-SET Clause The CODE-SET clause speci es the character code convention that represents data stored in sequential les. This clause may be speci ed for all les with sequential organization. This clause is optional, with ASCII being the default if it is not speci ed. Syntax Parameters alphabet-name-1 a previously de ned name related to either EBCDIC, EBCDIK, STANDARD-1, STANDARD-2 or NATIVE.
FILE SECTION File Description (FD, SD) Clauses DATA RECORDS Clause DATA RECORDS Clause The DATA RECORDS clause is an obsolete feature of the 1985 ANSI COBOL standard. For any type of le (random, sequential, sort-merge, and so forth) the DATA RECORDS clause serves only to document the names of data records associated with a le. This clause is, therefore, optional for both FD and SD level le descriptions. Syntax Parameters data-name-2 and its subsequent occurrences are the names of data records.
FILE SECTION File Description (FD, SD) Clauses EXTERNAL Clause EXTERNAL Clause NNNNNNNNNNNNNNNNNNNNNNNNNN The EXTERNAL clause is a feature of the 1985 ANSI COBOL standard. The EXTERNAL clause speci es the external attributes of a le connector, the associated data records, and the associated data items. Syntax IS EXTERNAL Description If the le description entry for a sequential le contains the LINAGE clause and the EXTERNAL clause, the LINAGE-COUNTER data item is an external data item.
FILE SECTION File Description (FD, SD) Clauses Global Clause GLOBAL Clause NNNNNNNNNNNNNNNNNNNN The GLOBAL clause is a feature of the 1985 ANSI COBOL standard. The GLOBAL clause speci es that the le connector, the data records and associated data items are available to the contained programs within a nested program in which the le is declared global. Syntax IS GLOBAL Description The GLOBAL clause can only be speci ed in the FD clause of the FILE SECTION.
FILE SECTION File Description (FD, SD) Clauses LABEL RECORDS Clause LABEL RECORDS Clause The LABEL RECORDS clause is an obsolete feature of the 1985 ANSI COBOL standard. The LABEL RECORDS clause speci es whether one or more labels exist on the le and, optionally, the names of the records containing the label. This clause does not apply to sort-merge les. This clause is optional.
FILE SECTION File Description (FD, SD) Clauses LINAGE Clause LINAGE Clause The purpose of the LINAGE clause is to describe the format of a logical page. It is used in conjunction with sequential les opened for output. Although there is not necessarily any relation between a logical and a physical page, it is advisable (particularly when writing a logical page to the line printer) to consider the size of a physical page when you are de ning a logical one. The LINAGE clause applies only to sequential les.
FILE SECTION File Description (FD, SD) Clauses LINAGE Clause Figure 7-1.
FILE SECTION File Description (FD, SD) Clauses LINAGE Clause FOOTING Phrase The FOOTING phrase is optional. If speci ed, however, it uses integer-7 or data-name-5 to de ne the FOOTING AREA of the page body. The entire page body can be the footing area. That is, integer-7 (or, the value of data-name-5 ) may be 1, in which case the footing area is all of the page body. The footing area is used in conjunction with the END-OF-PAGE phrase of the WRITE statement.
FILE SECTION File Description (FD, SD) Clauses LINAGE Clause Use of Data Names Versus Use of Integers The use of integers in a LINAGE clause allows for less exibility than does the use of data names. When an integer (either integer-6, integer-7, or integer-8 ) is speci ed, it is used when the le associated with the LINAGE clause is opened for output. This value is used for every logical page written for the le and cannot change during a particular execution of the program in which it appears.
FILE SECTION File Description (FD, SD) Clauses LINAGE Clause LINAGE-COUNTER Any time a LINAGE clause is speci ed for a le, a LINAGE-COUNTER is supplied for the le. Because you can have more than one le whose description contains a LINAGE clause, you must qualify the LINAGE-COUNTER of each le by using the le name. The value of a LINAGE-COUNTER at any given time is the current line number of the associated page body.
FILE SECTION File Description (FD, SD) Clauses RECORD CONTAINS Clause RECORD CONTAINS Clause The RECORD CONTAINS clause speci es the size, in characters, of data records in a le. Because each data record of a le is completely de ned in a record description entry, this clause is optional for any le description entry.
FILE SECTION File Description (FD, SD) Clauses RECORD CONTAINS Clause Description The size of a record is determined by taking the sum of the numbers of all characters in all xed length elementary items, and adding to that sum the maximum number of characters in any variable length item subordinate to the record. This sum may di er from the actual size of the record because of slack bytes. Refer to the SYNCHRONIZED and USAGE clause descriptions appearing later in this chapter.
FILE SECTION File Description (FD, SD) Clauses RECORD CONTAINS Clause During execution of a RELEASE, REWRITE, or WRITE statement, the number of character positions in the record is determined by the following three conditions: If data-name-1 is speci ed, by the content of the data item referenced by data-name-1 . If data-name-1 is not speci ed and the record does not contain a variable occurrence data item, by the number of character positions in the record.
FILE SECTION File Description (FD, SD) Clauses RECORD CONTAINS Clause Example The following example illustrates use of the RECORD VARYING clause. IDENTIFICATION DIVISION. PROGRAM-ID. COBVAR. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IFILE ASSIGN TO "IFILE". SELECT IFILE2 ASSIGN TO "IFILE". DATA DIVISION. FILE SECTION. FD IFILE RECORD IS VARYING FROM 10 TO 50 DEPENDING ON LEN. 01 IREC. 05 FILLER PIC X OCCURS 10 TO 50 TIMES DEPENDING ON LEN. FD IFILE2 RECORD IS VARYING FROM 10 TO 50.
FILE SECTION File Description (FD, SD) Clauses RECORD CONTAINS Clause DISPLAY IREC2 DISPLAY WREC CLOSE IFILE2.
FILE SECTION File Description (FD, SD) Clauses RECORDING MODE Clause RECORDING MODE Clause The RECORDING MODE clause is an HP extension to the ANSI COBOL standard. The RECORDING MODE clause speci es how logical records are contained in the le, and whether or not the logical record being read or written spans more than one physical record (generally because of hardware constraints or for I-O e ciency). This clause does not apply to sort-merge les. This clause is optional.
FILE SECTION File Description (FD, SD) Clauses RECORDING MODE Clause Description If none of the above codes is speci ed, an F is the default value. Logical records are contained in les as either xed, variable, or unde ned in length. A xed length record le contains logical records whose lengths are all the same. A variable length record le contains logical records whose lengths may vary. In such a le, each record is preceded by a two-byte count, which speci es the length of that particular record.
FILE SECTION File Description (FD, SD) Clauses VALUE OF Clause VALUE OF Clause The VALUE OF clause is an obsolete feature of the 1985 ANSI COBOL standard. The VALUE OF clause allows you to access existing les on labeled tapes or to create a new labeled tape. A label contains identi cation, whether the label is in IBM or ANSI standard format, the expiration date of the le protection, and the position of the le on the tape. This clause does not apply to sort-merge les.
FILE SECTION File Description (FD, SD) Clauses VALUE OF Clause Table 7-1. Values of the LABEL INFO and DATA NAME Parameters in the VALUE OF Clause label-info-n VOL Meaning Volume identi cation. LABELS SEQ ANSI standard or IBM format. Relative position of le on a magnetic tape. Date when le may be written over. Until that time, the le is protected. EXDATE data-name-n or literal-n Any combination of one to six characters from the set A through Z, and 0 through 9. ANS or IBM. 0 to 9999, NEXT, or ADDF.
DATA DIVISION FILE SECTION Data Description Entries Data Description Entries A data description entry is composed of a level number followed by a data name, and then followed by a set of data clauses. The level numbers can be 01 to 49 for record description entries, 77 for unrelated data items, 66 for alternative groupings of elementary items in the preceding record description entry, and 88 for condition names.
DATA DIVISION FILE SECTION Data Description Entries Record Description Entries At least one record description entry must follow each FD or SD le description entry. This discussion of record description entries is applicable to either type of le description, as well as for the LINKAGE and WORKING-STORAGE SECTIONS. A record description consists of one or more data description entries. Associated with each data description entry is a level number chosen from the set 01 to 49, 66, or 88.
DATA DIVISION FILE SECTION Data Description Entries DATA DIVISION 7-33
DATA DIVISION FILE SECTION Data Description Entries In the rst format, the level number may be any number from 01 to 49, or 77. It cannot be 66 or 88. If it is used, the data name or FILLER clause must immediately follow the level number, and the REDEFINES clause (if used) must immediately follow the data-name-1 clause. Except for these two conditions, all other clauses, if used, may be written in any order. The PICTURE clause must be used for every elementary item except an index data item.
DATA DIVISION FILE SECTION Data Name or FILLER Clause Data Name or FILLER Clause A data name clause speci es the name of the data being described. The keyword, FILLER, implies that you are specifying an elementary item of the logical record being described that cannot be referenced explicitly. If this clause is omitted, the record is treated as though FILLER had been speci ed.
DATA DIVISION Record Descriptions BLANK WHEN ZERO Clause BLANK WHEN ZERO Clause The BLANK WHEN ZERO clause causes a numeric or numeric-edited data item to be lled with spaces when the value of the data item is zero. This clause is optional. If used, it may refer only to a numeric or numeric-edited elementary data item. When this clause is used with a numeric data item, the category of the data item is considered to be numeric-edited.
DATA DIVISION Record Descriptions EXTERNAL Clause EXTERNAL Clause NNNNNNNNNNNNNNNNNNNNNNNNNN The EXTERNAL clause is a feature of the 1985 ANSI COBOL standard. The EXTERNAL clause speci es external attributes of a WORKING-STORAGE SECTION data description entry, the associated data record, and its subordinate data items. Syntax IS EXTERNAL Description The EXTERNAL clause can only be speci ed in data description entries in the WORKING-STORAGE SECTION whose level number is 01.
DATA DIVISION Record Descriptions GLOBAL Clause GLOBAL Clause NNNNNNNNNNNNNNNNNNNN The GLOBAL clause is a feature of the 1985 ANSI COBOL standard. The GLOBAL clause speci es that a 01 record description and its subordinate data items are available to all contained programs within a nested program in which the record is declared global. Refer to Chapter 11, \Interprogram Communication," for more detailed information.
DATA DIVISION Record Descriptions JUSTIFIED Clause JUSTIFIED Clause The JUSTIFIED clause allows you to right-justify alphabetic or alphanumeric data items. It cannot be used with numeric or edited data items, and only applies to elementary data items being used to receive data. This clause is optional. Syntax Parameters JUST is an abbreviation for JUSTIFIED.
DATA DIVISION Record Descriptions OCCURS Clause OCCURS Clause The OCCURS clause is used to de ne a table containing up to seven dimensions. Its use eliminates the need for separate entries to describe repeated data items, and provides information required for the application of subscripts or indices. Refer to Chapter 4, \Tables", for a description of the formation and use of tables.
DATA DIVISION Record Descriptions OCCURS Clause the items identi ed by data names in this phrase must be within the group item that is the subject of this entry, and must not contain an OCCURS clause. There must not be any entry containing an OCCURS clause between the items identi ed in the KEY IS phrase and the subject of this entry. The second format of the OCCURS clause is used to de ne a variable length table.
DATA DIVISION Record Descriptions OCCURS Clause Data-name-4 , and its contents, must be described in a separate data description entry, and may be quali ed. If the OCCURS clause is speci ed in a data description entry included in a record description entry containing the EXTERNAL clause, data-name-4 , if speci ed, must reference a data item possessing the external attribute that is described in the same DATA DIVISION.
DATA DIVISION Record Descriptions OCCURS Clause But, the following two records are not allowed: 01 ROAD. 02 SURFACE OCCURS 10 TIMES. 03 SIDE OCCURS 1 TO 8 TIMES DEPENDING ON SIZER PIC X(9). 01 ROAD. 02 SURFACE OCCURS 1 TO 10 TIMES DEPENDING ON SIZER. 03 SIDE OCCURS 1 TO 8 TIMES DEPENDING ON SIZEUP PIC X(9). Not allowed. Not allowed.
DATA DIVISION Record Descriptions PICTURE Clause PICTURE Clause The PICTURE clause describes the category, length, and editing requirements for an elementary item. It applies only to elementary data items and must be used for every elementary data item. It is not allowed for an index data item. Syntax Parameters PICTURE and PIC character-string equivalent. a set of up to 30 characters, arranged in certain allowable combinations; these combinations determine the category of the elementary item.
DATA DIVISION Record Descriptions PICTURE Clause Numeric Data Numeric data consists of a combination of the Arabic numerals 0 through 9, optionally including the positive or negative sign, or a representation of an operational sign as de ned in the SIGN clause. Note that a decimal point is not part of the possible set of characters allowed in forming numeric data for a COBOL program. You must specify the data without a decimal point.
DATA DIVISION Record Descriptions PICTURE Clause The symbol P indicates an assumed decimal scaling position and is used to specify the location of an assumed decimal point when the point is not within the number appearing in the data item. That is, for each appearance of a P in the PICTURE of a data item, the data item is assumed to be multiplied by 10, or by one tenth, depending upon whether the P symbol is on the right, or on the left of the character string used to de ne the eld.
DATA DIVISION Record Descriptions PICTURE Clause Alphanumeric Data Alphanumeric data is made up of any valid character used on an HP computer. To de ne an alphanumeric data item, you can use the symbols A, 9, or X. The PICTURE clause for this type of data, however, must contain at least one X symbol, or a combination of the A and 9 symbols to indicate that it represents an alphanumeric data item.
DATA DIVISION Record Descriptions PICTURE Clause Numeric-Edited Data In standard data format, numeric-edited data consists of a combination of the numerals zero through 9 and an optional decimal point. Editing of this type of data in HP COBOL II consists of leading zero suppression, lling or replacement, placement and alignment of a decimal point and a currency symbol, insertion of a sign, commas, blanks, or strokes. This is accomplished through use of the following symbols: P, V, 9, B, /, r, Z, (,), (.
DATA DIVISION Record Descriptions PICTURE Clause The appearance of a currency symbol in a PICTURE clause represents the position into which a currency symbol is to be placed. If you do not specify an alternative currency symbol through the CURRENCY SIGN clause of the SPECIAL-NAMES paragraph, the dollar ($) symbol is used. This symbol must appear as the leftmost symbol in the character string, except that it may be preceded by a plus (+) or minus (-) symbol.
DATA DIVISION Record Descriptions PICTURE Clause Size of Elementary Data Items The size of an elementary data item is de ned as being the number of character positions occupied by the elementary item in standard data format. This size is determined by counting the number of allowable symbols used to represent character positions within a PICTURE clause for that item. With the exception of the S, V, period (.), CR and DB symbols, all symbols in the PICTURE clause may use repetition factors.
DATA DIVISION Record Descriptions PICTURE Clause Editing Rules There are two general methods for performing editing in the PICTURE clause: insertion , and zero suppression and replacement . Editing takes place only when data is moved into an elementary data item whose PICTURE clause speci es editing (that is, whose PICTURE clause is alphabetic, alphanumeric-edited or numeric-edited). Therefore, data moved into a numeric eld is not edited.
DATA DIVISION Record Descriptions PICTURE Clause Special Insertion Editing. The period (.) is used in special insertion editing. In addition to being an insertion character, it is also used for alignment purposes when the sending data item is numeric and contains a decimal point. The result of this form of editing is the appearance of the period in the same position as it appears in the PICTURE clause for the item.
DATA DIVISION Record Descriptions PICTURE Clause Fixed Insertion Editing. Fixed insertion editing uses the currency symbol and the editing sign control symbols, +, -, CR, and DB. Only one currency symbol and one editing sign control symbol can be used in a given PICTURE clause when you wish to use xed insertion editing. When the CR or DB symbol is used, each represents two characters, and must be in the rightmost character positions counted in determining the size of the receiving item.
DATA DIVISION Record Descriptions PICTURE Clause 1. The leading character of the sending data item is checked to see if it has a zero value. If it is zero, the oating insertion character is inserted in the corresponding character position of the receiving data item and the preceding character of this data item is replaced with a space. 2. The next character of the sending data item is then checked for a zero value, and if it is zero, the action described in step 1 is repeated. 3.
DATA DIVISION Record Descriptions PICTURE Clause Zero Suppression Editing. Zero suppression editing allows you to replace leading zeros of the sending data item with either spaces or asterisks in the receiving data item. You can replace one or more leading zeros with spaces by placing a Z in the corresponding positions of the PICTURE character string used to represent the receiving data item.
DATA DIVISION Record Descriptions PICTURE Clause Table 7-5. PICTURE Character Precedence Chart First Symbol Second Symbol Floating Insertion Symbols Other Symbols Non-Floating Insertion Symbols + + CR Z Z + + A B 0 / , . - - DB cs * * - - cs cs 9 X S V P P B x x x x x x x x x x x x x x x x x 0 x x x x x x x x x x x x x x x x x / x x x x x x x x x x x x x x x x x , x x x x x x x x x x x x x x x x .
DATA DIVISION Record Descriptions REDEFINES Clause REDEFINES Clause The REDEFINES clause allows you to de ne the same storage area in main memory for di erent data items whose lengths are not described as variable in an OCCURS clause. Syntax Parameters level-number and data-name-1 and FILLER data-name-2 level number and data name of the data item being described; these are not part of the REDEFINES clause.
DATA DIVISION Record Descriptions REDEFINES Clause Examples 01 RECORD-IN PICTURE X(80). 01 RECORD-PARTS REDEFINES RECORD-IN. 02 NAME PICTURE X(30). 02 STREET PICTURE X(20). 02 CITY PICTURE X(20). 02 STATE PICTURE X(10). 01 PARTS-TABLE. 02 PART OCCURS 35 TIMES. 03 NAME PIC X(10). 03 QUANTITY PIC 9(04). 03 UNIT-PRICE PIC 9(06). 03 LOCALE PIC X(10). 03 SITE-INFO REDEFINES LOCALE. 04 BUILDING-NO PIC X(03). 04 FLOOR-NO PIC X(02). 04 SECTION-NO PIC X(02). 04 BIN-NO PIC X(03).
DATA DIVISION Record Descriptions SIGN Clause SIGN Clause The SIGN clause is only used with a signed numeric data description item or description entry whose usage is DISPLAY, or a group item containing at least one such data description entry. It states the position of the sign, whether leading or trailing, as well as whether the sign was formed by overpunching in the rst or last character of the data item (see the USAGE IS DISPLAY clause, below) or was formed separately.
DATA DIVISION Record Descriptions SIGN Clause In either the default case, or the case when the optional SEPARATE CHARACTER phrase is not used, the letter \S" in the PICTURE CLAUSE is not counted in determining the size of the item when represented in standard data format. To illustrate the SIGN clause: The data to be entered is 123489F In this case, no SIGN clause is required because the default is SIGN IS TRAILING.
DATA DIVISION Record Descriptions SYNCHRONIZED Clause SYNCHRONIZED Clause The SYNCHRONIZED clause is used to align items de ned as USAGE IS COMPUTATIONAL or BINARY on word boundaries in order to facilitate arithmetic operations. A word size is de ned by the operating system environment (a word is 32 bits on MPE XL). NNNNNNNNNNNNNNNNNNNNNNNNNNNNN All other items are aligned on byte boundaries.
DATA DIVISION Record Descriptions SYNCHRONIZED Clause The computation of boundary addresses is a ected by the $CONTROL SYNC option. This option changes the alignment of SYNCHRONIZED data items, which a ects the number of slack bytes generated in a record. Items with the SYNC clause are aligned along 16-bit (2 characters) boundaries, if SYNC16 is in e ect. Items with the SYNC clause are aligned along 32-bit (4 character) boundaries, if SYNC32 is in e ect.
DATA DIVISION Record Descriptions SYNCHRONIZED Clause Example The following illustrates the use of $CONTROL SYNC: $CONTROL SYNC32 01 OUT-REC. 05 A 05 B 05 C PIC X. PIC S9999 BINARY SYNC. PIC X. $CONTROL SYNC16 01 IN-REC. 05 A 05 B 05 C PIC X. PIC S9999 BINARY SYNC. PIC X. In the above example, three slack bytes are inserted before B of OUT-REC. One slack byte is inserted before B of IN-REC. Note Due to the $CONTROL SYNC option, boundary alignment within a record is constant.
DATA DIVISION Record Descriptions USAGE Clause USAGE Clause The USAGE clause speci es how the data item being described is stored internally. When used with index, the USAGE clause speci es that the data item being described contains a value equal to the value of an index name associated with an occurrence number for a table element.
DATA DIVISION Record Descriptions USAGE Clause USAGE IS DISPLAY When usage of a data item is de ned (implicitly or explicitly) as DISPLAY, the data is stored internally as ASCII characters. This means that each character of data is stored as an 8-bit byte. If you are using the data item in a noncomputational manner (that is, printing or displaying it), this is the appropriate type of usage to be speci ed.
DATA DIVISION Record Descriptions USAGE Clause Zone signs cause the signed digit to have the same punch con guration as certain other characters. This is the purpose of the S symbol in the PICTURE clause; it informs the compiler that the last digit in the eld is to be interpreted as a number and a sign, and not as the character that it would otherwise represent. Table 7-6 shows the data character equivalents to each possible rightmost digit sharing a zone sign.
DATA DIVISION Record Descriptions USAGE Clause NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Table 7-8. COMPUTATIONAL-3 or PACKED-DECIMAL Sign Configuration Bit Hexadecimal Sign Con guration Value + 1100 C 1101 D Unsigned 1111 F Table 7-9 gives a graphic illustration of packed-decimal elds as they might appear in memory or in a le. Notice that these items follow the normal rules for truncation, even though the eld may include an unused half-byte position.
DATA DIVISION Record Descriptions USAGE Clause USAGE IS INDEX An elementary data item whose usage is de ned as INDEX is called an index data item. Its purpose is to hold the contents of a table index while the table is being processed. Therefore, any value within the index data item must correspond to an occurrence number of an element in a table. An index data item is stored as a synchronized unsigned computational integer, both internally and externally.
DATA DIVISION Record Descriptions VALUE Clause VALUE Clause The VALUE clause is used to de ne the values of constants and to initialize the values of WORKING-STORAGE data items. For information on VALUE clauses in condition names, refer to \Condition Names" later in this chapter. Syntax [VALUE IS literal-1 ] Parameters literal-1 the value assigned to the data item being described. Description The above format for the VALUE clause can only be used in the WORKING-STORAGE SECTION.
DATA DIVISION Record Descriptions VALUE Clause Restrictions on the Use of the VALUE Clause The following restrictions apply to the use of the VALUE clause. They also apply to the VALUE clause in condition names. The VALUE clause cannot be used in a data description entry containing a REDEFINES clause (except when used with a condition name), or in an entry subordinate to an entry containing a REDEFINES clause.
DATA DIVISION Record Descriptions RENAMES Clause RENAMES Clause The RENAMES clause permits alternative, possibly overlapping groupings of elementary items. This clause is always associated with a 66 level entry. Syntax The level number (66) and data-name-1 are not part of the RENAMES clause, but are used to clarify the purpose of the clause. Parameters THROUGH and THRU equivalent.
DATA DIVISION Record Descriptions RENAMES Clause Example 01 STUDENT-REC. 03 NAME 03 ID-NO 03 MAJOR 03 CLASSES 05 CLASS-ID 05 DEPT 66 STUD-INFO 66 MAJOR-DEPT PIC X(20). PIC X(9). PIC X(3). OCCURS 5 TIMES. PIC X(3). PIC X(3). RENAMES NAME THRU MAJOR. RENAMES MAJOR. In the above example, CLASSES, CLASS-ID, and DEPT may not be named in a RENAMES clause because of the OCCURS clause. Note The above paragraph implies that data-name-3 cannot be subordinate to data-name-2 .
DATA DIVISION Record Descriptions Condition Names Condition Names A condition name is always subordinate to another data item called the conditional variable . The level number 88 is used to describe it. The characteristics of a condition name are implicitly those of its conditional variable. This must be re ected in the value or values assigned to the condition name. A condition name is assigned one or more values.
DATA DIVISION Record Descriptions Condition Names Example 01 CONDVAR PIC 9(5) USAGE DISPLAY. 88 COND1 VALUE 10 THRU 25, 100 THRU 250. 01 ALPHAVAR 88 ALPHACOND 7-74 DATA DIVISION PIC A. VALUE "A" , "M" THROUGH "Z".
8 PROCEDURE DIVISION The PROCEDURE DIVISION is the division that speci es the operations to be carried out by the program. It is an optional part of a COBOL program and may contain declarative as well as nondeclarative procedures. Generally, statements in the PROCEDURE DIVISION are executed by the compiler in the order in which you enter them. However, you can alter this sequential ow by using one of the following statements: IF, PERFORM, GO TO, or EVALUATE .
PROCEDURE DIVISION PROCEDURE DIVISION Header The PROCEDURE DIVISION header has the following format: f g PROCEDURE DIVISION [USING data-name-1 . . . ] The PROCEDURE DIVISION header begins in Area A of the program. Note that the header must be terminated by a period followed by a space. USING Clause The USING clause in the PROCEDURE DIVISION header is required only if the program containing it is to be called by another COBOL program through the CALL statement.
PROCEDURE DIVISION PROCEDURE DIVISION Format The body of the PROCEDURE DIVISION has two general formats: The rst format of the PROCEDURE DIVISION body can be used when you wish to use no section names in your program. In such a case, only paragraph names are used to de ne procedures. This is generally not the best way to write a COBOL program, since it does not allow for USE procedures or segmentation of the object program. It may be bene cial, however, if you are writing a very short, simple program.
PROCEDURE DIVISION The second format of the PROCEDURE DIVISION body is used when you wish to allow for segmentation of your program or de ne declarative procedures. In the second format, section names may be used to de ne procedures, with paragraph names being used as subsections. If any part of the PROCEDURE DIVISION is written using a section name, the entire PROCEDURE DIVISION must be written using section names.
PROCEDURE DIVISION PROCEDURE DIVISION Syntax Rules This section discusses syntax rules for the following areas: Declarative Sections Procedures Sections and Section Headers Segmentation Declarative Sections Declarative sections are optional. If used, they may appear in COBOL subprograms as well as main programs.
PROCEDURE DIVISION Below is an example of the declaratives portion of a COBOL program: PROCEDURE DIVISION. DECLARATIVES. IN-FILE-ERR SECTION. USE AFTER STANDARD ERROR PROCEDURE ON IN-FILE. REPORT-ERR-PARA. DISPLAY "ERROR IN IN-FILE. ". DISPLAY "FILE-STATUS ITEM IS " FILE-STAT. DISPLAY "WHAT ACTION?". DISPLAY "ENTER C OR A FOR CONTINUE OR ABORT". ACCEPT DECISION. IF DECISION IS EQUAL TO "A" MOVE "ON" TO STOP-IT. FILE-LABEL SECTION. USE AFTER STANDARD BEGINNING FILE LABEL PROCEDURE ON OUT-FILE.
PROCEDURE DIVISION Sections and Section Headers A section consists of a section header followed by zero or more successive paragraphs. A paragraph consists of a paragraph name followed by a period, a space, and zero or more successive sentences. (Paragraphs, sentences, statements, and so forth are described in Chapter 2.) In the PROCEDURE DIVISION, a section header consists of a section name followed by the word SECTION, an optional segment number, then a period.
PROCEDURE DIVISION The second exception is when a subprogram is called from a section whose segment number is greater than 49. In this case, if the EXIT PROGRAM or GOBACK statement is executed in the called program, the calling program is reentered at the statement following the CALL statement. If this statement is within the same segment as the CALL statement, the segment is in its last used state when it is reentered. The third exception is when a PERFORM statement is executed.
PROCEDURE DIVISION Statements and Sentences PROCEDURE DIVISION Statements and Sentences There are three types of statements and sentences in the PROCEDURE DIVISION: Conditional statements and sentences. Compiler directing statements and sentences. Imperative statements and sentences. Conditional Statements and Sentences A conditional statement speci es that a condition is to be tested, and depending upon the truth value of the condition, determines the action of the object program.
PROCEDURE DIVISION Statements and Sentences Imperative Statements and Sentences An imperative statement either begins with an imperative verb and speci es an unconditional action to be taken, or it is a conditional statement that is delimited by its explicit scope terminator (delimited scope statement). Scope terminators are described later in this chapter. An imperative statement may consist of a sequence of one or more imperative statements.
PROCEDURE DIVISION Statements and Sentences Categories of Statements HP COBOL II statements fall into 11 categories. These categories, and the verbs used in them, are listed in Table 8-2. Table 8-2.
PROCEDURE DIVISION Statements and Sentences Table 8-2.
PROCEDURE DIVISION Statements and Sentences Scope Terminators Scope terminators mark the end of the PROCEDURE DIVISION statements that contain them. There are two types of scope terminators: explicit and implicit.
PROCEDURE DIVISION Arithmetic Expressions Arithmetic Expressions Arithmetic expressions are used in the COMPUTE statement and in relation conditions. They enable you to use exponentiation, as well as the addition, subtraction, multiplication, division, and negation operations that can be performed using arithmetic statements. Arithmetic expressions allow you to combine arithmetic operations without the restrictions on \composites of operands" and receiving data items that exist for arithmetic statements.
PROCEDURE DIVISION Arithmetic Expressions The following are unary operators: + is equivalent to multiplying by +1. is equivalent to multiplying by -1. An arithmetic expression may only begin with a left parenthesis, a plus or minus sign, or an identi er or numeric literal. It may only end with an identi er or numeric literal, or with a right parenthesis.
PROCEDURE DIVISION Arithmetic Expressions Use of Parentheses Parentheses may be used in arithmetic expressions to specify the order in which elements are to be evaluated. Always use parentheses in pairs. Expressions within parentheses are evaluated rst. Within nested parentheses, evaluation begins with the innermost set of parentheses, and continues outward until the expression contained in the outermost set is evaluated.
PROCEDURE DIVISION Arithmetic Expressions Valid Combinations in Arithmetic Expressions The ways in which operators, variables, and parentheses may be combined in an arithmetic expression are summarized in Table 8-3 below. The word \Variable" means a numeric literal or an identi er of a numeric elementary item. Table 8-3. Valid Combinations of Symbols in Arithmetic Expressions Second Symbol First Symbol Variable + - * / ** Unary + or - Variable Not valid. Permissible + - * / ** Permissible.
PROCEDURE DIVISION Conditional Expressions Conditional Expressions Conditional expressions identify conditions to be tested to select one of alternate paths of control. This selection is determined by the truth value of a condition. Conditional expressions are used in the IF, SEARCH, EVALUATE, and PERFORM statements. There are two categories of conditions associated with conditional expressions: Simple conditions. Complex conditions.
PROCEDURE DIVISION Conditional Expressions Sign Condition The sign condition tests whether or not the algebraic value of an arithmetic expression is less than, greater than, or equal to zero. The sign condition has the following format: Parameters arithmetic-expression NOT any valid arithmetic expression, as described on the preceding pages. It must contain at least one reference to a variable. coupled with one of the next keywords, algebraically tests arithmetic-expression .
PROCEDURE DIVISION Conditional Expressions Class Condition The class condition determines whether an operand consists entirely of numbers and an operational sign, or letters, or a user-de ned class. Syntax Parameters identi er-1 names the operand to be tested. It must be described implicitly or explicitly as USAGE IS DISPLAY. Other restrictions apply if the keyword NUMERIC is used. HP COBOL II allows PACKED-DECIMAL items to be tested for NUMERIC as an HP extension to the ANSI COBOL standard.
PROCEDURE DIVISION Conditional Expressions Description You cannot use a NUMERIC test if the operand has a data description de ning it as alphabetic, or as a group item composed of elementary items whose data descriptions indicate the presence of an operational sign or signs. If the data description of the operand does not indicate the presence of an operational sign, the operand is considered numeric only if it consists of numerals, and has no operational sign.
PROCEDURE DIVISION Conditional Expressions Switch-Status Condition A switch-status condition determines the on or o status of a de ned switch. The function name and the on or o value associated with the condition must be speci ed in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. The Switch-Status condition has the following format: condition-name-1 Parameter condition-name-1 the name associated with the function name in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION.
PROCEDURE DIVISION Conditional Expressions Relation Conditions There are two types of relation conditions in HP COBOL II. One is ANSI standard; the other is used for checking condition codes after intrinsic calls. The intrinsic relation condition is described following the description of ANSI standard relation conditions.
PROCEDURE DIVISION Conditional Expressions Parameters identi er-1 or literal-1 or arithmetic-expression-1 or index-name-1 identi er-2 or literal-2 or arithmetic-expression-2 or index-name-2 [NOT] GREATER THAN [NOT] LESS THAN [NOT] EQUAL TO NOT the subject of the condition. the object of the condition. equivalent to [NOT] > equivalent to [NOT] < equivalent to [NOT] = or < > (< > is an HP extension to the ANSI COBOL standard.
PROCEDURE DIVISION Conditional Expressions Comparisons Using Index Names and Index Data Items. Relation tests may be made using any of the index names and index data items described below. Two index names. The result is the same as if the corresponding occurrence numbers were compared. An index name and a data item (other than an index data item) or literal. The occurrence number corresponding to the value of the index name is compared to the data item or literal.
PROCEDURE DIVISION Conditional Expressions The size of an operand is the total number of standard data format characters in the operand. When operands are of unequal size, comparison proceeds as though the shorter operand is extended on the right by su cient spaces to make the operands of equal size.
PROCEDURE DIVISION Conditional Expressions Condition Name Conditions In a condition name condition, a conditional variable is tested to determine whether or not its value is equal to one of the values associated with condition-name . Condition names have the following format: condition-name-1 Parameter condition-name-1 an identi er described under an 88 level data description entry in the DATA DIVISION.
PROCEDURE DIVISION Conditional Expressions Intrinsic Relation Conditions Intrinsic relation conditions are an HP extension to the ANSI COBOL standard. Intrinsic relation conditions are used only to test the condition codes returned by HP operating system intrinsics after they have been called with the CALL INTRINSIC statement.
PROCEDURE DIVISION Conditional Expressions Note When using CALLs to operating system intrinsics, the condition code returned is not saved by COBOL and as such is only available until an instruction is executed that changes the condition code. The condition code can be successfully tested with the following examples that illustrate possible correct and incorrect methods. Examples The following are correct and incorrect examples of intrinsic relation conditions.
PROCEDURE DIVISION Conditional Expressions Complex Conditions A complex condition is formed by using the logical operators AND and OR to combine simple, combined, and/or complex conditions, or by negating these conditions with the logical negation operator, NOT. The truth value of a complex condition, regardless of the use of parentheses, results from the interaction of all the stated logical operators on the individual truth values of simple conditions.
PROCEDURE DIVISION Conditional Expressions Although you do not need parentheses when you form a combined condition using AND or OR, you may use parentheses to clarify and to a ect the nal result of a combined condition. Table 8-4 indicates the ways in which conditions and logical operators can be combined and parenthesized. There must be a one-to-one correspondence between left and right parentheses. Any left parenthesis must be to the left of its corresponding right parenthesis.
PROCEDURE DIVISION Conditional Expressions Negated Simple Conditions The NOT operator can be used to negate simple conditions. A negated simple condition has a value of \true" only if the value of the simple condition is \false". Conversely, a negated simple condition has a value of \false" only if the simple condition itself has a value of \true".
PROCEDURE DIVISION Conditional Expressions Condition Evaluation Rules You may use parentheses to specify the order in which individual conditions of complex conditions are to be evaluated when you wish to modify the precedence rules (as listed below) for evaluating such conditions. Conditions within parentheses are evaluated rst. Within nested parentheses, the condition bounded by the innermost set is evaluated rst, followed by the condition within the next innermost set.
PROCEDURE DIVISION Conditional Expressions Figure 8-1. Evaluation of the hierarchical level condition-1 and condition-2 and . . .
PROCEDURE DIVISION Conditional Expressions Figure 8-2. Evaluation of the hierarchical level condition-1 or condition-2 or . . .
PROCEDURE DIVISION Conditional Expressions Figure 8-3.
PROCEDURE DIVISION Conditional Expressions Figure 8-4.
PROCEDURE DIVISION Conditional Expressions Abbreviated Combined Relation Conditions If you combine simple or negated simple relation conditions with logical connectives (AND and OR) in a consecutive sequence in such a way that: No parentheses are used in the consecutive sequence, and A succeeding relation condition contains the same subject as the preceding relation condition, or A succeeding relation condition contains the same subject and the same relational operator, you can abbreviate any relation cond
PROCEDURE DIVISION Conditional Expressions Examples A > B AND NOT < C OR D is equivalent to: ((A > B) AND (A NOT < C)) OR (A NOT < D) A NOT EQUAL B OR C is equivalent to: (A NOT EQUAL B) OR (A NOT EQUAL C) NOT A = B OR C is equivalent to: (NOT (A = B)) OR (A = C) NOT (A GREATER B OR < C) is equivalent to: NOT ((A GREATER B) OR (A < C)) NOT (A NOT > B AND C AND NOT D) is equivalent to: NOT ((((A NOT > B) AND ( A NOT > C)) AND (NOT (A NOT > D)))) PROCEDURE DIVISION 8-39
PROCEDURE DIVISION Common Phrases Common Phrases NNNNNNNNNNN The NOT , ROUNDED, SIZE ERROR, and CORRESPONDING phrases are common phrases used in several PROCEDURE DIVISION statements. In order to avoid describing each of these phrases each time they appear in a particular statement, they are described just once in the following paragraphs. In the description that follows, the term resultant identi er means the identi er associated with a result of an arithmetic operation.
PROCEDURE DIVISION Common Phrases ROUNDED Phrase The ROUNDED phrase consists entirely of the keyword, ROUNDED. In an arithmetic operation, if, after decimal point alignment, there are more decimal places in the fraction of the result than is speci ed for the resultant identi er, truncation is performed on the result. The number of digits truncated is dependent upon the number of decimal places speci ed for the fractional part of the resultant identi er.
PROCEDURE DIVISION Common Phrases Example 1 If the following arithmetic operation forces a SIZE ERROR condition for B, but not for C, only B has an unde ned value: ADD A TO B, C When the SIZE ERROR phrase is speci ed for an arithmetic operation and a SIZE ERROR condition exists for the values of one or more of the resultant identi ers involved, their values remain as they were before the operation was executed. Values of other resultant identi ers involved in the operation are una ected by size errors.
PROCEDURE DIVISION Common Phrases CORRESPONDING Phrase The CORRESPONDING phrase consists entirely of the word CORRESPONDING, or of the equivalent abbreviation, CORR. The purpose of the CORRESPONDING phrase is to allow you to add, subtract, or move a data item subordinate to a group item to a data item subordinate to some other group item. Two data items are said to correspond if three conditions are met. For purposes of description, assume that D1 and D2 are group items.
PROCEDURE DIVISION Common Phrases Note There is a limit of approximately 500 matching pairs allowed in a single MOVE CORRESPONDING statement. Multiple MOVEs are necessary to exceed this limit. Compiler errors 390 and 457 are given for this condition.
PROCEDURE DIVISION Common Arithmetic Features Common Features of Arithmetic Statements The ve arithmetic statements, ADD, SUBTRACT, MULTIPLY, DIVIDE, and COMPUTE have the following features in common: 1. The data descriptions of operands in an arithmetic statement need not be the same. If operands are of mixed types, the compiler generates any data conversion routines necessary to format the data. Note that this does increase the size of the code space.
PROCEDURE DIVISION Common Arithmetic Features Example The following example illustrates how a temporary location is used in an ADD statement: ADD A, B, C TO C, D, E The above ADD statement is equivalent to the following ADD statements, where TEMP is a temporary location that stores the intermediate result: ADD A,B,C GIVING TEMP ADD TEMP TO C ADD TEMP TO D ADD TEMP TO E Overlapping Operands and Incompatible Data When a sending and a receiving data item in an arithmetic statement or an INSPECT, MOVE, SET
PROCEDURE DIVISION I-O Error Handling Input-Output Error Handling Procedures Input-output error handling procedures are controlled by the following programming options in the sequence shown. First, the FILE STATUS item (if declared) is set for the associated le. Second, the INVALID KEY, AT END, or AT EOP phrases on selected I-O statements are executed. Third, if no INVALID KEY, AT END, or AT EOP is executed, a USE statement and its associated procedure is executed.
PROCEDURE DIVISION I-O Error Handling Figure 8-5.
9 PROCEDURE DIVISION Statements All statements that can be used in the PROCEDURE DIVISION are described in alphabetical order in this chapter. ACCEPT Statement The ACCEPT statement can be used for low volume input from a speci ed device.
ACCEPT Parameters a valid data name; it receives the data entered by the execution of the ACCEPT statement. in a batch job, the input stream le; in a session, this name indicates the terminal used to initiate execution of your program. There is no indication of a pending user response; thus, you should use the DISPLAY statement immediately before the ACCEPT statement to indicate that the ACCEPT statement is awaiting input. The SYSIN device for jobs (that is, in batch mode), is the stream le.
ACCEPT DAY NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN DAY-OF-WEEK TIME composed of the year of the century and day of the year, in that order. For example, February 16, 1985 is accessed as 85047. COBOL moves this data as an unsigned elementary numeric integer data item ve digits in length. composed of a single data element whose content represents the day of the week. The value, 1 represents Monday, 2 represents Tuesday, . . . , and 7 represents Sunday.
ACCEPT If the identi er named in the ACCEPT statement names a numeric or numeric-edited data item, the input must be a numeric value, with an optional leading separate sign. Any necessary conversion takes place automatically as in elementary moves (see the \MOVE Statement"). In any case other than numeric or numeric-edited data, input is assumed to be alphanumeric. No conversion takes place, but justi cation and space lling is performed as described above.
ACCEPT The following is user input to the above program: DOUBLE& TROUBLE & BUBBLE GUM The result of the above user input would be: DATA TOO LONG 'DOUBLETROUBLE BUBBL' And if the following were user input to the above program: ADD & GET ## OF SUM# The result would be: t 'ADD & GET # OF SUM ' In the rst response above, the message DATA TOO LONG was returned because the user response exceeded 19 characters. Note that the data stored did not include the ve characters, E GUM.
ACCEPT Note An ACCEPT operation prematurely terminated by a :EOD or :EOJ (in job mode) causes a read error condition and abort of the program. You can use the linefeed key to continue the transmission of characters from your screen after you have reached the right margin. This allows you to enter up to 256 characters per line before you press the RETURN key. In most cases, this avoids the necessity of sending only part of the characters required to ll the receiving data item at a given time.
ACCEPT Examples The following coding is a typical example of an ACCEPT statement. Notice the use of the DISPLAY statement before the ACCEPT statement. DISPLAY "IS THIS END-OF-MONTH? REPLY YES OR NO". ACCEPT E-O-M-FLAG. The following example presents one technique for removing a period entered as a part of a numeric eld that must be used for subsequent arithmetic operations. The following data description coding appears in the WORKING-STORAGE SECTION: 01 01 01 INPUT-AMOUNT.
ACCEPT Example 1: Minus sign conversion method This example illustrates a method whereby the person entering the data precedes the quantity with a minus sign, and the program checks for the character and converts the value to an internal negative value. ID DIVISION. PROGRAM-ID. JUNK-1. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 IN-DATA. 02 SIGN-BYTE PIC X. 02 DATA-BYTES PIC 9(6). 01 DATA-VAL PIC S9(6). PROCEDURE DIVISION. 01-ENTER-DATA.
ACCEPT ACCEPT Statement - Format 3 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Format 3 is used to transmit the date, day, day of the week , or time from the internal software clock of the system to the identi er named in the ACCEPT statement. The hardware clock is not used for these items. Example ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. FROM-TERMINAL IS SYSIN. DATA DIVISION. WORKING-STORAGE SECTION. 01 NUMBER-IN PIC 999V99. 01 DATE-IN. 02 YR PIC X(2). 02 MO PIC X(2).
ADD ADD Statement The ADD statement computes the sum of two or more operands and stores the result.
ADD Parameters In format 1 and 2, identi er-1 , identi er-2 , and so forth must refer to elementary numeric items, except that in format 2, each identi er following the word GIVING may also be an edited numeric data item. Also, the word literal means numeric literal. In format 3, both identi ers must refer to group items.
ADD Example Following is an example of the ADD statement using format 2. The operands and their assumed values are: 01 SUM-IT 01 SUM-AT PICTURE 9(9)V999. PICTURE 999V9. The receiving data items are: 01 01 TAKE-1 TAKE-2 PICTURE 9(9)V999. PICTURE 9(8)V9. The example ADD statement is: ADD SUM-IT, SUM-AT GIVING TAKE-1 TAKE-2 ROUNDED ON SIZE ERROR PERFORM REPORT-IT. ^ The composite of operands is: 329 182 The results of the ADD statament are: ^ TAKE-2 has the value 533^ 1 because of the ROUNDED phrase.
ALTER ALTER Statement The ALTER statement is an obsolete feature of the 1985 ANSI COBOL standard. The ALTER statement allows you to modify a predetermined sequence of operations. Syntax g f ALTER procedure-name-1 TO [PROCEED TO] procedure-name-2 . . . Parameters procedure-name-1 procedure-name-2 a paragraph containing a single sentence consisting of a GO TO without the DEPENDING phrase. a paragraph or section in the PROCEDURE DIVISION.
CALL, CANCEL CALL Statement In ANSI COBOL, the CALL statement can be used to transfer control from one object program to another within the same run-unit. HP COBOL II adds the ability to invoke operating system intrinsics from within a given object program. For more information on the CALL statement refer to Chapter 11, \Interprogram Communication". CANCEL Statement The CANCEL statement restores a program to its initial state and closes all les currently in open mode.
CLOSE CLOSE Statement The CLOSE statement terminates the processing of sequential, random, relative, and indexed les. It can only be executed for an open le. Syntax The CLOSE statement has two formats, depending upon whether you want to close a sequential le or one of the other three types of les. Sequential Files - Format 1 Description Rules that apply to a CLOSE statement for any type of le are described below.
CLOSE The FILE STATUS data item, if any, speci ed for the le named in the CLOSE statement is updated to indicate the success or failure of the closing operation. Refer to \FILE STATUS Clause" in Chapter 6 for valid status keys. Using a format 1 CLOSE statement, as shown above, allows you to terminate the processing of les whose organization is sequential.
CLOSE Random, Relative and Indexed Files - Format 2 The second format of the CLOSE statement is: CLOSE f le-name-1 [WITH LOCK] g . . . This form of CLOSE closes the les named by le-name-1 , and so forth, and optionally locks the les so that they cannot be opened again during execution of the current run-unit. The les named by le-name-1 , and so forth need not all have the same organization or access.
COMPUTE COMPUTE Statement The COMPUTE statement evaluates an arithmetic expression (Refer to Chapter 8, under \Arithmetic Expressions"), and assigns the result to one or more data items. Syntax Parameters identi er-1 arithmetic-expression refers to either an elementary numeric, or an elementary numeric-edited data item. any valid COBOL arithmetic expression.
COMPUTE Calculation of Intermediate Results The following description presents the conceptual compiler algorithms for determining the size and number of decimal places reserved for intermediate results. This information is provided since the manipulations performed on the intermediate results are not always obvious. These algorithms apply to all arithmetic and compute statements. The following abbreviations are used: d number of decimal places carried for an intermediate result.
COMPUTE The compiler determines the maximum value that the ir can contain by performing the statement in which the ir occurs. If an operand in this statement is a data name, the value for the data name is equal to the numerical value of the PICTURE for the data name (for example, PICTURE 9V99 has the value 9.99). If an operand is a literal, the literal's actual value is used, except in case of DIVIDE.
CONTINUE CONTINUE Statement The CONTINUE statement indicates that no executable statement is present. It is a no-operation statement and has no e ect on the execution of the program. Syntax CONTINUE Description CONTINUE can be used anywhere a conditional statement or an imperative statement is used. Example IF A < B THEN IF A < C THEN CONTINUE ELSE MOVE ZERO TO A END-IF ADD B TO C. SUBTRACT C FROM D.
DELETE DELETE Statement The DELETE statement logically removes a record from a relative or indexed le. Syntax Parameters le-name-1 imperative-statement-1 and imperative-statement-2 the name of the le from which the record is to be deleted. The le must be an indexed or relative le opened in input-output mode. one or more imperative statements. Description If the speci ed le is being used in sequential access mode, the INVALID KEY or NOT INVALID KEY phrase must not be speci ed.
DELETE For les being used in sequential access mode, the record to be deleted is the last record read by a successfully executed READ statement. The READ statement must be the last input-output operation performed on the le prior to execution of the DELETE statement. For les in dynamic or random access mode, the record removed is that record identi ed by the contents of the RELATIVE KEY or RECORD KEY data item associated with the speci ed le.
DELETE Example The following example shows the DELETE statement: . . . ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT REL-FILE ASSIGN TO "DATAFL1" ORGANIZATION IS RELATIVE ACCESS MODE IS SEQUENTIAL FILE STATUS IS CHK-REL-FILE. SELECT INDX-FILE ASSIGN TO "DATAFL2" ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS KEY-DATA FILE STATUS IS CHK-INDX-FILE. DATA DIVISION. FILE SECTION. FD REL-FILE. 01 REL-DATA 02 DATA-1 PIC 99. FD INDX-FILE. 01 INDX-DATA. 02 KEY-DATA PIC X(5).
DISPLAY DISPLAY Statement The DISPLAY statement can be used to transfer low volume data to the operator's console, a terminal, or the line printer. If more than one name is speci ed, each data item is listed in the order speci ed in the DISPLAY statement.
DISPLAY Length of Data Being Displayed As with the ACCEPT statement, hardware record sizes determine the display of the data speci ed in the DISPLAY statement. The following methods are used, depending upon whether the size of the sending item is equal to, shorter than, or longer than the hardware device designated to receive the data: If the sending item is the same length, no problem arises and the data is transmitted.
DISPLAY Example 1 Following is an example DISPLAY statement: WORKING-STORAGE SECTION. 01 BEGIN-MSG PIC X(21) VALUE " PROGRAM BEGINNING ". . . . PROCEDURE. DIVISION. . . DISPLAY CURRENT-DATE, BEGIN-MSG, TIME-OF-DAY UPON SYSOUT. t tt If the date is Tuesday, July 30, 1991 at exactly 10:45 a.m.
DIVIDE DIVIDE Statement The DIVIDE statement divides one numeric data item into one or more others, assigns the result to a data item, and optionally assigns a remainder to another data item.
DIVIDE Parameters identi er-1, identi er-2 , and so forth literal-1, literal-2 , and so forth names of elementary numeric items, except that those associated with a GIVING or REMAINDER phrase may be elementary numeric-edited items. numeric literals. Description The ROUNDED and SIZE ERROR phrases are described under the heading, \Common Phrases", in Chapter 8.
DIVIDE When format 1 of the DIVIDE statement is used, each identi er following the INTO keyword is divided, in turn, by the identi er or literal to the left of the INTO keyword. Each result is rounded if speci ed and necessary, and is then stored in the data item referenced by the identi er that acted as the dividend in that particular division.
DIVIDE Example FILE SECTION. FD PAY-FILE. 01 PAY-INFO. 02 EMP-NAME PIC X(30). 02 EMP-NUM PIC X(9). 02 PAY PIC 999V99. 02 HOURS PIC 99. WORKING-STORAGE SECTION. 77 RATE PIC 99 VALUE ZERO. 77 CHECK PIC V99 VALUE ZERO. . . . PROCEDURE DIVISION. MAIN-100. DIVIDE PAY BY HOURS GIVING RATE REMAINDER CHECK ON SIZE ERROR PERFORM SIZE-ERR. . . . SIZE-ERR. IF RATE = 0 THEN DISPLAY "SIZE ERROR IN RATE USING " PAY, HOURS ELSE DISPLAY "SIZE ERROR IN CHECK". . . . The DIVIDE statement above uses format 5.
ENTER, ENTRY ENTER Statement The ENTER statement is an obsolete feature of the 1985 ANSI COBOL standard. In ANSI COBOL'74, this statement provides a means of allowing the use of more than one language in the same program. It is, however, not allowed in HP COBOL II. Thus, if speci ed in your program, it is treated as a comment. The format is listed below for information only. The format of this statement is shown below: ENTER language-name [routine-name ].
EVALUATE EVALUATE Statement The EVALUATE statement adds a multi-condition case construct to COBOL. This statement causes a set of subjects to be evaluated and compared with a set of objects. The results of these evaluations determine the subsequent sequence of code execution.
EVALUATE Subjects and Objects The operands or the words TRUE and FALSE that appear before the rst WHEN phrase of the EVALUATE statement are referred to individually as subjects . Collectively, they are referred to as the set of subjects . The operands or the words TRUE, FALSE, and ANY that appear in a WHEN phrase of an EVALUATE statement are individually called objects . Collectively, they are called the set of objects . The words THROUGH and THRU are equivalent.
EVALUATE If the NOT phrase is speci ed for an object, the values assigned to that item are all values that are not equal to the value, or included in the range of values, that would have been assigned to the item without the NOT phrase. Refer to Chapter 8, \Relation Conditions," for more information on NOT phrases.
EVALUATE Examples The following example shows an EVALUATE statement with two data items (HOURS-WORKED and EXEMPT) as subjects: EVALUATE HOURS-WORKED WHEN 0 WHEN NOT 0 WHEN 1 THRU 40 WHEN NOT 1 THRU 40 WHEN OTHER END-EVALUATE. ALSO ALSO ALSO ALSO ALSO EXEMPT ANY PERFORM NO-PAY "Y" PERFORM SALARIED "N" PERFORM HOURLY-PAY "N" PERFORM OVERTIME-PAY DISPLAY HOURS-WORKED DISPLAY EXEMPT MOVE 0 TO HOURS-WORKED The following shows a relation condition (GRADE > 3.
EVALUATE EVALUATE INPUT-FLAG WHEN "Y" MOVE PROD-NO TO OUTPUT-REC WHEN "N" MOVE SPACES TO OUTPUT-REC WHEN "Q" PERFORM TERMINATION-ROUTINE WHEN "C" CONTINUE WHEN OTHER PERFORM GET-INPUT END-EVALUATE. The following example shows two WHEN phrases without an intervening imperative statement.
EXAMINE EXAMINE Statement The EXAMINE statement is an HP extension to the ANSI COBOL standard. It has been replaced by the INSPECT statement, covered later in this chapter. Although HP COBOL II includes the EXAMINE statement for compatibility with COBOL'68, it is advisable that you use the INSPECT statement for coding new programs. The EXAMINE statement replaces or counts the number of occurrences of a given character in a data item.
EXAMINE TALLYING Phrase When the TALLYING phrase is used in an EXAMINE statement, a count is placed in the special HP COBOL II register named TALLY. This count is an integer and represents a value that is dependent upon the keywords following the word TALLYING. If TALLYING UNTIL FIRST is speci ed, the integer in the TALLY register after execution of an EXAMINE statement is the number of occurrences of characters in identi er before the rst occurrence of literal-1 .
EXCLUSIVE EXCLUSIVE Statement The EXCLUSIVE statement is an HP extension to the ANSI COBOL standard. The EXCLUSIVE statement provides you with a method for locking a le that has been opened for shared access. Note Use of EXCLUSIVE within a program causes any OPEN of the associated le to enable the dynamic locking facility. This \locking" does not stop anyone from accessing the le. Locking and unlocking les must be done on a cooperative basis.
EXCLUSIVE Programs that are to access an indexed le concurrently, within an environment that includes modi cation of the le, must include EXCLUSIVE/UN-EXCLUSIVE statements to maintain data integrity. Refer to \MPE XL System Dependencies" in Appendix H for more information. Example The following example shows the EXCLUSIVE statement: ENVIRONMENT DIVISION. FILE-CONTROL. SELECT CUSTFILE ASSIGN TO "CUSTDATA" FILE STATUS IS CHECKER. . . . PROCEDURE.DIVISION. . . OPEN I-O CUSTFILE.
EXIT EXIT Statement The EXIT statement provides a common end point for a series of procedures. Syntax paragraph-name . EXIT. paragraph/section-name . Paragraph-name and paragraph/section-name are not a part of the EXIT statement. They are shown to clarify the fact that: EXIT must appear in a sentence by itself. EXIT must be the only sentence in a paragraph. An EXIT statement serves only to enable you to terminate a procedure and has no other e ect on the compilation or execution of the program.
EXIT PROGRAM, GOBACK EXIT PROGRAM Statement The EXIT PROGRAM statement marks the logical end of a program. For more information on the EXIT PROGRAM statement refer to Chapter 11, \Interprogram Communication". GOBACK Statement The GOBACK statement is an HP extension to the ANSI COBOL standard. The GOBACK statement marks the logical end of a program. For more information on the GOBACK statement refer to Chapter 11, \Interprogram Communication".
GO TO GO TO Statement The GO TO statement transfers control from one part of the PROCEDURE DIVISION to another. The optionality of procedure-name-1 of the GO TO statement is an obsolete feature of the 1985 ANSI COBOL standard. See the description below for more information. Syntax The GO TO statement has two formats: GO TO [procedure-name-1 ] f g GO TO procedure-name-1 . . .
GO TO Examples In the program below, the GO TO statement in the GO-PARA paragraph is equivalent to GO TO WHICH because of the ALTER statement preceding it. This form of the GO TO statement is an obsolete feature of the 1985 ANSI COBOL standard. The second GO TO statement branches to UNDER, OVER, or EXACT, depending upon whether SELECTOR has a value of 1, 2, or 3 respectively. If SELECTOR has any other value, the DISPLAY statement is executed. WORKING-STORAGE SECTION. 01 SELECTOR PIC 9(3). . . . PROCEDURE.
IF IF Statement The IF statement evaluates a condition and, depending upon the truth value of the condition, determines the subsequent action of the program. Syntax Parameters statement-1 and each are imperative or conditional statements, optionally followed by a conditional statement. statement-2 condition-1 any valid COBOL condition as described under \Conditional Expressions" in Chapter 8.
IF When an IF statement is executed, the following transfers of control occur: If the truth value of the condition is \true" and statement-1 is speci ed, then if statement-1 is a procedure branching or conditional statement, control is explicitly transferred according to the rules for that statement. If statement-1 does not contain such a statement, then statement-1 is executed and control passes to the end of the IF statement.
IF Example BEGIN SECTION. DATA-IN. READ REC-FILE RECORD INTO DATA-REC. . . . IF DATA-REC IS NOT ALPHABETIC THEN IF DATA-REC IS NOT NUMERIC PERFORM ILLEGAL-CHARACTER ELSE NEXT SENTENCE ELSE PERFORM ALPHA-TYPE. . . . The IF statements above check that the data read into DATA-REC is either all alphabetic or all numeric. The rst IF statement consists of the IF/ELSE pair: IF DATA-REC IS NOT ALPHABETIC...ELSE PERFORM ALPHA-TYPE. The second IF/ELSE pair is: IF DATA-REC IS NOT NUMERIC...ELSE NEXT SENTENCE.
INITIALIZE INITIALIZE Statement The INITIALIZE statement sets selected types of data elds to prede ned values. For example, INITIALIZE can set numeric data to zeros or alphanumeric data to spaces. Syntax Parameters literal-1 and identi er-2 identi er-1 represent the sending area. represents the receiving area. Description The description of the data item referenced by identi er-1 or any items subordinate to identi er-1 may not contain the DEPENDING phrase of the OCCURS clause.
INITIALIZE Initializing Data Fields Following are rules for initializing data elds: The keyword following the word REPLACING corresponds to a category of data as de ned under \PICTURE Clause" in Chapter 7 of this manual. INITIALIZE is executed as if a series of moves had been written. The receiving item of each MOVE is always an elementary item even if identi er-1 refers to a group item.
INITIALIZE Example WORKING-STORAGE SECTION. 01 A. 05 B PIC 999. 05 C REDEFINES B. 10 D PIC X. 10 E. PIC XX. . . PROCEDURE.DIVISION. . . INITIALIZE A. INITIALIZE C. INITIALIZE C A. When the INITIALIZE statements in the example above are executed, the data items are initialized as follows: 1. In the rst INITIALIZE, B is set to zeroes, while C, D and E are ignored. 2. In the second INITIALIZE, D and E are set to blanks. 3. In the third INITIALIZE, D and E are set to blanks. B is set to zeroes.
INSPECT INSPECT Statement The INSPECT statement can be used to perform one of three actions: It can count the number of occurrences of a given character or character substring within a data item. It can replace a given character or characters within a speci ed data item with another character or set of characters. It can perform both of the functions described above in a single operation.
INSPECT Parameters identi er-1 identi er-2 a variable representing either a group item or any category of elementary item described implicitly or explicitly as USAGE IS DISPLAY. This is the data item to be inspected. names an elementary numeric data item. It is used to contain the results of tallying occurrences of a character or characters in the data item represented by identi er-1 .
INSPECT In formats 2 and 3, the size of the data referenced by literal-3 or identi er-5 must be equal to the size of the data item referenced by literal-1 or identi er-3 . If literal-3 is a gurative constant, its size is implicitly equal to the size of literal-1 , or the size of the data item referenced by identi er-3 . If literal-1 is a gurative constant, the data referenced by literal-3 or identi er-5 must be a single character.
INSPECT Example The following two INSPECT statements are equivalent: INSPECT D-ITEM CONVERTING "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#". INSPECT D-ITEM REPLACING ALL "A" BY "X" AFTER ALL "B" BY "Y" AFTER ALL "C" BY "Z" AFTER ALL "D" BY "X" AFTER QUOTE QUOTE QUOTE QUOTE BEFORE BEFORE BEFORE BEFORE "#" "#" "#" "#".
INSPECT If all sets are used and no matches have occurred, comparison begins again, starting with the character of data to the right of the leftmost character of data . This continuing cycle of shifting one character to the right in the characters of data and using all of the sets of searchchars is terminated when, if no matches have occurred, the rightmost character of data has been used in a comparison with the last set of searchchars .
INSPECT 4. No match occurred. Begin the comparison again, starting at the fourth character: YEEXE9XY " =X? 5. A match occurred. Increment COUNTER by 1, and begin the comparison again, starting with the fth character of YEEXE9XY: YEEXE9XY " =X? 6. No match occurred. Begin the comparison again, starting with the sixth character: YEEXE9XY " =X? 7. No match occurred. Begin the comparison again, starting with the seventh character: YEEXE9XY " =X? 8. A match occurred.
INSPECT 13. No match occurred. Begin the comparison again, starting with the sixth character: YOXXE9XY "" =EE? ! YOXXE9XY " =9? 14. A match occurred. Replace 9 by E in YOXXE9XY, and begin the comparison again, at the seventh character of YOXXEEXY: ! YOXXEEXY "" " YOXXEEXY =EE? =9? 15. No match occurred. Begin the comparison again, starting with the eighth character: YOXXEEXY "" ! YOXXEEXY " =EE? =9? 16. No match occurred.
INSPECT LEADING Phrase If the LEADING phrase is used in an INSPECT statement, it causes identi er-2 (the variable used to hold the tally) to be incremented by one for each contiguous matching of searchchars with a character of data, provided that the matching begins with the leftmost character of the characters that make up data.
INSPECT INSPECT PETE REPLACING LEADING "BV" BY "AT", CHARACTERS BY "0" AFTER INITIAL "F". In the following example, COUNT-n is assumed to be zero immediately prior to execution of the statement. Table 9-1 shows the result of executing the two successive INSPECT statements. INSPECT ITEM COUNT-0 COUNT-1 COUNT-2 TALLYING FOR ALL "AB" BEFORE "BC" FOR LEADING "B" AFTER "D" FOR CHARACTERS AFTER "A" BEFORE "C".
MOVE MOVE Statement The MOVE statement transfers data to one or more data areas in accordance with the rules of editing. Syntax The MOVE statement has two general formats: Parameters identi er-1 and literal-1 identi er-2 CORR the sending areas. The special registers, TALLY, TIME-OF-DAY, CURRENT-DATE, and WHEN-COMPILED may be used as sending items. and its subsequent occurrences, are the receiving areas. an abbreviation for CORRESPONDING.
MOVE Where temp is an intermediate result item used internally by the compiler. Note that the move of A(B) to B a ects the element of C to which A(B) is moved. That is, if B is initially one and A(B) is 9, then after 9 is moved to B, A(1) is moved to C(9). It is not moved to C(1). Rules For Moving Data All data is moved according to the rules for moving elementary data items to elementary data items. This is called an elementary move.
MOVE Alphanumeric or Alphanumeric-Edited Receiving Item When an alphanumeric-edited or alphanumeric item is a receiving data item, alignment and any necessary space lling takes place as de ned under \Data Alignment" in Chapter 4. If the size of the sending item is larger than the receiving item, the excess characters are truncated on the right after the receiving data item is lled. If the sending item is a signed numeric item, the sign is not moved, regardless of whether the sign is separate or not.
MOVE Table 9-2.
MOVE Example FILE SECTION. FD FILE-IN. 01 FILE-REC. 02 EMP-FIELD. 03 NAME PIC X(20). 03 AGE PIC 99. 03 EMP-NO PIC X(9). 02 LOCALE PIC X(35). . . . WORKING-STORAGE SECTION. 01 FIELD. 02 SUB-F1 PIC BBXX 02 SUB-F2 PIC XX/XX/XX 01 NUM-IN PIC S9(3)V99 01 CARD-NUM PIC S9(3)V99 01 NUM-JUNK PIC S9(5) 01 INFO-OUT. 02 EMP-FIELD. 03 NAME 03 AGE 03 EMP-NO 02 EXEMPTIONS PIC PIC PIC PIC VALUE SPACES. VALUE SPACES. VALUE -12099. SIGN IS TRAILING VALUE ZERO.
MOVE Assuming that the current contents of FILE-REC are in order: t NAME AGE EMP-NO LOCALE ttttttttt JASON PENNY AGE 585241215 WASHINGTON DISTRICT OF COLUMBIA t t t tttt and the current contents of INFO-OUT are all spaces for NAME, AGE, and EMP-NO, and zeros for EXEMPTIONS, then the statement MOVE CORRESPONDING FILE-REC TO INFO-OUT gives the following results in INFO-OUT, NAME AGE EMP-NO EXEMPTIONS t tttttttttttt ttt t t ttt JASON PENNY 39 585 24 1215 00 Finally, the MOVE statement: MOVE NUM-IN
MULTIPLY MULTIPLY Statement The MULTIPLY statement multiplies a number by one or more other numbers and stores the result in one or more locations. Syntax The MULTIPLY statement has the following two formats: Parameters identi er-1 , identi er-2 , and so forth literal-1 and literal-2 numeric elementary items, except that in format 2, each identi er following the GIVING keyword may be numeric-edited elementary items. any numeric literal.
MULTIPLY Description The composite of operands (that is, the hypothetical data item resulting from the superimposition of all receiving data items aligned on their decimal points) in any given MULTIPLY statement must not contain more than 18 digits. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN The ROUNDED, SIZE ERROR, and NOT ON SIZE ERROR phrases, as well as multiple results and overlapping operands, are described in Chapter 8.
OPEN OPEN Statement The OPEN statement opens a speci ed le or les. It also performs checking and writing of labels, and other input or output operations. Syntax Where le-name-1 through le-name-4 are the les to be opened. Description The NO REWIND phrase can only be used for sequential les. It has no meaning for indexed, random, or relative les and must not be used for such les. When using ANSI74 entry point, EXTEND can only be used for sequential les.
OPEN The OUTPUT phrase creates a le if it does not already exist and opens it for output operations. When the output le is opened, it contains no data records. The le created is a job or session temporary le using the formal le designator speci ed in the SELECT clause. For information about how INDEX les are created, see Appendix H, \MPE XL System Dependencies." The I-O phrase permits the opening of a le for both input and output operations.
OPEN written in accordance with input-output label writing. Any user labels speci ed for the le are processed according to the procedure speci ed by a format 2 USE statement.
OPEN When label records are speci ed, but are not present, and the le was opened using the INPUT phrase, an input-output routine error results. When label records are present, but not speci ed, and the le was opened using the INPUT phrase, the label records are ignored. EXTEND, REVERSE, and NO REWIND Phrases The REVERSE and NO REWIND phrases apply to sequential les. When using the ANSI74 entry point, EXTEND can only be used for sequential les.
OPEN Table 9-4. Relative and Indexed Organization File Access Method Statement Open Mode Input Output Input-Output Sequential READ X WRITE X X REWRITE X START X X DELETE X SEEK (Rel. only) Random READ X WRITE X X X REWRITE X START DELETE Dynamic X SEEK (Rel. only) X X READ X X WRITE X X REWRITE X START X X DELETE X SEEK (Rel. only) Note X X For ANSI, EXTEND can be used with the WRITE statement only if Access Mode Sequential.
OPEN FILE STATUS Data Item If the le named in the OPEN statement has a FILE STATUS data item associated with it, the FILE STATUS data item is updated following the execution of the OPEN statement to indicate whether or not the attempt to open the le was successful. Refer to \FILE STATUS Clause" in Chapter 6 for valid combinations of status keys 1 and 2. For more information on handling I/O errors, see \Input-Output Error Handling Procedures" in Chapter 8.
PERFORM PERFORM Statement The PERFORM statement transfers control explicitly to one or more procedures, and implicitly returns control to the statement after the current PERFORM statement when execution of the speci ed procedure or procedures is complete. The PERFORM statement is also used to control execution of one or more imperative statements that are within the scope of that PERFORM statement. These parameters are used by the four general formats of the PERFORM statement.
PERFORM Syntax Format 1 of the PERFORM statement is the basic PERFORM statement. The speci ed set of statements is executed once as described on the preceding pages. Control then passes to the next executable statement following the PERFORM statement.
PERFORM A format 2 PERFORM statement allows you to perform the speci ed set of statements the number of times speci ed by integer-1 or the numeric integer named by identi er-1 . Following the execution of the statements, control is passed to the next executable statement following the PERFORM statement. If identi er-1 is a negative integer or zero (0) when the PERFORM statement is executed, control immediately passes to the next executable statement following the PERFORM statement.
PERFORM A format 3 PERFORM statement uses condition-1 to control the number of times the speci ed set of statements is performed. The statements are performed as long as condition-1 is false. When condition-1 is true, control passes to the next executable statement after the PERFORM. Note Be sure that, within the speci ed set of statements, condition-1 eventually has a value of true.
PERFORM PROCEDURE DIVISION Statements 9-79
PERFORM Up to six AFTER phrases can be speci ed in format 4. However, if procedure-name-1 is omitted, the AFTER phrase cannot be speci ed. Any literal used in the BY phrase, and data items referenced by identi er-4 , identi er-7 , and identi er-10 must not have a value of zero.
PERFORM Out-of-Line PERFORM When a PERFORM statement is executed, control is transferred to the rst statement of the procedure named procedure-name-1 . This transfer occurs only once for each execution of a PERFORM statement. An implicit transfer of control to the next executable statement following the PERFORM statement is established as follows: If procedure-name-1 is a paragraph name and procedure-name-2 is not speci ed, then the return occurs after the last statement of procedure-name-1 .
PERFORM In-Line PERFORM If an in-line PERFORM statement is speci ed, an execution of the PERFORM statement is completed after the last statement contained within it has been executed. When an in-line PERFORM statement is executed, control is transferred to the rst statement of imperative-statement-1 . This transfer occurs only once for each execution of a PERFORM statement. Following is an example of an in-line PERFORM statement: PERFORM MOVE A TO B ADD 1 TO B END-PERFORM.
PERFORM Range of the PERFORM Statement The range of the PERFORM statement includes all statements that are executed as a result of executing the PERFORM statement through an implicit transfer of control to the end of the PERFORM statement. The range includes all statements that are executed as the result of a transfer of control by CALL, EXIT, GO TO and PERFORM statements within the range of the PERFORM statement.
PERFORM PERFORM Constructs Figure 9-1 gives three illustrations of valid PERFORM constructs. Figure 9-1. Valid PERFORM Constructs Note Refer to \MPE XL System Dependencies" in Appendix H for more information on the PERFORM statement.
PERFORM NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN When the TEST BEFORE phrase is specified or implied: NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
PERFORM NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN When the TEST AFTER phrase is specified: NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNN
PERFORM Variation of Two or More Identifiers Variation of two or more identi ers is accomplished using format 4 of the PERFORM statement in the following form: Note The format indicates that variation of two or more identi ers only applies to the out-of-line PERFORM; AFTER phrases are not included in the in-line PERFORM. There are three cases of the PERFORM . . . VARYING statement with two or more identi ers. The rst case conforms to ANSI COBOL'74, and the other two cases conform to ANSI COBOL'85.
PERFORM ANSI COBOL'74 In this case, parameter-1 and parameter-4 are set to the current values of parameter-2 and parameter-5 respectively. Following this, condition-1 is tested and if true, causes the PERFORM statement to cease execution. Control is transferred to the next executable statement following the PERFORM statement. If condition-1 is false, condition-2 is tested with the same consequences as condition-1 if the result is true.
PERFORM The owchart in Figure 9-4 illustrates PERFORM . . . VARYING with two conditions. Figure 9-4.
PERFORM ANSI COBOL'85 NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN When TEST BEFORE is specified: NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NN
PERFORM Figure 9-5 illustrates the PERFORM . . . VARYING statement with the TEST BEFORE phrase having two conditions. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Figure 9-5.
PERFORM NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN When TEST AFTER is specified: NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN NNNNNNNNNNNNNNNNN
PERFORM Figure 9-6 illustrates the PERFORM . . . VARYING statement with the TEST AFTER phrase having two conditions. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Figure 9-6.
PERFORM Variation of More than Two Identifiers When data items referenced by two identi ers are varied, the data item referenced by identi er-5 goes through a complete cycle (FROM, BY, UNTIL) each time the content of the data item referenced by identi er-2 is varied. When the contents of three or more data items referenced by identi ers are varied, the mechanism is the same as for two identi ers.
PERFORM Examples The following program fragment shows several examples of PERFORM statements. 01 DISKIN-RECORD. 03 DI-DATA OCCURS 4 TIMES. 05 DI-NAME PIC X(20). 05 DI-ADDRESS PIC X(20). 05 DI-CTY-ST PIC X(20). 05 DI-ZIP PIC 9(05). 05 DI-AMOUNT PIC 9(03)V99 OCCURS 3 TIMES. 01 WS-FILE-CTR. 03 WS-AMOUNT PIC 9(06)V99 COMP VALUE 0. 03 SUB-1 PIC 9(01). 03 SUB-2 PIC 9(01). 03 WS-DISKIN-CTRL PIC 9(01) VALUE 0. 88 WS-DISKIN-TO-OPEN VALUE 0. 88 WS-DISKIN-OPEN VALUE 1. 88 WS-DISKIN-EOF VALUE 2. PROCEDURE DIVISION.
PERFORM ** EXAMPLE OF PERFORM USING # OF TIMES OPTION ************ PERFORM 270-ACCUMULATE-AMOUNTS 3 TIMES. 270-ACCUMULATE-AMOUNTS. ADD 1 TO SUB-2. ADD DI-AMOUNT (SUB-1,SUB-2)TO WS-AMOUNT. 300-GET-DISKIN-RTN. IF WS-DISKIN-TO-OPEN OPEN INPUT DISKIN-FILE MOVE 1 TO WS-DISKIN-CTRL. READ DISKIN-FILE AT END CLOSE DISKIN-FILE MOVE 2 TO WS-DISKIN-CTRL. 300-GET-DISKIN-EXIT. EXIT.
READ READ Statement The READ statement makes a record of a le available to your program. Syntax READ has three formats depending on the type of organization of the le from which a record is made available.
READ Parameters imperativestatement-1 name of the le to be read. data item described in the WORKING-STORAGE or FILE SECTION. one or more imperative statements, executed when an INVALID KEY or AT END condition occurs.
READ READ Statement - Format 1 A format 1 READ statement may be used for sequential, relative, random, or indexed les. The READ statement must be used for relative or indexed les whose access mode is sequential (see the SELECT clause). It must also be used, including the NEXT phrase, when the access mode for a relative or indexed le is dynamic and records of the le are being accessed sequentially and to read records sequentially from a random access le.
READ Following the unsuccessful execution of any READ statement, the contents of the associated record area and the position of the le position indicator are unde ned. For indexed les, the key of reference is also unde ned.
READ Next, if there is a USE procedure for the le, and an INVALID KEY condition exists but the INVALID KEY phrase was not speci ed in the READ statement, the procedure named in the USE statement is executed. If there is no USE procedure speci ed for the le, the INVALID KEY phrase must be used in the READ statement; when an INVALID KEY condition exists, control is passed to imperative-statement-1 in the INVALID KEY phrase.
RELEASE, RETURN RELEASE Statement The RELEASE statement can be used in an input procedure of a SORT statement to transfer records from your program to the initial phase of the sort operation. For more information on the RELEASE statement refer to Chapter 12, \SORT/MERGE Operations". RETURN Statement The RETURN statement can be used in an output procedure of a SORT or MERGE statement. It cannot be used in any other type of procedure.
REWRITE REWRITE Statement The REWRITE statement logically replaces an existing record in a sequential, relative, random, or indexed mass storage le. The le position indicator is una ected by the execution of a REWRITE statement. Variable length records are not allowed when using the REWRITE statement. Syntax There are two formats of the REWRITE statement: Parameters record-name-1 identi er-1 imperativestatement-1 name of a logical record in the FILE SECTION of the DATA DIVISION.
REWRITE Description The le associated with record-name-1 must be a mass storage le, and must be opened in I-O mode when the REWRITE statement is executed. The number of character positions in the record referenced by record-name-1 must be equal to the number of character positions in the record being replaced.
REWRITE For more information on handling I/O errors, see \Input-Output Error Handling Procedures" in Chapter 8. When an indexed le is the object of a REWRITE statement, the contents of alternate record key data items of the record being rewritten may di er from those of the record being replaced. These alternate keys are used during the execution of the REWRITE statement in such a way that subsequent access of the record may be made based upon any of the speci ed record keys.
SEARCH SEARCH Statement The SEARCH statement searches a table for an element that satis es some condition, and sets the table's index name to the value of the occurrence number of the element that was found.
SEARCH Parameters identi er-1 identi er-2 condition-1 and condition-2 condition-name-1 and condition-name-2 data-name-1 and data-name-2 identi er-3 and identi er-4 arithmetic-expression-1 and arithmetic-expression-2 imperative-statement-1 and imperative-statement-2 name of a table. It must not be subscripted or indexed, and must also contain an OCCURS and an INDEXED BY clause in its description. If used in format 2, it must also contain a KEY IS phrase in its OCCURS clause.
SEARCH SEARCH Statement - Format 1 When you use a format 1 SEARCH statement, a serial search is performed, starting with the current index setting of the index name associated with identi er-1 . If the index name associated with identi er-1 contains a value corresponding to an occurrence number greater than the highest possible occurrence number of identi er-1 , the SEARCH statement is terminated immediately. If an AT END phrase is speci ed, the imperative-statement-1 within the phrase is executed.
SEARCH The owchart in Figure 9-7 shows the execution of a format 1 SEARCH statement specifying two WHEN phrases. Figure 9-7.
SEARCH SEARCH Statement - Format 2 If you use a format 2 SEARCH statement, a binary search is done. The index name used in the search is the rst (or only) index name appearing in the INDEXED BY phrase of identi er-1 . Any other index names for identi er-1 remain unchanged. The results of a format 2 SEARCH statement are predictable only under three conditions: 1.
SEARCH Example WORKING-STORAGE SECTION. 01 PARTS-TABLE. 02 PARTS-INFO OCCURS 10 TIMES INDEXED BY PT-INDX. 03 PART-NAME PIC X(20). 03 PART-NUMBER PIC X(10). 03 MEASURES OCCURS 5 TIMES ASCENDING KEY IS VOLUME, HEIGHT, WIDTH INDEXED BY IND-T2. 04 HEIGHT PIC 999V999. 04 WIDTH PIC 999V999. 04 LGTH PIC 999V999. 04 VOLUME PIC 999V999. 77 NEXT-NUM PIC 99 VALUE 1. 01 CONTAINER-INFO. 02 PT-NAME PIC X(20). 02 FILLER PIC X(5) VALUE SPACES. 02 PT-NO PIC X(10). 02 FILLER PIC X(3) VALUE SPACES. 02 DIMENSIONS.
SEARCH CONTAINER-SELECTION. DISPLAY "THIS SECTION SEARCHES FOR A CONTAINER". DISPLAY "OF A SPECIFIED VOLUME WHOSE HEIGHT AND". DISPLAY "WIDTH BOTH ARE FIVE. PLEASE SPECIFY THE VOLUME". DISPLAY "REQUIRED (IN AN EVEN NUMBER OF CUBIC FEET.)". ACCEPT NEEDED-VOLUME. SEARCH-PARTS-TABLE. MOVE 1 TO NEXT-NUM. SET PT-INDX IND-T2 TO 1. SEARCH ALL MEASURES AT END PERFORM NO-SUCH-CONTAINER. WHEN VOLUME (PT-INDX, IND-T2) = NEEDED-VOLUME AND WIDTH (PT-INDX, IND-T2) = 5 AND HEIGHT (PT-INDX, IND-T2) = 5 PERFORM FOUND-IT. .
SEEK SEEK Statement The SEEK statement is an HP extension to the ANSI COBOL standard. It is provided for COBOL'68 compatibility. The SEEK statement initiates access to a relative le whose access mode is dynamic or random, and to a random access le, prior to execution of a format 2 READ statement. Syntax SEEK le-name RECORD Description The SEEK statement is valid only for input les. The le speci ed in a SEEK statement must be opened prior to the rst SEEK statement.
SET SET Statement The SET statement establishes reference points for table handling operations by setting index names associated with table elements. This statement can also be used to alter the status of external switches, and to alter the value of conditional variables.
SET Parameters identi er-1 , identi er-2 identi er-3 integer-1 and integer-2 index-name-1 , index-name-2 , and so forth mnemonic-name-1 condition-name-1 Note must each name either index data items or elementary items described as integers. must be described as an elementary numeric integer. may be signed, with the restriction that integer-1 must be positive. each related to a given table. must be associated with a software switch, whose status can be altered.
SET Table 9-6 shows the validity of various operand combinations in the SET statement. Table 9-6. Validity of Different Combinations of Operands in the SET Statement Sending Item Integer Literal Receiving Item Integer Data Item Index Name Index Data Item Not allowed Valid Not allowed Integer Data Item Not allowed Valid Not allowed Index Name Valid Valid1 Valid2 Index Data Item Not allowed Valid2 Valid2 1 No conversion takes place if row sizes are equal. 2 No conversion takes place.
START START Statement The START statement provides a basis for logical positioning within a relative or indexed le, in sequential or dynamic access mode, for subsequent retrieval of records. Syntax Note The required relational characters '>' , '<' , '>=' , and '=' are not underlined to avoid confusion with other symbols such as ' ' (greater than or equal to). Parameters le-name-1 data-name-1 imperative-statement-1 and imperative-statement-2 the name of a relative or indexed le.
START Description When the START statement executes, a comparison is made between a key associated with le-name-1 , and a data item. If the KEY phrase is unused, the relational operator, \IS EQUAL TO" is assumed. The data item used in the comparison depends upon whether the le named in the START statement is a relative or an indexed le. If the le is a relative le, the comparison uses the data item referenced in the RELATIVE KEY clause of the le's SELECT statement.
START Upon completion of a successful START statement for an indexed le, a key of reference is established and used in subsequent format 1 READ statements. If the KEY phrase is not speci ed in an indexed le START statement, the primary key is established as the key of reference. If the KEY phrase is speci ed, and data-name-1 is any record key (primary or alternate) for the le, that record key becomes the key of reference.
STOP STOP Statement The STOP statement provides a means of temporarily suspending execution of your object program, as well as a means of stopping it completely. Syntax Parameters RUN literal-1 if speci ed, causes the entire run-unit to cease execution when it is encountered, regardless of whether the STOP RUN statement is in a subprogram or a main program. Control is then returned to the operating system. may be numeric, nonnumeric, or any gurative constant except ALL.
STRING STRING Statement The STRING statement concatenates the partial or complete contents of two or more data items into a single data item. Syntax Parameters literal-1 and literal-2 identi er-1 and identi er-2 identi er-3 identi er-4 imperative-statement-1 and imperative-statement-2 any gurative constant or any nonnumeric literal except ALL; none of them may be numeric literals. described implicitly or explicitly as USAGE DISPLAY.
STRING Description All references to identi er-1 , identi er-2 , identi er-3 , literal-1 , and literal-2 apply equally to identi er-4 , respectively, and all recursions thereof.
STRING The POINTER phrase is available for you to de ne the starting position of identi er-3 to which data is to be moved. For example, if the phrase WITH POINTER COUNT is used and the value of COUNT is 10, the rst character transferred from the sending items is placed in the tenth character position (from the left) of identi er-3 . Not using the POINTER phrase is equivalent to specifying WITH POINTER 1.
STRING With the de nitions of data names as described in the WORKING-STORAGE SECTION, and with CHAR-COUNT set to 2, the STRING statement lls RECEIVER as follows: If the three statements below are used instead, an over ow condition is caused. MOVE SPACES TO RECEIVER. MOVE 10 TO CHAR-COUNT STRING SENDER-A DELIMITED BY SIZE INTO RECEIVER WITH POINTER CHAR-COUNT ON OVERFLOW DISPLAY "OVERFLOW IN RECEIVER" DISPLAY "VALUE OF COUNTER IS ", CHAR-COUNT.
SUBTRACT SUBTRACT Statement The SUBTRACT statement subtracts one or more numeric data items from one or more numeric data items and stores the result in one or more data items.
SUBTRACT Parameters identi er-1 , identi er-2 , and so forth elementary numeric data items, or if to the right of the keyword GIVING, may be elementary numeric-edited data items. The exception is in format 3, where identi er-1 and identi er-2 must be group items. literal-1 , literal-2 , numeric literals. and so forth CORR abbreviation for CORRESPONDING. Description The compiler always ensures that enough places are carried in order to avoid losing signi cant digits.
SUBTRACT Examples SUBTRACT FIRST-YR, SECOND-YR FROM THIRD-YR. SUBTRACT HIRE-DATE FROM AGE GIVING YEARS-OF-SERVICE. In the rst example above, the value of FIRST-YR is added to the value of SECOND-YR, and this sum is subtracted from, and stored in THIRD-YR. In the second example, the value of AGE is subtracted from the value of HIRE-DATE, and the results are stored in YEARS-OF-SERVICE.
UN-EXCLUSIVE UN-EXCLUSIVE Statement The UN-EXCLUSIVE statement is an HP extension to the ANSI COBOL standard. The UN-EXCLUSIVE statement releases a le that has been previously locked by the EXCLUSIVE statement. Syntax UN-EXCLUSIVE le-name-1 Parameter le-name-1 is the name of a le that has been locked using the EXCLUSIVE statement. Description It is not necessary to unlock a locked le before closing it. An implicit UN-EXCLUSIVE statement is performed when you close the le.
UNSTRING UNSTRING Statement The UNSTRING statement divides data in a sending eld and places the segments of the data into multiple receiving elds. Syntax Parameters literal-1 and literal-2 identi identi identi identi identi er-1 , er-2 , er-3 , and er-5 , er-4 identi er-7 Note identi er-6 and identi er-8 nonnumeric literals; may also be any gurative constants without the optional word ALL. must be described implicitly or explicitly as alphanumeric data items. Identi er-1 may not be reference modi ed.
UNSTRING Description No identi er may name a level 88 entry. If the DELIMITED BY phrase is not speci ed, the DELIMITER IN and COUNT IN phrases must not be used. Identi er-1 represents the sending item. Identi er-4 represents the receiving data item. Identi er-2 or its associated literal, and identi er-3 or its associated literal, represent delimiters on the sending item. If a gurative constant is used as a delimiter, it stands for a single character nonnumeric literal.
UNSTRING Execution of the UNSTRING Statement When the UNSTRING statement is initiated, the current receiving item is the rst receiving item. If the POINTER phrase is speci ed, the sending item is examined beginning with the character position indicated by the contents of the data item referenced by identi er-7 . If this phrase is not used, examination begins with the leftmost character of the sending item.
UNSTRING Overflow Conditions An over ow condition is caused by one of two situations. The rst, described under the parameters description above, is caused by an invalid value for the data item represented by identi er-7 . The second situation is when all receiving items have been acted upon, but there remain unexamined characters in the sending item. When an over ow condition occurs, execution of the UNSTRING condition ceases.
UNSTRING Example DATA DIVISION. WORKING-STORAGE SECTION. 01 ID-INFO PIC X(35). 01 EMPLOYEE-TABLE. 02 EMPLOYEE-STATS OCCURS 30 TIMES. 03 NAME PIC X(40). 03 BIRTH-DATE PIC X(6). 03 HAIR-COLOR PIC X(12). 03 EYE-COLOR PIC X(12). 03 HEIGHT PIC X(2). 01 01 01 01 01 SUBSCRIPTOR PIC X. SUBSCRIPT PIC 99 VALUE 1. INCREMENT PIC X VALUE ";". CHARS PIC S9(4) USAGE COMP. COMPLETE-INFO PIC S9(4) USAGE COMP. . . . MOVE 1 TO CHARS. MOVE 0 TO COMPLETE-INFO.
UNSTRING Phase 2: WILSON JAMES,030250, " new pointer " delimiter found Move 030250 into BIRTH-DATE(1). Increment the value of CHARS by 7, giving 21. Phase 3: WILSON JAMES,030250,BLONDE, " new pointer " delimiter found Move \BLONDE" into HAIR-COLOR(1) , lling in spaces to the left of the rightmost character. Increment the value of CHARS by 7, giving 28. Phase 4: WILSON JAMES,030250,BLONDE,BLUE, " " new pointer delimiter found Move \BLUE" into EYE-COLOR(1) .
USE USE Statement The USE statement speci es procedures for input-output error handling, user label processing, and debugging. These procedures are an addition to the standard procedures provided by the input-output control system. Syntax There are three general formats of the USE statement: For a description of format 3, refer to Chapter 12, \Debug Module".
USE Description The rules below apply to both formats of the USE statement. A USE statement, when speci ed, must immediately follow a section header in the declaratives section and must be followed by a period and a space. The remainder of the section must consist of zero, one, or more procedural paragraphs that de ne the procedures to be used. These paragraphs make up the procedures that are executed when required. The USE statement itself is never executed.
USE USE Statement - Format 2 This format of the USE statement is an HP extension to the ANSI COBOL standard. The format 2 USE statement is for reading and writing user labels on a le, starting immediately after the operating system label at the beginning of a le. There may be as many as eight user labels following an operating system label, and each label may consist of 80 characters. When user labels are read by your program, only one location is made available for them in memory.
USE The purpose of the exception mentioned above is to allow you to read or write more than one user label (up to eight). The exception is the use of the GO TO MORE-LABELS statement within a format 2 USE procedure. The function of this statement varies according to how the le was opened: Input les - Control returns to the software that reads an additional user label, and then transfers control back to the rst statement of the USE procedure.
WRITE WRITE Statement The WRITE statement releases a logical record. To use the WRITE statement for a sequential le, the le must be opened in the OUTPUT or EXTEND mode. To use the WRITE statement with an indexed, relative, or random le, the le must be opened in either OUTPUT, I-O mode, or EXTEND for access mode sequential.
WRITE Parameters record-name-1 identi er-1 identi er-2 integer-1 mnemonic-name-1 END-OF-PAGE and EOP imperative-statement-1 and imperative-statement-2 , the name of a logical record in the FILE SECTION of the DATA DIVISION. It may be quali ed. Record-name-1 must not reference the same storage area as identi er-1 . Additionally for random access les, record-name-1 must not be part of a SORT le. the name of a data item described within the DATA DIVISION, or a function-identi er.
WRITE FROM Phrase The results of executing a WRITE statement using the FROM phrase is equivalent to executing the statement, MOVE identi er-1 TO record-name-1 and then executing the same WRITE statement without the FROM phrase. Unlike the record area for record-name-1 , the data in identi er-1 always remains in memory and is available after execution of the WRITE statement, regardless of whether a SAME RECORD AREA clause was used for any le in which identi er-1 names a data item.
WRITE does not contain a LINAGE clause, the repositioning is to the rst line of the next logical page. If PAGE is speci ed for a device to which it has no meaning, advancing is provided that is equivalent to ADVANCING 1 LINE. If mnemonic-name-1 is speci ed, the le receiving the record must not contain a LINAGE clause in its description and must be a line printer device le.
WRITE END-OF-PAGE Phrase The END-OF-PAGE phrase can be used only in conjunction with the LINAGE clause of a sequential le description entry.
WRITE Two conditions may occur that cause the execution of the END-OF-PAGE phrase. The rst occurs when a footing area has been de ned using integer-2 or data-name-2 of the LINAGE Clause. In this case, when a WRITE statement using the END-OF-PAGE phrase is executed, and this execution causes printing or spacing within the footing area, an end-of-page condition occurs. This is controlled by the value of the LINAGE-COUNTER for the associated le.
WRITE Multiple Reel/Unit Files After an end-of-reel condition has been recognized for a multiple reel labeled tape, the WRITE statement performs the standard ending reel or unit procedure, requests a reel or unit swap, and then performs the standard reel or unit label procedure. The record is then written according to the speci cations of the WRITE statement. Print Files A print le is organized like a sequential organization le and has carriage control.
WRITE Carriage Control Codes. The carriage control codes that COBOL uses are de ned within the MPE FWRITE intrinsic. They are written in the rst byte of each data record or passed through the control parameter. The carriage control codes and their meanings are shown in Table 9-7. Table 9-7. Carriage Control Codes and Their Meanings Code Meaning %2n Space n lines (no automatic page eject). The number n is in the range 0 through %77 (63). %3n Channel options C01 through C16.
WRITE Relative Files When a format 2 WRITE statement is issued for a relative le, and the le is open for output in sequential mode, the rst execution of a WRITE statement for the le releases a record to that le, assigning a relative record number of 1 to it. Subsequent WRITE statements assign relative record numbers of 2,3,4, and so on as records are released to the le.
WRITE Note A WRITE statement for an indexed le open in sequential access mode must write records to the le in ascending order of prime record key values. A WRITE statement for an indexed le in random or dynamic access mode writes a record to the le in whatever order your program speci es. When a WRITE statement is successfully executed for an indexed le, all keys of the record are used in such a way that subsequent access of the record may be made based upon any of the speci ed record keys.
10 COBOL Functions This chapter describes the built-in COBOL functions and how to call them. These functions were de ned in 1989 by Addendum 1 of the ANSI COBOL '85 standard. The built-in functions provide the capability to reference a data item whose value is derived automatically at the time of reference during the execution of the program. The following tables list and brie y describe each function: Table 10-1.
COBOL Functions Table 10-3. General Functions Function MAX MIN ORD-MAX ORD-MIN Type Depends on parameters. Depends on parameters. Integer Integer Value Returned Maximum value of all parameters. Minimum value of all parameters. Ordinal position of maximum parameter. Ordinal position of minimum parameter. Table 10-4.
COBOL Functions Table 10-6. Trigonometric Functions Function COS SIN TAN ACOS ASIN ATAN Type Numeric Numeric Numeric Numeric Numeric Numeric Value Returned Cosine of an angle in radians. Sine of an angle in radians. Tangent of an angle in radians. Arccosine, in radians, of a numeric value. Arcsine, in radians, of a numeric value. Arctangent, in radians, of a numeric value. The $CONTROL POST85 Option You must specify $CONTROL POST85 in any program that calls a COBOL function.
COBOL Functions Function Types Functions are treated like temporary, elementary data items. Use them wherever you would use an elementary data item, with the exceptions noted below. Functions cannot be receiving operands. Functions return alphanumeric, numeric, or integer values, as follows: Alphanumeric functions are of the class and category alphanumeric, and have an implicit usage of DISPLAY. Numeric functions are of the class and category numeric and always have an operational sign.
COBOL Functions Function Parameters Some of the functions require one or more parameters. Function parameters can be identi ers, arithmetic expressions, or literals. See the description of each function for speci c information about its parameters. If a function requires parameters and you do not supply any, or if the parameters supplied do not comply with all restrictions for parameters to that function, the value returned by the function is unde ned.
COBOL Functions Calling COBOL Functions To call any of the COBOL functions, simply put the function call in any statement where a data item of the function type is valid. You must use $CONTROL POST85 and the ANSI85 entry point to the HP COBOL II/XL compiler when calling any COBOL function. Examples To change all the characters in a string to lower case, use the LOWER-CASE function in a MOVE statement: 77 MY-NAME PIC X(5) VALUE "STEVE". . . . DISPLAY MY-NAME. MOVE FUNCTION LOWER-CASE (MY-NAME) TO MY-NAME.
ACOS ACOS Function The ACOS function returns the arccosine of the parameter. The function type is numeric. Syntax FUNCTION ACOS (parameter-1) Parameters parameter-1 Must be class numeric and must be between -1 and 1, inclusive. Return Value The value returned is the approximation of the arccosine of parameter-1 and is between 0 and , inclusive. The return value is a numeric value in radians. Example 77 COS-OF-ANGLE PIC S9V9(5) VALUE +0.70711. 77 ANGLE-RADIANS PIC S99V9(5) VALUE ZERO. . . .
ANNUITY ANNUITY Function The ANNUITY function (annuity immediate) returns a numeric value that is the ratio of an annuity paid at the end of each period for the number of periods speci ed by parameter-2 to an initial investment of one. Interest is earned at the rate speci ed by parameter-1 and is applied at the end of the period before the payment. The function type is numeric. Syntax FUNCTION ANNUITY (parameter-1 parameter-2) Parameters Must be class numeric and must be greater than or equal to zero.
ASIN ASIN Function The ASIN function returns the arcsine of the parameter. The function type is numeric. Syntax FUNCTION ASIN (parameter-1) Parameters parameter-1 Must be class numeric and must be between -1 and 1, inclusive. Return Value The value returned is the approximation of the arcsine of parameter-1 and is between - /2 and /2, inclusive. The return value is a numeric value in radians. Example 77 SIN-OF-ANGLE PIC S9V9(5) VALUE +0.70710. 77 ANGLE-RADIANS PIC S99V9(5) VALUE ZERO. . . .
ATAN ATAN Function The ATAN function returns the arctangent of the parameter. The function type is numeric. Syntax FUNCTION ATAN (parameter-1) Parameters parameter-1 Must be class numeric. Return Value The value returned is the approximation of the arctangent of parameter-1 and is between - /2 and /2, inclusive. The return value is a numeric value in radians. Example 77 TAN-OF-ANGLE PIC S9(5)V9(5) VALUE +00000.99998. 77 ANGLE-RADIANS PIC S99V9(5) VALUE ZERO. . . .
CHAR CHAR Function The CHAR function returns a one-character alphanumeric value that is a character in the program collating sequence having the ordinal position equal to the value of parameter-1 . The function type is alphanumeric. Syntax FUNCTION CHAR (parameter-1) Parameters parameter-1 Must be an integer. Must be greater than zero and less than or equal to the number of positions in the collating sequence.
COS COS Function The COS function returns the cosine of an angle. The function type is numeric. Syntax FUNCTION COS (parameter-1) Parameters parameter-1 The size of an angle in radians. Must be class numeric. Return Value The value returned is the approximation of the cosine of parameter-1 and is between -1 and 1, inclusive. The value returned is numeric. Example 77 ANGLE-RADIANS PIC S99V9(5) VALUE 3.14159. 77 COS-OF-ANGLE PIC S9V9(5) VALUE ZERO. . . .
CURRENT-DATE CURRENT-DATE Function The CURRENT-DATE function returns the calendar date, time of day, and the di erence between the local time and Universal Coordinated Time (UTC), or Greenwich Mean Time. To get the correct time di erential, you need to set the environment variable TZ to your local time zone. See below for more information. The function type is alphanumeric. This function is di erent from the CURRENT-DATE special register word (described in Chapter 3).
CURRENT-DATE Character Positions 18-19 Contents Depending on the value of character position 17, one of the following: Position 17 20-21 Contents - Two numeric digits in the range 00 through 12 indicating the number of hours that the reported time is behind Greenwich Mean Time. + Two numeric digits in the range 00 through 13 indicating the number of hours that the reported time is ahead of Greenwich Mean Time. 0 The value 00 is returned.
CURRENT-DATE Table 10-7. Time Zones and TZ Environment Variable Values TZ Value Time Zone Geographic Area HST10 Hawaiian Standard Time, Hawaiian Daylight Time. Unites States: Hawaii. AST10ADT Aleutian Standard Time, Aleutian Daylight Time. United States: Alaska (parts). YST9YDT Yukon Standard Time, Yukon Daylight Time. United States: Alaska (parts). PST8PDT Paci c Standard Time, Paci c Daylight Time. Canada: British Columbia.
CURRENT-DATE Table 10-7. Time Zones and TZ Environment Variable Values (continued) TZ Value Time Zone Geographic Area SAST-2SADT South Africa Standard Time, South Africa Daylight Time. South Africa. JST-9 Japan Standard Time. Japan. WST-8:00 Australian Western Standard Time. Australia: Western Australia. CST-9:30 Australian Central Standard Time. Australia: Northern Territory. CST-9:30CDT Australian Central Standard Time, Australian Central Daylight Time. Australia: South Australia.
CURRENT-DATE Example 01 FULL-CURRENT-DATE. 05 C-DATE. 10 C-YEAR PIC 9(4). 10 C-MONTH PIC 99. 10 C-DAY PIC 99. 05 C-TIME. 10 C-HOUR PIC 99. 10 C-MINUTES PIC 99. 10 C-SECONDS PIC 99. 10 C-SEC-HUND PIC 99. 05 C-TIME-DIFF. 10 C-GMT-DIR PIC X. 10 C-HOUR PIC 99. 10 C-MINUTES PIC 99. . . . MOVE FUNCTION CURRENT-DATE TO FULL-CURRENT-DATE. DISPLAY "Full date is: ", FULL-CURRENT-DATE. DISPLAY "Year is: ", C-YEAR. DISPLAY "Month is: ", C-MONTH. DISPLAY "Day is: ", C-DAY. DISPLAY "Hour is: ", C-HOUR OF C-TIME.
DATE-OF-INTEGER DATE-OF-INTEGER Function The DATE-OF-INTEGER function converts a date in the Gregorian calendar from integer date form to standard date form (YYYYMMDD). The function type is integer. Syntax FUNCTION DATE-OF-INTEGER (parameter-1) Parameters parameter-1 Is a positive integer that represents a number of days succeeding December 31, 1600 in the Gregorian calendar. Return Value The returned value represents the ISO Standard date equivalent of the integer speci ed in parameter-1 .
DATE-OF-INTEGER Example The following example shows both the INTEGER-OF-DATE and DATE-OF-INTEGER functions. First, the year-month-day form of the date is converted to an integer using INTEGER-OF-DATE. This integer represents the number of days since December 31, 1600. Then, 30 is added to this number and it is converted back to the year-month-day form. 01 INT-DATE PIC 9(8) VALUE ZERO. 01 DATE-TODAY PIC 9(8) VALUE ZERO. 01 DUE-DATE PIC 9(8) VALUE ZERO. . . . MOVE 19910220 TO DATE-TODAY.
DAY-OF-INTEGER DAY-OF-INTEGER Function The DAY-OF-INTEGER function converts a date in the Gregorian calendar from integer date form to Julian date form (YYYYDDD). The function type is integer. Syntax FUNCTION DAY-OF-INTEGER (parameter-1) Parameters parameter-1 Is a positive integer that represents a number of days succeeding December 31, 1600 in the Gregorian calendar. Return Value The returned value represents the Julian equivalent of the integer speci ed in parameter-1 .
DAY-OF-INTEGER Example The following example shows both the INTEGER-OF-DAY and DAY-OF-INTEGER functions. First the year-day form of the date is converted to an integer using INTEGER-OFDAY. This integer represents the number of days since December 31, 1600. Then 30 is added to the integer form and it is converted back to the year-day form using DAY-OF-INTEGER. 01 INT-DATE PIC 9(8) 01 DATE-TODAY PIC 9(7) 01 DUE-DATE PIC 9(7) . . . MOVE 1991051 TO DATE-TODAY. COMPUTE INT-DATE = FUNCTION DISPLAY DATE-TODAY.
FACTORIAL FACTORIAL Function The FACTORIAL function returns an integer that is the factorial of parameter-1 . The function type is integer. Syntax FUNCTION FACTORIAL (parameter-1) Parameters parameter-1 Must be an integer greater than or equal to zero. (The largest value parameter-1 can be is 20 in order for the result to t in 18 digits.) Return Value If the value of parameter-1 is zero, the value one is returned. If the value of parameter-1 is positive, the factorial of parameter-1 is returned.
INTEGER INTEGER Function The INTEGER function returns the greatest integer value that is less than or equal to the argument. The function type is integer. Syntax FUNCTION INTEGER (parameter-1) Parameters parameter-1 Must be class numeric. Return Value The returned value is the greatest integer less than or equal to the value of parameter-1 . For example, if the value of parameter-1 is -1.5, a value of -2 is returned. If the value of parameter-1 is +1.5, the value of +1 is returned.
INTEGER-OF-DATE INTEGER-OF-DATE Function The INTEGER-OF-DATE function converts a date in the Gregorian calendar from standard date form (YYYYMMDD) to integer date form. The function type is integer. Syntax FUNCTION INTEGER-OF-DATE (parameter-1) Parameters parameter-1 Must be an integer of the form YYYYMMDD, whose value is determined as follows: (YYYY * 10000) + (MM * 100) + DD where YYYY represents the year in the Gregorian calendar and must be an integer greater than 1600.
INTEGER-OF-DATE Example The following example shows both the INTEGER-OF-DATE and DATE-OF-INTEGER functions. First the year-month-day form of the date is converted to an integer using INTEGER-OF-DATE. This integer represents the number of days since December 31, 1600. Then 30 is added to this number and it is converted back to the year-month-day form. 01 INT-DATE PIC 9(8) VALUE ZERO. 01 DATE-TODAY PIC 9(8) VALUE ZERO. 01 DUE-DATE PIC 9(8) VALUE ZERO. . . . MOVE 19910220 TO DATE-TODAY.
INTEGER-OF-DAY INTEGER-OF-DAY Function The INTEGER-OF-DAY function converts a date in the Gregorian calendar from Julian date form (YYYYDDD) to integer date form. The function type is integer. Syntax FUNCTION INTEGER-OF-DAY (parameter-1) Parameters parameter-1 Must be an integer of the form YYYYDDD, whose value is obtained as follows: (YYYY * 1000) + DDD where YYYY represents the year in the Gregorian calendar and must be an integer greater than 1600.
INTEGER-OF-DAY Example The following example shows both the INTEGER-OF-DAY and DAY-OF-INTEGER functions. First the year-day form of the date is converted to an integer using INTEGER-OFDAY. This integer represents the number of days since December 31, 1600. Then 30 is added to the integer form and it is converted back to the year-day form using DAY-OF-INTEGER. 01 INT-DATE PIC 9(8) 01 DATE-TODAY PIC 9(7) 01 DUE-DATE PIC 9(7) . . . MOVE 1991051 TO DATE-TODAY. COMPUTE INT-DATE = FUNCTION DISPLAY DATE-TODAY.
INTEGER-PART INTEGER-PART Function The INTEGER-PART function returns an integer that is the integer portion of parameter-1 (parameter-1 is truncated). The function type is integer. Syntax FUNCTION INTEGER-PART (parameter-1) Parameters parameter-1 Must be class numeric. Return Value One of the following, depending on the value of parameter-1 : parameter-1 Return Value 0 0 Positive The greatest integer less than or equal to the value of parameter-1 . For example, if the value of parameter-1 is +1.
LENGTH LENGTH Function The LENGTH function returns an integer equal to the length of the argument in character positions (bytes). To conform to ANSI standard COBOL, you can use the LENGTH function instead of the .LEN. pseudo-intrinsic (see Chapter 11, \Interprogram Communication," for details on .LEN.). The function type is integer. Syntax FUNCTION LENGTH (parameter-1) Parameters A nonnumeric literal or a data item of any class or category.
LENGTH Example 2 77 SIZER PIC 99. 77 NUM PIC 999. 01 TAB-REC. 05 TAB-ELEMENT OCCURS 1 TO 10 TIMES DEPENDING ON SIZER. 10 TAB-ITEM-1 PIC X(3). 10 TAB-ITEM-2 PIC S9(9) COMP SYNC. PROCEDURE DIVISION. 010-PARA. MOVE 5 TO SIZER. COMPUTE NUM = FUNCTION LENGTH (TAB-ELEMENT (1)). DISPLAY "TAB-ELEMENT LENGTH = " NUM. COMPUTE NUM = FUNCTION LENGTH (TAB-REC). DISPLAY "TAB-REC LENGTH = " NUM. STOP RUN.
LOG LOG Function The LOG function returns a numeric value that is the logarithm to the base e (natural log) of parameter-1 . The function type is numeric. Syntax FUNCTION LOG (parameter-1) Parameters parameter-1 Must be class numeric and greater than zero. Return Value The value returned is the approximation of the logarithm to the base e of parameter-1 . Example 77 NUM-LOG PIC 9(3)V9(5) VALUE ZERO. . . . COMPUTE NUM-LOG = FUNCTION LOG (10). DISPLAY NUM-LOG.
LOG10 LOG10 Function The LOG10 function returns a numeric value that is the logarithm to the base 10 of parameter-1 . The function type is numeric. Syntax FUNCTION LOG10 (parameter-1) Parameters parameter-1 Must be class numeric and greater than zero. Return Value The value returned is the approximation of the logarithm to the base 10 of parameter-1 . Example 77 NUM-LOG10 PIC 9(3)V9(5) VALUE ZERO. . . . COMPUTE NUM-LOG10 = FUNCTION LOG10 (50). DISPLAY NUM-LOG10.
LOWER-CASE LOWER-CASE Function The LOWER-CASE function returns a character string that is the same length as parameter-1 with each uppercase letter replaced by the corresponding lowercase letter. The function type is alphanumeric. Syntax FUNCTION LOWER-CASE (parameter-1) Parameters parameter-1 Must be class alphabetic or alphanumeric and must be at least one character in length.
MAX MAX Function The MAX function returns the content of the parameter-1 that contains the maximum value. The function type depends on the parameter type, as follows: Parameter Type Function Type Alphabetic Alphanumeric Alphanumeric Alphanumeric All parameters integer Integer Numeric (some parameters may be integer) Numeric Syntax FUNCTION MAX ({parameter-1}...) Parameters parameter-1 If more than one parameter-1 is speci ed, all parameters must be of the same class.
MAX Example 77 77 77 77 A B C D PIC PIC PIC PIC 77 77 77 77 77 77 01 I J K L MAX-VALUE MAX-VALUE-2 TAB. 05 ELEMENT X X X X VALUE VALUE VALUE VALUE PIC PIC PIC PIC PIC PIC "A". "Z". "m". "9". 9 VALUE 9 VALUE 9 VALUE 9 VALUE 9 VALUE S999V99 8. 3. 6. 1. ZERO. VALUE 0. PIC S999V99 OCCURS 4 TIMES VALUE ZERO. . . . DISPLAY FUNCTION MAX (A B C D). COMPUTE MAX-VALUE = FUNCTION MAX (I J K L). DISPLAY MAX-VALUE. MOVE MOVE MOVE MOVE 1.25 3.50 8.75 0.25 TO TO TO TO ELEMENT ELEMENT ELEMENT ELEMENT (1).
MEAN MEAN Function The MEAN function returns a numeric value that is the arithmetic mean (average) of its parameters. The function type is numeric. Syntax FUNCTION MEAN ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The value returned is the arithmetic mean of the parameter-1 series. The value returned is de ned as the sum of the parameter-1 series divided by the number of occurrences referenced by parameter-1 . Example 01 TAB.
MEDIAN MEDIAN Function The MEDIAN function returns the content of the parameter whose value is the middle value in a list formed by arranging the parameters in sorted order. The function type is numeric. Syntax FUNCTION MEDIAN ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The value returned is the content of parameter-1 having the middle value in a list formed by arranging all the parameter-1 values in sorted order.
MIDRANGE MIDRANGE Function The MIDRANGE (middle range) function returns a numeric value that is the arithmetic mean (average) of the value of the minimum parameter and the maximum parameter. The function type is numeric. Syntax FUNCTION MIDRANGE ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The returned value is the arithmetic mean of the greatest parameter-1 value and the least parameter-1 value.
MIN MIN Function The MIN function returns the content of the parameter-1 that contains the minimum value. The function type depends on the parameter type, as follows: Parameter Type Function Type Alphabetic Alphanumeric Alphanumeric Alphanumeric All parameters integer Integer Numeric (some parameters may be integer) Numeric Syntax FUNCTION MIN ({parameter-1}...) Parameters parameter-1 If more than one parameter-1 is speci ed, all parameters must be of the same class.
MIN Example 77 77 77 77 A B C D PIC PIC PIC PIC X X X X VALUE VALUE VALUE VALUE "A". "Z". "m". "9". 77 77 77 77 77 01 I PIC J PIC K PIC L PIC MIN-VALUE PIC TAB. 05 ELEMENT 9 9 9 9 9 VALUE VALUE VALUE VALUE VALUE 8. 3. 6. 1. ZERO. PIC S999V99 OCCURS 4 TIMES VALUE ZERO. . . . DISPLAY FUNCTION MIN (A, B, C, D). COMPUTE MIN-VALUE = FUNCTION MIN (I, J, K, L). DISPLAY MIN-VALUE. MOVE 1.25 TO ELEMENT (1). MOVE 3.50 TO ELEMENT (2). MOVE 8.75 TO ELEMENT (3). MOVE 0.25 TO ELEMENT (4).
MOD MOD Function The MOD function returns an integer value that is parameter-1 modulo parameter-2 . The function type is integer. Syntax FUNCTION MOD (parameter-1 parameter-2) Parameters parameter-1 parameter-2 Must be an integer. Must be a non-zero integer. Return Value The returned value is parameter-1 modulo parameter-2 .
NUMVAL NUMVAL Function The NUMVAL function returns the numeric value represented by the character string speci ed by parameter-1 . Leading and trailing spaces are ignored. The function type is numeric. Syntax FUNCTION NUMVAL (parameter-1) Parameters parameter-1 Must be a nonumeric literal or alphanumeric data item whose content has one of the following formats: where space is a string of zero or more spaces and digits is a string of one to eighteen digits.
NUMVAL-C NUMVAL-C Function The NUMVAL-C function returns the numeric value represented by the character string speci ed by parameter-1 . Any optional currency sign speci ed by parameter-2 and any optional commas preceding the decimal point are ignored. The function type is numeric.
NUMVAL-C Example 1 77 ALPHA-NUM PIC X(16) VALUE "$ 123.45 CR ". 77 NUM PIC S9(5)V99. PROCEDURE DIVISION. 010-PARA. COMPUTE NUM = FUNCTION NUMVAL-C (ALPHA-NUM). DISPLAY ALPHA-NUM. DISPLAY NUM. STOP RUN. The above example displays the following: $ 123.45 CR -00123.45 Example 2 ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. DECIMAL-POINT IS COMMA. DATA DIVISION. WORKING-STORAGE SECTION. 77 ALPHA-NUM PIC X(16) VALUE SPACES. 77 NUM PIC S9(5)V99. PROCEDURE DIVISION. 010-PARA. MOVE "DM 1.
ORD ORD Function The ORD function returns an integer value that is the ordinal position of parameter-1 in the collating sequence for the program. The lowest ordinal position is 1. The function type is integer. Syntax FUNCTION ORD (parameter-1) Parameters parameter-1 Must be one character in length and must be class alphabetic or alphanumeric. Return Value The returned value is the ordinal position of parameter-1 in the collating sequence for the program. Example 77 NUM PIC 999 VALUE ZERO. . . .
ORD-MAX ORD-MAX Function The ORD-MAX function returns a value that is the ordinal number of the parameter-1 that contains the maximum value. The function type is integer. Syntax FUNCTION ORD-MAX ({parameter-1}...) Parameters parameter-1 If more than one parameter-1 is speci ed, all parameters must be of the same class. Return Value The returned value is the ordinal number that corresponds to the position of the parameter-1 having the greatest value in the parameter-1 series.
ORD-MIN ORD-MIN Function The ORD-MIN function returns a value that is the ordinal number of the argument that contains the minimum value. The function type is integer. Syntax FUNCTION ORD-MIN ({parameter-1}...) Parameters parameter-1 If more than one parameter-1 is speci ed, all arguments must be of the same class. Return Value The returned value is the ordinal number that corresponds to the position of the parameter-1 having the least value in the parameter-1 series.
PRESENT-VALUE PRESENT-VALUE Function The PRESENT-VALUE function returns a value that approximates the present value of a series of future period-end amounts speci ed by parameter-2 at a discount rate speci ed by parameter-1 . The function type is numeric. Syntax FUNCTION PRESENT-VALUE (parameter-1 {parameter-2}...) Parameters parameter-1 parameter-2 Must be of the class numeric; must be greater than -1. Must be of the class numeric.
RANDOM RANDOM Function The RANDOM function returns a numeric value that is a pseudo-random number for a rectangular distribution. The function type is numeric. Syntax FUNCTION RANDOM [(parameter-1)] Parameters parameter-1 parameter-1 is used as the seed value to generate a sequence of pseudorandom numbers. If speci ed, must be in integer between zero and 999999999, inclusive. If a subsequent reference speci es parameter-1 , a new sequence of pseudo-random numbers is started.
RANDOM Example 77 RANDOM-NUMBER PIC V99999 VALUE ZERO. . . . COMPUTE RANDOM-NUMBER = FUNCTION RANDOM (1) DISPLAY RANDOM-NUMBER COMPUTE RANDOM-NUMBER = FUNCTION RANDOM DISPLAY RANDOM-NUMBER COMPUTE RANDOM-NUMBER = FUNCTION RANDOM DISPLAY RANDOM-NUMBER COMPUTE DISPLAY COMPUTE DISPLAY COMPUTE DISPLAY RANDOM-NUMBER = FUNCTION RANDOM (2893) RANDOM-NUMBER RANDOM-NUMBER = FUNCTION RANDOM RANDOM-NUMBER RANDOM-NUMBER = FUNCTION RANDOM RANDOM-NUMBER The above example displays the following: .04163 .36480 .73704 .
RANGE RANGE Function The RANGE function returns a value that is equal to the value of the maximum parameter minus the value of the minimum parameter. The function type is either integer or numeric depending on the type of the parameters, as follows: Parameter Type Function Type All parameters integer Integer Numeric (some parameters may be integer) Numeric Syntax FUNCTION RANGE ({parameter-1}...) Parameters Must be class numeric.
REM REM Function The REM function returns a numeric value that is the remainder of parameter-1 divided by parameter-2 . The function type is numeric. Syntax FUNCTION REM (parameter-1 parameter-2) Parameters parameter-1 parameter-2 Must be class numeric. Must be class numeric; must not be zero. Return Value The returned value is the remainder of parameter-1 / parameter-2 .
REVERSE REVERSE Function The REVERSE function returns a character string of exactly the same length as parameter-1 and whose characters are exactly the same as those of parameter-1 , except that they are in reverse order. The function type is alphanumeric. Syntax FUNCTION REVERSE (parameter-1) Parameters parameter-1 Must be class alphabetic or alphanumeric and must be at least one character in length.
SIN SIN Function The SIN function returns the sine of an angle, expressed in radians. The function type is numeric. Syntax FUNCTION SIN (parameter-1) Parameters parameter-1 The size of an angle in radians. Must be class numeric. Return Value The value returned is the approximation of the sine of parameter-1 and is between -1 and 1, inclusive. The value returned is numeric. Example 77 ANGLE-RADIANS PIC S99V9(5) VALUE 3.14159. 77 SIN-OF-ANGLE PIC S9V9(5) VALUE ZERO. . . .
SQRT SQRT Function The SQRT function returns a numeric value that is the square root of parameter-1 . The function type is numeric. Syntax FUNCTION SQRT (parameter-1) Parameters parameter-1 Must be class numeric; the value must be zero or positive. Return Value The returned value is the absolute value of the approximation of the square root of parameter-1 . Example 01 A-NUMBER PIC 99 VALUE 35. 01 NUM-SQ-ROOT PIC 999V999 VALUE ZERO. . . . COMPUTE NUM-SQ-ROOT = FUNCTION SQRT (81). DISPLAY NUM-SQ-ROOT.
STANDARD-DEVIATION STANDARD-DEVIATION Function The STANDARD-DEVIATION function returns a numeric value that approximates the standard deviation of its arguments. The function type is numeric. Syntax FUNCTION STANDARD-DEVIATION ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The returned value is the approximation of the standard deviation of the parameter-1 series. The returned value is calculated as follows: 1.
SUM SUM Function The SUM function returns a value that is the sum of the parameters. The function type is either integer or numeric depending on the type of the parameters, as follows: Parameter Type Function Type All parameters integer Integer Numeric (some parameters may be integer) Numeric Syntax FUNCTION SUM ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The returned value is the sum of the parameters.
TAN TAN Function The TAN function returns the tangent of an angle, expressed in radians. The function type is numeric. Syntax FUNCTION TAN (parameter-1) Parameters parameter-1 The size of an angle in radians. Must be class numeric. Return Value The value returned is the approximation of the tangent of parameter-1 . The value returned is numeric. Example 77 ANGLE-RADIANS PIC S99V9(5) VALUE 3.14159. 77 TAN-OF-ANGLE PIC S9(5)V9(5) VALUE ZERO. . . . COMPUTE TAN-OF-ANGLE = FUNCTION TAN (ANGLE-RADIANS).
UPPER-CASE UPPER-CASE Function The UPPER-CASE function returns a character string that is the same length as parameter-1 with each lowercase letter replaced by the corresponding uppercase letter. The function type is alphanumeric. Syntax FUNCTION UPPER-CASE (parameter-1) Parameters parameter-1 Must be class alphabetic or alphanumeric and must be at least one character in length.
VARIANCE VARIANCE Function The VARIANCE function returns a numeric value that approximates the variance of its parameters. The function type is numeric. Syntax FUNCTION VARIANCE ({parameter-1}...) Parameters Must be class numeric. parameter-1 Return Value The returned value is the approximation of the variance of the parameter-1 series. The returned value is de ned as the square of the standard deviation of the parameter-1 series.
WHEN-COMPILED WHEN-COMPILED Function The WHEN-COMPILED function returns the date and time the system compiled your program and the di erence between the local time when your program was compiled and Universal Coordinated Time (UTC) or Greenwich Mean Time. To get the correct time di erential, you need to set the environment variable TZ to your local time zone before compiling programs that contain this function. See below for more information. The function type is alphanumeric.
WHEN-COMPILED Character Positions 18-19 Contents Depending on the value of character position 17, one of the following: Position 17 20-21 Contents - Two numeric digits in the range 00 through 12 indicating the number of hours that the reported time is behind Greenwich Mean Time. + Two numeric digits in the range 00 through 13 indicating the number of hours that the reported time is ahead of Greenwich Mean Time. 0 The value 00 is returned.
WHEN-COMPILED Example 01 FULL-COMPILED-DATE. 05 C-DATE. 10 C-YEAR PIC 9(4). 10 C-MONTH PIC 99. 10 C-DAY PIC 99. 05 C-TIME. 10 C-HOUR PIC 99. 10 C-MINUTES PIC 99. 10 C-SECONDS PIC 99. 10 C-SEC-HUND PIC 99. 05 C-TIME-DIFF. 10 C-GMT-DIR PIC X. 10 C-HOUR PIC 99. 10 C-MINUTES PIC 99. . . . MOVE FUNCTION WHEN-COMPILED TO FULL-COMPILED-DATE. DISPLAY "Full date is: ", FULL-COMPILED-DATE. DISPLAY "Year is: ", C-YEAR. DISPLAY "Month is: ", C-MONTH. DISPLAY "Day is: ", C-DAY. DISPLAY "Hour is: ", C-HOUR OF C-TIME.
11 Interprogram Communication Program modules consist of separately compiled,but logically coordinated programs, which, at execution time, are subdivisions of a single process. This approach to programming lends itself to making a large problem more easily programmed and debugged, by breaking a problem into logical modules and coding each module separately. In COBOL terminology, a program is either a source or an object program.
Interprogram Communication Transfer of Control The CALL statement is the means used in COBOL programs to pass control from one object program to another, and there are no restrictions on a called program itself calling another object program. Caution should be used, however, to avoid calling a program that preceded, in the calling chain, the program currently having control. Otherwise, results of the run unit are unpredictable.
Interprogram Communication Reference to Common Data through Parameter Passing Because a called program often accesses data that is also used by the calling program, both programs must have access to the same data items if you wish to pass data to, or return data from, the called program. In the calling program, it does not matter which section in the DATA DIVISION is used to describe the common data.
Interprogram Communication Reference to Common Data and Files through External Objects This is a feature of the 1985 ANSI COBOL standard Accessible data items usually require that certain representations of data be stored. File connectors usually require that certain information concerning les be stored. The storage associated with a data item or a le connector can be external or internal to the program in which the object is declared.
Interprogram Communication PROGRAM-ID Paragraph De ne a subprogram using the PROGRAM-ID paragraph of the IDENTIFICATION DIVISION. Syntax Description For more information on the PROGRAM-ID paragraph, see Chapter 5, \IDENTIFICATION DIVISION.
Interprogram Communication EXTERNAL Clause NNNNNNNNNNNNNNNNNNNNNNNNNN The EXTERNAL clause is a feature of the 1985 ANSI COBOL standard The EXTERNAL clause speci es that a data item or a le connector is external. The corresponding data items and data group items of an external data record are available to every program in the run unit that describes that record.
Interprogram Communication Example The following example illustrates interprogram communication using EXTERNAL items. A main program and a subprogram share an EXTERNAL le and an EXTERNAL data item. IDENTIFICATION DIVISION. PROGRAM-ID. EXTITEMS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SOUT ASSIGN TO "FILEOUTP". DATA DIVISION. FILE SECTION. * * THE EXTERNAL FILE SPECIFICATION * FD SOUT EXTERNAL. 01 REC-OUT. 05 NAME PIC X(20). 05 LOCN PIC X(10). WORKING-STORAGE SECTION.
Interprogram Communication * * READ/DISPLAY THE SHARED FILE CONTENTS * OPEN INPUT SOUT. READ-FILE-RECS. READ SOUT AT END CLOSE SOUT STOP RUN. DISPLAY REC-OUT. GO TO READ-FILE-RECS. $CONTROL SUBPROGRAM IDENTIFICATION DIVISION. PROGRAM-ID. SUB1. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT SOUT ASSIGN TO "FILEOUTP". DATA DIVISION. FILE SECTION. FD SOUT EXTERNAL. 01 REC-OUT. 05 NAME PIC X(20). 05 LOCN PIC X(10). WORKING-STORAGE SECTION. 01 EXTERNAL-DATA-ITEM EXTERNAL PIC X(18).
Interprogram Communication GLOBAL Clause NNNNNNNNNNNNNNNNNNNN The GLOBAL clause is a feature of the 1985 ANSI COBOL standard The GLOBAL clause speci es that the data item or le connector can be referenced by the contained programs within a nested program in which the item is declared global.
Interprogram Communication Types of Subprograms HP COBOL II has three kinds of subprograms: 1. Non-Dynamic. 2. Dynamic. 3. ANSISUB. Specify which kind of subprogram you want by using one of the following: Table 11-1. Types of Subprograms and How to Specify Them Subprogram Type Option or Clause NonDynamic. $CONTROL SUBPROGRAM Dynamic. $CONTROL DYNAMIC or the INITIAL clause of the PROGRAM-ID paragraph.
Interprogram Communication Dynamic Subprograms Use $CONTROL DYNAMIC or the INITIAL clause of the PROGRAM-ID paragraph to specify a dynamic subprogram. The INITIAL clause is part of the ANSI standard. Dynamic subprograms are equivalent to PROGRAM IS INITIAL and have local data storage and are always in their initial state when called. This implies that any les opened in dynamic subprograms should be closed before exiting. Otherwise, the le is closed for you.
END PROGRAM END PROGRAM Header NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN The END PROGRAM header is a feature of the 1985 ANSI COBOL standard The END PROGRAM header indicates the end of the named COBOL program. It must begin in Area A. Syntax END PROGRAM program-name . Description The following rules should be observed when using the END PROGRAM header: The program-name must be identical to the program-name declared in the preceding PROGRAM-ID paragraph.
CALL CALL Statement In ANSI COBOL, you can use the CALL statement to transfer control from one object program to another within the same run unit. An HP extension to the 1985 ANSI COBOL standard adds the ability to invoke operating system intrinsics from within a given object program.
CALL An HP extension to the 1985 ANSI COBOL standard adds the keyword INTRINSIC to the following formats to specify that an intrinsic, not a program, is being called. Also added is the capability to pass a data item by value. These can only be used when calling non-COBOL programs. The last format of the CALL statement is the GIVING identi er-4 phrase. This phrase allows you to name an identi er that holds the result of a call to a typed procedure.
CALL Parameters identi er-1 literal-1 nn @ identi er-2 identi er-2 , names an alphanumeric data item whose value is a program name. Refer to \CALL Identi er" (below) for a description of conditions that may occur when using this operation. nonnumeric literal that either names an operating system intrinsic, or names a program. If an intrinsic is named by literal-1 , the keyword, INTRINSIC, must precede it.
CALL Description A CALL statement may appear anywhere within a segmented program. The compiler provides all controls necessary to ensure that the proper logic ow is maintained. When a CALL statement to a subprogram appears in a section with a segment number greater than or equal to 50, and when control is returned to this segment by the EXIT PROGRAM statement in the called subprogram, this segment is in the same state as when it issued the CALL statement.
CALL Calling Intrinsics The INTRINSIC phrase is used to indicate that the CALL statement in which it appears is calling an operating system intrinsic rather than a subprogram. When the INTRINSIC phrase is used, literal-1 must be used and must name an operating system intrinsic. The USING phrase speci es the various parameters to be passed to the intrinsic. When the intrinsic is a \typed procedure", the GIVING phrase speci es the parameter to be returned by the intrinsic.
CALL Example The following shows some calls to intrinsics: SPECIAL-NAMES. CONDITION-CODE IS C-C. . . . WORKING-STORAGE SECTION. 01 SHOWME. 02 MPE-COMMAND PIC X(07) VALUE "SHOWJOB". 02 CARRIAGE-RETURN PIC X VALUE %15. 01 ERR PIC S9999 USAGE IS COMP VALUE ZERO. 01 CATCHPARM PIC S9999 USAGE IS COMP VALUE ZERO. 01 REPLY. PIC X(03) VALUE SPACES. . . PROCEDURE. DIVISION. . . CALL INTRINSIC "COMMAND" USING SHOWME ERR CATCHPARM. IF C-C NOT = 0 THEN DISPLAY "COMMAND FAILED" STOP RUN. MOVE SPACES TO REPLY.
CALL Execution-Time Loading When you use the identi er-1 form of the CALL statement, the value of identi er-1 determines which subprogram is called. When the program is executed, an attempt is made to load the subprogram. If the load fails, an exception condition occurs. For more information, see \System Dependencies" in Appendix H. If the ON EXCEPTION or ON OVERFLOW phrase is speci ed, control is passed to the imperative statement of that phrase.
CALL Pseudo-Intrinsics The following pseudo-intrinsics are an HP extension to the ANSI COBOL standard. Caution Pseudo-intrinsics are highly machine-dependent and should not be used in programs that may be run on di erent machines and architectures now or in the future. .LOC. Pseudo-Intrinsic The .LOC. pseudo-intrinsic allows you to call several useful operating system intrinsics, such as GENMESSAGE, CREATEPROCESS, MYCOMMAND, and other intrinsics that require identi ers to contain addresses.
CALL USING Phrase (COBOL Subprograms) The USING phrase speci ed in a CALL statement to another program makes data and les of the calling program available to the called program. If a CALL statement containing the USING phrase calls a COBOL program, then the called COBOL program must contain a USING phrase in its PROCEDURE DIVISION header (or in the ENTRY statement, if a secondary entry point name is used by the CALL statement).
CALL Index names in the calling and called programs always refer to di erent indices. To pass an index value from a calling program to a called program, you must rst move the index value associated with an index name to a data item that appears in the USING phrase of the calling program. The corresponding data item in the called program can then be used to set an equivalent index name to this value.
CALL USING Phrase (Non-COBOL Subprograms) This positional correspondence extends to non-COBOL called programs. Thus, for example, if the called program is a Pascal program, then the names in the parameter list of the procedure declaration in that program are identi ed with those data items whose names appear in the corresponding position of the USING phrase in the calling program.
CALL GIVING Phrase When Calling COBOL Subprograms As an HP extension to the ANSI COBOL standard, you can return a value from a COBOL subprogram using the RETURN-CODE special register in the subprogram and the GIVING phrase in the calling program. The data item in the GIVING phrase must be de ned as PIC S9(9) BINARY. If it is not, a type checking error may occur at link time. The value returned is the value placed into the RETURN-CODE special register by the called program.
CALL Example The following example shows a main program and a subprogram with a secondary entry point. The main program calls the subprogram twice and displays the value returned in the GIVING phrase. Notice that the special register RETURN-CODE is not de ned anywhere in the DATA DIVISION of the subprogram. IDENTIFICATION DIVISION. PROGRAM-ID. RETURN-CODE-TEST. DATA DIVISION. WORKING-STORAGE SECTION. 01 BUF PIC S9(9) BINARY VALUE 99. 01 RESULT PIC S9(9) BINARY VALUE -99. PROCEDURE DIVISION. START-IT.
CALL GIVING Phrase When Calling Non-COBOL Subprograms The GIVING phrase also allows you to call non-COBOL typed procedures. A typed procedure (for example, a Pascal function declaration) must always return a value when it completes execution. In HP COBOL II, this is assumed to be a 2-, 4-, or 8-byte binary value of up to eighteen digits. The purpose of the GIVING phrase is to provide for this returned value.
CANCEL CANCEL Statement The CANCEL statement restores a program to its initial state and closes all les currently in open mode. Syntax Parameters identi er-1 literal-1 de ned as an alphanumeric data item whose contents name a subprogram compiled by the HP COBOL II compiler. nonnumeric literal that names a COBOL subprogram compiled by the HP COBOL II compiler.
ENTRY ENTRY Statement The ENTRY statement is an HP extension to the ANSI COBOL standard. The ENTRY statement establishes a secondary entry point in an HP COBOL II subprogram. In nested programs, this statement must begin in Area A. However, like all other COBOL statements in the PROCEDURE DIVISION, the ENTRY statement must be in a paragraph. Syntax f g ENTRY literal-1 [USING data-name-1 . . . ] Parameters literal-1 data-name-1 nonnumeric literal.
ENTRY Example The following example shows a main program and a subprogram. The subprogram has a secondary entry point named by the ENTRY statement. The CALL statement in MAINPROG speci es that SUBPRO1 is to be executed, starting at the ENTRY statement rather than at the rst line following the PROCEDURE DIVISION header. Also, the data areas of INV-FILE and SALES-FILE are to be used in both programs. Following is the main program: IDENTIFICATION DIVISION. PROGRAM ID. MAINPROG. . . . DATA DIVISION.
ENTRY Following is the subprogram: IDENTIFICATION DIVISION. PROGRAM-ID. SUBPRO1. . . . DATA DIVISION. FILE SECTION. FD PRINT-FILE. 01 P-REC PIC X(132). . . . WORKING-STORAGE SECTION. 01 HEADER. .. . 01 WRITE-SALES. 02 FILLER PIC X(15) VALUE SPACES. 02 NAME PIC X(30) VALUE SPACES. 02 FILLER PIC X(5) VALUE SPACES. 02 NUM-1 PIC X(10) VALUE SPACES. 02 FILLER PIC X(5) VALUE SPACES. 02 QUANTITY PIC Z(3)9(3) VALUE ZERO. 02 FILLER PIC X(5) VALUE SPACES. 02 GROSS-SALES PIC $Z(10).99 VALUE ZEROS.
EXIT PROGRAM EXIT PROGRAM Statement The EXIT PROGRAM statement marks the logical end of a program. Syntax EXIT PROGRAM Description If you use an EXIT PROGRAM statement in a program (called or otherwise), it must appear as the only statement in a sentence, and the sentence must be the only sentence in a paragraph. Also, EXIT PROGRAM must not appear in a declarative procedure that has a GLOBAL phrase.
GOBACK GOBACK Statement The GOBACK statement is an HP extension to the ANSI COBOL standard. The GOBACK statement marks the logical end of a program. Syntax GOBACK Description The GOBACK statement must be the only statement in a sentence. If used in a series of imperative statements, it must be the last statement in the series.
12 SORT/MERGE Operations The sort/merge capabilities of HP COBOL II allow you to sort one or more les of records, or to combine two or more identically ordered les of records one or more times within a given execution of a COBOL program. Additionally, you have the ability to specially process individual records by input or output procedures that are part of the sort or merge operation. For a sort operation, this special processing may be applied before, as well as after the records have been sorted.
MERGE MERGE Statement The MERGE statement combines two or more identically sequenced les on a set of speci ed keys. As part of the merge operation, it makes records available in their merged order to an output procedure or an output le. The records are made available following the actual merging of the les. The output procedure or the moving of records to an output le is considered part of the merge process.
MERGE Parameters le-name-1 data-name-1 alphabet-name language-name language-id le-name-2 le-name-3 sort/merge le, and is described in a sort/merge le description (SD level) entry in the DATA DIVISION. data items described in records associated with le-name-1 . Each may be quali ed and may vary in length. None of these data names can be described by an entry either containing an OCCURS clause, or subordinate to an entry containing such a clause.
MERGE Description The words THROUGH and THRU are equivalent, and can be used interchangeably. The MERGE statement merges all records contained in the les named in the USING phrase. The les to be merged are automatically opened and closed by the merge operation with all implicit functions performed, such as the execution of any associated USE procedures.
MERGE GIVING and OUTPUT PROCEDURE Phrases You must specify either the GIVING or OUTPUT PROCEDURE phrase in a MERGE statement. If you specify the GIVING phrase, all merged records are automatically written to one or more occurrences of le-name-4 . Files named in the GIVING phrase can be sequential, relative, or indexed . NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN If you use the OUTPUT PROCEDURE phrase, there are several rules you must follow in writing the procedure.
MERGE Segmentation Considerations The following restrictions apply to the MERGE statement when it is used in a segmented program. If the MERGE statement appears in a section whose segment number is less than 50, any output procedure named in the MERGE statement must either be totally contained within a segment (or segments) whose segment number (or numbers) is less than 50 or be wholly contained in a single segment whose segment number is greater than 49.
RELEASE RELEASE Statement The RELEASE statement can be used in an input procedure of a SORT statement to transfer records from your program to the initial phase of the sort operation. Syntax RELEASE record-name-1 [FROM identi er-1 ] Parameters record-name-1 identi er-1 the name of a logical record in the sort/merge le description entry of the le referenced in the associated SORT statement. It may be quali ed. Record-name-1 must not refer to the same storage area as identi er-1 .
RETURN RETURN Statement The RETURN statement can be used in an output procedure of a SORT or MERGE statement. It cannot be used in any other type of procedure. When used, the RETURN statement obtains either sorted records from the nal phase of a sort operation, or merged records during a merge operation. Each record is obtained by a RETURN statement in the order speci ed by the keys listed in the SORT or MERGE statement.
RETURN INTO Phrase The INTO phrase, if speci ed in the RETURN statement, moves the current record into the record area associated with le-name-1 , and then uses an implicit MOVE statement (without the CORRESPONDING phrase) to move a copy of the data from the record area to the storage area referenced by identi er-1 . Thus, the data obtained from the SORT or MERGE statement is available in the data area associated with identi er-1 as well as to the input record area.
SORT SORT Statement The SORT statement creates a sort le either by executing an input procedure, or by transferring records from another le. The records of the sort le are then sorted using a speci ed set of keys, and are made available in sorted order to either an output procedure or an output le. Syntax Parameters le-name-1 data-name-1 alphabet-name language-name a sort/merge le, and is described in a sort/merge le description entry in the DATA DIVISION.
SORT language-id le-name-2 an integer data item containing the identi cation number of the language to use. This parameter is an HP extension to the ANSI COBOL standard. the les whose records are to be sorted. These les must not be open at the time the SORT statement is executed. Each must be a sequential, relative , or indexed le described in an FD level le description entry in the DATA DIVISION. No more than one of these le names may name a le on a multiple le reel.
SORT Note Specifying the same le for the USING and GIVING le name is not recommended. The le contents may be contaminated if the SORT operation is abnormally terminated, for any reason. If the same le is to be used, you should ensure that a backup copy exists in case a le recovery becomes necessary. For example, assume that the records to be sorted use the rst three key data items, and that the unsorted records appear as shown below.
SORT and INFILE is described in part as: FD INFILE. 01 IN-REC. 03 FIRST 03 SECOND . . . PIC 9. PIC XX. Note that the third pass of the sort left the records unchanged from their order in the result of the second pass. The records are arranged in their proper sequences by chance. The SORT statement would not actually go through this third pass, as it recognizes the records as already being sorted. This saves execution time.
SORT DUPLICATES Phrase If the DUPLICATES phrase is speci ed and the contents of all the key data items associated with one data record are equal to the contents of the corresponding key data items associated with one or more other data records, then the order of return of these records is: 1. The order of the associated input les as speci ed in the SORT statement. Within a given input le the order is that in which the records are accessed from that le. 2.
SORT If you do so, then section-name-1 through section-name-2 must de ne an input procedure. Control is passed to this procedure before le-name-1 is sorted. The compiler inserts a return mechanism at the end of the last statement in the statement in the section named by section-name-2 , and when control passes to the last statement in the input procedure, the records that have been released to le-name-1 are sorted.
SORT Sorting Large Files Normally, the le descriptions compiled into the object program (using information from the SELECT, FD, and SD clauses) provide all the information required to execute the object program. However, to override these le descriptions, you can supply MPE commands when executing the program. These commands are e ective only for the current execution of the program.
SORT Note It is possible that a permanent le with the same name as the SORT-FILE within job streams may cause undesired aborts. To avoid this, include the following command in the stream le: :FILE SORT;NEW; DISC=15000 The le name used in the :FILE command is the one speci ed in the SELECT clause. Figure 12-1.
SORT Segmentation Considerations The following restrictions apply to the SORT statement when it is used in a segmented program. If the SORT statement appears in a section whose segment number is less than 50, then any output procedure named in the SORT statement either must be totally contained within a segment (or segments) whose segment number (or numbers) is less than 50, or must be entirely contained in a single segment whose segment number is greater than 49.
13 Debug Module The Debug Module provides a means by which you can describe a debugging algorithm including the conditions under which procedures are to be monitored during the execution of the object program. Note With the exception of debug lines, this module is an obsolete feature of the 1985 ANSI COBOL standard. The decisions of what to monitor and what information to display on the output device are explicitly yours.
USE FOR DEBUGGING Note The object-time switch does not control the debugging lines . Recompilation without the \WITH DEBUGGING MODE" clause is necessary to disable the debugging lines. 3. A special register: DEBUG-ITEM The reserved word DEBUG-ITEM is the name for a special register generated automatically by the compiler. Only one DEBUG-ITEM is allocated per program. The names of the subordinate data items in DEBUG-ITEM are also reserved words. 4.
USE FOR DEBUGGING USE FOR DEBUGGING statement The USE FOR DEBUGGING statement identi es the user procedures that are to be monitored by the associated debugging section. The USE FOR DEBUGGING statement has the following format: Syntax The following syntax rules apply to the USE FOR DEBUGGING statement: Debugging section(s), if speci ed, must appear together immediately after the DECLARATIVES header.
USE FOR DEBUGGING The following general rules apply to the USE FOR DEBUGGING statement: 1. When procedure-name-1 is speci ed in a USE FOR DEBUGGING statement that debugging section is executed: a. Immediately before each execution of the named procedure. b. Immediately after the execution of an ALTER statement which references procedure-name-1 . 2.
USE FOR DEBUGGING 9. DEBUG-SUB-1, DEBUG-SUB-2, . . . are treated only as ller items in HP COBOL II. 10. DEBUG-CONTENTS is a data item that is large enough to contain the data required by the following general rules. 11. If the rst execution of the rst nondeclarative procedure in the program causes the debugging section to be executed, the following conditions exist: a. DEBUG-LINE identi es the rst statement of that procedure. b. DEBUG-NAME contains the name of that procedure. c.
Debugging Lines 16. If procedure-name-1 is a USE procedure that is to be executed, the following conditions exist: a. DEBUG-LINE identi es the statement that causes execution of the USE procedure. b. DEBUG-NAME contains procedure-name-1 . c. DEBUG-CONTENTS contains \USE PROCEDURE". 17. If an implicit transfer of control from the previous sequential paragraph to procedure-name-1 causes the debugging section to be executed, the following conditions exist: a.
Debugging Lines The ANSI Debug Module Example 001000 IDENTIFICATION DIVISION. 001100 PROGRAM-ID. EXAMPLE. 001200 ENVIRONMENT DIVISION. 001300 CONFIGURATION SECTION. 001400 SOURCE-COMPUTER. HP3000 WITH DEBUGGING MODE. 001500 OBJECT-COMPUTER. HP3000. 001600 DATA DIVISION. 001700 WORKING-STORAGE SECTION. 001800 01 GRP. 001900 05 N-1 PIC S9(4) VALUE 0 002000 SIGN IS LEADING SEPARATE. 002100 05 N-2 PIC S9(4) VALUE 0 002200 SIGN IS LEADING SEPARATE. 002300 05 N-3 PIC S9(4) COMP-3. 002400 PROCEDURE DIVISION.
Debugging Lines Using the ANSI Debug Module Example The above program displays the value of DEBUG-NAME and DEBUG-CONTENTS at the start of each section and paragraph. Note the use of the following source lines: 1. Source line 001400 - the WITH DEBUGGING MODE clause enables compilation of the debugging procedures and lines. 2.
14 Source Text Manipulation This chapter describes the source text manipulation module, which is made up of the COPY statement and the REPLACE statement. These statements can function independently of or in conjunction with each other to provide an extensive capability to insert and replace source program text during source program compilation. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN Note In this chapter, the term word implies text word .
COPY COPY Statement The COPY statement is the method by which source records in a COBOL library are copied into your source program. This statement may appear anywhere in your source program, from the IDENTIFICATION DIVISION to the end of the PROCEDURE DIVISION. Aside from allowing you to copy modules into your source le, it also allows you to replace occurrences of a string of words, a substring, an identi er, a literal, or a word appearing in the module being copied.
COPY literal-1 and literal-2 identi er-1 and identi er-2 word-1 and word-2 Note each can be any COBOL literal. can each be any COBOL identi er and can be quali ed. can each be any single COBOL word. Where the sequence consists only of a single element, using the identi er-1 , literal-1 , or word-1 format is more e cient. ==pseudo-text-2== a sequence of words, comment lines, or spaces delimited on either end by double equal signs.
COPY REPLACING Phrase To facilitate the following discussion, the REPLACING phrase is rewritten as shown below. REPLACING text-to-replace BY replace-text Before the comparison to determine which text, if any, is to be replaced in the copied module, spaces, commas, and semicolons to the left of the rst word in the records of the module are moved into the source program. The rst word of the record in a module is the rst part of the module to be compared.
COPY Example 1 This example uses a module named RITESTUF in a library called UTIL to illustrate the COPY statement. 001000 WRITE-ROUTINE. 001100 OPEN OUTPUT CHECKS. 002000 WRITE AMOUNT BEF-AFT ADVANCING X LINES 003000 AT EOP IMP-STAT. RITESTUF RITESTUF RITESTUF RITESTUF The COPY statement appears as follows: 100000 PROCEDURE.DIVISION. . .
REPLACE REPLACE Statement The REPLACE statement is used to replace source program text. This statement may appear anywhere in a program, from the IDENTIFICATION DIVISION to the end of the PROCEDURE DIVISION. However, a better way to edit the source text permanently is by using an editor. Syntax Parameters ==pseudo-text-1== Note a sequence of words, comments, or spaces delimited on either end by double equal signs.
REPLACE Description A REPLACE statement can appear in a source program anywhere a character string or a separator can occur. However, a REPLACE statement cannot appear in another REPLACE statement. When a REPLACE statement is used, it must be preceded by a space and terminated by a period. Any REPLACE statements contained in a source program are processed after the processing of the COPY statements contained in a source program.
REPLACE The comparison operation continues until the rightmost word in the source program text (within the scope of the REPLACE statement) has either been matched or has been considered as a leftmost word in the source program and completed a comparison cycle. A comment line in text-to-replace or in the source program is interpreted as a single space for purposes of matching.
REPLACE The code sent to the compiler would be: IDENTIFICATION DIVISION. PROGRAM-ID. PROG1. DATA DIVISION. 01 NAME PIC X(30). 01 TESTT PIC X. 88 TRUE-FLAG VALUE "T". PROCEDURE DIVISION. P1. ACCEPT TESTT. IF TRUE-FLAG PERFORM P2. IF NAME IS ALPHABETIC-UPPER THEN SET TRUE-FLAG TO TRUE. PERFORM P3 WITH TEST AFTER UNTIL NAME IS NOT ALPHABETIC. . . . Example 2 This example shows how the REPLACE statement can be used to replace substrings.
A HP COBOL II Error Messages This appendix explains how to read compiler error messages that occur when using the HP COBOL II compiler and run-time error messages that occur when your program is running. Error messages and their explanatory text are in the le named COBCAT.PUB.SYS. This appendix contains a complete listing of the COBCAT error messages. You can also obtain the most current listing of error messages for each compiler version update by listing the le COBCAT.PUB.SYS .
Run-Time Error Messages HP COBOL II error messages have been divided into seven categories: Table A-1. Kinds of Error Messages Message Number 1-99 Classi cation Meaning Warnings (W) Something is incorrect in the code, but the compiler can probably x it to produce what you intended. 100-399 Questionable Errors (Q) An error has occurred that will be xed, but the compiler probably will not produce what you intended. 400-449 Serious Errors (S) The error is either too di cult or impossible to x.
Run-Time Error Messages Run-Time Error Messages Run-time error messages are numbered from 540 through 899. They are at the end of the COBCAT.PUB.SYS le within the $SET 30 and $SET 31 catalog sets. These error messages are issued when run-time procedures encounter errors while performing the following: Input-output functions. Converting or moving illegal data. Detecting invalid index, subscript, or reference modi cation values. Performing exponential computations.
Warnings Warnings 1 2 ERROR MESSAGE ILLEGAL CHARACTER IN COLUMN 7. CAUSE Only space, *, -, $, D, or / allowed. ERROR MESSAGE DEBUGGING LINE ILLEGAL BEFORE OBJECT-COMPUTER PARAGRAPH. CAUSE 3 4 5 ERROR MESSAGE TOO MANY CHARACTERS IN SYMBOL !. CAUSE Symbol ! is limited to 30 characters. ERROR MESSAGE MISSING SPACE. CAUSE Separator space is needed here. ERROR MESSAGE CONTINUATION RECORD NOT ALLOWED HERE. CAUSE 6 7 8 9 ERROR MESSAGE MISSING QUOTE.
Warnings 16 18 20 24 25 26 ERROR MESSAGE START VALID ONLY WITH RELATIVE, RANDOM OR INDEXED. CAUSE The \START" verb can only be used with RELATIVE, INDEXED or RANDOM I/O. Not valid with ACCESS mode RANDOM. ERROR MESSAGE SEEK VALID ONLY WITH RELATIVE OR RANDOM. CAUSE The \SEEK" verb can only be used with RANDOM or RELATIVE les. ERROR MESSAGE INVALID DATA TYPE FOR KEY. CAUSE Sort or Merge keys may only be of the following types: ALPHABETIC, ALPHANUMERIC, NUMERIC, or DISPLAY.
Warnings 32 ERROR MESSAGE OCCURS CLAUSE USED ON 01 LEVEL ITEM. CAUSE 33 34 35 36 37 38 39 40 ERROR MESSAGE VALUE CLAUSE IN AN ITEM SUBORDINATE TO AN OCCURS TABLE. CAUSE The VALUE clause is not permitted within an entry subordinate to an OCCURS. ANSI74 entry point only. ERROR MESSAGE MISSING AT END/INVALID KEY PHRASE. CAUSE AN AT END or INVALID KEY phrase is required since no applicable USE procedure is speci ed. ERROR MESSAGE ILLEGAL INVALID KEY PHRASE.
Warnings 42 43 45 46 47 48 49 ERROR MESSAGE INVALID COMMENT ENTRY. CAUSE Comment entry is not allowed here. ERROR MESSAGE ILLEGAL IDENTIFICATION DIVISION PARAGRAPH. CAUSE Check against legal IDENTIFICATION DIVISION paragraphs. ERROR MESSAGE UNPROCESSED SOURCE ON SUBSYSTEM COMMAND LINE. CAUSE Unprocessed source is ignored. ERROR MESSAGE SUBSYSTEM COMMAND CHARACTER STRING WAS TRUNCATED.
Warnings 55 56 57 58 59 60 61 62 65 66 ERROR MESSAGE LEFT TRUNCATION MAY OCCUR. CAUSE This warning is generated whenever signi cant digits will be truncated in a numeric move. ERROR MESSAGE VALUE OF CLAUSE NOT APPLICABLE TO NON-SEQUENTIAL FILES, IGNORED. CAUSE The VALUE OF clause is meaningful only for sequential les. If it occurs in any other type of le it is ignored. ERROR MESSAGE REDEFINING ITEM ! CONTAINS A VALUE CLAUSE.
Questionable Errors Questionable Errors 100 101 102 103 104 105 106 107 108 ERROR MESSAGE ILLEGAL INTEGER. CAUSE A non-integer literal or an integer which is too large has occurred in a context where the compiler expects an integer. ERROR MESSAGE ALPHABET-NAME IN CODE-SET CLAUSE MAY NOT SPECIFY LITERAL PHRASE. CAUSE An alphabet-name which was de ned using the literal phrase has been used in a code set clause. ERROR MESSAGE DATA-NAME ! IS NOT AN ALPHABET-NAME OR CLASS-NAME.
Questionable Errors 109 112 113 121 122 123 124 ERROR MESSAGE BAD RECORDING MODE SPECIFICATION!. CAUSE The RECORDING MODE speci cation must be \F", \V", \U", or \S". ERROR MESSAGE NEGATIVE NUMBER OF OCCURRENCES SPECIFIED. CAUSE A table may not contain a negative number of occurrences. ERROR MESSAGE MINIMUM NUMBER OF OCCURRENCES IS GREATER THAN MAXIMUM NUMBER OF OCCURRENCES.
Questionable Errors 125 126 132 133 140 141 142 143 ERROR MESSAGE ILLEGAL EXTERNAL CLAUSE. (!) CAUSE External clause must be on a FD or 01 in working storage section. The name must be unique. (See error 351). The item must be contain a rede nes or renames clause. For les, it must not have the same area or multiple le clause. Rede ning a 01 external item can't be larger. (See warning 52.) ERROR MESSAGE ILLEGAL GLOBAL CLAUSE.
Questionable Errors 144 145 146 147 148 149 150 151 152 ERROR MESSAGE MULTIPLE FLOAT CHARACTERS IN PICTURE. CAUSE Either \*" or \Z" has been encountered in a picture string and some other character has already been determined to be the oating insertion character (\*", \Z", \+" used as oating insertion character, \-" used as oating insertion character, and currency sign used as oating insertion character, are mutually in a picture string). ERROR MESSAGE MULTIPLE REPETITION FACTORS IN PICTURE.
Questionable Errors 153 154 155 156 157 158 159 ERROR MESSAGE NO DIGIT OR CHARACTER POSITIONS IN PICTURE. CAUSE At least one of the characters \A", \X", \Z", \9", or \*" or at least two of the characters \+", \-", or the currency symbol must occur in a picture string. ERROR MESSAGE ILLEGAL COMBINATION OF PICTURE CHARACTERS. CAUSE Certain combination of characters may not occur in a picture string. ERROR MESSAGE ILLEGAL SEQUENCE OF PICTURE CHARACTERS.
Questionable Errors 160 161 162 163 164 165 166 167 168 ERROR MESSAGE ILLEGAL CLAUSE FOR 66-LEVEL ENTRY. CAUSE The only clause which may be speci ed for a 66-level entry is the RENAMES clause. ERROR MESSAGE ILLEGAL REDEFINES CLAUSE. CAUSE The item being rede ned is not declared immediately subordinate to the item containing the rede nes clause, or the item being rede ned is a table or variable size item or, the item being rede ned is a 66-level or 88-level item.
Questionable Errors 170 172 173 174 175 176 177 178 183 ERROR MESSAGE ILLEGAL RENAMES CLAUSE. CAUSE A RENAMES clause may only be speci ed in a 66-level item. The item(s) it renames must be de ned in the immediately preceding record and must be special level (66,77,88) items, table items, table elements, or variable size items.
Questionable Errors 184 185 186 188 189 200 201 ERROR MESSAGE ILLEGAL LITERAL. CAUSE A literal has occurred in a value clause and either the corresponding data item is an index item, the corresponding data item is numeric and the literal is nonnumeric, or the corresponding data item is nonnumeric and the literal is numeric. ERROR MESSAGE MULTIPLE INITIAL VALUES FOR A DATA ITEM. CAUSE When the value clause is used to specify an initial value for a data item it may only specify one value.
Questionable Errors 202 205 206 207 ERROR MESSAGE ILLEGAL COBOL CHARACTER IGNORED. CAUSE Check list of legal COBOL characters. ERROR MESSAGE RESERVED WORD ! NOT LEGAL IN THIS DIVISION. CAUSE The speci ed word is a Reserved word used in another division. ERROR MESSAGE PICTURE CHARACTER STRING TOO LONG. CAUSE Picture character string is limited to 30 characters. ERROR MESSAGE ILLEGAL OCTAL DIGIT. CAUSE 208 210 211 212 213 ERROR MESSAGE LITERAL TOO LONG.
Questionable Errors 218 ERROR MESSAGE CURRENCY SIGN HAS MORE THAN ONE CHARACTER. CAUSE 219 ERROR MESSAGE ILLEGAL SUBSTITUTE CURRENCY SIGN. CAUSE 220 ERROR MESSAGE ILLEGAL COMBINATION OF FILE ORGANIZATION AND ACCESS METHODS. CAUSE 221 222 ERROR MESSAGE MISSING FILE POSITION NUMBER(S). CAUSE Missing le position numbers in MULTIPLE FILE clause. ERROR MESSAGE DUPLICATE FILE NAME ! IN MULTIPLE FILE TAPE CLAUSE. CAUSE 223 ERROR MESSAGE DUPLICATE FILE POSITION IN MULTIPLE FILE TAPE CLAUSE.
Questionable Errors 230 ERROR MESSAGE FILE NAME ! HAS ALREADY BEEN USED. CAUSE 232 ERROR MESSAGE DUPLICATE CHARACTER IN ALPHABET OR CLASS DEFINITION. CAUSE 233 ERROR MESSAGE NUMERIC LITERAL IN ALPHABET/CLASS/SYMBOLIC CHARACTER HAS SIGN ,SIGN DROPPED. CAUSE 234 ERROR MESSAGE NUMERIC LITERAL IN ALPHABET/CLASS/SYMBOLIC CHARACTER MUST BE 1 THRU !. CAUSE For alphabets and classes the value is 256. For symbolic character the value depends on the alphabet.
Questionable Errors 244 ERROR MESSAGE ILLEGAL RECORDING MODE !. CAUSE 245 ERROR MESSAGE ILLEGAL DEVICE NAME !. CAUSE 246 ERROR MESSAGE DEVICE CODE MUST CONTAIN 3 DIGITS. CAUSE 247 ERROR MESSAGE FILE SIZE HAS MORE THAN 9 DIGITS. CAUSE 249 ERROR MESSAGE FORMS MESSAGE HAS MORE THAN 49 CHARACTERS. CAUSE 250 ERROR MESSAGE FORMS MESSAGE MUST END WITH A PERIOD. CAUSE 251 252 253 254 258 259 ERROR MESSAGE ILLEGAL LOCKING PARAMETER !. CAUSE 'L' is locking parameter.
Questionable Errors 260 262 266 267 268 269 272 273 274 281 ERROR MESSAGE FILE NAME ! IS NOT DEFINED IN THIS SCOPE. CAUSE A le access is being attempted in a scope in which the le is not de ned. The 'FD' may require the 'GLOBAL' clause. ERROR MESSAGE KEY WORD "!" IGNORED. CAUSE For CLOSE REEL/UNIT the close will not be performed. Otherwise the keyword is ignored (END & BEFORE). ERROR MESSAGE NAME OF "SD" ENTRY FOUND, EXPECTED "FD" ENTRY.
Questionable Errors 282 283 ERROR MESSAGE INVALID SUBSYSTEM COMMAND PARAMETER. CAUSE Invalid or missing parameter. ERROR MESSAGE INVALID SUBSYSTEM COMMAND. CAUSE 284 285 ERROR MESSAGE TOO MANY PARAMETERS IN MACRO CALL. CAUSE Check macro de nition. ERROR MESSAGE INVALID FILENAME IN $INCLUDE COMMAND. CAUSE 286 ERROR MESSAGE INVALID CHARACTER IN $PREPROCESSOR COMMAND. CAUSE 287 288 289 ERROR MESSAGE PSEUDO-TEXT CAN'T BE NULL, BLANK, COMMA, OR SEMICOLON.
Questionable Errors 307 308 309 310 ERROR MESSAGE LABELS MUST BE NONNUMERIC LITERAL = "IBM" OR "ANS". CAUSE When the LABELS phrase of the value of clause speci es a literal, the literal must be \IBM" or \ANS". ERROR MESSAGE SEQ MUST BE AN UNSIGNED NUMERIC LITERAL. CAUSE When the SEQ phrase of the value of clause speci es a literal, the literal must be numeric and unsigned. ERROR MESSAGE EXDATE MUST BE NONNUMERIC LITERAL OF THE FORM "MM/DD/YY".
Questionable Errors 320 321 ERROR MESSAGE FILE ! RECORD SIZE IS ZERO. CAUSE When the largest record for a le is 0 characters and there is a block contains clause in the le description which contains the characters phrase, it is impossible to compute the blocking factor. ERROR MESSAGE INTEGER-1 MUST BE <= INTEGER-2 IN 'TO' PHRASE. CAUSE 322 330 331 337 338 ERROR MESSAGE INVALID REFERENCE MODIFICATION. CAUSE Either the starting position or length is incorrect or the item is not USAGE DISPLAY.
Questionable Errors 349 350 351 352 354 355 356 357 358 359 ERROR MESSAGE REFERENCE TO A DEBUG-ITEM OUTSIDE OF A DEBUG SECTION. CAUSE A reference to DEBUG-ITEM or one of its subordinate items was made outside of a Debugging Section. ERROR MESSAGE NO CORRESPONDING OR INITIALIZE ITEMS FOUND. CAUSE A CORRESPONDING statement has no CORRESPONDING pairs. An INITIALIZE statement didn't nd any items. ERROR MESSAGE REFERENCE TO ! IS NOT UNIQUE.
Questionable Errors 360 361 362 363 364 365 366 367 368 ERROR MESSAGE ILLEGAL GO TO STATEMENT. CAUSE The GO TO statement is incorrect, for example, GO TO. appears, but it is not the rst statement in a paragraph, so it can't be ALTERed. ERROR MESSAGE ILLEGAL ALTER STATEMENT. CAUSE The ALTER statement references a non-existent paragraph name or it does not reference an alterable GO TO. ERROR MESSAGE ILLEGAL PERFORM TIMES COUNT. CAUSE The count must be an unsigned, positive integer.
Questionable Errors 369 370 371 372 373 374 377 378 ERROR MESSAGE ILLEGAL FUNCTION NAME !. CAUSE Mnemonic-name is ACCEPT/DISPLAY statements may only be SYSIN, SYSOUT or CONSOLE. The function name is changed to SYSIN/OUT. ERROR MESSAGE ILLEGAL STATEMENT FORMAT. CAUSE For example, PERFORM-VARYING statement with more than 7 levels. ACCEPT . . . ON INPUT ERROR without the FREE option. SEARCH ALL with missing keys or referencing the same key twice.
Questionable Errors 379 380 ERROR MESSAGE FROM/INTO IDENTIFIER ! SHARES SAME AREA AS RECORD-NAME. CAUSE The compiler has found a READ, REWRITE, RELEASE, RETURN, or WRITE statement that refers to the same area as the record-name reserved for the le. ERROR MESSAGE INVALID USE OF A SEPARATOR CHARACTER. CAUSE 381 382 ERROR MESSAGE MISSING PERIOD IN COPY OR REPLACE STATEMENT. CAUSE The statement must be terminated by a period. ERROR MESSAGE ERROR OR MISSING PROGRAM-ID PARAGRAPH.
Questionable Errors 389 390 391 392 393 394 395 396 ERROR MESSAGE PARAMETER ! IS NOT ALIGNED PROPERLY. CAUSE A data item being passed by reference is required to be on a word or half-word boundary. Use SYNC or move to 01/77. For CM, it is 16-bit word boundary only. ERROR MESSAGE COMPILER ERROR: UNIMPLEMENTED CASE ! IN PROCEDURE !. CAUSE The compiler was not prepared for a given situation. See directions on line .3 of the le COBCAT.PUB.SYS if it is the only error or warning.
Questionable Errors 397 398 399 ERROR MESSAGE ILLEGAL OBJECT OPERAND FOR EVALUATE SUBJECT. CAUSE The type of the object operand does not match its corresponding subject. For example, comparing TRUE with an item instead of a condition. Or comparing an item or literal with a condition. ERROR MESSAGE ILLEGAL OPERAND ! FOR INITIALIZE. CAUSE The operand does not exist or is illegal. ERROR MESSAGE REPLACING CATEGORY IS SPECIFIED TWICE IN INITIALIZE.
Serious Errors Serious Errors 401 ERROR MESSAGE ASSIGN CLAUSE REQUIRED WITH SELECT STATEMENT. CAUSE 402 403 ERROR MESSAGE MISSING ! KEY CLAUSE. CAUSE RELATIVE, RECORD or ACTUAL KEY is missing. ERROR MESSAGE FUNCTION NOT ALLOWED AS OPERAND. CAUSE Functions are not allowed in the following cases: 1. Target of any statement. 2. Operand of a call. 3. Where speci c rules of the statement disallow functions. 404 405 406 409 ERROR MESSAGE NUMERIC FUNCTION NOT ALLOWED AS OPERAND.
Serious Errors 410 412 413 414 415 ERROR MESSAGE SYNTAX ERROR. FOUND: !; EXPECTING ONE OF THE FOLLOWING:!!. CAUSE An item appears in some context that the compiler cannot recognize. The items which are allowed at this point are listed. EXPECTING . . . Disabled reserved word probably means the wrong entry was used to invoke the compiler. The compiler attempts to recover from this error. ERROR MESSAGE PARAMETER ! MUST BE 01 OR 77 LEVEL ITEM IN LINKAGE SECTION.
Serious Errors 420 421 ERROR MESSAGE SECTION MISPLACED OR DUPLICATED. CAUSE FILE SECTION, WORKING-STORAGE SECTION and LINKAGE SECTION must appear in that order when used. ERROR MESSAGE OPERAND ! HAS ILLEGAL FORMAT FOR STATEMENT. CAUSE This type of operand may not be used in the ACCEPT or DISPLAY statements. Bad identi er-1 for CALL or identi er for CALL INTRINSIC. EXAMINE identi er not usage DISPLAY or literals not one character. GO TO . . . DEPENDING identi er not an integer.
Serious Errors 423 424 425 426 427 428 ERROR MESSAGE MORE THAN 500 ENTRIES IN A GO TO DEPENDING ON STATEMENT. CAUSE A GO TO DEPENDING ON statement has too many paragraph/section names in the list. ERROR MESSAGE MORE THAN {255/57} NON-REDEFINED 01/77 LEVEL ITEMS IN LINKAGE SECTION. CAUSE The limit of independent 01/77 level items in the LINKAGE SECTION has been exceeded. The maximum is 255 on HP COBOL II/XL and 57 on HP COBOL II/V. Use REDEFINES if possible.
Disastrous Errors Disastrous Errors 450 451 452 ERROR MESSAGE USL FILE OVERFLOW. CAUSE The USL le may over ow under the following conditions: A $CONTROL USLINIT command may be missing, the default size of 1023 records may be too small, or there may not be enough records left in the usl le. ERROR MESSAGE PARSE STACK OVERFLOW; POSSIBLE LIMIT EXCEEDED. CAUSE The parse stack in compiler over owed. This may have been caused by too many levels of nesting of IF . . . THEN . . . ELSE statements.
Disastrous Errors 458 459 460 ERROR MESSAGE COMPILER ERROR: INVALID INTERNAL LABEL. CAUSE The compiler has generated or referenced an invalid internal label number. This could also be caused by too many VALUE clauses on table elements. If the error is not in the DATA DIVISION or it is the only error, then see directions on line .3 of the le COBCAT.PUB.SYS. ERROR MESSAGE TOO MANY VALUE CLAUSES. CAUSE USL entry over ows maximum size.
Disastrous Errors 467 468 470 471 491 ERROR MESSAGE OPEN ERROR ON SYMBOL TABLE FILE. CAUSE An error has occurred while trying to open the symbol table le (an internal temporary le). See directions on line .4 of the le COBCAT.PUB.SYS. The most likely cause of this is a lack of disk space. ERROR MESSAGE OPEN ERROR ON DATA TABLE FILE. CAUSE An error has occurred while trying to open the data table le (an internal temporary le). See directions on line .4 of the le COBCAT.PUB.SYS.
Disastrous Errors 496 ERROR MESSAGE EARLY END OF FILE ON FILE !. CAUSE This could occur with the following errors: Syntax of COPY or REPLACE statement is bad. Syntax in program, such as a period is missing. IDENTIFICATION DIVISION paragraph is incorrect. This could occur on writes to COBLIST, COBTEMP, COBMAC, or COBXDB. The disc le is not big enough to contain all of its data. The lesize can be increased with a le equation :FILE COBTEMP;DISC=nnnnn 498 ERROR MESSAGE UNABLE TO SAVE FILE !.
Nonstandard Warnings Nonstandard Warnings 500 503 ERROR MESSAGE INTERNAL SORT/MERGE ERROR ! (COBERR 500) CAUSE This is a run-time error. See the section \Run-Time Errors" later in this appendix for more information. ERROR MESSAGE NONSTANDARD ORDERING OF CLAUSES OBJECT-COMPUTER PARAGRAPH. CAUSE 505 ERROR MESSAGE PROCESSING MODE CLAUSE IS NONSTANDARD. CAUSE 509 ERROR MESSAGE STATEMENT MUST BEGIN IN AREA A IN STANDARD COBOL.
Nonstandard Warnings 520 ERROR MESSAGE ITEM REDEFINES AN ITEM CONTAINING A REDEFINES CLAUSE. CAUSE An item may not rede ne an item that contains a rede nes clause. See also error 520 ITEM REDEFINES AN ITEM CONTAINING A REDEFINES CLAUSE in the section \Run-Time Errors." 521 522 526 ERROR MESSAGE REDEFINE OF FILE RECORD IGNORED. CAUSE The rede nes clause is illegal at the 01-level in the le section. ERROR MESSAGE !! FOR !. CAUSE This error message is for non-standard forward references.
Run-Time Errors Run-Time Errors Errors that can occur while your program is executing are listed here. Some error messages include a number in square brackets. These numbers indicate the le status codes. Unless otherwise indicated, the following action is taken for a run-time I/O error (messages 520 through 699 are I/O errors). The error message is printed. If the error is le related (most are) the le system error is printed and a PRINTFILEINFO is executed.
Run-Time Errors 500 520 ERROR MESSAGE INTERNAL SORT/MERGE ERROR ! (COBERR 500) CAUSE See previous errors, for the detailed HPSORT error. The substitution is the status returned by HPSORT. ERROR MESSAGE ATTEMPT TO CLOSE A FILE THAT IS NOT OPEN [42] (COBERR 520) CAUSE An attempt was made to CLOSE a le which is not open. This is usually the result of a program logic error. Remove the redundant CLOSE statement or insert any necessary OPEN statement and recompile the source program.
Run-Time Errors 632 633 636 637 638 639 640 641 642 ERROR MESSAGE READ MUST PRECEDE ! [43] (COBERR 632) CAUSE In sequential access mode, a READ must be the previous operation on the le, before REWRITE or DELETE. ERROR MESSAGE UNABLE TO CLOSE FILE, SEE FILE SYSTEM ERROR [9x] (COBERR 633) CAUSE An error occurred while attempting to CLOSE a le. Refer to the le system error.
Run-Time Errors 644 645 646 647 648 649 650 653 ERROR MESSAGE UNABLE TO OPEN FILE, SEE FILE SYSTEM ERROR [9x] (COBERR 644) CAUSE An attempt to execute an OPEN statement failed. Refer to the le system error. ERROR MESSAGE I/O ERROR ON OPEN [9x] (COBERR 645) CAUSE An I/O error occurred while attempting to write CCTL information during an OPEN. Refer to the le system error.
Run-Time Errors 655 658 659 664 665 666 668 671 672 ERROR MESSAGE SEQ ERROR ON LABELED TAPE (COBERR 655) CAUSE An OPEN statement resulted in a SEQ error for a labeled tape. Refer to the le system error. ERROR MESSAGE RELATIVE KEY OVERFLOW [14,24] ! (COBERR 658) CAUSE The value for a RELATIVE KEY item has over owed while attempting to execute WRITE/READ statement to a relative le. The PICTURE for the RELATIVE KEY needs more digits.
Run-Time Errors 673 706 707 708 709 710 * ERROR MESSAGE FD DESCRIPTION LARGER THAN RECORD SIZE, TRUNCATED [44] (COBWARN 673) CAUSE The record length found when the le was opened for output was smaller than the FD record description. Data written to this le will be truncated. ERROR MESSAGE UNDERFLOW IN EXPONENTIATE (COBERR 706) CAUSE The result value of an exponentiation operation has resulted in an under ow. The result falls in the range -10**-28 to +10**-28.
Run-Time Errors 711 * 745 ERROR MESSAGE ILLEGAL ASCII DIGIT (COBERR 711) CAUSE An illegal ASCII digit was encountered in execution. The invalid data and the location is printed. Correct the data, if necessary, and re-run the program. NM : The program may abort or continue to execute based on the VAR COBRUNTIME. CM : Possible instructions are: CVDA, CVAD, CVDB, EDIT, CVND.
Run-Time Errors 748 * 749 750 751 * 752 753 * 754 * ERROR MESSAGE PARAGRAPH STACK OVERFLOW (COBERR 748) CAUSE Recursive performs, or performs with common exit points. Or illegal GOTOs out of a PERFORMed procedure. ERROR MESSAGE COLLATING SEQUENCE NOT SUPPORTED, ERROR ! (COBERR 749) CAUSE NLINFO (Native Language) returned an error. ERROR MESSAGE DEPENDING-ON IDENTIFIER OUT OF BOUNDS (COBERR 750) CAUSE The depending on identi er was not between occurs-1 and occurs-2.
Informational Messages Informational Messages 980 981 982 ERROR MESSAGE ATTEMPTING TO RECOVER FROM SYNTAX ERROR. CAUSE The indicated item is where the compiler is attempting to recover from the previous syntax error. The items between the two messages were ignored by the compiler. ERROR MESSAGE DEBUGGING SECTION ! IGNORED, NO DEBUGGING MODE CLAUSE. CAUSE The indicated Debugging Section is ignored because the WITH DEBUGGING MODE clause was not speci ed in the SOURCE-COMPUTER paragraph.
B Preprocessor Commands and $CONTROL Options HP COBOL II contains special language independent compile-time features designed to simplify the compilation process. These features allow you to modify input text, set certain compilation options, or control the contents of the list output. All these options are implemented by a simple compile-time language, consisting of commands, statements, variables or identi ers, and macro calls for text substitution.
Preprocessor Preprocessor Programming Language The preprocessor programming language is a simple language consisting of variables and commands. All of the preprocesses are performed at compile-time. None is performed at run-time. Table B-1 lists all of the preprocessor commands. They are described in the remainder of this appendix. Table B-1. Preprocessor Commands Command Purpose $COMMENT Writing comment lines. $DEFINE $PREPROCESSOR De ning and using macros. $IF $SET Conditional compilation.
Preprocessor Description The required dollar sign is used to identify a preprocessor command. This symbol must appear in the rst column of a line of source code, immediately following the sequence number eld. The second, optional, dollar sign is used to indicate that the preprocessor command of which it is a part is to be executed, but is not to be copied (in a merging process) to the new le.
Preprocessor $COMMENT Command The $COMMENT command has the following format: $COMMENT [ comment-text ] where comment-text is a string containing anything you want to enter. comment-text requires no delimiters. It ends at the end of the line where the $COMMENT command is issued unless a continuation character is used. Use of COBOL comments, \*", is preferred. The example below illustrates the $COMMENT command: 000100$COMMENT THIS LINE IS AN EXAMPLE OF THE $COMMENT PRE- & 000200$ PROCESSOR COMMAND.
Using Macros Defining and Using Macros One of the most powerful facilities of the preprocessor is the macro processor. This processor associates a macro name with a string of text. When the macro name is used by itself in a COBOL sentence, the preprocessor sends the de nition of the macro to the compiler. See also the COPY and REPLACE statements. Macros can have up to nine formal parameters.
Using Macros Example. 000100 $DEFINE %INCA=ADD 1 TO ALPHA-COUNTER. 000200 ADD ALPHA-COUNTER TO BETA-COUNTER. 000300* INCREMENT THE VALUES OF COUNTERS ALPHA-COUNTER & 000400* BETA-COUNTER.# In the above example, the entire de nition of the macro, %INCA, is the following set of sentences: 000100 000200 000300* 000400* ADD 1 TO ALPHA-COUNTER. ADD ALPHA-COUNTER TO BETA-COUNTER. INCREMENT THE VALUES OF COUNTERS ALPHA-COUNTER & BETA-COUNTER.
Using Macros Because the macro de nition starts on the same line as the macro name, the de nition of the macro replaces the macro call starting in exactly the same column as the macro call. 000100$DEFINE %CHECKIF= 000200 IF STAT-ITEM EQUAL "10" 000300 THEN PERFORM STATUS-REPORT 000400 ELSE NEXT SENTENCE.# In this case, because the characters between the equal sign and the end of line 000100 are blanks, the macro de nition begins on line 000200.
Using Macros Macro Calls There are two di erent forms of a macro call: macro-name and macro-name(p1#,p2#,p3#,...,pn#) Parameters macro-name p1,p2,...,pn the name of a macro which has been previously de ned in the source program, using a $DEFINE command. the actual parameters. Each of p1 , p2 , and so on may be either a null string or any combination of characters and numerals, including spaces.
Using Macros Relationship of Formal Parameters to Actual Parameters The numeric value of a formal parameter determines which actual parameter in the macro call is to replace it. That is, for a formal parameter, !n (where n is 1 through 9), the n th actual parameter from the left in the macro call replaces !n , as illustrated below. Examples. Macro de nition: $DEFINE %OPENSTATE= OPEN INPUT !1. DISPLAY !2,!3.
Using Macros When you specify a formal parameter in a macro de nition, you can choose not to use it in the macro call by entering only a comma and a pound sign in the appropriate position within the macro call. This is shown in the next example: Macro de nition: 000100$DEFINE %INITSTUFF= 000200 IDENTIFICATION DIVISION. 000300 PROGRAM-ID. !1 000400 AUTHOR. !2 000500 DATE-COMPILED. !3# Macro call: 001000 %INITSTUFF(MACRO-TEST.
Using Macros Nested Macro Calls You can pass the result of one macro call as an actual parameter to another macro by using the $PREPROCESSOR command discussed in the next section. By rede ning the macro delimiter for the nested macro, you can use a call to that macro as a parameter to another macro. The following examples illustrate two slightly di erent ways of nesting macro calls. Example 1. This example de nes two macros, %M1 and %M2 . The macro %M2 is passed as a parameter to %M1 .
Using Macros $PREPROCESSOR Command The $PREPROCESSOR command allows you to change the default characters used in macro de nitions and names. The default characters are: % used as the initial character in a macro name. ! used as the rst character of a formal parameter in macro de nitions. # used to delimit string-text in a macro de nition, and actual parameters.
Conditional Compilation Conditional Compilation Usually, when you compile a source le, you want the entire program compiled. However, there may be occasions when you want only part of the program compiled. Conditional compilation, that is, compilation of source code contingent upon whether a switch is on or o , is accomplished by using the $SET and $IF preprocessor commands. $SET Command The $SET preprocessor command may be used to turn ten compilation switches on or o .
Conditional Compilation The $IF command may appear anywhere in the source text. The appearance of a $IF command always terminates the in uence of any preceding $IF command. When a $IF command is entered without a parameter, it has the same e ect as a $IF command whose condition is true. That is, the text following the command is compiled, and any previous $IF command is canceled. Note that the merging of a text and master source le, and copying of this merged le to a new le is una ected by $IF commands.
$INCLUDE Command File Insertion, and Merging and Editing Operations There are essentially two types of le merging functions available to you through the preprocessor. The rst uses the preprocessor command, $INCLUDE. The second merging function is done using any of the operating system's COBOL commands, and optionally, the $EDIT preprocessor command. $INCLUDE Command The $INCLUDE command allows you to specify an entire le to be sent, line by line, to the compiler as part of your source le.
$INCLUDE Command Example 000100$INCLUDE INITFILE 001000 ENVIRONMENT DIVISION. 001100 CONFIGURATION SECTION. . . . If INITFILE contains the records, 000200$CONTROL SUBPROGRAM 000300 IDENTIFICATION DIVISION. 000400 PROGRAM-ID. SUBDUMMY. 000500 AUTHOR. JPW. 000600 INSTALLATION. GSD. 000700 DATE-WRITTEN. DUMMY-WRITTEN-05/08/85. 000800 DATE-COMPILED. WHEN-USED. 000900 SECURITY. NONE-ON-DUMMY. Then when the $INCLUDE statement above is executed, the results are as follows.
Merging Files Merging Files and the $EDIT Command This section is obsolete and its use is not recommended. Merging and editing operations are done prior to other preprocessor functions. The following editing and merging operations are available to you at compile-time: 1. Merge corrections or additional source text in the text le with an existing source program (master le) to produce a new source program and commands. 2. Omit sections of the old source program during merging. 3.
Merging Files The above description implies that records from the master le with blank sequence elds are always compiled. This is because the records of the master le with blank sequence elds will either eventually be less than a sequence eld for a text le record, or the entire text le will have been used. When an end-of- le condition is encountered on either text le or master le, merging terminates (except for the continuing in uence of an unterminated VOID parameter in an EDIT command).
$EDIT Command $EDIT Command The $EDIT preprocessor command can be used to bypass all records of the master le whose sequence elds contain a certain value, and renumber the numeric sequence elds of records in the new le created by merging a text le and a master le. The $EDIT command has the following format: $EDIT [ parameter=subparameter ] [, parameter=subparameter ] [ . . . ] Parameters parameter subparameter either VOID, SEQNUM, NOSEQ, or INC.
$EDIT Command If the sequence number subparameter of the SEQNUM command is of insu cient length to ll the sequence eld of the new le, su cient zeroes are appended to the left of the sequence number to ll the sequence eld of the records in the new le. NOSEQ Parameter The NOSEQ parameter of the $EDIT command is used to terminate the resequencing of a new le initiated by a $EDIT SEQNUM command.
$COPYRIGHT Command Compiler-Dependent Options This section covers the ve preprocessor commands that are compiler-dependent. This means that they are processed by the HP COBOL II compiler. The compiler-dependent preprocessor commands are $COPYRIGHT, $PAGE, $TITLE, $VERSION, and $CONTROL. $COPYRIGHT Command With the $COPYRIGHT command you can put a copyright string into your object le. Syntax $COPYRIGHT [string [, string ] . . . ] Parameter string the data to be placed into the object le.
$PAGE Command $PAGE Command The $PAGE command allows you to replace the rst line of the title portion of the standard page heading in a list le, and to advance to the next logical page of the list le. Syntax $PAGE [string [, string ] . . . ] Parameter string the data to be used in replacing the rst line of the title. The characters of string must be preceded and followed by a quotation mark. The total number of characters used in the strings is limited to 97.
$TITLE Command $TITLE Command The $TITLE command is similar to $PAGE in that it can be used to replace the rst line of a title in the list le. However, it can also be used to replace the second line of the title as well as the rst, or only the second line; unlike $PAGE, it does no page advancement on the logical page of the list le. Syntax $TITLE [ (n ) ] [string [, string ] . . . ] Parameters n string speci es which line of the title is to be replaced.
$VERSION Command $VERSION Command With the $VERSION command you can put a version string into your object le. Syntax $VERSION [string [, string ] . . . ] Parameter string the data to be placed into the object le. The characters of string must be preceded and followed by a quotation mark (") or an apostrophe ('). The total number of characters used in the strings is limited to 255. This includes any blanks appearing in strings, but does not include the quotation marks used to delimit the strings.
$CONTROL Command $CONTROL Command The $CONTROL command controls compilation and list options. It has the following format: $CONTROL option [ , optionlist ] Parameters one or more valid options, each separated from the preceding option by a comma and zero or more optional spaces. See Table B-2 for a complete list of $CONTROL options. a valid option for the $CONTROL command. Table B-2 lists all the $CONTROL options. optionlist option The following lists all the $CONTROL options: Table B-2.
$CONTROL Options ANSISORT This option is provided to allow you to open the les speci ed in the USING or GIVING clause of the SORT statement in the input or output procedure of the same SORT statement. This capability will degrade the performance of SORT statements in the program. It is also not recommended to use the USING le as an output le in the output procedure of the SORT. If you do, you will not be able to recover the data that went into the sort if the program should abnormally terminate.
$CONTROL Options CROSSREF The CROSSREF option of $CONTROL requests a cross reference if symbols and procedures used on the expanded source le. This cross reference is sent to the list le. NOCROSSREF The NOCROSSREF option of $CONTROL requests that no cross reference of symbols and labels used in the expanded source le be listed in the list le. This is the default; thus, its use is to cancel a previously issued $CONTROL CROSSREF command.
$CONTROL Options LIST The LIST option of the $CONTROL command enables the listing of all source text, as well as error and warning messages, subsystem initiation and completion messages, and all other listings requested by the $CONTROL command (as for example, $CONTROL MAP). Initially, this listing option is in e ect by default. You might wish to use it to cancel a previously issued $CONTROL NOLIST, or $CONTROL LOCOFF command.
$CONTROL Options NOMAP The NOMAP option requests that no symbol table map be included in your list le. This is the default; thus, the purpose of the NOMAP option is to negate a previously issued $CONTROL MAP command. MIXED The MIXED option of the $CONTROL command requests that the list le include all preprocessor commands used in the expanded source le. Note that the $PAGE and $TITLE preprocessor commands are not listed even if this option is in e ect.
$CONTROL Options STDWARN 2 8 > > HIGH 6 > > INT 6 > > 6 > < INTSG 6 STDWARN 6 = 6 > MIN 6 > > > 4 > MINDB > > : MINSG 93 > > > 7 > > 7 > > =7 7 7 > 7 > 7 > > > 5 > > ; The STDWARN option requests that the compiler detect and ag features in your source le that are part of HP COBOL II but not part of one of three levels of Federal Standard COBOL (FIPS). The three levels are minimum, intermediate, and high. The default, high, ags HP COBOL II extensions. These agged features are listed in your list le.
$CONTROL Options Table B-3.
$CONTROL Options Note With the SYMDEBUG option, the compiler places signi cantly more information in the object le. SYNC16 and SYNC32 This option changes the alignment of SYNCHRONIZED data items. This alignment a ects the number of slack bytes generated in a record. If SYNC16 is in e ect, index data items and items with the SYNCHRONIZED clause are aligned along 16-bit boundaries. If SYNC32 is in e ect, these items are aligned along 32-bit boundaries.
$CONTROL Options WARN The WARN option enables the agging of possible, but not clearly, erroneous conditions within your expanded source le. These agged conditions are listed in your list le, along with an appropriate warning message. WARN is a default condition. Thus, you need only use it to negate the use of a previously issued $CONTROL NOWARN command. NOWARN The NOWARN option disables the agging and listing of possible erroneous conditions and their associated warning messages.
Differences Between ANSI COBOL'74 and ANSI COBOL'85 C This appendix describes the di erences and incompatibilities between the 1974 ANSI COBOL standard and the 1985 ANSI COBOL standard and identi es obsolete features that will be deleted from standard COBOL. ANSI74 Entry Point Differences The following is a list of the ANSI COBOL'74 features accessible through the ANSI74 entry point.
Differences between ANSI COBOL'74 and ANSI COBOL'85 Note COBOL'68 syntax that was treated as comments by the compiler, is implemented in the HP COBOL II compiler. However, use of this feature in future programming is not suggested. (Refer to \System Dependencies" in Appendix H for more information.) For example, the PROCESSING MODE IS SEQUENTIAL phrase of the SELECT statement is COBOL'68 syntax that is treated as comments .
Differences between ANSI COBOL'74 and ANSI COBOL'85 Incompatibilities between ANSI COBOL'74 and ANSI COBOL'85 The following paragraphs summarize the syntax and run-time incompatibilities between ANSI COBOL'74 and ANSI COBOL'85. Syntax Incompatibilities Syntax incompatibilities are: The keyword ALPHABET must precede each alphabet name within the ALPHABETNAME clause of the SPECIAL-NAMES paragraph. New reserved words have been added. Refer to Appendix F for more information.
Differences between ANSI COBOL'74 and ANSI COBOL'85 Table C-1 describes the di erence between the I/O status codes received using the ANSI74 and ANSI85 entry points. It shows the equivalent ANSI74 codes for the new ANSI85 codes and any di erence in execution for these codes as well as codes whose de nition has changed. Table C-1.
Differences between ANSI COBOL'74 and ANSI COBOL'85 Table C-1. New I-O Status Codes (continued) ANSI85 Status Code ANSI74 Status Code New, Old, or Changed Execution Di erences between the Entry Points 38 00 New Using ANSI74, the OPEN fails and a message is printed even though an error status code is not returned. Using ANSI85, the OPEN fails and a permanent error condition exists for that le. 39 00 New ANSI74 entry point successfully opens the le and may print an error message.
Differences between ANSI COBOL'74 and ANSI COBOL'85 Obsolete Features Obsolete features are elements of the language that are now part of the 1985 ANSI COBOL standard, but will be deleted from the full standard after ANSI COBOL'85. The ANSI85 entry point will continue to support these features. The following items have been placed in the obsolete category: AUTHOR, DATE-WRITTEN, DATE-COMPILED, and SECURITY paragraphs in the IDENTIFICATION DIVISION. MEMORY-SIZE clause of the OBJECT-COMPUTER paragraph.
D ASCII and EBCDIC Character Sets This appendix presents a table showing the ASCII (American Standard Code for Information Interchange) and EBCDIC (Extended Binary Coded Decimal Interchange Code) character sets. How to Use This Table 1. The table is sorted by character code, each code being represented by its decimal, octal, and hexadecimal equivalent. 2. Each row of the table gives the ASCII and EBCDIC meaning of the character code.
ASCII and EBCDIC Character Sets Table D-1.
ASCII and EBCDIC Character Sets Table D-1.
ASCII and EBCDIC Character Sets Table D-1.
ASCII and EBCDIC Character Sets Table D-1.
E COBOL Glossary The terms in this appendix are de ned in accordance with their meaning as used in this document describing COBOL and may not have the same meaning for other languages. These de nitions are also intended to be either reference material or introductory material to be reviewed prior to reading the detailed language speci cations. For this reason, these de nitions are, in most instances, brief and do not include detailed syntactical rules. Definitions Abbreviated Combined Relation Condition.
COBOL Glossary Arithmetic Operator. A single character, or a xed two-character combination, that belongs to the following set: Character + * / ** Meaning addition subtraction multiplication division exponentiation Arithmetic Statement. A statement that causes an arithmetic operation to be executed. The arithmetic statements are the ADD, COMPUTE, DIVIDE, MULTIPLY, and SUBTRACT statements. Ascending Key.
COBOL Glossary Character Position. A character position is the amount of physical storage required to store a single standard data format character described as usage is DISPLAY. Further characteristics of the physical storage are de ned by the implementor. Character String. A sequence of contiguous characters which for COBOL word, a literal, a PICTURE character string, or a comment entry. Class Condition.
COBOL Glossary Collating Sequence. The sequence in which the characters that are acceptable in a computer are ordered for purposes of sorting, merging, and comparing. Column. A character position within a print line. The columns are numbered from 1, by 1, starting at the leftmost character position of the print line and extending to the rightmost position of the print line. Combined Condition. A condition that is the result of connecting two or more conditions with the 'AND' or the 'OR' logical operator.
COBOL Glossary Concatenated Programs. A source le that contains more than one COBOL program appended to the previous program, of which at least one program is not a nested program. The previous program must be terminated with END PROGRAM statement. In the following example, PROGRAM-1 and PROGRAM-2 are concatenated programs. PROGRAM-3 is a nested program. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN IDENTIFICATION DIVISION. PROGRAM-ID. PROGRAM-1. . . . END PROGRAM PROGRAM-1. IDENTIFICATION DIVISION. PROGRAM-ID.
COBOL Glossary CONFIGURATION SECTION. A section of the ENVIRONMENT DIVISION that describes overall speci cation of source and object programs. Containing and Contained Programs. Programs that are nested. For example, in the program below, PROGRAM-1 and PROGRAM-2 are containing programs because PROGRAM-1 contains PROGRAM-2 and PROGRAM-3, and PROGRAM-2 contains PROGRAM-3. PROGRAM-2 and PROGRAM-3 are contained programs. IDENTIFICATION DIVISION. PROGRAM-ID. PROGRAM-1. . . . IDENTIFICATION DIVISION. PROGRAM-ID.
COBOL Glossary Debugging Line. A debugging line is any line with 'D' in the indicator area of the line. Debugging Section. A debugging section is a section that contains USE FOR DEBUGGING statement. Declaratives. A set of one or more special purpose sections, written at the beginning of the PROCEDURE DIVISION, the rst of which is preceded by the keyword DECLARATIVES and the last of which is followed by the keywords END DECLARATIVES.
COBOL Glossary Editing Character. A single character or a xed two -character combination belonging to the following set: Character B 0 + CR DB Z * $ , . / Meaning space zero plus minus credit debit zero suppress check protect currency-sign comma (decimal-point) period (decimal-point) stroke (virgule, slash) Elementary Item. A data item that is described as not being further logically subdivided. End of PROCEDURE DIVISION.
COBOL Glossary File. A collection of records. File Clause. A clause that appears as part of any of the follow DATA DIVISION entries: File description (FD) Sort-merge le Description (SD) Communication description (CD) Not used in HP COBOL II. File Connector. A storage area which contains information about a le and is used as the linkage between a le name and a physical le and between a le name and its associated record area. FILE-CONTROL.
COBOL Glossary Function. A temporary data item whose value is determined at the time the function is referenced during the execution of a statement. Function-Identi er. A syntactically correct combination of character-strings and separators that references a function. The data item represented by a function is uniquely identi ed by a function name with its arguments, if any. A function-identi er may include a reference-modi er.
COBOL Glossary Index. A computer storage position or register, the contents of represent the identi cation of a particular element in a table. Index Data Item. A data item in which the value associated with an index name can be stored in a form speci ed by the implementor. Index Name. A user-de ned word that names an index associated a speci c table. Indexed Data Name. An identi er that is composed of a data name followed by one or more index names enclosed in parentheses. Indexed File.
COBOL Glossary Intra-Record Data Structure. The entire collection of groups and elementary data items from a logical record which is de ned by a contiguous subset of the data description entries which describe that record. These data description entries include all entries whose level number is greater than the level number of the rst data description entry describing the intra-record data structure. Invalid Key Condition.
COBOL Glossary LINKAGE SECTION. The section in the DATA DIVISION of the called program that describes data items available from the calling program. These data items may be referred to by both the calling and called program. Literal. A character string whose value is implied by the order set of characters comprising the string. Logical Operator. One of the reserved words AND, OR, or NOT. I formation of a condition, both or either of AND and OR can be used as logical connectives.
COBOL Glossary Nested Programs. A COBOL program that contains another COBOL program. In the following example, TEST1 is a nested program. TEST contains TEST1. IDENTIFICATION DIVISION. PROGRAM-ID. TEST. . . . IDENTIFICATION DIVISION. PROGRAM-ID. TEST1. END PROGRAM TEST1. . . . END PROGRAM TEST. See \Containing and Contained Programs" in this glossary. Next Executable Sentence. The next sentence to which control will be transferred after execution of the current statement is complete.
COBOL Glossary Object Computer Entry. An entry in the OBJECT-COMPUTER paragraph of the ENVIRONMENT DIVISION which contains clauses which describe the computer environment in which the object program is to be executed. Object of Entry. A set of operands and reserved words, within a DIVISION entry, that immediately follows the subject of the entry. Object Program. A set or group of executable machine language instructions and other material designed to interact with data to provide problem solution.
COBOL Glossary Page. A vertical division of a report representing a physical separation of report data, the separation being based on internal reporting requirements and/or external characteristics of the reporting medium. Page Body. That part of the logical page in which lines can be written and/or spaced. Page Footing. A report group that is presented at the end of a report page as determined by the Report Writer Control System. Page Heading.
COBOL Glossary Procedure. A paragraph or group of logically successive paragraphs, or a section or group of logically successive sections, within the PROCEDURE DIVISION. Procedure Branching Statement. A statement that causes the explicit transfer of control to a statement other than the next executable statement in the sequence in which the statements are written in the source program.
COBOL Glossary Random access. An access mode in which the program-speci ed value of a key data item identi es the logical record that is obtained from, deleted from or placed into a relative or indexed le. Record. (See Logical Record) Record Area. A storage area allocated for the purpose of processing the record described in a record description entry in the FILE SECTION. Record Description. (See Record Description Entry) Record Description Entry.
COBOL Glossary Relational Operator. A reserved word, a relation character, a group of consecutive reserved words, or a group of consecutive reserved words and relation characters used in the construction of a relation condition.
COBOL Glossary Section Header. A combination of words followed by a period and a space that indicates the beginning of a section in the ENVIRONMENT, DATA and PROCEDURE divisions. In the ENVIRONMENT and DATA divisions, a section header is composed of reserved words followed by a period and a space. The permissible section headers are: In the ENVIRONMENT DIVISION: CONFIGURATION SECTION. INPUT-OUTPUT SECTION. In the DATA DIVISION: FILE SECTION. WORKING-STORAGE SECTION. LINKAGE SECTION. COMMUNICATION SECTION.
COBOL Glossary Simple Condition. Any single condition chosen from the set: relation condition class condition condition name condition switch-status condition sign condition (simple-condition) Sort File. A collection of records to be sorted by a SORT state. The sort- le is created and can be used by the sort function only. Sort-Merge File Description Entry.
COBOL Glossary Special Character Word. A reserved word which is an arithmetic operator or a relation character. SPECIAL-NAMES. The name of an ENVIRONMENT DIVISION paragraph in which implementor names are related to user-speci ed mnemonic names. Special Names Entry.
COBOL Glossary Text-Word. A character or a sequence of contiguous characters within area A and/or area B in a COBOL library, source program, or in pseudo-text that is: A separator (except for: a space, a pseudo-text delimiter, the opening and closing delimiters for nonnumeric literals.) The right and left parentheses are always considered text-words. A literal (including, in the case of nonnumeric literals, the opening quotation mark and the closing quotation mark that bound the literal.
F COBOL Reserved Word List This appendix lists all the reserved words in COBOL. Table F-1.
COBOL Reserved Words Table F-1.
COBOL Reserved Words Table F-1.
G COBEDIT Program and COPY Libraries This appendix explains the COBEDIT program that allows you to copy source statements from COBOL COPY libraries. With COBEDIT you can develop and maintain COBOL COPY libraries. The EDIT, EXIT, HELP, and LIBRARY commands are discussed as features in using the COPY Library. The COBEDIT Program The COBEDIT program resides in the PUB group of the SYS account. This program allows you to create, modify, and look at a COBOL COPY Library le.
COBEDIT Program, COPY Libraries COPY Libraries The COPY statement is a COBOL feature that enables you to copy COBOL source statements into your program from COPY Libraries. In this way, multiple programs can use a single paragraph, le description or record description. On an HP computer system, COBEDIT copy libraries are KSAM les of ASCII records which contain one or more modules. These modules are the sets of text which can be copied into your program.
COBEDIT Program, COPY Libraries COBEDIT Commands There are 10 commands in the COBEDIT program. Each is listed in Table G-1 and discussed on the following pages. Note that user input is underlined in each example of the commands. Table G-1. COBEDIT Commands Command Meaning BUILD Build a COPYLIB le. COPY Copy modules into the library as in the BUILD command. EDIT Create or edit a module to add to a COPYLIB le. EXIT Leave the COBEDIT program. HELP List all COBEDIT commands.
COBEDIT BUILD Command BUILD Command The BUILD command allows you to build a new KSAM le to be used as a library le. Once this library le is built, it remains open and available for use until you exit the COBEDIT program, or specify a new library by issuing another BUILD command or a LIBRARY command. Syntax BUILD [ le-name ] [ ,maxrecs ] Parameters le-name maxrecs any name you wish to give your new library le, subject to the naming conventions for any MPE le.
COBEDIT BUILD Command If you respond with Y for YES, COBEDIT attempts to copy the requested le. Note that if the text-name is blank, the COBEDIT program copies the records into your library and assigns a default text-name, BOO-BOO. If a negative response is given, COBEDIT asks you for a text-name to be used for the copied records. This text-name must be from one to eight characters long. After a le has been copied into your library, you are asked if there are more les to be copied.
COBEDIT BUILD Command Note that if you name a le to be copied into your library le and the library le does not have a su cient amount of free space to contain the records of the le being copied, no records are copied and the BUILD command is terminated. A library le that is too small to contain the records from a speci ed le is used to illustrate this. >BUILD ATLAS, 3 Name a key file to be used with ATLAS: KEYATLAS To copy a file into ATLAS now, enter the file name.
COBEDIT COPY Command COPY Command The COPY command allows you to copy additional modules into a library that was created previously using the BUILD command. To use COPY, the library must be the current library or it must be activated by using the LIBRARY command. COPY prompts and executes in a way similar to the BUILD command. Syntax COPY Example :RUN COBEDIT.PUB.SYS HP32233A.02.00 COPYLIB EDITOR - COBEDIT MON, MAR 26, 1991, 10:12 AM (C) HEWLETT-PACKARD CO. 1986 TYPE "HELP" FOR A LIST OF COMMANDS.
COBEDIT EDIT Command EDIT Command The EDIT command calls the EDIT/3000 subsystem, and optionally allows you to name a module from the currently active library to be edited. Syntax EDIT [ text-name ] Parameters text-name the name of a module in the currently active library. Description EDTXT is created by COBEDIT as a permanent le when required for edit operations. EDTXT is purged by COBEDIT when no longer required. Thus, only one user per logon group can be editing any library le.
COBEDIT EDIT Command Example 1 >EDIT HP32201A.07.20 EDIT/3000 TUE, MAR 26, 1991, 10:15 AM (C) HEWLETT-PACKARD CO. 1990 NOTE: FORMAT=COBOL VALUES SET FOR LENGTH,RIGHT,FROM,DELTA,FRONT /L ALL .001 /D .001 *** WARNING *** WORK FILE IS EMPTY. /A 1 $CONTROL SUBPROGRAM 1.1 PROGRAM-ID. FRESHTEST. 1.2 AUTHOR. JAMES FISH. 1.3 // ...
COBEDIT EDIT Command Example 2 >EDIT MODULE1 Previous Edit text was not saved. OK to clear? (Y/N) Y HP32201A.07.20 EDIT/3000 TUE, MAR 26, 1991, 10:18 AM (C) HEWLETT-PACKARD CO. 1990 NOTE: FORMAT=COBOL VALUES SET FOR LENGTH,RIGHT,FROM,DELTA,FRONT /L ALL 1. SORT-PARA. 1.1 SORT SORTFL ON ASCENDING KEY FIRST-KEY 1.2 INPUT PROCEDURE IS INP-SECTION 1.3 OUTPUT PROCEDURE IS OUTP-SECTION 1.4 THROUGH OUTP-END-SECTION. /ADD 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 INP_SECTION.
COBEDIT EDIT Command Example 3 As a nal illustration of using the EDIT command, a le created outside of the COBEDIT program is joined to the work space associated with EDTXT. >EDIT Previous Edit text was not saved. OK to clear? (Y/N) N > >KEEP MODULE4 >EDIT HP32201A.07.20 EDIT/3000 TUE, MAR 26, 1991, 10:21 AM (C) HEWLETT-PACKARD CO. 1990 NOTE: FORMAT=COBOL VALUES SET FOR LENGTH,RIGHT,FROM,DELTA,FRONT /L ALL .001 /M MODIFY .
COBEDIT EXIT Command EXIT Command The EXIT command is used to exit the COBEDIT program. Syntax E[XIT] Description To exit COBEDIT, type EXIT or E. If you have used the EDIT command, and no KEEP command was issued before the EXIT command is executed, the following message is displayed: Edit text not empty. OK to clear? If you respond with anything except Y or YES, the EXIT command terminates, and COBEDIT remains active.
COBEDIT EXIT Command Example 3 :RUN COBEDIT.PUB.SYS HP32233A.02.00 COPYLIB EDITOR - COBEDIT MON, MAR 26, 1991, 10:27 AM (C) HEWLETT-PACKARD CO. 1986 TYPE "HELP" FOR A LIST OF COMMANDS. >LIB MYLIB >LIST ALL Text-name MODULE1 001000$CONTROL SUBPROGRAM 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. DUMMY-SUB. Text-name MODULE2 005100 WORKING-STORAGE SECTION. 005200 01 UNIV-TOTALER PIC 9(8) COMP-3. 005300 01 UNIV-ACCUM PIC 9(8) COMP-3. Text-name MODULE3 008000 008100 008200 008300 PERFORM TEST-IT.
COBEDIT HELP Command HELP Command The HELP command lists and gives a brief description of all commands available in the COBEDIT program. Syntax HELP Example > HELP The following is a list of COBEDIT commands: BUILD library-name [ , filesize ] Create a new library file with name "library-name". COPY Copy modules into library, as in Build command. EDIT [ text-name ] Activate EDIT/3000 and text in that module of the current library which contains "text-name" in the id field. EXIT Exit the COBEDIT program.
COBEDIT KEEP Command KEEP Command The KEEP command allows you to add a module to the currently active library, or replace an already existing module. Syntax KEEP [ text-name ] Parameters text-name is the name to be used for the module being kept. Description If the module to be kept is one that already exists on the le, and you named that module in a previous EDIT command, you do not have to specify a text-name in the KEEP command.
COBEDIT KEEP Command 1. $CONTROL SUBPROGRAM 1.1 IDENTIFICATION DIVISION. 1.2 PROGRAM-ID. DUMMY-SUB. /M 1.2 MODIFY 1.2 PROGRAM-ID. DUMMY-SUB. RTEST-KEEP. PROGRAM-ID. TEST-KEEP. /A 1.3 AUTHOR. MYSELF. 1.4// ... /E EDTXT ALREADY EXISTS - RESPOND YES TO PURGE OLD AND KEEP NEW PURGE OLD? Y >KEEP "MODULE1 " already exists on Library MYLIB. OK to clear? Y >LIST ALL Text-name MODULE1 001000$CONTROL SUBPROGRAM 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. TEST-KEEP. 001300 AUTHOR. MYSELF.
COBEDIT KEEP Command Example 2 >EDIT HP32201A.07.20 EDIT/3000 TUE, MAR 26, 1991, 10:36 AM (C) HEWLETT-PACKARD CO. 1990 NOTE: FORMAT=COBOL VALUES SET FOR LENGTH,RIGHT,FROM,DELTA,FRONT /MODIFY MODIFY .001 I*THIS MODULE WILL BE ADDED TO MYLIB BY *THIS MODULE WILL BE ADDED TO MYLIB BY /A .002*USING A TEXT NAME IN THE KEEP COMMAND .003// ... /E EDTXT ALREADY EXISTS - RESPOND YES TO PURGE OLD AND KEEP NEW PURGE OLD?Y >KEEP MOD5 >LIST ALL Text-name MODULE1 001000$CONTROL SUBPROGRAM 001100 IDENTIFICATION DIVISION.
COBEDIT KEEP Command Text-name MOD4 000101* THIS IS TO SHOW WHAT HAPPENS WHEN A KEEP COMMAND 000201* IS ISSUED BEFORE THE EXIT COMMAND IS USED. Text-name MOD5 000101* THIS MODULE WILL BE ADDED TO MYLIB BY 000201* USING A TEXT NAME IN THE KEEP COMMAND. Note that if you use the KEEP command without a text-name, and the data in EDTXT was not entered by using text from an already existing module, the message Invalid text-name is returned.
COBEDIT LIBRARY Command LIBRARY Command The LIBRARY command allows you to select the library that you wish to access. When you issue this command, the currently active library is closed, and the speci ed library is opened and made available. Syntax LIBRARY library-name Parameters library-name is the name of the library le you want to access. Description It can be in any group and account. Note that only one user at a time can be editing a particular library le.
COBEDIT LIBRARY Command Example >LIB Library name? MYLIB >SHOW ************************************************ Library file: MYLIB.MANAGERS.USERS Text-name: Key file: KMYLIB ************************************************ >LIB COPYLIB >SHOW ************************************************ Library file: COPYLIB.MANAGERS.USERS Text-name: Key file: KCOPYLIB ************************************************ >LIB CLIB.PUB.USERS SECURITY VIOLATION (FSERR 93) FILE CLIB.PUB.USERS NOT OPENED. >:TELL WENDY.
COBEDIT LIST Command LIST Command The LIST command allows you to list information about your currently active library. The information available is a list of all module names within the library, or a list of all or one of the modules in the library. A control Y terminates the listing.
COBEDIT LIST Command The following examples illustrate the use of redirection and batch jobs. Example of Redirection :FILE PRINT; DEV=LP :RUN COBEDIT.PUB.SYS;STDLIST=*PRINT HP32233A.02.00 COPYLIB EDITOR - COBEDIT MON, MAR 26, 1991, 10:43 AM (C) HEWLETT-PACKARD CO. 1986 TYPE "HELP" FOR A LIST OF COMMANDS. >LIB COPYLIB >SHOW >LIST ALL >EXIT Example of Batch Job :JOB LIBPRINT,USER.ACCOUNT :RUN COBEDIT.PUB.
COBEDIT LIST Command Example >LIBRARY MYLIB >LIST Text-names of modules in MYLIB: MODULE1 MODULE2 MODULE3 MOD4 MOD5 >LIST MODULE2 Text-name MODULE2 005100 WORKING-STORAGE SECTION. 005200 01 UNIV-TOTALER PIC 9(8) COMP-3. 005300 01 UNIV-ACCUM PIC 9(8) COMP-3. >LIST ALL Text-name MODULE1 001000$CONTROL SUBPROGRAM 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. TEST-KEEP. 001300 AUTHOR. MYSELF. Text-name MODULE2 005100 WORKING-STORAGE SECTION. 005200 01 UNIV-TOTALER PIC 9(8) COMP-3.
COBEDIT PURGE Command PURGE Command The PURGE command allows you to purge either a single module from your currently active library, or the entire library. If you choose to purge the entire library, it no longer exists after successful execution of the PURGE command. Syntax f PURGE text-name fALL g g Parameters text-name ALL is the name of a module to be purged from the currently active library. This is the module to be purged.
COBEDIT PURGE Command Example To illustrate the PURGE command, a le called MESSEDUP is used. This library contains only two modules. The rst is a module copied into it at the time MESSEDUP was created. This module has no text-name associated with it. Thus, it is accessed with the default text-name assigned by COBEDIT that is BOO-BOO.
COBEDIT SHOW Command SHOW Command The SHOW command is used to nd out the name of the currently active library, its key le, and the name of the module that was most recently accessed by COBEDIT. If no library is open, the message No library is open occurs. Syntax SHOW Example :RUN COBEDIT.PUB.SYS HP32233A.02.00 COPYLIB EDITOR - COBEDIT MON, MAR 26, 1991, 11:03 AM (C) HEWLETT-PACKARD CO. 1986 TYPE "HELP" FOR A LIST OF COMMANDS. >SHOW No library is open.
COBEDIT SHOW Command ************************************************ Library name: MYLIB.USERS.
H MPE XL System Dependencies This appendix gives system-speci c information about the HP COBOL II/XL programming language on the MPE XL operating system. It does not explain every feature of HP COBOL II/XL. For more information, refer to the main body of this manual. Introduction HP COBOL II/XL is Hewlett-Packard's implementation of the 1985 ANSI COBOL standard (X3.23-1985) and the 1974 ANSI COBOL standard (X3.
MPE XL System Dependencies The HP COBOL II/XL product consists of a compiler, which translates HP COBOL II/XL programs into machine object les, and a run-time library. The object code that the compiler generates contains calls to routines in the run-time library. HP COBOL II/XL runs on the MPE XL operating system. You can use the debuggers that run on MPE XL to debug your HP COBOL II/XL programs. They are DEBUG (the MPE XL System Debugger), HP Symbolic Debugger/XL, and HP TOOLSET/XL.
Compiling, Linking, and Executing Programs Compiling, Linking, and Executing Programs To make your HP COBOL II source program a valid MPE XL program le, you must compile, link, and execute it. There are two ways to perform these tasks: With command les. With the RUN command and the Link Editor. This section describes compilation, linking, and execution and explains the di erent ways of performing them. Overview The HP COBOL II compiler compiles the source program, which is created in a text le.
Compiling, Linking, and Executing Programs Command Files Table H-2 lists the MPE XL system-wide command les that you can use to compile, link, and execute HP COBOL II programs. You can enter these commands as part of the input stream in job or batch mode or from your terminal in a session. The rst three command les invoke the HP COBOL II compiler through the entry point that conforms to the 1985 ANSI COBOL standard.
Compiling, Linking, and Executing Programs Syntax COB85XL [text le][,[object le][,[list le][,[master le] [,new le]]]] [;INFO="info"][;WKSP=workspacename] [;XDB=xdb le] COB85XLK [text le][,[prog le][,[list le][,[master le] [,new le]]]] [;INFO="info"][;WKSP=workspacename] [;XDB=xdb le] COB85XLG [text le][,[list le][,[master le][,new le]]] [;INFO="info"][;WKSP=workspacename] [;XDB=xdb le] COB74XL [text le][,[object le][,[list le][,[master le] [,new le]]]] [;INFO="info"][;WKSP=workspacename] [;XDB=xdb le] COB74
Compiling, Linking, and Executing Programs info A string whose value is a command list of the form: "$compiler command[$compiler command]..." where no compiler command contains the character $. If the number of commands is long enough, you can use an ampersand (&) to continue the info string. The length limit for a compiler command is the same as the length limit for a source program line. In the listing le, the string \INFO=" appears where the sequence numbers normally appear.
Compiling, Linking, and Executing Programs Compiling Your Program With the RUN Command The MPE XL RUN command runs the HP COBOL II compiler, which compiles your source program. You can invoke the HP COBOL II compiler and compile your HP COBOL II program with either the RUN command or a command le. Syntax RUN COBOL ANSI85 .PUB.
Compiling, Linking, and Executing Programs info A string whose value is a command list of the form: "$compiler command[$compiler command]..." where no compiler command contains the character $ (even if it is within quotes). Refer to Appendix B for more information on compiler commands. If the number of commands is long enough, you can use an ampersand (&) to continue the info string. The length limit for a compiler command is the same as the length limit for a source program line.
Compiling, Linking, and Executing Programs Table H-3. PARM Values and Their Meanings (continued) p PARM Value 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 means \Do not use the default for this le:" new le p p p p p p p p p p p p p p p p master le object le list le text le p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p p The following is an example of a command le. It can be used as a template to create a command le that merges master and text les to create new les.
Compiling, Linking, and Executing Programs Linking Your Program To link your main program and a subprogram and create a single program le, use the HP Link Editor/XL LINK command. If the main program object code le is mainobj , the subprogram object code le is subobj , and the program le to be created is prog le , then the command is: LINK FROM = mainobj,subobj; TO = prog le This is one of the simplest cases. For more examples, refer to the HP COBOL II/XL Programmer's Guide .
Compiling, Linking, and Executing Programs After executing the following command: RUN MYPROG;PARM=%112000 The switch word looks like the following: Hexadecimal constants can also be used for the PARM value. Setting the Object-Time Debug Module Switch Bit 15 of the PARM parameter is the object-time debug module switch. If bit 15 of the PARM parameter in the RUN command has a value of 1, the object-time DEBUG mode is active. Otherwise, it is inactive.
Control Options Control Options Control options are used with the $CONTROL command. Control options fall into these three categories: MPE XL speci c control options that depend on the MPE XL operating system. These options work for HP COBOL II/XL but not other COBOL versions. Control options that work for both HP COBOL II/XL and other COBOL versions, but they work di erently. Obsolete control options, which HP COBOL II/XL no longer supports.
Control Options CMCALL The CMCALL option is provided as a tool for migration from MPE V to MPE XL based systems. This option a ects all external names except those generated by a CALL identi er statement. An external name is generated according to the following rules: Hyphens within names are removed. Uppercase characters are converted to lowercase. Names are truncated to 15 characters.
Control Options ON OFF LITERALS COMPARE Enables NLS support for both string literals and comparisons. This provides the same service that both the LITERALS value and the COMPARE value provide. Disables NLS support. This is the default value. Enables handling of international characters in string literals during compilation of an HP COBOL II program. LITERALS and COMPARE are mutually exclusive. Use NLS ON to enable LITERALS and COMPARE at the same time.
Control Options For more values and more information on NLDATALANG, refer to the Native Language Support Reference Manual . Using $CONTROL NLS decreases both compile-time and run-time performance in some cases and always reduces the backwards compatibility of your programs. Only single-byte CURRENCY-SIGNs and single-byte DECIMAL-POINTs are supported. Their values are overridden by NLS, not by the program-collating sequence.
Control Options Example 2. This example compares two NLS strings. Substitute # signs with NLS characters to make this example work. 001000$CONTROL NLS=ON 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. EXAMPLE1. 001700 DATA DIVISION. 002300 WORKING-STORAGE SECTION. 002400 01 NLS-FIELD PIC X(08) VALUE "G#K#". 002410 01 NLS-FIELD-1 PIC X(06) VALUE "G#K#". 002500 01 NLS-FIELD-2 PIC X(6) VALUE "G#K#". 002600 PROCEDURE DIVISION. 002700 NLSONEXAMPLE.
Control Options OPTFEATURES The OPTFEATURES option for the $CONTROL command allows you to make your programs run faster by generating more e cient code. Syntax. $CONTROL OPTFEATURES = [CALLALIGNED[16]] [LINKALIGNED[16]] If both CALLALIGNED and LINKALIGNED are speci ed, you must separate them with a space. By default, the compiler expects parameters passed to subprograms by reference to be byte-aligned.
Control Options OPTIMIZE The OPTIMIZE option speci es the level of object code optimization you want. If your program does not contain the OPTIMIZE option, the object code is not optimized. This is equivalent to specifying optimization level zero. OPTIMIZE must appear before the IDENTIFICATION DIVISION. Syntax. =0 $CONTROL OPTIMIZE =1 The following table summarizes the levels of optimization you can request. Table H-5. $CONTROL OPTIMIZE Parameters If you specify: Nothing You get: No optimization.
Control Options RLFILE and RLINIT When you compile a program on an MPE XL system, the compiler produces a relocatable object le ( le code NMOBJ) for the program. You can then use the HP Link Editor/XL to place the relocatable object le in a relocatable library ( le code NMRL). Alternatively, you can direct the compiler to place the relocatable program in a relocatable library directly. The RLFILE option of the $CONTROL command lets you do this.
Control Options VALIDATE and NOVALIDATE The VALIDATE and NOVALIDATE options allow you to specify whether or not you want the program to check the validity of the data. VALIDATE causes the compiler to generate code for each arithmetic operation or MOVE and to check for valid decimal digits and signs in the data associated with all identi ers having USAGE IS DISPLAY, PACKED-DECIMAL, or COMPUTATIONAL-3 clauses.
Control Options BOUNDS In addition to its normal functionality (described in Appendix B), the control options BOUNDS and OPTFEATURES=LINKALIGNED (or LINKALIGNED16) provide run-time checking of the LINKAGE SECTION. When you specify both the BOUNDS and LINKALIGNED options in a $CONTROL command, the compiler generates code that checks whether or not all the parameters passed to a subprogram are aligned on 32-bit or 16-bit boundaries.
Language Dependencies Data Alignment and Limits on MPE XL All addresses on MPE XL systems are byte addresses that are aligned in some way. Addresses divisible by 2 are half-word aligned. Addresses divisible by 4 are word aligned. A word aligned address is also half-word aligned and byte aligned. Refer to the HP COBOL II/XL Programmer's Guide for more information on addressing.
Language Dependencies HP COBOL II/XL Language Dependencies HP COBOL II/XL language dependencies are features of HP COBOL II/XL that depend on the MPE XL operating system. Often they are tailored to the architecture of the computer on which MPE XL runs. This section groups these language dependencies by what they a ect| the program division or interprogram communication.
Language Dependencies DATA DIVISION The following are dependencies in the DATA DIVISION: Word size|The word size on MPE XL systems is 32 bits or 4 bytes. Index names|Index names are 4 bytes long. Subscripts|The performance when referencing table elements using subscripts de ned as PIC S9(9) COMP SYNC is the same as referencing table elements using index names. Synchronization|The default synchronization is on 32-bit boundaries. LINAGE-COUNTER|The LINAGE-COUNTER is a 9-digit unsigned integer.
Language Dependencies Error Handling|Decimal data is not checked for validity unless you specify the control option VALIDATE. When you specify this option, a program aborts on the following conditions: Illegal ASCII digit. Illegal decimal digit. Illegal signs. Your program may abort with the following conditions: Division by zero. An over ow condition occurs without an ON SIZE ERROR phrase. Using a common point to exit from multiple PERFORM statements may also cause errors in HP COBOL II.
Language Dependencies OPEN Statement|INDEX organization les are implemented as MPE KSAM les. Compatibility Mode KSAM les use two les, a data le and a key le. The key le name for an INDEX le is the data le name plus the letter \K". If the le name is already eight characters long, the last character is replaced by \K". Native Mode INDEX les use one Native Mode KSAM le. When only ANSI85 is speci ed, les with U or V type records will not be checked for record length mismatch.
Interprogram Communication Interprogram Communication This section explains these aspects of interprogram communication: External names. Subprogram types. Intrinsics. Parameter alignment. External Names An external name is one that is visible to other programs.
Interprogram Communication Calling Intrinsics You must include the INTRINSIC phrase to call all MPE operating system intrinsics. Using the INTRINSIC phrase is also recommended for calling subsystem intrinsics to provide for more thorough error checking and greater portability of programs. Parameter passing to intrinsics is described in detail in the HP COBOL II/XL Programmer's Guide . The system intrinsic le is SYSINTR.PUB.SYS. .LOC.
Run-Time Trap Handling Run-Time Trap Handling The HP COBOL II compiler handles run-time traps for a variety of run-time error conditions. You can control your program's response to these conditions. This section: Describes the traps that the HP COBOL II compiler supports. Explains how to specify what actions should be taken when run-time errors occur. Explains when and how to enable the trap mechanism.
Run-Time Trap Handling Handling Run-Time Errors with COBRUNTIME The default action when one of these errors occurs is to print an error message and abort the program. To specify an action other than the default, you need to do both of the following: Compile your program with $CONTROL VALIDATE and $CONTROL BOUNDS. Set a global variable, called COBRUNTIME, to a set of characters before running the program. A global variable is similar to a job control word.
Run-Time Trap Handling Setting COBRUNTIME You set the run-time environment using the MPE XL SETVAR command with the variable COBRUNTIME. For example: SETVAR COBRUNTIME "string" In the above example \string" is a string of nine either uppercase or lowercase characters representing the run-time options A, C, D, I, M, N, or blank, as shown in Table H-6. A blank in the string is interpreted as \A", or \Abort," the default.
Run-Time Trap Handling M can only appear in the rst character position, and N can only appear in character positions 1, 7, and 8. This is because the action taken by M and N only applies to an illegal ASCII or decimal digit errors. If either letter appears in any other character position, it is treated as a blank. If character positions 7 or 8 are blank or are not equal to N or I, the action speci ed in character position 1 is used.
Run-Time Trap Handling The COBOL Trap Mechanism and Other Languages In order to work, the COBOL trap mechanism must be armed for the ON SIZE ERROR phrase, $CONTROL VALIDATE command, and $CONTROL BOUNDS command. (The traps must actually be enabled and armed. However, in this section, the term armed implies enabled and armed. For more details, see the Trap Handling Programmer's Guide .) Besides the HP COBOL II run-time library, the COBOL trap mechanism uses the DEBUG macro le COBMAC.PUB.SYS.
Run-Time Trap Handling The following are recommended programming steps for three possible trap-handling scenarios: HP COBOL II programs and subprograms calling an HP COBOL II subprogram: Because the COBOL trap mechanism is armed in the HP COBOL II main program, there is no need to call COBOLTRAP in the subprogram. HP COBOL II programs and subprograms calling a subprogram written in another language: Step 1: Arm or disarm the trap mechanism for the other language.
Run-Time Trap Handling Example 1 This example shows how an HP COBOL II/XL program calling a Pascal procedure can arm the software traps for Pascal and then rearm the traps for HP COBOL II/XL. This example sets the trap mechanism to the default for languages such as Pascal, FORTRAN, and HP C. 001000 IDENTIFICATION DIVISION. 001100 PROGRAM-ID. COBOLPROF. 001300 DATA DIVISION. 001400 WORKING-STORAGE SECTION. 001500 77 PARM1 PIC S99V99 COMP. 001600 77 PARM2 PIC X(18). 001700 PROCEDURE DIVISION. 001710 P1.
Run-Time Trap Handling Example 2 This example shows how an HP COBOL II/XL program calling a FORTRAN procedure can arm the software traps for FORTRAN and then rearm the traps for HP COBOL II/XL. This example saves and restores the state of the trap mechanism before and after the call to the non-COBOL subprogram. This method must be used if the called subprogram changes the default trap mechanism.
Run-Time Trap Handling Example 3 This example shows how a Pascal program calling an HP COBOL II/XL subprogram can arm the software traps for HP COBOL II/XL and then rearm the traps for Pascal.
Run-Time Trap Handling 001000$CONTROL SUBPROGRAM,OPTFEATURES=LINKALIGNED 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. COBOLSUBPROG. 001300 DATA DIVISION. 001400 WORKING-STORAGE SECTION. 001500 01 J PIC ----,---,---. 001600 LINKAGE SECTION. 001700 01 I PIC S9(9) BINARY. 001800 PROCEDURE DIVISION USING I. 001900 P1. 002000 MOVE I TO J. 002100 DISPLAY "INPUT PARM WAS" J.
Example HP COBOL II/XL Program Example HP COBOL II/XL Program This section contains a complete COBOL program listing from the HP COBOL II/XL compiler. PAGE 0001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 COBOL II/XL HP31500A.04.03 [85] FRI, JUN 7, 1991, PM Copyright Hewlett-Packard CO.
Example HP COBOL II/XL Program PAGE 0002/COBTEXT EXAMPLE 00040 040000/ ****** D A T A D I V I S I O N ****** 00041 041000 DATA DIVISION. 00042 042000 FILE SECTION. 00043 043000* 00044 044000 FD OLD-INV-MAST. 00045 045000* 00046 046000 01 OLD-INV-MAST-REC. 00047 047000 03 OM-PART-NBR PIC X(05). 00048 048000 03 FILLER PIC X(35). 00049 049000* 00050 050000 FD NEW-INV-MAST. 00051 051000* 00052 052000 01 NEW-INV-MAST-REC PIC X(40). 00053 053000* 00054 054000 FD TRAN-FILE. 00055 055000* 00056 056000 01 TRAN-REC.
Example HP COBOL II/XL Program PAGE 0003/COBTEXT EXAMPLE 00075 075000/ ****** W O R K I N G S T O R A G E ****** 00076 076000 WORKING-STORAGE SECTION. 00077 077000* 00078 078000* 00079 079000 01 WS-PRINT-CONTROL. 00080 080000 03 WS-LINE-CTR PIC S9(03) BINARY VALUE 999. 00081 081000 03 WS-PAGE-CTR PIC S9(03) BINARY VALUE 0. 00082 082000 03 WS-SPACING PIC S9(01) BINARY VALUE 1. 00083 083000 03 WS-LINE-LMT PIC S9(03) BINARY VALUE 45. 00084 084000* 00085 085000 01 WS-ACCUMULATORS.
Example HP COBOL II/XL Program PAGE 0004/COBTEXT EXAMPLE 00132 132000 00133 133000 00134 134000 00135 135000 00136 136000 00137 137000 00138 138000 00139 139000 00140 140000 00141 141000 00142 142000 00143 143000 00144 144000 00145 145000* 00146 146000 01 00147 147000 00148 148000 00149 149000 00150 150000 00151 151000 00152 152000* 00153 153000 01 00154 154000 00155 155000 00156 156000 00157 157000* 00158 158000 01 00159 159000 00160 160000 00161 161000 00162 162000* 00163 163000 01 00164 164000 00165 1650
Example HP COBOL II/XL Program PAGE 0005/COBTEXT EXAMPLE 00189 189000 00190 190000 00191 191000 00192 192000 00193 193000 00194 194000 00195 195000* 03 03 03 03 03 03 PIC PIC PIC WS-UP-PART-QUANTITY PIC PIC WS-UP-UPDT-MESSAGE PIC WS-UP-PART-PRICE X(03) VALUE SPACES. ZZ,ZZZ.99-. X(05) VALUE SPACES. ZZZ9. X(04) VALUE SPACES. X(10). PAGE 0006/COBTEXT EXAMPLE 00196 196000/ ****** P R O C E D U R E D I V I S I O N ***** 00197 197000 PROCEDURE DIVISION. 00198 198000 100-MAIN-PROGRAM.
Example HP COBOL II/XL Program PAGE 0007/COBTEXT EXAMPLE 00239 239000/ 00240 240000 210-MASTER-COMPARED-HIGH. 00241 241000* 00242 242000 IF TR-ADD-CODE 00243 243000 PERFORM 220-ADD-TO-MASTER 00244 244000 ELSE 00245 245000 PERFORM 230-TRAN-IN-ERROR. 00246 246000* 00247 247000 220-ADD-TO-MASTER.
Example HP COBOL II/XL Program PAGE 0008/COBTEXT EXAMPLE 00296 296000 PERFORM 300-GET-TRANSACTION 00297 297000 ADD 1 TO WS-DELETES-CTR. 00298 298000* 00299 299000 270-CHANGE-MASTER.
Example HP COBOL II/XL Program PAGE 0009/COBTEXT EXAMPLE 00353 353000* 00354 354000 400-WRITE-PRINT-LINE. 00355 355000 WRITE PRINT-REC BEFORE ADVANCING WS-SPACING 00356 356000 MOVE SPACES TO PRINT-REC 00357 357000 ADD WS-SPACING TO WS-LINE-CTR. 00358 358000* 00359 359000 410-PRINT-HEADING.
Example HP COBOL II/XL Program PAGE 0010/COBTEXT EXAMPLE LINE# LVL SOURCE NAME GORY R O J BZ SYMBOL TABLE MAP BASE OFFSET SIZE USAGE CATE FILE SECTION 00030 00046 00047 00048 00032 00052 00034 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00036 00071 00038 00074 FD 01 03 03 FD 01 FD 01 03 88 88 88 03 03 03 05 03 05 03 05 FD 01 FD 01 OLD-INV-MAST OLD-INV-MAST-REC OM-PART-NBR FILLER NEW-INV-MAST NEW-INV-MAST-REC TRAN-FILE TRAN-REC TR-UPDATE-CODE TR-ADD-CODE TR-CHANGE-COD
Example HP COBOL II/XL Program PAGE 0011/COBTEXT EXAMPLE LINE# LVL SOURCE NAME GORY R O J BZ 00108 00110 00111 00112 00114 00115 00117 00119 00121 00123 00125 00127 00130 00131 00133 00135 00137 00139 00141 00143 00146 00147 00149 00151 00153 00154 00156 00158 00159 00161 00163 00164 00166 00168 00169 00171 00173 00174 00176 00178 00179 00181 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 03 03 03 03 01 03 03 03 03 03 03 03 01 03 03 03 03 03 03 03 01 03 03 03 01 03 03 01 03 03 01 0
Example HP COBOL II/XL Program PAGE 0012/COBTEXT EXAMPLE LINE# LVL SOURCE NAME GORY R O J BZ STORAGE LAYOUT SYMBOL TABLE MAP BASE OFFSET ERROR-FILE ERROR-REC HDG-1 HDG-2 HDG-3 HDG1-DATE HDG1-PAGE-NBR HDG1-REPORT-NAME NEW-INV-MAST NEW-INV-MAST-REC OLD-INV-MAST OLD-INV-MAST-REC OM-PART-NBR PRINT-FILE PRINT-REC 00391 00393 TALLY TOT1-HDG-DATE TOT2-CHANGES TOT3-ADDITIONS TOT4-DELETIONS TOT5-UPDATES TOT6-ERRORS TOT7-TRANS-READ TOTALS-HDG-1 TOTALS-HDG-2 TOTALS-HDG-3 TOTALS-HDG-4 TOTALS-HDG-5 TOTALS-HDG-6 TOTALS
Example HP COBOL II/XL Program WS-ACCUMULATORS WS-ADDITION-MSG WS-ADDITIONS-CTR WS-CHANGE-MSG WS-CHANGES-CTR WS-DELETE-MSG WS-DELETES-CTR WS-ERRORS WS-LINE-CTR WS-LINE-LMT PAGE 0014/COBTEXT WS-MASTER-REC WS-MR-DESCRIPTION WS-MR-PART-COST WS-MR-PART-NBR 00085 00095 00087 00094 00086 00096 00088 00090 00080 00083 EXAMPLE 00288 WS-MR-PART-PRICE WS-MR-PART-QUANTITY WS-PAGE-CTR WS-PRINT-CONTROL WS-SPACING 00370 WS-TOTAL-CTR WS-TRANS-READ WS-UP-DESCRIPTION WS-UP-PART-COST WS-UP-PART-NBR WS-UP-PART-PRICE WS-UP-
Example HP COBOL II/XL Program PAGE 0015/COBTEXT EXAMPLE 100-MAIN-PROGRAM 210-MASTER-COMPARED-HIGH 220-ADD-TO-MASTER 230-TRAN-IN-ERROR 240-MASTER-COMPARED-LOW 250-MASTER-AND-TRAN-EQUAL 260-DELETE-MASTER 270-CHANGE-MASTER 300-GET-TRANSACTION 310-GET-OLD-MASTER 320-PRINT-UPDATE 330-WRITE-NEW-MASTER 400-WRITE-PRINT-LINE 00390 00392 410-PRINT-HEADING 420-PRINT-TOTALS EXAMPLE CROSS REFERENCE LISTING PROCEDURES and PROGRAMS 00198 00240 00219 00247 00243 00266 00245 00284 00272 00221 00277 00225 00287 00280 002
Example HP COBOL II/XL Program PAGE 0016/COBTEXT EXAMPLE STMT OFFSET STMT 198 203 205 207 208 209 210 214 215 217 218 219 220 221 222 224 225 227 231 236 237 240 242 243 244 245 247 248 249 250 251 252 253 254 255 256 257 258 58 58 110 124 154 224 238 250 274 2A0 2A4 2D4 2E8 31C 330 360 360 374 37C 390 3FC 414 414 424 438 440 468 468 488 4E4 56C 5D8 620 638 658 6B4 6FC 73C 259 260 261 262 263 264 266 267 268 269 270 272 273 274 275 277 278 279 280 281 282 283 284 285 287 288 289 290 291 292 293 294 2
Index A ACCEPT statement, 9-1, 9-3, 9-9, H-24 free- eld format, 9-3 FREE phrase, 9-3 INPUT ERROR phrase, 9-3 programming considerations, 9-6 without FREE phrase, 9-5 ACCESS MODE clause, 6-37 ACOS function, 10-7 ACTUAL KEY clause, 6-39 address alignment trap, H-29 ADD statement, 9-10 ADVANCING PAGE phrase, 7-20 algebraic signs editing, 4-6 operational, 4-6 alignment, H-17, H-22, H-28 alignment of data items, 7-61 ALL literal, 3-6 allocation, H-13 ALL subscript, 4-21, 10-5 ALPHABET clause, 6-14 ALPHABETIC cla
scope, 11-16 USING phrase, 11-21 CANCEL statement, 11-11, 11-27 carriage control, 6-35, 9-145 carriage control codes, 9-146 carriage control tape, 6-11 categories of data items, 4-5, 7-44 categories of statements, 8-11 CCTL (carriage control), 6-35, 9-145 channels, 6-11 character set, 3-20 character string, 3-2 CHAR function, 10-11 CHECKSYNTAX control option, B-26 class user-de ned, 6-21 CLASS clause, 6-21 class condition, 6-21, 8-20 ALPHABETIC, 8-20 ALPHABETIC-LOWER, 8-20 ALPHABETIC-UPPER, 8-20 NUMERIC, 8-
comparison of nonnumeric operands, 8-25 comparison of numeric operands, 8-25 comparisons using index data items, 8-25 compiler directing statements, 8-9 compile time, 13-2 compile-time error messages, A-2 compile-time processes, B-1 compiling your program, H-3 command les, H-4 RUN command, H-7 complex condition, 8-30 composite of operands, 8-45 COMP, USAGE IS, 7-61, 7-64, 7-66 COMPUTATIONAL-3, USAGE IS, 7-61, 7-64, 7-66 COMPUTATIONAL, USAGE IS, 7-61, 7-64, 7-66 computer name, 3-11 COMPUTE statement, 9-18 co
control optionsnBIGSTACK, H-21 control optionsnCALLALIGNED, H-28 control optionsnCALLALIGNED16, H-28 control optionsnLINKALIGNED, H-28 control optionsnLINKALIGNED16, H-28 control optionsnOPTFEATURES, H-28 control optionsnSORTSPACE, H-21 control options with added functionality ANSISUB, H-20 BOUNDS, H-21, H-32 CODE, H-21 USLINIT, H-21 $CONTROL POST85, 10-3 COPY, COBEDIT command, G-7 COPYLIB, 14-2 COPY libraries, G-2 COPY statement, 14-2 CORRESPONDING phrase, 8-43 COS function, 10-12 CROSSREF control option,
elementary data item, 4-2 size of, 7-50 enabling traps, H-33 END-OF-PAGE clause, 7-17 END-OF-PAGE condition, 7-20 END PROGRAM header, 11-12 ENTER statement, 9-32 entry, 2-9 ENTRY statement, 11-28 ENVIRONMENT DIVISION, 2-4, 6-1, H-23 general format, 6-1 error handling, H-25, H-29 error messages, A-1 compile-time, A-2 disastrous, A-35 le containing, A-1 informational, A-49 nonstandard warning messages, A-39 questionable, A-9 run-time, A-3, A-41 serious, A-31 warning messages, A-4 ERRORS control option, B-27 E
H handling run-time errors, H-29 hardware clock, 3-4, 10-16 HELP, COBEDIT command, G-14 hierarchy of arithmetic operations, 8-15 HIGH-VALUE gurative constant, 3-6, 6-17 HIGH-VALUES gurative constant, 3-6 HP COBOL II/XL.
VOL, 7-29 label records, 9-70 LABEL RECORDS clause, 7-16 LABELS, of VALUE OF clause, 7-30 language dependenciesnHP COBOL II/XL, H-23 language name, 3-11 LENGTH function, 10-29 .LEN.
NLS option, H-13 NOCODE control option, B-26 NOCROSSREF control option, B-27 NOLIST control option, B-28 NOLIST, of COPY statement, 14-2 NOMAP control option, B-29 NOMIXED control option, B-29 non-COBOL programs, calling, 11-23, 11-26 noncontiguous data items, 7-31 non-dynamic subprogram, 11-11, 11-27 nonnumeric literal, 3-15 nonstandard warning messages, A-39 no-operation statement, 9-21 NOSEQ parameter, of $EDIT command, B-20 no size error trap, H-29 NOSOURCE control option, B-29 NO SPACE CONTROL function
permissible I-O statements, 9-72 phrase, 2-9 phrasesnUSING, H-28 physical record, 4-2 PICTURE character strings, 3-17 PICTURE clause, 7-34, 7-44 precedence rules, 7-55 POSITIVE sign condition, 8-19 precision of numeric functions, 10-5 $PREPROCESSOR command, B-12 preprocessor programming language, B-2 PRESSENT-VALUE function, 10-48 print les, 9-145 procedure, 8-6 PROCEDURE DIVISION, 2-4, 8-1, H-24 general format, 8-3 header, 8-2 sentences, 2-9 statements, 9-1 proceduresnCOBOLTRAP, H-33 processing environment
implicit, 8-13 SD level indicator, 7-7, 7-9 SEARCH statement, 9-106 VARYING phrase, 9-108 secondary entry point, 11-28 section, 2-5, 8-6, 8-7 section header, 2-5, 8-7 section name quali ers, 4-10 SEEK statement, 9-113 segmentation, 8-7, 9-13, H-24 segmentation considerations, 12-6, 12-18 SEGMENT-LIMIT clause, 6-6 SELECT clause, 6-34 SELECT statement, H-23 sentence, 2-9 separator, 3-19 SEQNUM parameter, of $EDIT command, B-19 SEQ, of VALUE OF clause, 7-30 sequence eld checking, B-18 sequence number, 3-22 seq
SYNCHRONIZED clause, 7-61 SYSIN, 6-13, 9-2 SYSIN function, 6-11 SYSOUT, 6-13, 9-25 SYSOUT function, 6-11 system name, 3-11 T tables, 4-14, 7-40 referencing, 4-15, 4-18 TALLYING phrase, 9-39 TALLY special register word, 3-4 TAN function, 10-58 text name, 4-13 TIME, 9-3, 9-9 TIME-OF-DAY special register word, 3-5, 9-25 time zones, 10-14 $TITLE command, B-23 TOP function, 6-11 trap handling, H-29 traps, H-25, H-29 trapsnenabling, H-33 truncation, 4-7 TSAM le, H-5 TurboIMAGE/XL, H-2 types of subprograms, 11-11