HP COBOL II/XL Programmer's Guide 900 Series HP 3000 Computer Systems ABCDE HP Part No. 31500-90002 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 version 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 pages change only when 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 HP COBOL II/XL Programmer's Guide for the Hewlett-Packard HP COBOL II/XL programming language is intended for experienced COBOL programmers who are familiar with the MPE XL le system and HP 3000 subsystems. It discusses selected HP COBOL II/XL topics in detail and explains statement interaction where necessary. It does not explain every feature of HP COBOL II/XL, as the HP COBOL II/XL Reference Manual does. The following brie y describes each chapter.
Additional Documentation Refer to the following manuals for more information about HP COBOL II/XL: HP COBOL II/XL Reference Manual (31500-90001) HP COBOL II/XL Quick Reference Guide (31500-90003) Refer to the following manual for information about migrating HP COBOL II/V programs to HP COBOL II/XL: HP COBOL II/XL Migration Guide (31500-90004) This manual references the following manuals: HP FORTRAN 77 Programmer's Guide (5957-4686) KSAM/3000 Reference Manual (30000-90079) Using KSAM/XL (32650-90168) Using
Acknowledgment At the request of the American National Standards Institute (ANSI), the following acknowledgment 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. 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. Uppercase words that are not underlined are optional, and may be included or omitted.
[ ] Within syntax statements, brackets enclose optional elements. In the following example, brackets around ,TEMP indicate that the parameter and its delimiter are not required: lename[,TEMP] When several elements within brackets are stacked, you can select any one of the elements or none.
; , . ^ NNNNNNNNNNNNNNNNNNNNNNN Shading LG200026 198 x The semicolon is used only to improve readability and is always optional. The comma is used only to improve readability, and is always optional. The period is a terminator or delimiter that is always required where shown; it must always be entered at the end of every division name, section name, paragraph name, and sentence. The caret is occasionally used in examples to represent an implied decimal point in computer memory.
Contents 1. Introduction Debugging COBOL Programs . . . . . . . . . . . . . . . . . . . . . Subsystems that Interface with HP COBOL II/XL . . . . . . . . . . . . 2. Features of the 1985 ANSI Standard Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . ANSI85 Features . . . . . . . . . . . . . . . . . . . . . . . . ANSI85 Features in the IDENTIFICATION DIVISION: . . . . . . The INITIAL Clause . . . . . . . . . . . . . . . . . . . . . The COMMON Clause . . . . . . . . . . . . . . . . . . . .
3. Programming Practices Introduction . . . . . . . . . . . . . . . . . . . . . . . . Structured Programming . . . . . . . . . . . . . . . . . . . END PROGRAM Header . . . . . . . . . . . . . . . . . IDENTIFICATION DIVISION: COMMON Clause . . . . . . DATA DIVISION: GLOBAL Data Items and Files . . . . . . PROCEDURE DIVISION . . . . . . . . . . . . . . . . . CONTINUE Statement . . . . . . . . . . . . . . . . . EVALUATE Statement . . . . . . . . . . . . . . . . . Explicit Scope Terminators . . . . . . . . . .
Execution-Time Binding . . . . . . . . . . Switch Stubs . . . . . . . . . . . . . . . . Calling COBOL Subprograms . . . . . . . . Types of Subprograms . . . . . . . . . . . Calling Non-COBOL Subprograms . . . . . . Calling Subprograms Written in C . . . . . Calling Subprograms Written in FORTRAN 77 Calling Subprograms Written in Pascal . . . Calling Subprograms Written in SPL . . . . Writing Switch Stubs . . . . . . . . . . EXTERNAL Data Items and Files . . . . . . EXTERNAL Items and FORTRAN . . . . .
Physical Files . . . . . . . . . ASSIGN Clause . . . . . . . . Temporary Physical Files . . . BUILD Command . . . . . . FILE Command . . . . . . . Dynamic Files (USING phrase) . Multiple Files on a Labelled Tape Overwriting Files . . . . . . . . Updating Files . . . . . . . . . Appending to Files . . . . . . . File Status Codes . . . . . . . . Sequence of Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Verb Map . . . . . . . . . . . . . . . . . . . . Link Map . . . . . . . . . . . . . . . . . . . . Maps for Chunked Program . . . . . . . . . . . . Example Maps for Nested and Concatenated Programs Subprogram Parameters . . . . . . . . . . . . . . Register Meanings . . . . . . . . . . . . . . . . Calculating Addresses of Data Items . . . . . . . . Calculating Code Addresses . . . . . . . . . . . . Debugging Trap Errors . . . . . . . . . . . . . . Redirecting Output from Traps . . . . . . . . . .
Figures 1-1. Relationships between HP COBOL II/XL and the ANSI Standards COBOL'74 and COBOL'85 . . . . . . . . . . . . . . . . 4-1. How a Switch Stub Works . . . . . . . . . . . . . . . . . . 4-2. The FILE Screen . . . . . . . . . . . . . . . . . . . . . . 4-3. The MAIN Screen . . . . . . . . . . . . . . . . . . . . . 4-4. The PROCINFO Screen . . . . . . . . . . . . . . . . . . . 4-5. The PARMINFO Screen for Parameter DINT . . . . . . . . . 4-6. The PARMINFO Screen for Parameter BASE . . . . . . . . . 4-7.
Tables 1-1. 1-2. 3-1. 4-1. 4-2. 4-3. 4-4. 4-5. 4-6. 4-7. 4-8. 5-1. 5-2. 5-3. 5-4. 5-5. 5-6. 5-7. 5-8. 5-9. 6-1. 6-2. 6-3. 6-4. 6-5. 6-6. 7-1. 7-2. 7-3. 7-4. 7-5. 7-6. 7-7. 7-8. 7-9. Components of HP COBOL II/XL . . . . . . . . . . . . . . . Subsystems that Interface with HP COBOL II/XL . . . . . . . . The Scope Terminators . . . . . . . . . . . . . . . . . . . . Argument Descriptor Fields . . . . . . . . . . . . . . . . . . Types of Subprograms and How to Specify Them . . . . . . . . .
1 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.23-1974), the COBOL programming languages that meet the 1985 and 1974 standards set by the American National Standards Institute (ANSI). The HP COBOL II/XL compiler compiles COBOL'74 programs as well as COBOL'85 programs. When you invoke it through its ANSI74 entry point (using the COB74XL command le), it accepts only syntax that conforms to COBOL'74.
Table 1-1 lists components of the HP COBOL II/XL product and describes their use. Table 1-1. Components of HP COBOL II/XL File Name Use COBOL.PUB.SYS The HP COBOL II/XL compiler. in XL.PUB.SYS The HP COBOL II/XL run-time library. COBCNTL.PUB.SYS Source le you can use to override the compiler defaults for the compiler options. The compiler automatically includes a le named COBCNTL.PUB.SYS in each source text le. COB85XL.PUB.SYS COB85XLK.PUB.SYS COB85XLG.PUB.SYS COB74XL.PUB.SYS COB74XLK.PUB.
Debugging COBOL Programs 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) and one of two symbolic debuggers: HP Symbolic Debugger/XL or HP TOOLSET/XL. Subsystems that Interface with HP COBOL II/XL Table 1-2 lists HP subsystems with which HP COBOL II/XL can interface. Table 1-2. Subsystems that Interface with HP COBOL II/XL Subsystem DEBUG Description MPE XL System Debugger.
2 Features of the 1985 ANSI Standard Introduction Throughout the rest of this manual, the term ANSI85 means \HP COBOL II/XL as invoked through its ANSI85 entry point," and the term ANSI74 means \HP COBOL II/XL as invoked through its ANSI74 entry point." ANSI85 features fall into these categories: Category Description of Category ANSI85 Features Features of ANSI COBOL 1985 that ANSI COBOL 1974 does not have. Post ANSI85 Features ANSI features implemented since ANSI COBOL 1985.
ANSI85 Features ANSI85 Features ANSI85 features are those that ANSI74 does not have. If you use them in your program, you must invoke the COBOL compiler through its ANSI85 entry point. The ANSI85 features are listed below, by division. Those marked with an asterisk (*) support structured programming, and are explained in Chapter 3. The others are explained in this chapter, by division.
ANSI85 Features ANSI85 Features in the IDENTIFICATION DIVISION: This section explains the INITIAL clause, one ANSI85 feature of the IDENTIFICATION DIVISION. The other ANSI85 feature of the IDENTIFICATION DIVISION, the COMMON clause, supports structured programming, and is explained in Chapter 3. The INITIAL Clause The INITIAL clause is in the PROGRAM-ID paragraph of the IDENTIFICATION DIVISION. It speci es that the program is in an initial state whenever it is called, not only when it is canceled.
ANSI85 Features ANSI85 Features in the ENVIRONMENT DIVISION The ENVIRONMENT DIVISION has two ANSI85 features: CLASS clause. SYMBOLIC CHARACTERS clause. Both are in the SPECIAL-NAMES paragraph. Note The SPECIAL-NAMES paragraph (in the ENVIRONMENT DIVISION) cannot appear in nested programs. All items in the SPECIAL-NAMES paragraph are implicitly global. CLASS Clause The CLASS clause is in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION.
ANSI85 Features SYMBOLIC CHARACTERS Clause The SYMBOLIC CHARACTERS clause is in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. It equates names with ASCII character numbers, creating gurative constants. You can use it to name and refer to characters whose ASCII values are in the range 1..256. It is especially useful for referencing unprintable characters. Example The following shows the SYMBOLIC CHARACTERS clause: SYMBOLIC CHARACTERS BELL IS 8, CARRIAGE-RETURN IS 14.
ANSI85 Features ANSI85 Features in the DATA DIVISION This section explains the following ANSI85 features of the DATA DIVISION: EXTERNAL data items and les. The keyword FILLER is now optional. The USAGE data item formats BINARY and PACKED-DECIMAL. The other ANSI85 feature of the DATA DIVISION, the GLOBAL clause, supports structured programming, and is explained in Chapter 3. EXTERNAL Data Items and Files EXTERNAL data items and les can be shared by two or more programs.
ANSI85 Features USAGE IS BINARY and USAGE IS PACKED-DECIMAL BINARY and PACKED-DECIMAL usage are alternatives to the default, DISPLAY (one digit per byte). They are the standard for specifying radixes of two (binary) and ten (packed decimal). In the past, BINARY was expressed as the implementor-de ned COMP and PACKEDDECIMAL was de ned as the HP extension COMP-3. COMP and COMP-3 still work the same, but BINARY and PACKED-DECIMAL allow greater future portability between machines.
ANSI85 Features ANSI85 Features in the PROCEDURE DIVISION This section explains the following ANSI85 features of the PROCEDURE DIVISION: ADD statement enhancement. ALPHABETIC-LOWER. ALPHABETIC-UPPER. CALL BY CONTENT. De-editing. INITIALIZE statement. INSPECT CONVERTING statement. Reference modi cation. Relational operators. REPLACE statement. Setting switches. Setting condition names. Table initialization.
ANSI85 Features ALPHABETIC-LOWER and ALPHABETIC-UPPER Class Tests The class test ALPHABETIC-LOWER returns TRUE if every character of the speci ed data item is a lowercase letter or a space. The class test ALPHABETIC-UPPER returns the value TRUE if every character of a speci ed data item is an uppercase letter or a space. Example The following show two IF statements that use the ALPHABETIC-LOWER and ALPHABETIC-UPPER class conditions: IF STRING1 IS ALPHABETIC-LOWER PERFORM UPSHIFT.
ANSI85 Features De-Editing De-editing converts an edited numeric eld to its numeric value, allowing you to move it to either a numeric eld or a numeric edited eld. Example The following shows an example of a de-edited move: WORKING-STORAGE SECTION. 01 PRINT-A PIC $ZZZ,ZZZ.99CR. 01 HOLD-A PIC S9(6)V99. PROCEDURE DIVISION. PARA-001. MOVE -76543.21 TO PRINT-A. MOVE PRINT-A TO HOLD-A. A de-edited MOVE statement. The rst move statement above sends the following data to PRINT-A: -076543.
ANSI85 Features INITIALIZE Statement The INITIALIZE statement sets the values of speci ed types of elementary items in a record to speci ed values. Example The following example shows the INTIALIZE statement: WORKING-STORAGE SECTION. 01 RECORD-1. 05 EMP-NO PIC 9(6). 05 EMP-NAME PIC X(20). 05 EMP-PAY PIC 9(5)V99. 05 JOB-TITLE. PIC X(20). . . PROCEDURE DIVISION. MAIN-100. INITIALIZE RECORD-1 REPLACING NUMERIC BY ZERO REPLACING ALPHANUMERIC BY SPACES.
ANSI85 Features INSPECT CONVERTING Statement The INSPECT CONVERTING statement is similar to the INSPECT REPLACING statement, but it is more e cient. It allows you to specify several replacements in one string, rather than requiring an entire line for each replacement. Example 1 The following two INSPECT statements are equivalent: INSPECT WORD CONVERTING "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#".
ANSI85 Features Reference Modification Reference modi cation allows you to reference part of an item whose usage is DISPLAY. To access a substring within a data item, specify the position of the leftmost character and length of the substring, in characters. You can specify the position and length with any integer expression.
ANSI85 Features REPLACE Statement The REPLACE statement a ects source program text the way the COPY REPLACING statement a ects library text. The scope of the REPLACE statement is from its start to the start of another REPLACE statement or the end of the current concatenated program, whichever comes rst. The program in the following example replaces ANSI85 reserved words that were not reserved in the 1974 ANSI standard. Remember that the REPLACE statement is executed each time the program is compiled.
ANSI85 Features The actual code sent to the compiler becomes the following: 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. . . . Statement 2 overrides statement 1 and the second occurrence of \TEST" remains unchanged.
ANSI85 Features Setting Condition Names The SET statement in COBOL can set condition names to the value TRUE. Example The following declares a condition name, EOF-FLAG: 01 READ-FLAG 88 EOF-FLAG PIC 9. VALUE 1. The following SET statement uses the condition name EOF-FLAG: SET EOF-FLAG TO TRUE. The SET statement above is equivalent to the following MOVE statement: MOVE 1 TO READ-FLAG.
Obsolete Features Obsolete Features Obsolete features of ANSI85 are those that will be deleted from the next full revision of the COBOL standard. HP COBOL II/XL supports them, but its successor may not. If you use obsolete features in your program, you may not be able to compile it on compilers that implement the next ANSI COBOL. This table lists the obsolete features, justi es their being obsolete, and tells you how to make your program independent of them.
Obsolete Features Obsolete Elements of ANSI85 COBOL (continued) Obsolete Feature MEMORY-SIZE clause Justi cation for Obsolescence How to Make Your Program Independent of the Feature This feature is a carry-over from Leave it out. The operating system performs its function. the time when many systems required a speci cation of memory size allocation to load the run unit. Memory capacity for a family of main frame models often ranged from 8K to 64K.
Obsolete Features Obsolete Elements of ANSI85 COBOL (continued) Obsolete Feature Justi cation for Obsolescence How to Make Your Program Independent of the Feature DATA RECORDS clause Leave it out. The same The DATA RECORDS clause gives redundant information and information is in the record description associated with the could mislead someone who le. reads the program. LABEL RECORDS clause Specifying the presence of le labels is a function of the operating system, not the COBOL program.
Obsolete Features Obsolete Elements of ANSI85 COBOL (continued) Obsolete Feature Debug Module features: * Object time switch (PARM=1 in RUN command), USE FOR DEBUGGING statement, Special register DEBUG-ITEM Justi cation for Obsolescence How to Make Your Program Independent of the Feature Today's computing environment Do not use features that support the Debug Module. Refer to the usually provides interactive HP COBOL II/XL Reference debug facilities, which provide Manual .
Incompatible Features Incompatible Features Incompatible features are those that work di erently in ANSI85 and ANSI74. When you invoke the COBOL compiler through its ANSI85 entry point, it compiles these features according to ANSI COBOL 1985. When you invoke the compiler through its ANSI74 entry point, it compiles them according to ANSI COBOL 1974. There are four exceptions, features that both entry points compile according to ANSI COBOL 1985.
Incompatible Features CANCEL and STOP RUN Statements Both ANSI85 and ANSI74 entry points conform to ANSI COBOL 1985, which speci es that the CANCEL and STOP RUN statements close all open les. ANSI COBOL 1974 does not specify the status of les that are in open mode when the program is canceled. Justification for Changing CANCEL and STOP RUN In 1974 Standard COBOL, the status of les left in the open mode when the program was canceled was not de ned.
Incompatible Features Exponentiation Both ANSI85 and ANSI74 entry points conform to ANSI COBOL 1985, which speci es the following: If an expression whose value is zero is raised to a negative or zero power, a size error occurs. If the value of an exponentiation is not a real number, a size error occurs. ANSI COBOL 1974 did not address these special cases of exponentiation.
Incompatible Features OCCURS Clause When a receiving item contains an OCCURS clause with a DEPENDING ON phrase, and the receiving item also contains the object of the DEPENDING ON phrase, ANSI85 assumes that the object has its maximum length. In the same situation, ANSI74 assumes that the object has the length of its current value.
Incompatible Features Justification for Changing the OCCURS Clause 1974 Standard COBOL computed the value of the length based on the value of the item in the DEPENDING ON phrase prior to execution of the statement. Using 1974 Standard COBOL rules with a MOVE or READ INTO statement could have caused loss of data if the value of the DEPENDING ON data item was not set to indicate the length of the sending data before the MOVE or READ INTO statement executed.
Incompatible Features VARYING ... AFTER Phrase in PERFORM Statement In the VARYING . . . AFTER phrase in a PERFORM statement, ANSI85 augments identi er-2 before it sets identi er-5 . ANSI74 performs these steps in reverse order: it sets identi er-5 before it augments identi er-2 . The reason for this change is that the ANSI74 PERFORM statement was often misinterpreted, resulting in incorrect programs. ANSI85 and ANSI74 produce di erent results when identi er-5 depends on identi er-2 or vice versa.
Incompatible Features File Status Codes File status code incompatibilities between ANSI85 and ANSI74 le status codes are shown in Table 5-9. Justification for Changing File Status Codes 1974 Standard COBOL speci ed only a few le status code conditions. This made the following true: A COBOL program could not distinguish the many di erent exceptional conditions and treat them di erently. Each implementor speci ed a di erent set of implementor-de ned status codes to cover many situations in many ways.
3 Programming Practices Introduction This chapter describes programming practices that can help you do the following: Make your programs structured, so that it is easier to design, code, read, and maintain. Make your programs faster at run-time. Make your programs more portable, so that you can run it on other machines with minimal changes. Structured Programming Structured programming makes your program easier to design, code, read, and maintain.
Structured Programming This section explains the following: ANSI85 structured programming features, by division. When to use nested programs and GLOBAL data. Note The SPECIAL-NAMES paragraph (in the ENVIRONMENT DIVISION) cannot appear in nested programs. All items in the SPECIAL-NAMES paragraph are implicitly GLOBAL. END PROGRAM Header The END PROGRAM header ends a COBOL source program explicitly, whereas the absence of additional source lines ends a program implicitly.
Structured Programming Example IDENTIFICATION DIVISION. PROGRAM-ID. A. PROCEDURE DIVISION. BEGIN-A. DISPLAY "A IS THE OUTERMOST PROGRAM". CALL "B". CALL "D". CALL "E". IDENTIFICATION DIVISION. PROGRAM-ID. B. PROCEDURE DIVISION. BEGIN-B. DISPLAY "B IS NESTED WITHIN A". CALL "C". IDENTIFICATION DIVISION. PROGRAM-ID. C. PROCEDURE DIVISION. BEGIN-C. DISPLAY "C IS NESTED WITHIN B". END PROGRAM C. END PROGRAM B. IDENTIFICATION DIVISION. PROGRAM-ID. D. PROCEDURE DIVISION. BEGIN-D. DISPLAY "D IS NESTED WITHIN A".
Structured Programming In the preceding example, the PROGRAM-ID paragraph/END PROGRAM header pairs describe this nesting hierarchy: Program A is the parent of programs B and D. (B and D are siblings). Program A is the grandparent of program C. (C is a child of program B.) Program E is a concatenated program. That is, it is in the same source le as A, B, C, and D, but is not nested within any of them. It is considered to be a separately compiled program.
Structured Programming IDENTIFICATION DIVISION: COMMON Clause The COMMON clause allows a nested program to be called by its siblings and their descendants, as well as its parent. (By default, it can only be called by its parent.) The COMMON clause does not allow recursion; that is, the common program cannot be called by its descendants or itself. See \Call Rules" in Chapter 4 for an example of the COMMON clause.
Structured Programming Example IDENTIFICATION DIVISION. PROGRAM-ID. OUTER. DATA DIVISION. WORKING-STORAGE SECTION. 01 ITEM-A IS GLOBAL PICTURE X(20) VALUE "Global item in OUTER". PROCEDURE DIVISION. BEGIN. DISPLAY ITEM-A. CALL "NESTED-1". IDENTIFICATION DIVISION. PROGRAM-ID. NESTED-1. PROCEDURE DIVISION. BEGIN. DISPLAY ITEM-A. CALL "NESTED-2". IDENTIFICATION DIVISION. PROGRAM-ID. NESTED-2. DATA DIVISION. WORKING-STORAGE SECTION. 01 ITEM-A PICTURE X(23) VALUE "Local item in NESTED-2". PROCEDURE DIVISION.
Structured Programming PROCEDURE DIVISION The PROCEDURE DIVISION has the following ANSI85 structured programming features: CONTINUE statement. EVALUATE statement. Explicit scope terminators. NOT phrases. PERFORM statement enhancements. USE GLOBAL AFTER ERROR PROCEDURE ON statement. CONTINUE Statement The CONTINUE statement is a nonexecutable substitute for a conditional or imperative statement or for the keyword EXIT in an EXIT paragraph. Example.
Structured Programming If condition 1 is true, NO-PAY is performed. If condition 1 is false and condition 2 is true, REG-PAY is performed. If conditions 1 and 2 are false and condition 3 is true, OVERTIME-PAY is performed. If conditions 1, 2, and 3 are false and condition 4 is true, REG-PAY is performed. If conditions 1, 2, 3, and 4 are false, PAY-ERROR is performed.
Structured Programming The following example is also equivalent to the example above, but it uses the structured form of the IF-THEN-ELSE statement with the END-IF scope terminator: Example 3.
Structured Programming The following example shows the END-IF scope terminator. The rst END-IF terminates the scope of IF PROCESS-2-OK. The second END-IF terminates the scope of IF PROCESS-1-OK. Example 1. IF PROCESS-1-OK THEN IF PROCESS-2-OK THEN MOVE 2 TO PROCESS-DATA-FLAG ELSE MOVE 1 TO PROCESS-DATA-FLAG END-IF PERFORM PROCESS-DATA ELSE PERFORM PROCESS-1-ERROR-CHECK END-IF A conditional statement used with an explicit scope terminator is called a delimited scope statement .
Structured Programming NOT Phrases A NOT phrase speci es a set of statements to be executed if an exception condition does not occur. The NOT phrases are listed below: NOT NOT NOT NOT NOT NOT NOT AT END AT END-OF-PAGE INVALID KEY ON EXCEPTION ON INPUT ERROR ON OVERFLOW ON SIZE ERROR Using NOT phrases can make code more readable and sometimes more e cient. Example. The following are functionally equivalent: READ IN-FILE AT END MOVE 'YES' TO EOF. IF EOF <> 'YES' THEN ADD 1 TO IN-CNT.
Structured Programming PERFORM Statement Enhancements The enhanced PERFORM statement can contain a list of statements rather than only procedure names if it ends with an END-PERFORM. This form of the PERFORM statement is called an in-line PERFORM statement. Example 1. The following is an in-line PERFORM statement: PERFORM 10 TIMES ADD A TO B ADD 1 TO A END-PERFORM Example 2. The in-line PERFORM statement can signi cantly reduce code fragmentation.
Structured Programming In-line PERFORM statements can be nested. Nested in-line PERFORM statements can make your program more readable and less fragmented. Example 4. The following shows an example without nested in-line PERFORM statements: PERFORM PROC-NAME-1 VARYING DEPARTMENT FROM FIRST-DEPT BY 1 UNTIL LAST-DEPARTMENT AFTER HOURS-PER-EMPLOYEE FROM FIRST-EMP BY 1 UNTIL LAST-EMPLOYEE. STOP. RUN. . . PROC-NAME-1. . . .
Structured Programming USE GLOBAL AFTER ERROR PROCEDURE ON Statement The USE GLOBAL AFTER ERROR PROCEDURE ON statement makes the scope of a USE procedure match the scope of the program that declares the USE procedure. That is, the statement applies to the program that contains it and to all programs directly or indirectly contained within that program. A USE GLOBAL AFTER ERROR PROCEDURE ON statement speci es either a le open mode or the name of a GLOBAL le. Using a File Open Mode.
Structured Programming When to Use Nested Programs and GLOBAL Data The structured programming features described in the previous section, \Structured Programming," are part of ANSI85 COBOL. They allow you to divide your application into programs whose nesting hierarchy and data organization express and document your programming approach. This clari es the logical structure of your program, making it easier to understand, debug, and maintain.
Structured Programming *************************** *PROGRAM-ID. PAYROLL. * Payroll declares and opens two global files CURR-PAY-REC and * EMPLOYEE-INFO. For each record in CURR-PAY-REC it calls * GET-CURR-GROSS and GET-CURR-DEDUCTIONS. It also updates the * year-to-date payroll fields in EMPLOYEE-INFO. * It declares a GLOBAL use procedure for INPUT mode, which will * be used when local files with tax and pay scale tables * (opened only in input mode) encounter errors.
Structured Programming $PAGE "PAYROLL" IDENTIFICATION DIVISION. PROGRAM-ID. PAYROLL. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CURR-PAY-FILE ASSIGN TO "CURRPAY" ORGANIZATION IS SEQUENTIAL. SELECT EMPLOYEE-INFO ASSIGN TO "EMPINFO" ORGANIZATION IS RELATIVE ACCESS IS RANDOM RELATIVE KEY IS EMP-INFO-KEY FILE STATUS IS FILE-STATUS. DATA DIVISION. FILE SECTION. * When the FD is GLOBAL, all subordinate records are also GLOBAL. FD CURR-PAY-FILE IS GLOBAL. 01 CURR-PAY-REC.
Structured Programming * * PROCEDURE DIVISION. DECLARATIVES. GLOBAL-USE-PROC SECTION. USE GLOBAL AFTER STANDARD ERROR PROCEDURE ON INPUT. GLOBAL-USE. This will be executed when local files TAX-RATES and PAY-RATES encounter an error. DISPLAY FILE-NAME, " Status is ", FILE-STATUS. END DECLARATIVES. PROCESS-PAYROLL SECTION. OPEN-FILES. OPEN I-O CURR-PAY-FILE OPEN I-O EMPLOYEE-INFO. READ-PAY-FILE.
Structured Programming $PAGE "GET-CURR-GROSS" $CONTROL DYNAMIC IDENTIFICATION DIVISION. PROGRAM-ID. GET-CURR-GROSS. * USE EMP-JOB-DESCRIPTOR TO INDEX TABLE-OF-PAY TO GET WAGE RATE * AND CALCULATE CURRENT GROSS SALARY. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAY-RATES ASSIGN TO "PAYRATES" FILE STATUS IS FILE-STATUS. DATA DIVISION. FILE SECTION. * PAY-RATES is LOCAL to this program. FD PAY-RATES. 01 TABLE-OF-PAY. 05 RATES OCCURS 99 TIMES.
Structured Programming HOURLY-LABOR. MOVE HOURLY-PAY (EMP-JOB-DESCRIPTOR) TO RATE MOVE CURR-HOURS TO OVERTIME EVALUATE WORKED-OVERTIME WHEN FALSE COMPUTE GROSS = CURR-HOURS * RATE WHEN TRUE COMPUTE GROSS = 40 * RATE + (CURR-HOURS - 40 * RATE * 1.5) END-EVALUATE. SALARIED-LABOR. MOVE SALARY (EMP-JOB-DESCRIPTOR) TO GROSS. END PROGRAM GET-CURR-GROSS.
Structured Programming $PAGE "GET-CURR-DEDUCTIONS" IDENTIFICATION DIVISION. PROGRAM-ID. GET-CURR-DEDUCTIONS. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TAX-RATES ASSIGN TO "TAXRATES" FILE STATUS IS FILE-STATUS. DATA DIVISION. FILE SECTION. * TAX-RATES is LOCAL to this program. * For simplicity, only social security tax is calculated. FD TAX-RATES. 01 TABLE-OF-TAXES. 05 FICA-TAX-RATE PICTURE 9999V999 USAGE PACKED-DECIMAL. WORKING-STORAGE SECTION.
Structured Programming $PAGE "HASHED-ACCESS-ON-EMPLOYEE-FILE" IDENTIFICATION DIVISION. PROGRAM-ID. HASHED-READ-ON-EMPLOYEE-FILE IS COMMON. DATA DIVISION. WORKING-STORAGE SECTION. 01 KEY-SWITCH PIC X. 88 SUCCESS VALUE "Y". 88 RESET-SWITCH VALUE "N". LINKAGE SECTION. 01 SS-NO PICTURE X(9). PROCEDURE DIVISION USING SS-NO. BEGIN-HASHED-READ.
Run-Time Efficiency Run-Time Efficiency You can improve your program's run-time e ciency with the following: An improved algorithm. This is the most important way you can improve your program's e ciency. Neither control options nor the optimizer can make up for a slow algorithm. A program that uses a binary search (without control options or optimization) is still faster than a program that uses a linear search (with control options and optimization). Coding heuristics. Control options. The optimizer.
Run-Time Efficiency Calculations involving multiplication, division, and exponentiation can require conversions for intermediate results. When the intermediate results of BINARY operands exceed 18 digits, the operands are converted to PACKED-DECIMAL. This takes many extra instructions. The rst of the following COMPUTE statements is faster then the second because the intermediate result is 18 digits. The second requires conversion to PACKED-DECIMAL because the intermediate result is 20 digits.
Run-Time Efficiency If a variable is a subscript or a varying identi er in a PERFORM loop, declare it to be of the type PIC S9(9) BINARY SYNC. When coding the UNTIL condition in a loop, keep this in mind: the comparisons equal and not equal are faster than the comparisons less than and greater than . Compile subprograms with the SUBPROGRAM or ANSISUB control option.
Run-Time Efficiency Coding Heuristics when Calling COBOL Functions The following are guidelines when your program calls COBOL functions. For more information on the COBOL functions, see Chapter 10, \COBOL Functions," in the HP COBOL II/XL Reference Manual . Some of the functions are implemented as calls to run-time libraries. The rest are implemented simply as inline code. Inline functions are generally faster than functions in the run-time library.
Run-Time Efficiency Control Options These control options make a program run faster: OPTIMIZE=1, which invokes the optimizer. See the section, \The Optimizer", for details. OPTFEATURES=LINKALIGNED[16], which generates code that accesses variables in the LINKAGE SECTION more e ciently. (If the called program speci es OPTFEATURES=LINKALIGNED[16], have the calling program specify OPTFEATURES=CALLALIGNED[16].) SYNC32, which allows the compiler to align variables along the optimum boundaries.
Run-Time Efficiency The Optimizer The optimizer is an optional part of the compiler that modi es your code so that it uses machine resources more e ciently, using less space and running faster. Note that the optimizer improves your code, not your algorithm. Optimization is no substitute for improving your algorithm. A good, unoptimized algorithm is always better than a poor, optimized one. You can compile your program with level one optimization by compiling it with the control option OPTIMIZE=1.
Run-Time Efficiency When to Use the Optimizer Compile your program with optimization only after you have debugged it. The optimizer can transform legal programs only. Once you have compiled your program with optimization, you cannot use the symbolic debugger to debug it. This is because debug information will be missing from it. The compiler does not generate debug information and perform optimizations at the same time.
Program Portability Portability Portability applies to both programs and les. The more portable your program or le is, the less you need to modify it to use it on machines other than the one for which you originally created it. This chapter assumes that you are creating your program or le for one HP 3000 machine and then transporting it to another HP 3000 machine or a non-HP machine. To make your program more portable in both cases, do the following: Make your program correct.
Program Portability Portability Between HP 3000 Architectures If you are writing your program for one HP 3000 machine but also intend to run it on another HP 3000 machine, you should do the following: Use the CALL INTRINSIC form of the verb to call an intrinsic. This tells the compiler an intrinsic is being called and allows it to adapt the call to a speci c operating system. Do not use the pseudo-intrinsics .LOC. or .LEN. which call operating system intrinsics.
Program Portability Portability Between HP 3000 and Non-HP Machines If you are writing your program for an HP 3000 machine but also intend to run it on a non-HP machine, you should do the following: Use only ANSI Standard features. Do not call system intrinsics directly. To ensure that your program conforms to the 1985 ANSI COBOL Standard, you can compile your program with the following $CONTROL options: ANSIPARM, ANSISORT, POST85, and STDWARN.
Program Portability If you are creating a le for an HP 3000 machine but also intend to use it on a non-HP machine, you should do the following: Never put indexed data items in the le. Do not use SYNC in the le unless the compiler on the non-HP machine uses 16- or 32-bit synchronization for COMP and BINARY items. In that case, compile your program with the control option SYNC16 or SYNC32.
Program Portability HP Extensions If your program uses HP extensions, you cannot transport it to non-HP computers. The following are HP extensions to ANSI COBOL 1985: NOLIST phrase in the COPY statement. USAGE COMP-3 (the standard equivalent is USAGE PACKED-DECIMAL). Intrinsic relation condition. Random access les. The USING phrase of the ASSIGN clause. WITH DUPLICATES phrase in the RECORD KEY clause of the SELECT statement. REMARKS paragraph in the IDENTIFICATION DIVISION.
4 Subprograms and Intrinsics Introduction A subprogram is a routine that either is not in the program that calls it, or is nested within another program. It is the object of a CALL statement. Its source language can be the same as that of the calling program, or di erent. An intrinsic is a system-supplied procedure, an external interface to the operating system or subsystem services that can be called through the intrinsic mechanism.
External Names External Names An external name is a compiler-generated name that is recognized outside the program. The compiler generates an external name for each of the following: program-id . ENTRY statement literal. EXTERNAL data item or le. Program name that a CALL or CANCEL statement speci es. y y y An external name is only generated for a program-id or ENTRY statement literal of a separately compiled program.
Internal Names Internal Names An internal name is a compiler-generated name that is not recognized outside the program. The compiler generates an internal name for each: program-id of a nested program. ENTRY statement literal of a nested program. Nested program name that a CALL or CANCEL statement speci es. Nested procedure for USE GLOBAL, ALTERable GOTO, and CALL or CANCEL identi er.
Chunk and Locality Set Names Chunk and Locality Set Names The locality set name is extracted from the PROGRAM-ID paragraph, according to the external naming convention (refer to the HP Link Editor/XL Reference Manual for the de nition of locality set ). The executable code resides in the program le or an executable library. For a large program, the executable code is in chunks. Each chunk is in a separate subspace, but they all reside in the same program le and locality set.
Chunk and Locality Set Names Example 2 The following program illustrates chunk names with nested and concatenated programs. The main program contains a subprogram, which contains another subprogram, and a concatenated program follows the main program's END PROGRAM header. All the programs are chunked. With nested or concatenated programs, a new chunk begins whenever a new program starts. Large programs may be chunked in the middle of the PROCEDURE DIVISION code. IDENTIFICATION DIVISION. PROGRAM-ID.
Data Alignment Data Alignment on MPE XL By default, COBOL data is aligned in the following way on MPE XL: In the WORKING-STORAGE and FILE sections: level 01 and 77, COMP or BINARY SYNCHRONIZED, and index data items are 32-bit-aligned. In the LINKAGE section, all data items are 8-bit-aligned (byte-aligned), even if the SYNCHRONIZED clause is speci ed. The SYNCHRONIZED clause adds slack bytes so that every synchronized item is aligned on the same boundary as if the record were in WORKING-STORAGE.
Parameter Checking Parameter Checking When your COBOL program calls an intrinsic, the compiler tries to match information about the type and alignment for each actual parameter. If this is not possible, the compiler issues an error message. When your program calls a subprogram, the actual parameter list that your program passes is checked at link or load time against the formal parameter list of the subprogram for the following: The number of parameters. The parameter alignment.
Parameter Passing Parameter Passing Your program can pass an actual parameter to a subprogram by reference, by content, or by value. Passing Parameters by Reference By default, your program passes an actual parameter by reference. This means that your program passes the address of the actual parameter to the subprogram. If the subprogram changes the value of its formal parameter, it also changes the value of your program's actual parameter.
Parameter Passing Parameter Alignment On MPE XL, the HP COBOL II/XL compiler assumes that all data items in the LINKAGE SECTION are byte-aligned unless the subprogram is compiled with the control option OPTFEATURES=LINKALIGNED or OPTFEATURES=LINKALIGNED16. In the rst case, it assumes that they are word-aligned. In the second case, it assumes that they are halfword-aligned. If the subprogram is compiled with the control option BOUNDS, the compiler will trap parameter misalignment.
Call Binding Call Binding The process of matching a subprogram call or an intrinsic call to its de nition is called call binding. Call binding can occur at compile time, link time, load time, or execution time. Di erent subprograms called by the same program can be bound di erently. Subprogram Libraries If your program contains a subprogram that other programs call, you may decide to put the subprogram in a library, making it available to other programs.
Call Binding Compile-Time Binding Compile-time binding is performed by the compiler. It can only happen when the CALL or CANCEL target is a nested or concatenated program in the current source le. The advantages of compile-time binding are: Calls to subprograms bound at compile time are faster than calls to subprograms bound at load time or execution time (but are the same speed as calls bound at link time). The program le is portable.
Call Binding Example. IDENTIFICATION DIVISION. PROGRAM-ID. OUTER. PROCEDURE DIVISION. BEGIN-OUTER. IDENTIFICATION DIVISION. PROGRAM-ID. MIDDLE. PROCEDURE DIVISION. BEGIN-MIDDLE. IDENTIFICATION DIVISION. PROGRAM-ID. INNER. PROCEDURE DIVISION. BEGIN-INNER. END PROGRAM INNER. Outermost program. Nested program. Nested program. END PROGRAM MIDDLE. END PROGRAM OUTER. IDENTIFICATION DIVISION. PROGRAM-ID. NEXT. PROCEDURE DIVISION. BEGIN-NEXT. END PROGRAM NEXT. Concatenated program.
Call Binding Call Rules The call rules that apply to subprograms bound at compile time are the following: Any program can call a concatenated program (except the program itself). Normally, a program can only call a nested program if it directly contains the nested program. However, if the nested program is COMMON, descendants of the program that contains the COMMON program can call it also. Only recursion is prohibited; that is, neither the COMMON program itself nor its descendants can call it.
Call Binding IDENTIFICATION DIVISION. PROGRAM-ID. C. PROCEDURE DIVISION. BEGIN-C. *Program C can call any COMMON program directly contained *by program A: program D. CALL "D". END PROGRAM C. END PROGRAM B. *Program D IS COMMON and is nested within program A. IDENTIFICATION DIVISION. PROGRAM-ID. D IS COMMON. PROCEDURE DIVISION. BEGIN-D. DISPLAY "SUCCESSFUL CALL TO COMMON PROGRAM". END PROGRAM D. END PROGRAM A. Make a program COMMON when programs at various nesting levels need the function that it performs.
Call Binding Link-Time Binding Link-time binding is performed by the link editor. Subprogram code becomes part of the program le. The advantages of link-time binding are: Calls to subprograms bound at link time are faster than calls to subprograms bound at load time or execution time. The program le is portable. The program le contains all the information that it needs to resolve calls to the subprogram. Other programmers can use your program without additional executable libraries.
Call Binding Load-Time Binding Load-time binding is performed by the loader, which is invoked by the RUN command immediately before it executes the program. The subprogram must reside in an executable library (not in a relocatable object le or relocatable library). Subprogram code does not become part of the program le. Intrinsics are bound at load time.
Call Binding Execution-Time Binding Execution-time binding is performed by a calling program that contains a CALL identi er statement or an ON EXCEPTION or ON OVERFLOW phrase. The value of identi er , a subprogram name, is not available until execution time. At that time, the program calls a special routine that checks to see if the called program is contained in the calling program. If so, the subprogram is nested, and the special routine binds it to the calling program that contains it.
Switch Stubs Switch Stubs A switch stub is a program that allows your Native Mode HP COBOL II/XL program to call a subprogram compiled in Compatibility Mode. You do not have to change or recompile your program or the subprogram. Figure 4-1 shows how a switch stub works. When the program calls the subprogram, what actually happens is that the program calls the switch stub and the switch stub calls the subprogram. This is transparent to the program and subprogram, except that performance is slower.
Calling COBOL Subprograms Calling COBOL Subprograms When your COBOL program calls a subprogram written in COBOL, you should understand the following: What type the subprogram is. How your program passes the actual parameters. Whether or not the subprogram uses the RETURN-CODE special register. When the calls to the COBOL subprogram will be bound to its de nition. Whether to put the subprogram in a library, and if so, what kind of library.
Calling COBOL Subprograms Table 4-3 compares some of the attributes of subprograms. Table 4-3. Comparison of Non-Dynamic, Dynamic, and ANSISUB Subprograms Characteristic Initialized: A ected by the CANCEL statement? Non-Dynamic ANSISUB Once, at link time. Once, at link time. No Yes Dynamic Each time the subprogram is called. No Non-dynamic subprograms and ANSISUB subprograms are initialized once, at link time.
Calling Non-COBOL Subprograms Calling Non-COBOL Subprograms Your COBOL program can call subprograms and intrinsics written in C, FORTRAN 77, Pascal, and SPL. For each call to such a subprogram, the COBOL compiler generates the following information for the linker: The type of the identi er in the GIVING clause of the CALL statement. The alignment of each identi er in the USING clause of the CALL statement (for parameters that are passed by value, the type is generated also). The number of parameters.
Calling C Subprograms Calling Subprograms Written in C Your COBOL program can call a subprogram written in C if the parameters of the C routine are of types that have compatible COBOL types. If the C routine is a function, it must return a type that has a compatible COBOL type, and the identi er in the GIVING clause of the CALL statement must be of that compatible COBOL type. Table 4-4.
Calling C Subprograms The following is a C subprogram that returns a void value: # 1 "CREVERS.PUBS.COBOL" void reverses (s) char *s; { int right = strlen (s) -1, left = 0; char t; for (; left < right; right--, left++) { t = s [right]; s [right] = s [left]; s [left] = t; } } Many C routines expect a null byte at the end of each ASCII string. The routine reverses, above, is an example of such a C routine. The following COBOL program, which calls reverses, declares a null-terminated ASCII string in COBOL.
Calling C Subprograms 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 011000 012000 PROCEDURE DIVISION. 013000 01-TEST. 014000 015000 MOVE 10 TO TABLE-EL(1). 016000 MOVE 8 TO TABLE-EL(2). 017000 MOVE 14 TO TABLE-EL(3). 018000 MOVE 9 TO TABLE-EL(4). 019000 MOVE 18 TO TABLE-EL(5). 020000 MOVE 98 TO TABLE-EL(6). 021000 MOVE 7 TO TABLE-EL(7). 022000 MOVE 23 TO TABLE-EL(8). 023000 025100 MOVE 8 TO LEN.
Calling FORTRAN Subprograms Calling Subprograms Written in FORTRAN 77 Your COBOL program can call a subprogram written in FORTRAN 77 if the parameters of the FORTRAN 77 routine are of types that have compatible COBOL types. Table 4-5 shows compatible COBOL and FORTRAN 77 types. FORTRAN 77 types that are not in Table 4-5 do not have compatible COBOL types. The number n is an integer. Table 4-5.
Calling FORTRAN Subprograms Example The following is a FORTRAN 77 subprogram: C C C C INTEGER*4 FUNCTION LARGER(A,L) INTEGER*4 A(8) INTEGER*4 LARGST,L THIS SUBROUTINE FINDS THE LARGEST VALUE IN AN ARRAY OF 'L' INTEGERS. LARGST = A(1) DO 100 I = 2,L IF (LARGST .LT.
Calling FORTRAN Subprograms The following COBOL program calls the FORTRAN 77 subprogram above: 001000 IDENTIFICATION DIVISION. 002000 PROGRAM-ID. CALLFTN. 003000 DATA DIVISION. 004000 WORKING-STORAGE SECTION. 005000 01 TABLE-INIT. 006000 05 PIC S9(9) COMP SYNC VALUE 10. 007000 05 PIC S9(9) COMP SYNC VALUE 8. 008000 05 PIC S9(9) COMP SYNC VALUE 14. 009000 05 PIC S9(9) COMP SYNC VALUE 9. 010000 05 PIC S9(9) COMP SYNC VALUE 18. 011000 05 PIC S9(9) COMP SYNC VALUE 98. 012000 05 PIC S9(9) COMP SYNC VALUE 7.
Calling FORTRAN Subprograms The following commands compile and link the FORTRAN 77 subprogram and the COBOL program: :cob85xl callftn, callftno, $null :ftnxl fortsub, fortsubo, $null :link from=callftno,fortsubo;to=callftnp The following command executes the COBOL program: :callftnp The COBOL program displays the following: +000000098 IS THE LARGEST VALUE IN THE TABLE ABCDEFGHIJ BACKWARDS IS JIHGFEDCBA 4-28 Subprograms and Intrinsics
Calling Pascal Subprograms Calling Subprograms Written in Pascal Your COBOL program can call a subprogram written in Pascal if the parameters of the Pascal subprogram are of types that have compatible COBOL types. Table 4-6 shows compatible COBOL and Pascal types, assuming default Pascal alignment. See the note below. Pascal types that are not in Table 4-6 do not have compatible COBOL types. The number n is an integer. Table 4-6.
Calling Pascal Subprograms Example The following is a Pascal subprogram: $SUBPROGRAM$ PROGRAM PASCSUB; TYPE STRING_TYPE = ARRAY_TYPE = PACKED ARRAY[1..10] OF CHAR; ARRAY[1..8] OF INTEGER; (* ***************************************** *) (* PROCEDURE REVERSE *) (* ***************************************** *) (* THIS PROCEDURE WILL REVERSE A STRING OF (* 'LEN' CHARACTERS.
Calling Pascal Subprograms (* ***************************************** *) (* PROCEDURE GRANDE *) (* ***************************************** *) (* THIS PROCEDURE WILL FIND THE LARGEST (* ITEM IN AN ARRAY OF 'L' ELEMENTS *) *) FUNCTION GRANDE( VAR ARR : ARRAY_TYPE; L : INTEGER) : INTEGER; VAR K : INTEGER; LARGEST : INTEGER; BEGIN LARGEST := ARR[1]; FOR K := 2 TO L DO IF LARGEST < ARR[K] THEN LARGEST := ARR[K]; GRANDE := LARGEST; END; BEGIN END.
Calling Pascal Subprograms The following COBOL program calls the Pascal subprogram above: 001000 002000 003000 004000 005000 006000 007000 008000 009000 010000 011000 012000 013000 014000 015000 016000 017000 018000 019000 020000 021000 022000 023000 024000 025000 026000 027000 028000 029000 030000 031000 032000 4-32 ID DIVISION. PROGRAM-ID. IC807R. DATA DIVISION. WORKING-STORAGE SECTION. 01 TABLE-1. 05 TABLE-EL OCCURS 8 01 LARGST 01 STRING-1 01 LEN PIC PIC PIC PIC S9(9) S9(9) X(10) S9(9) BINARY SYNC.
Calling Pascal Subprograms The following commands compile, link, and execute the program and subprogram: :pasxl pascsub,pascsubo,$null :cob85xl callpas,callpaso,$null :link from=callpaso,pascsubo;to=callpasp :run callpasp The COBOL program displays the following: +000000098 ABCDEFGHIJ BACKWARDS IS STRING JIHGFEDCBA Pascal and COBOL variables are both byte-aligned if: The Pascal subprogram includes the option $ALIGNMENT 1$. The COBOL program does not specify SYNC on elementary items in records.
Calling Pascal Subprograms The following Pascal program contains a procedure that the COBOL program calls: $SUBPROGRAM$ PROGRAM PASREC; TYPE PASCAL_RECORD = RECORD CHAR1 : CHAR; INT_16_BITS : SHORTINT; INT_32_BITS : INTEGER; STRING : PACKED ARRAY [1..10] OF CHAR; END; PROCEDURE DISPLAY_RECS( VAR PREC : PASCAL_RECORD); BEGIN WITH PREC DO BEGIN CHAR1 := 'A'; INT_16_BITS := 9999; INT_32_BITS := -888888888; STRING := 'LMNOPQRSTU'; END; END; BEGIN END.
Calling Pascal Subprograms To achieve byte-alignment in the corresponding Pascal record, use $ALIGNMENT 1$ as shown below: In the Pascal record, the types shortint 1 and integer 1 are declared as follows: shortint_1 = $ALIGNMENT 1$ shortint; integer_1 = $ALIGNMENT 1$ integer; Equivalent Pascal record: packed_record = RECORD p1 : PACKED ARRAY [1..3] OF char; p2 : shortint_1; p3 : PACKED ARRAY [1..
Writing Switch Stubs Calling Subprograms Written in SPL Your COBOL program can call a subprogram written in SPL if the parameters of the SPL subprogram are of types that have compatible COBOL types. Table 4-7 shows compatible COBOL and SPL types. SPL types that are not in Table 4-7 do not have compatible COBOL types. The number n is an integer. Table 4-7. Compatible COBOL and SPL Types COBOL Type PIC X(n ) SPL Type BYTE ARRAY PIC S9 to S9(4)1 USAGE COMP or BINARY. Level 01 or 77, or SYNC.
Writing Switch Stubs When a Native Mode program calls a Compatibility Mode program, the Compatibility Mode program must be in an SL. When a Compatibility Mode program calls a Native Mode program, the Native Mode program must be in an executable library. Note Example The following illustrates the steps for a Native Mode COBOL program to call a Compatibility Mode SPL program. Step 1.
Writing Switch Stubs END. ELSE IF base = 16 THEN BEGIN MOVE hexstring := "0123456789ABCDEF"; FOR i := 7 STEP -1 UNTIL 0 DO BEGIN string(i):=hexstring(lint.(12:4)); dint := dint & DLSR(4); END; cascii := 8; << always hex string length >> END ELSE IF base = 2 THEN BEGIN FOR i := 31 STEP -1 UNTIL 0 DO BEGIN IF lint.(15:1) THEN string(i) := "1" ELSE string(i) := "0"; dint := dint & DLSR(1); END; cascii := 32; END ELSE cascii := 0; END; << cascii >> Step 1 Continued.
Writing Switch Stubs Step 2. Use SWAT to generate the switch stub: To invoke SWAT, type the following command at the MPE XL prompt: :SWAT The rst screen is the FILE screen. Type in the name of the le where you want the switch stub to go. In this case the le name is SWCASCII. Then press the 4Enter5 key. Screen 1.
Writing Switch Stubs Screen 2. The next screen is the MAIN screen. Here you specify the name of the Compatibility Mode procedure and its parameters. Here these are cascii, dint, base, and string, respectively. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986.
Writing Switch Stubs The next screen is the PROCINFO screen. Here you specify information about the Compatibility Mode procedure. Screen 3. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs The next three screens are the PARMINFO screens where you specify information about each of the parameters of the Compatibility Mode procedure. Screen 4. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs Screen 5. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs Screen 6. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs Screen 7. The next screen is the ARRAYLEN screen where you specify information about the array parameter STRING. NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs Screen 8. process. The nal screen is the COMMIT screen where you start the code generation NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN HP30363A.01.00 Switch Assist Tool COPYRIGHT (C) HEWLETT-PACKARD 1986. ALL RIGHTS RESERVED.
Writing Switch Stubs This is the switch stub generated: $check_actual_parm 0$ $check_formal_parm 0$ $os 'MPE/XL'$ $standard_level 'ext_modcal'$ $tables off$ $code_offsets off$ $xref off$ $type_coercion 'representation'$ {******************************************************} {* *} {* Generated: THU, OCT 8, 1987, 5:46 PM *} {* *} {* Switch Assist Tool HP30363A.00.
Writing Switch Stubs Hp__GENERIC_BUFFER = PACKED ARRAY [1..
Writing Switch Stubs PROCEDURE QUIT; INTRINSIC; { End of OUTER BLOCK GLOBAL declarations } $PAGE$ FUNCTION CASCII $ALIAS 'CASCII'$ ( DINT : HP__INTEGER; BASE : HP__SHORTINT; ANYVAR STRING : Hp__GENERIC_BUFFER ) : HP__SHORTINT OPTION UNCHECKABLE_ANYVAR; VAR Hp__proc Hp__parms Hp__method Hp__nparms Hp__funclen Hp__funcptr Hp__byte_len_of_parm Hp__cond_code Hp__status : : : : : : : : : Hp__SCM_PROCEDURE; Hp__SCM_PARM_DESC_ARRAY; INTEGER; INTEGER; INTEGER; INTEGER; Hp__BIT16; SHORTINT; HP__STATUS_TYPE; VAR
Writing Switch Stubs { Setup misc. variables } Hp__method Hp__nparms := := Hp__Method_Normal; 3; { Setup length/pointers for functional return if this } { is a FUNCTION. Set length to zero, pointer to NIL } { if this is not a FUNCTION. } Hp__funclen Hp__funcptr := := SIZEOF(Hp__retval); INTEGER(LOCALANYPTR(ADDR(Hp__retval))); { Make a local copy of all VALUE parameters } Hp__loc_DINT := DINT; Hp__loc_BASE := BASE; { Build parameter descriptor array to describe each } { parameter.
Writing Switch Stubs { Do the actual SWITCH call } HPSWITCHTOCM(Hp__proc, Hp__method, Hp__nparms, Hp__parms, Hp__funclen, Hp__funcptr, Hp__cond_code, Hp__status); { { { { { { { { Procedure info Switch copy method Number of parameters Parm descriptor array func ret value length Addr of func return cond. code return SWITCH status code } } } } } } } } if (Hp__status.Hp__all Hp__all_ok) then BEGIN { SWITCH subsystem error } QUIT(Hp__status.
Writing Switch Stubs Step 3. Compile the SPL program. :spl cascii,casciio,$null Step 4. Using the segmenter, put the SPL program USL in an SL: :segmenter HP32050A.02.00 SEGMENTER/3000 (C) HEWLETT-PACKARD CO 1985 -buildsl sl,300,1 -usl casciio -listusl USL FILE CASCIIO.PUBS.COBOL74 SEG' CASCII FILE DIR. DIR. DIR. 152 P SIZE USED GARB. AVAIL. A C N R 144000( 620. 0) 235( 1. 35) 0( 0. 0) 14143( 60.143) INFO USED INFO GARB. INFO AVAIL. 161( 0.161) 0( 0. 0) 127217( 535.
Writing Switch Stubs Step 5. Compile the COBOL and switch stub programs: :cob85xl callspl,callsplo,$null :pasxl swcascii,swcascio,$null Step 6. Link the COBOL program and the switch stub: :link from=callsplo,swcascio;to=callsplp Step 7.
EXTERNAL Items EXTERNAL Data Items and Files EXTERNAL data items and les can be shared by two or more programs (for the purpose of this discussion, a subprogram is also a program). For programs to share an EXTERNAL item: Each program must declare the EXTERNAL item (data item or le). Each program must give the EXTERNAL item exactly the same name, because the Link Editor matches it to itself in all programs by its external name (see \External Naming Convention").
EXTERNAL Items Example This example shows how to invoke 4CONTROL5 Y traps from COBOL. The main program executes a loop until 4CONTROL5 Y is pressed. The subprogram arms the 4CONTROL5 Y trap to execute its secondary entry point when 4CONTROL5 Y is pressed. The main program and subprogram communicate through EXTERNAL data items. The following is the main program: 001000 IDENTIFICATION DIVISION. 001100 PROGRAM-ID. CONTROL-Y-TEST. 001200 ENVIRONMENT DIVISION. 001300 CONFIGURATION SECTION.
EXTERNAL Items The following is the subprogram: 000100$CONTROL DYNAMIC 001200 IDENTIFICATION DIVISION. 001300 PROGRAM-ID. ARM-CONTROL-Y. 001800 DATA DIVISION. 001900 WORKING-STORAGE SECTION. 002000 1 TOTAL PIC S9(9) COMP VALUE 0. 002100 1 PROCNAME PIC X(20) VALUE "!control_y_trap!". 002200 1 PLABEL PIC S9(9) COMP. 002300 1 OLDPLABEL PIC S9(9) COMP. 002400 1 PROGFILE PIC X(40). 002500* another way to pass data 002510 1 CONTROL-Y EXTERNAL PIC X. 002520 88 CONTROL-Y-HIT VALUE "Y".
EXTERNAL Items EXTERNAL Items and FORTRAN The Link Editor matches FORTRAN named common blocks and COBOL EXTERNAL records by name (one FORTRAN named common block matches one COBOL EXTERNAL record). If the FORTRAN named common block declares more than one variable, it is your responsibility to align the elementary items of the COBOL record along the proper boundaries. You may have to specify unused bytes with FILLER.
EXTERNAL Items COBOL, FORTRAN, and Pascal Example This COBOL main program, FORTRAN subprogram, and Pascal subprogram can pass information to each other through shared EXTERNAL items. The following is the COBOL main program with EXTERNAL records: 001000 001100 001200 001300 001400 001500 001600 001610 001620 001700 001800 001900 002000 002000 002000 002100 002200 IDENTIFICATION DIVISION. PROGRAM-ID. COBEXT. DATA DIVISION. WORKING-STORAGE SECTION. 01 A EXTERNAL.
EXTERNAL Items The following is the Pascal subprogram. It is compiled with the EXTERNAL option: $EXTERNAL,SUBPROGRAM$ PROGRAM STUFF; TYPE COM = RECORD I: INTEGER; J: SHORTINT; K: INTEGER; END; VAR A : COM; PROCEDURE FTN; EXTERNAL FTN77; PROCEDURE PAS; BEGIN A.I:=5; A.J:=-5; A.K:=6; FTN; END; BEGIN END.
GLOBAL Items GLOBAL Data Items and Files GLOBAL data items and les can be shared by two or more programs (or subprograms). For programs to share a GLOBAL item: One program must declare the GLOBAL item (data item or le). The other programs must be nested within the program that declares the GLOBAL item. A program nested within the program that declares the GLOBAL item cannot have a local item with the same name and quali cation as the GLOBAL item.
Calling Intrinsics Calling Intrinsics The section explains some aspects of calling intrinsics. For more information about HP Intrinsics, see the MPE XL Intrinsics Reference Manual . Using $CONTROL CALLINTRINSIC Intrinsics are subprograms whose declarations reside in the intrinsic le, SYSINTR.PUB.SYS. Ideally, your program always calls an intrinsic with CALL INTRINSIC instead of CALL, and does not use the control option CALLINTRINSIC.
Calling Intrinsics Table 4-8 lists the intrinsic parameter types and their corresponding COBOL types. Table 4-8.
Calling Intrinsics For BINARY elds, an intrinsic may return a value outside the range of valid numbers for the COBOL type. Calculations with such values may cause a SIZE ERROR. To prevent the error, use a MOVE statement to move the contents of such elds to larger BINARY elds. For example, the WHO intrinsic may return 16385 for the terminal parameter.
5 Files Introduction Files are the basis for input and output. Your COBOL program reads input from les and writes output to them. Files are also a means of interprogram communication. Two or more programs can communicate using a shared le. See \DATA DIVISION: GLOBAL Data Items and Files" in Chapter 3 and \EXTERNAL Data Items and Files" in Chapter 4. Files that your program declares are called logical les . Files that exist outside your program are called physical les .
Files Table 5-1 lists each I-O statement and how each statement is used with each le type. The following explains what each entry in Table 5-1 means: Meanings of Entries in Table 5-1 Table Entry 5-2 Files Meaning Comment This verb or clause is treated as a comment. Illegal This verb or clause is illegal for this le type. Optional This verb or clause is optional. Use it if you want the functionality it provides. Required This verb or clause is required.
Files Table 5-1.
Logical Files Table 5-1.
Logical Files Logical Files A logical le is a data structure that your program declares and accesses. Your program can declare logical les of these four types: Sequential organization, including MPE special les. Random access. Relative organization. Indexed organization. Each le type name re ects the way les of that type are organized and can be accessed. Organization and access method, the major attributes of a le type, determine some of its other attributes.
Logical Files Table 5-2 summarizes the attributes of the four le types for the purpose of comparison. This section explains each le type in detail. De nitions and explanations of some of the terms in Table 5-2 follow the table. Table 5-2.
Logical Files Below are de nitions of the terms in column one of Table 5-2. Term De nition Key A value within a record that serves to distinguish it from other records. Input open mode Allows a program to read a le, but not write it. A le that is open for input access can be used for input, but not output. Output open mode Allows a program to write a le, but not read it. A le that is open for output access can be used for output, but not input. Input-Output open mode Allows a le to be read and written.
Sequential Organization Files Sequential Organization Files A sequential organization le is so named because it can only be accessed sequentially. It does not use keys. Because of this simplicity, a sequential organization le: Is completely portable (when you are making an ANSI LABELLED TAPE and all data in the records is USAGE DISPLAY). Does not limit the portability of the programs that use it. Requires space only for records that are actually written to it. Can reside on any device.
Sequential Organization Files How to Code Sequential Organization Files The minimum code your program needs to perform input and output with sequential organization les is: In the ENVIRONMENT DIVISION, a SELECT statement with an ASSIGN clause for each le. In the FILE SECTION of the DATA DIVISION, an FD entry to match each SELECT statement, with an 01 record for each le. In the PROCEDURE DIVISION, procedures to OPEN, READ, WRITE, and CLOSE the les.
Sequential Organization Files Example 1. The following uses a sequential organization le: IDENTIFICATION DIVISION. PROGRAM-ID. FILE-EX1. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT IFILE ASSIGN "IFILE". SELECT PFILE ASSIGN "PFILE". DATA DIVISION. FILE SECTION. FD IFILE. 01 IREC. 05 NAME PIC X(30). 05 SOC-SEC PIC X(9). 05 HIRE-DATE. 10 MO PIC XX. 10 DA PIC XX. 10 YR PIC XX. 05 SALARY PIC S9(6). 05 PIC X(29). FD PFILE. 01 PREC. 05 SOC-SEC PIC X(9). 05 PIC XX. 05 NAME PIC X(30).
Sequential Organization Files IF WYR = YR OF IREC THEN ADD 1 TO LNCNT IF LNCNT > 50 PERFORM HEADINGS END-IF MOVE SPACES TO PREC MOVE CORR IREC TO PREC WRITE PREC AFTER ADVANCING 1 LINE END-IF END-READ END-PERFORM CLOSE IFILE PFILE STOP RUN. HEADINGS. MOVE "SOC SEC NO" TO HSOC-SEC. MOVE "NAME" TO HNAME. MOVE "HIRE DATE" TO HHIRE-DATE. WRITE PREC AFTER ADVANCING PAGE. MOVE 0 TO LNCNT.
Sequential Organization Files The CODE-SET Clause By default, a sequential le contains ASCII data. If your sequential le contains non-ASCII data, you must use the CODE-SET clause to specify its character code convention. Example. The following program illustrates the CODE-SET clause: IDENTIFICATION DIVISION. PROGRAM-ID. FILE-EX1. * This program converts an EBCDIC file into an ASCII file. ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. ALPHABET EBCDIC IS EBCDIC. INPUT-OUTPUT SECTION.
Sequential Organization Files Circular Files A circular le is organized like a sequential organization le, except that it has no \last" record when being written. The record that would be \last" in an ordinary sequential organization le is followed (conceptually) by the record that would be \ rst." The diagrams below shows an ordinary sequential organization le with eight records and a circular le with eight records, for comparison.
Sequential Organization Files This example program uses the following: A circular le for output. A variable record le input. See \Variable Records." A SYMBOLIC CHARACTERS clause, an ANSI85 feature. See Chapter 2. Example.
Sequential Organization Files P1. OPEN INPUT IFILE OUTPUT OFILE. PERFORM WITH TEST AFTER UNTIL IREC = "//" READ IFILE AT END MOVE 2 TO LEN MOVE "//" TO IREC NOT AT END IF IREC "//" ADD 1 TO LEN MOVE CR TO ICHARS(LEN) CALL INTRINSIC "COMMAND" USING IREC ERROR-CODE PARM WRITE OREC FROM IREC END-IF END-READ END-PERFORM CLOSE IFILE OFILE STOP RUN.
Sequential Organization Files Message Files A message le is organized like a sequential organization le that is open for input or output access. Programs use message les to communicate with each other. The two ways to create a message le are: Use the MPE BUILD command, like this: lename;MSG Use the MPE FILE command to cause COBOL to create a message le, like this: FILE lename;MSG You must open a message le with the INPUT, OUTPUT, or EXTEND option.
Sequential Organization Files 020000 021000 022000 023000 024000 025000 026000 027000 028000 029000 030000 031000 032000 033000 034000 035000 036000 037000 038000 039000 040000 041000 042000 043000 044000 045000 046000 047000 048000 049000 050000 051000 052000 053000 01 REDEFINES DEPENDENCY-TABLE. 05 PROGRAM-NAME PIC X(8) OCCURS 5 TIMES ASCENDING KEY IS PROGRAM-NAME INDEXED BY I. PROCEDURE DIVISION. P1. WAITING-TO-GO. OPEN INPUT IFILE. CALL INTRINSIC "FCONTROL" USING IFILE, 45, TRUE-VALUE.
Sequential Organization Files Each of the ve jobs contains code similar to this: 001000 002000 003000 004000 005000 006000 007000 008000 009000 010000 011000 012000 013000 014000 015000 016000 017000 5-18 Files IDENTIFICATION DIVISION. PROGRAM-ID. FILEX51. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT OFILE DATA DIVISION. FILE SECTION. FD OFILE. 01 OREC PROCEDURE DIVISION. P1. OPEN EXTEND OFILE. MOVE "FILEX51" TO OREC WRITE OREC CLOSE OFILE STOP RUN. ASSIGN "MFILE". PIC X(8).
Sequential Organization Files This job stream streams the ve jobs and the summary job: :job jfilemsg,user.account :purge mfile :build mfile;msg;rec=-8,,,ascii;disc=10 :stream ,% %job jfilex6,me.myacct/paswd;inpri=7;outclass=pp,3 %file mfile;semi %run pfilex6 %eoj %job jfilex51,me.myacct/paswd;inpri=7;outclass=pp,3 %file mfile;semi %run pfilex51 %eoj %job jfilex52,me.myacct/paswd;inpri=7;outclass=pp,3 %file mfile;semi %run pfilex52 %eoj %job jfilex53,me.
Random Access Files Random Access Files A random access le is so named because any record can be accessed at any time by its key. The key corresponds to the record number minus one (for example, key zero is the rst record and key four is the fth record). The MPE XL operating system does not distinguish between random access and sequential organization les. Therefore, a random access le can be treated like a sequential organization le.
Random Access Files How to Code Random Access Files The code that your program needs in order to perform input and output with random access les is the following: 1. In the ENVIRONMENT DIVISION, a SELECT statement with an ASSIGN clause for each le. The clauses ACCESS MODE IS RANDOM and ACTUAL KEY are required. 2. In the FILE SECTION of the DATA DIVISION, an FD entry to match each SELECT statement, with an 01 record for each le. 3.
Random Access Files Example. The following program uses random access les. 001000 IDENTIFICATION DIVISION. 002000 PROGRAM-ID. RANDCRSC. 003000* This program creates a simple random file to show the 004000* blank record created. 005000 ENVIRONMENT DIVISION. 006000 INPUT-OUTPUT SECTION. 007000 FILE-CONTROL. 008000 SELECT RANDFILE ASSIGN TO "RANDFILE" 009000 ACCESS IS RANDOM 009100 ACTUAL KEY IS RANDKEY. 010000 011000 DATA DIVISION. 012000 FILE SECTION. 013000 FD RANDFILE. 014000 01 RANDREC.
Random Access Files The preceding program creates a temporary random access le named RANDFILE.
Relative Organization Files Accessing Random Access Files Sequentially The MPE XL operating system does not distinguish between random access and sequential organization les. The distinction is made by the HP COBOL II/XL compiler, which generates di erent code for random access les. This means that a le can be created as a sequential organization le by one program and treated as a random access le by another program, or vice versa.
Relative Organization Files How to Code Relative Organization Files The code that your program needs to perform input and output with relative organization les depends on how you want to access the le. You can access a relative organization le sequentially, randomly, or dynamically. Sequential access is the default. You may specify ACCESS IS SEQUENTIAL in the SELECT statement or omit it. Sequential access allows you to access records in order.
Relative Organization Files Table 5-4 lists the access modes for relative organization les, the open modes associated with them, the I-O statements that are valid with those open modes, and the phrases that are valid and invalid with those I-O statements. Table 5-4.
Relative Organization Files Table 5-4. Acess Modes, Open Modes, and Valid I-O Statements for Relative Organization Files (continued) Access Mode Random Open Mode Valid Statements Valid Phrases INPUT READ INTO, INVALID KEY, NOT INVALID KEY, END-READ AT END, NOT AT END OUTPUT WRITE All phrases. None. I-O READ INTO, INVALID KEY, NOT INVALID KEY, END-READ AT END, NOT AT END REWRITE, All phrases. DELETE, WRITE Dynamic Invalid Phrases None. READ None. All phrases.
Relative Organization Files This program writes records to a relative le, using a simple hashing algorithm to map Social Security numbers to three-digit numbers. The hashing algorithm uses the last three digits of the Social Security number as the key. If there is a duplicate key, the hashing algorithm adds one to the key until it is unique. Example. 001000 IDENTIFICATION DIVISION. 002000 PROGRAM-ID. HASHSC. 003000* This program writes records to a relative file using 004000* a hashing scheme.
Relative Organization Files 029000 030000 031000 032000 033000 034000 035000 036000 037000 038000 039000 040000 041000 042000 043000 044000 045000 046000 047000 048000 049000 050000 051000 052000 053000 054000 055000 PROCEDURE DIVISION. 000-MAIN-PROG. OPEN OUTPUT RELFILE. PERFORM 100-GET-SS PERFORM WITH TEST AFTER UNTIL NO-MORE-SS-NUMBERS PERFORM 200-WRITE-TO-RELFILE UNTIL SUCCESS SET RESET-SWITCH TO TRUE PERFORM 100-GET-SS END-PERFORM CLOSE RELFILE. STOP RUN. 100-GET-SS. ACCEPT IN-SS-NO.
Indexed Organization Files Indexed Organization Files An indexed le is so named because each record has an index, which is an alphanumeric key. An indexed le is organized as an MPE XL KSAM le is organized. You can access both Native Mode and Compatibility Mode KSAM les from HP COBOL II/XL programs. Refer to Using KSAM/XL and the KSAM/3000 Reference Manual for details.
Indexed Organization Files Example. The following program uses an indexed organization le: 001000 IDENTIFICATION DIVISION. 002000 PROGRAM-ID. INDEXSC. 003000* This program reads an indexed file dynamically. It does a 004000* random read to get to the specific ALUM record desired, then 005000* it reads sequentially forward through the records of that alumnus 006000* to total all the gifts made by that alumnus. 007000 ENVIRONMENT DIVISION. 008000 INPUT-OUTPUT SECTION. 009000 FILE-CONTROL.
Indexed Organization Files 040000 041000 042000 043000 044000 045000 046000 047000 048000 049000 050000 051000 052000 053000 054000 055000 056000 057000 058000 059000 060000 061000 062000 063000 064000 065000 066000 067000 068000 069000 070000 071000 072000 073000 074000 075000 076000 077000 078000 079000 080000 081000 5-32 Files PROCEDURE DIVISION. 000-MAIN-PROG. OPEN INPUT ALUMFILE OUTPUT PRINT-FILE.
Indexed Organization Files Creating Indexed Files If your program is to use an indexed le that does not exist, HP COBOL II/XL (Native Mode) by default creates a temporary Native Mode KSAM le|one le. If an indexed le has variable length records, HP COBOL II/XL creates a temporary Compatibility Mode KSAM le. HP COBOL II/V (Compatibility Mode) by default creates a temporary Compatibility Mode KSAM le. Compatibility Mode KSAM les consist of two temporary les: a data le and an index le.
Indexed Organization Files 003410 003500 003600 003610 003620 003630 003700 003710 003780 READ TFILE AT END MOVE ALL "9" TO TREC END-READ PERFORM UNTIL TREC = ALL "9" WRITE NREC FROM TREC INVALID KEY DISPLAY "ERROR" TREC END-WRITE READ TFILE AT END MOVE ALL "9" TO TREC END-READ END-PERFORM CLOSE TFILE NEWFILE STOP RUN. Sequential Access of Indexed Files For an indexed le, sequential access is in ascending key order.
Indexed Organization Files Generic Keys A generic key is a partial key, the rst n digits of a key. It is speci ed in the START statement. In the following example, SOURCE-NO is a generic key. The START statement nds the rst record that contains the generic key. Example. SELECT I-FILE ASSIGN TO "INVFILE" ORGANIZATION IS INDEXED RECORD KEY IS PART-NO. 01 IREC. 05 PART-NO. 10 SOURCE-NO PIC XXXX. 10 ITEM-NO PIC XXXX. 05 FILLER PIC X(72).
Variable Length Records Variable Length Records Variable length records are allowed in every logical le organization. For random access les and relative organization les, HP COBOL II simulates variable length records by using xed length records. HP COBOL II builds the le with a record size two bytes longer than the largest logical record, rounded up to a two-byte boundary, de ned by the program. No space is saved.
Variable Length Records When reading variable length records, do one of the following: In the FILE SECTION, de ne the record as OCCURS DEPENDING ON, using the same data item as you use in the DEPENDING ON phrase of the RECORD IS VARYING and OCCURS clauses. Use a READ . . . INTO statement to blank out the un lled part of the record in the WORKING-STORAGE SECTION. Before each READ statement executes, blank out the record associated with the FD level indicator.
Variable Length Records Example The following program illustrates variable length records. It opens the same le with and without the DEPENDING ON phrase. Note that in EXAMPLE 2, IREC2 is not overwritten by a READ statement, but READ INTO does overwrite the working storage record. 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.
Variable Length Records DISPLAY "EXAMPLE 3 READ INTO WREC" MOVE ALL "X" TO IREC2 WREC READ IFILE2 INTO WREC AT END MOVE -1 TO LEN DISPLAY IREC2 DISPLAY WREC CLOSE IFILE2.
Physical Files Physical Files A physical le exists outside your program, on a device such as a tape or disk. In contrast, a logical le is a data structure that your program declares. When you associate a physical le with a logical le and execute your program, everything that your program does to the logical le happens to the physical le. This section explains the following: The ASSIGN clause, which associates a logical le with a physical le.
Physical Files ASSIGN Clause The ASSIGN clause associates a logical le with a physical le. It is required for les of all types. The OPEN statement looks for a physical le named in the ASSIGN clause to associate with the logical le. It looks for these physical les in this order: 1. A le equation rst. 2. A temporary physical le second. 3. A permanent physical le last. Note If present, the contents of the item in the USING phrase is used instead of the literal in the ASSIGN clause.
Physical Files FILE Command The MPE FILE command, also called a le equation, performs one or both of the following: Associates a physical le in the MPE environment with the logical le de ned by your program. Speci es attributes for the logical le, overriding the name and other attributes that the program speci es in the OPEN statement. The FILE command can override the following attributes: File name, including optional node name. File size, including number of extents (new les only).
Physical Files Figure 5-2 shows the algorithm that the run-time library uses to determine le attributes when it opens a le. For the default attributes of the :FILE command, see this command in the MPE XL Commands Reference Manual . Figure 5-2. Algorithm for Determining File Attributes Some le attributes are xed. That is, they are established when the le is created and cannot be changed. The xed le attributes are: Organization. Alternate record key. Primary record key. Code set.
Physical Files Dynamic Files (USING phrase) You can assign a logical le to a physical le dynamically, at run time. Normally, you assign the physical le statically in the ASSIGN clause by naming the le in the TO phrase. With the USING phrase of the ASSIGN clause, instead of specifying the name of the physical le, you specify a data item to contain the name of the physical le. You can then change the value of the data item at run time to open di erent physical les.
Physical Files 003000 003100 003200 003300 003400 003500 003600 003700 003800 003900 004000 004100 004200 004300 004400 004500 004600 004700 004800 004900 005000 005100 005200 005300 005400 005500 005600 005700 005800 005900 006000 006100 006200 006300 006400 006500 006600 006700 006800 PROCEDURE DIVISION. FIRST-PARA. PERFORM UNTIL NO-MORE-FILES MOVE SPACES TO FILE-NAME, INFILE-STAT DISPLAY "Enter the name of the file to list.
Overwriting, Updating and Appending to Files Below is sample output from the above program. Enter the name of the file to list. Enter // if no more files: FILE1 Here is line 1 of FILE1. Here is line 2 of FILE1. Press Return: Enter the name of the file to list. Enter // if no more files: FILEA Here is line 1 of FILEA. Here is line 2 of FILEA. Here is line 3 of FILEA. Here is line 4 of FILEA. Press Return: Enter the name of the file to list. Enter // if no more files: FILE2 Could not find the file.
Overwriting, Updating and Appending to Files Overwriting Files When you overwrite an existing le, you cannot make it larger unless it is on tape. If it is not on tape, space is limited to the original allocation. Updating Files You can update a sequential le with the REWRITE statement if the le resides on a disk. If it resides on tape, you cannot update it. Appending to Files To append records to a le, you must include the EXTEND phrase in the OPEN statement.
File Status Codes File Status Codes The optional FILE STATUS clause speci es a data-item that contains a le status code after any I-O statement (except RETURN) is applied to the le. Your program can contain USE procedures that examine the values of such data-item s and perform accordingly. The rst digit of a le status code indicates one of the following: The I-O operation was successful. An AT END condition occurred. An INVALID KEY condition occurred. A permanent error occurred. A logical error occurred.
File Status Codes Note The COBOL error message catalog le, COBCAT.PUB.SYS, is updated and released with each compiler version. It contains all the documentation relevant to the compiler and run-time error messages for the matching compiler version, including cause and action information for each error. Following each new update of the product version, you should use the new version of COBCAT.PUB.SYS for this information.
File Status Codes Table 5-7 groups the ANSI 1985 le status codes by category and explains what each code means for sequential access les, random access les, relative organization les, and indexed le Each entry applies to the columns that it crosses; for example, the information on the le status code 00 applies to all le types. Table 5-7.
File Status Codes Table 5-7. ANSI 1985 File Status Codes (continued) File Status Code Category INVALID KEY File Status Code 21 22 23 24 Permanent Error 30 31 34 35 37 38 39 File Type Random Access or Relative Organization Indexed Organization (KSAM) Sequence error. WRITE or WRITE error. REWRITE error. Tried to write a duplicate key (does Tried to write a not apply to duplicate key. REWRITE.) Not applicable. START or READ of missing optional le, or record does not exist.
File Status Codes Table 5-7. ANSI 1985 File Status Codes (continued) File Status Code Category Logic Error File Status Code 41 42 43 44 46 47 48 49 ImplementationDe ned 5-52 Files 9x File Type Indexed Random Access or Organization Relative Sequential Organization (KSAM) Access OPEN on le that is already open. CLOSE on le that was not open. No READ before No READ before REWRITE or REWRITE. READ DELETE. is required before REWRITE.
File Status Codes Table 5-8 groups the ANSI 1974 le status codes by category and explains what each code means for sequential access les, random access les, relative organization les, and indexed le Each entry applies to the columns that it crosses; for example, the information on the le status code 00 applies to all le types. Table 5-8.
File Status Codes Table 5-9. Differences between ANSI 1985 and ANSI 1974 File Status Codes ANSI 1985 Status Code 00 02 04 05 07 10 14 Equivalent ANSI 1974 Status Code Same. Same. 00 00 00 Same. 00 21 22 23 24 Same. Same. Same. 24 30 34 35 Same. None. 00 5-54 Files Execution Di erence ANSI 1985 ANSI 1974 Not applicable. Not applicable. Same. Same. Same. Not applicable. READ fails becaust the value READ succeeds. of the data item is greater than the PICTURE that describes the key. Not applicable.
File Status Codes Table 5-9. Differences between ANSI 1985 and ANSI 1974 File Status Codes (continued) ANSI 1985 Status Code 37 38 39 41 42 43 44 46 47 48 49 Execution Di erence Equivalent ANSI ANSI 1985 ANSI 1974 1974 Status Code The OPEN succeeds and the 00 The OPEN fails and a program continues to permanent error condition execute, although it can exists for the le. abort later for another reason.
File Status Codes Sequence of Events If the le status code indicates that the I-O operation was successful, the following occur: The NOT AT END or NOT INVALID KEY phrase is executed, if present. USE procedures, the AT END phrase, and the INVALID KEY phrase are not executed. If the SELECT phrase for the le contains a FILE STATUS phrase, the appropriate le status code is returned.
File Status Codes Example 1 The following program declares a FILE STATUS item, CHECK-TAPE, and checks it after the READ statement. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT TAPEIN ASSIGN TO "READTAPE" FILE STATUS IS CHECK-TAPE. DATA DIVISION. FILE SECTION. FD TAPEIN. 01 TAPE-REC PIC X(80). WORKING-STORAGE SECTION. 77 MPE-ERROR PIC 9(4) USAGE DISPLAY. 01 CHECK-TAPE. 02 STAT-KEY-1 PIC X. 02 STAT-KEY-2 PIC X. PROCEDURE DIVISION. . . . READ TAPEIN AT END PERFORM NO-MORE-TAPE.
File Status Codes Figure 5-3 shows what happens when a run-time I-O error occurs. Figure 5-3.
File Status Codes Example 2 The following program creates a tape le, closes it, then opens it as an input le. Fields in the input records are compared to the values written to ensure that they were processed correctly. The program uses the FILE STATUS clause and a USE statement for error handling. IDENTIFICATION DIVISION. PROGRAM-ID. EXAMPLE. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT FILE-A ASSIGN TO TNAME1 ORGANIZATION SEQUENTIAL ACCESS SEQUENTIAL FILE STATUS IS STATUS-FIELD.
File Status Codes PROCEDURE DIVISION. DECLARATIVES. SECT-EXAMPLE-01 SECTION. USE AFTER STANDARD EXCEPTION PROCEDURE ON FILE-A. TEST-STATUS. IF SFIELD EQUAL TO "1" MOVE 1 TO EOF-FLAG GO TO EXIT-PARA. ADD 1 TO RECORDS-IN-ERROR. EXIT-PARA. EXIT. END DECLARATIVES. SECT-EXAMPLE-02 SECTION. INITIAL-PARA. MOVE SPACE TO STATUS-FIELD. MOVE "FILE-A" TO XFILE-NAME. MOVE "EXAMPLE" TO XPROGRAM-NAME. MOVE 500 TO RECORDS-IN-FILE. MOVE "S" TO XLABEL-TYPE. MOVE 000001 TO XRECORD-NUMBER. OPEN OUTPUT FILE-A. INIT-FILE.
File Status Codes TEST-READ. READ FILE-A RECORD. IF EOF-FLAG EQUAL TO 1 GO TO TEST-READ-01. MOVE FILE-RECORD TO FILE-RECORD-INFO-1. ADD 1 TO COUNTER. IF COUNTER GREATER THAN 500 DISPLAY "MORE THAN 500 RECORDS" GO TO FAIL-TEST. IF COUNTER NOT EQUAL TO XRECORD-NUMBER ADD 1 TO RECORDS-IN-ERROR GO TO TEST-READ. IF XFILE-NAME NOT EQUAL TO "FILE-A" ADD 1 TO RECORDS-IN-ERROR GO TO TEST-READ. IF XLABEL-TYPE NOT EQUAL TO "S" ADD 1 TO RECORDS-IN-ERROR. GO TO TEST-READ. TEST-READ-01.
6 From Program Creation to Program Execution Introduction This chapter explains the following: How to input your source program to the compiler. The control le that the compiler puts in the front of your source le. The control options with which you can compile your program. How to compile, link, and edit your program.
Program Creation and Execution Source Program Input You can input your source program to the COBOL compiler in these three ways: 1. In an ASCII le. 2. In an HP TOOLSET TSAM le. 3. One line at a time, through the standard input le, $STDIN (which can be your terminal). ASCII File Using an editor, you can create your program in an ASCII le. Then, you can input the ASCII le to the COBOL compiler. TSAM File Using HP TOOLSET, you can create your program in a TSAM le.
Program Creation and Execution $STDIN File You can input your program one line at a time through the standard input le, $STDIN. The default for $STDIN is your terminal if you are running the compiler interactively. If you are running the compiler from a job stream, the default for $STDIN is the job stream le. In either case, end the source program with \:4RETURN5". Example In this example, your input from the terminal is underlined. :COB85XL PAGE 0001 HP31500A.00.00 [85] (C) HEWLETT-PACKARD CO.
Control File Control File When you compile your COBOL program, the compiler includes the control le at the beginning of your source le. The default control le is COBCNTL.PUB.SYS. It contains only comments, but you can add control options to it. If a le equation that names COBCNTL.PUB.SYS as a formal le designator is in e ect when you run the HP COBOL II/XL compiler, the compiler uses that le equation to nd the control le to include in your program.
Control Options Control Options You can put control options in any of these places: Control le (COBCNTL.PUB.SYS or its substitute). COBOL source code. RUN command info string. When the source le contains nested or concatenated programs, certain control options must appear at the beginning of the source le. If they appear elsewhere, the compiler issues a warning and ignores them. They need only be turned on once.
Control Options Listing Options Listing options a ect the content of the compiler listing. The listing options and their e ects are: Listing Option E ect CROSSREF Prints a cross reference to the list le. The cross reference lists each data and procedure name and the lines that use them. The default is NOCROSSREF. ERRORS=n Sets the error limit to n, an integer. The error limit is the number of errors that the compiler can nd before it aborts the program. The default is ERRORS=100.
Control Options Debugging Options Debugging options aid in debugging. The debugging options and their e ects are: Debugging Option E ect BOUNDS Causes the compiler to generate code that checks for values out of bounds at run time. You can use this information for these purposes: 1. To locate values that are out of range in: a. OCCURS DEPENDING ON identi er statements. b. Subscripts. c. Indexes. d. Reference modi cations. 2. To locate illegal execution of performed paragraphs, speci cally: a.
Control Options Debugging Option VALIDATE E ect Checks numeric and packed decimal operands for illegal digits and signs in every arithmetic operation. If an operand is invalid, the program traps to the trap handler, which does what the programmer speci ed in the COBRUNTIME variable. Whether the program continues after that depends on the value of COBRUNTIME (see \Traps" in Chapter 7).
Control Options Migration Options Migration options aid in migration (from one machine to another and from one COBOL standard to another). The migration options and their e ects are: Migration Option E ect CALLINTRINSIC Causes the compiler to check all CALL statements against the intrinsic le, SYSINTR.PUB.SYS. If the subprogram is in the intrinsic le, but was not called with the CALL INTRINSIC statement, the compiler issues a warning message and generates code to call the intrinsic.
Control Options RLFILE The RLFILE control option, with the RLINIT control option, simulates MPE V object module functionality. On the MPE V operating system, programs and subprograms are compiled into Relocatable Binary Modules, or RBMs. RBMs are stored by compilers in USLs (User Segmented Libraries) which are manipulated by the segmenter and the compilers.
Control Options COBSRCO is an NMRL because the source le speci ed RLFILE. A LISTRL command on COBSRCO in the Link Editor will show three separate object modules in COBSRCO, containing the entries main p , sub 1 , and sub 2 , respectively. These object modules correspond to the three concatenated programs in COBSRC, and they can be purged or separately manipulated in the Link Editor.
Control Options RLINIT The RLINIT control option reinitializes an NMRL object le to empty (similar to USLINIT on MPE V). It has no e ect on an NMOBJ object le. Example. The following example uses COBSRC1 from the previous example: $INCLUDE SUB1 END PROGRAM SUB-1. $INCLUDE SUB2 END PROGRAM SUB-2. The following command compiles COBSRC1: COB85XL COBSRC1,COBSRCO;INFO="$CONTROL RLINIT" The e ect of this step depends on the le code of COBSRCO.
Control Options Table 6-2 applies when no le is speci ed for COBOBJ and $NEWPASS is the object le. Table 6-2. RLFILE/RLINIT Functionally With Default File RLFILE RLINIT Speci ed Object File Action ON ON Nonexistent Existing NMRL Existing NMOBJ Incorrect le code.1 Create NMRL. Rewrite NMRL Create NMRL Create NMRL ON OFF Nonexistent Existing NMRL Existing NMOBJ Incorrect le code.
Control Options Standard Conformance Options Standard conformance options do one of these three things: Cause the compiler to generate ANSI standard code in certain cases (ANSISORT and ANSISUB). Cause the compiler to ag features that conform to one standard but not another (DIFF74, STDWARN). Cancel another standard conformance option (NOSTDWARN).
Control Options Interprogram Communication Options Interprogram communication options make interprogram communication possible. The interprogram communication options and their e ects are: Interprogram Communication Option E ect ANSISUB Maintains values of data items across calls (as SUBPROGRAM does) and allows you to use the CANCEL statement to reset data items to their initial values. The default is that the compilation unit is a main program.
Control Options Example The following shows four programs, A, B, C, and D. ANSISUB applies to programs B and C because C is contained by B, but not to programs A and D. The INITIAL clause in program D's IDENTIFICATION DIVISION has the same e ect and scope as DYNAMIC. In this case it only means that program D is DYNAMIC. Notice that IS INITIAL takes precedence over the control options. IDENTIFICATION DIVISION. PROGRAM-ID. A. DATA .. DIVISION. . PROCEDURE DIVISION. BEGIN. .. .
Control Options Miscellaneous Options Miscellaneous options do not t into any of the preceding option categories. The miscellaneous options and their e ects are: Miscellaneous Option E ect LOCKING Allows your program to lock all les that are opened during its execution (does not lock the les itself). This is not the default. USLINIT This is an HP COBOL II/V option that is ignored by HP COBOL II/XL.
Compiling, Linking, and Executing Programs Compiling, Linking, and Executing Your Program When you compile your program, the COBOL compiler translates your COBOL source program to object code and resolves calls to nested programs. When you link your program, the link editor resolves calls to subprograms that are to be bound at link time (not all subprograms; see Chapter 4). Your program must be linked whether it calls such subprograms or not. The link editor uses object code to produce a program le.
Compiling, Linking, and Executing Programs Figure 6-2 shows the input to the COBOL compiler and the output from it. Note that COPYLIB and INCLUDE les can also be used for input. Formal le designators are in italic capital letters. Figure 6-2. COBOL Compiler Input and Output The rest of this section explains the following: The two compiler entry points and the two compiler modes. How to use le equations with the FILE command. How to run the COBOL compiler with the MPE XL RUN command.
Compiling, Linking, and Executing Programs Compiler Entry Points and Modes The COBOL compiler is \two compilers in one." That is, it has two entry points, ANSI74 and ANSI85. When you invoke it through the ANSI74 entry point, ANSI COBOL 1974 syntax and semantics apply. When you invoke it through the ANSI85 entry point, ANSI COBOL 1985 syntax and semantics apply. The ANSI74 entry point is provided for compatibility with older COBOL compilers.
Compiling, Linking, and Executing Programs File Equations When you use a le equation (the FILE command), its formal designator must match the le name in the ASSIGN clause of the SELECT statement. Example The following SELECT statement declares the logical le MY-FILE: SELECT MY-FILE ASSIGN TO "MFILE".
Compiling, Linking, and Executing Programs Native Mode Compiler Command Files and RUN Command You can invoke the Native Mode COBOL compiler and compile your COBOL program in Native Mode with either the RUN command or one of the six command les COB85XL, COB85XLK, COB85XLG, COB74XL, COB74XLK, or COB74XLG. These command les can compile, link, and execute your program. You can use one of the six existing command les or write your own.
Compiling, Linking, and Executing Programs Syntax of UDCs COBOLIIX [text le][,[usl le[,[list le][,[master le] [,[new le]]]]]][,info] COBOLIIXPREP [text le][,[prog le[,[list le][,[master le] [,[new le]]]]]][,info] COBOLIIXGO [text le][,[list le][,[master le] [,[new le]]]][,info] Syntax of Commands COBOLII [text le][,[usl le[,[list le][,[master le] [,[new le]]]]]] [;INFO=info][;WKSP=workspacename] COBOLIIPREP [text le][,[prog le[,[list le][,[master le] [,[new le]]]]]][;INFO=info][;WKSP=workspacename] COBO
Compiling, Linking, and Executing Programs Parameters text le usl le prog le list le master le new le info MPE or TSAM le containing your source program. This le can be compiled. The formal designator is COBTEXT. The default is $STDIN. Relocatable object code le. This le can be linked. The formal designator is COBUSL. The default is $OLDPASS. Executable program le. This le can be executed. The default is $NEWPASS. MPE le on which your source code will be listed. The formal designator is COBLIST.
Compiling, Linking, and Executing Programs Libraries Your program can use subprograms from relocatable libraries and executable libraries. Relocatable and executable libraries di er in content and in when they are referenced. The following table lists these di erences: Table 6-6. Differences between Relocatable and Executable Libraries Library Contents Referenced At Relocatable (RL) Relocatable object modules. Link time. Executable (XL) Executable object modules. Run time.
Compiling, Linking, and Executing Programs Executable Libraries An executable library contains executable object modules and is referenced at run time. The three ways to tell the operating system which executable library contains the subprograms for your program are: 1. Specify the library in the LINK command. The advantage of this method is that you need not remember to specify the library in the RUN command each time you execute your program.
Compiling, Linking, and Executing Programs Examples of Compiling, Linking, and Executing Programs This section contains several examples of compiling, linking and executing programs. Example 1 The rst example compiles, links, and executes a program. Either the program calls no subprograms, or the subprograms that it calls are in the executable library NL.PUB.SYS or XL.PUB.SYS.
Compiling, Linking, and Executing Programs The END PROGRAM header is not necessary for the last concatenated program in a le. This is an easy way to migrate your current main and subprograms to concatenated programs, and simplify your compiles and links. The following commands compile and link the le COBSRC: :COB85XL COBSRC :LINK :$OLDPASS The defaults for the object le and program le are used above. The RUN keyword is not necessary to run the program le, $OLDPASS.
7 Debugging Your Program Introduction This chapter does the following: Lists the control options that aid debugging (explained in Chapter 6.) Explains how to use the compiler listing and link map in debugging your program. Lists messages issued at compile time and run time. Describes Debug, the MPE XL System Debugger. Describes the symbolic debuggers (HP Symbolic Debugger/XL and HP TOOLSET/XL debugger). Lists compiler limits and how to work around some of them.
Debugging Your Program Compiler Listing The compiler listing that the compiler produces when you specify the control options MAP and VERBS provides most of the information that you need to debug your program. The remainder of the information is supplied by the link map. For information on the MAP and VERBS control options, see Chapter 6. For information on the link map, see \Link Map," under \Using Debug.
Debugging Your Program 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 031000 PROCEDURE DIVISION USING DATE-IN DATE-OUT. 032000 STARTA.
Debugging Your Program [12] PAGE 0003/COBTEXT DATEFORMAT LINE# LVL SOURCE NAME BASE STORAGE LAYOUT SP SP SP (1) SP SP SP (2) SP SP [28] -130 -124 -120 -11C -118 -118 -88 -80 4 \ 4 | 4 | 4 | [27] 4 | 90 | 8 | 44 / The symbol table map on PAGE 0003 is due to the control option MAP. The address of each data name in the program is speci ed in terms of base and o set to that base.
Debugging Your Program PAGE 0005/COBTEXT DATEFORMAT CHAR-CNT DATE-IN DATE-OUT DD-IN I MM-IN MONTH-NAME MONTH-NAMES MONTH-TABLE PGM-ID YEAR-4 YY-IN [32] CROSS REFERENCE LISTING IDENTIFIERS 00013 00042 00045 00049 00032 00037 00039 00036 00037 00044 00048 00035 00047 00030 00040 00043 00034 00040 00029 00043 00015 00028 00028 00012 00014 00041 00047 00033 00041 00051 00051 [33] PAGE 0006/COBTEXT DATEFORMAT EXIT-PARA STARTA PAGE 0007/COBTEXT COBOL ERRORS: DATEFORMAT LINE # SEQ # COL ERROR ------ -
Debugging Your Program The bracketed numbers on the preceding compiler listing have these meanings: Num- Meaning of Listing ber [1] Version number of the compiler. Use this number when communicating with Hewlett-Packard about this compiler. [2] Entry point (85 for ANSI85, 74 for ANSI74). [3] Compilation date. [4] Copyright for compiler. [5] Control le (COBCNTL.PUB.SYS here). [6] info string. [7] Compiler-generated listing line number (also called statement number).
Debugging Your Program [17] [18] [19] [20] [21] O set from base (in hexadecimal, positive or negative). An asterisk after an o set indicates non-optimal alignment of data name. Size in bytes (hexadecimal). USAGE. Terms and meanings are: Term Meaning DISP DISPLAY. COMP COMPUTATIONAL or BINARY. COMP-SYNC COMPUTATIONAL SYNCHRONIZED or BINARY SYNCHRONIZED. COMP-3 COMPUTATIONAL-3 or PACKED-DECIMAL. INDEX Index (in USAGE IS INDEX). INDEX NAME Index name (in an INDEXED BY clause).
Debugging Your Program [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] 7-8 Category. The categories and their meanings are: Category Meaning N Numeric A Alphabetic AN Alphanumeric NE Numeric edited ANE Alphanumeric edited NS Signed numeric, sign trailing SN Signed numeric, sign leading NS-SEP Signed numeric; sign trailing, separate SEP-SN Signed numeric; sign leading, separate R indicates REDEFINES clause. O indicates OCCURS clause.
Debugging Your Program Messages This section explains the messages that help you debug your program. They are of two types, compile-time messages and run-time error messages. Compile-time messages are issued by the compiler, and are not always associated with errors. Run-time error messages are issued by the COBOL run-time library, and are always associated with errors. Text for both types of errors comes from the le COBCAT.PUB.SYS (COBOL CATalog). Beneath the text of each error message, COBCAT.PUB.
Debugging Your Program For each class of compile-time message, Table 7-2 gives the message number range, the JCW setting, an explanation, and advice. Table 7-2. Compile-Time Message Severities Message Severity Message Number Range JCW Setting Explanation Advice If the \worst case" could happen, change the code so that it will execute correctly in that case. Warning (W) 1-99 Not set. The compiler generated code for the program, but it will not execute correctly in the \worst case.
Debugging Your Program Run-Time Error Messages Run-time error messages are numbered from 500 to 755 and are issued by the HP COBOL II/XL run-time library. Unlike compile-time messages, they are always associated with errors. The errors fall into two classes: input-output errors and traps. This section explains input-output errors and data validation, a related issue. This section only brie y describes traps. The HP COBOL II/XL Reference Manual explains traps and how to handle them.
Debugging Your Program Run-Time Traps A run-time trap is an interruption of the ow of program control, caused by an exception condition. After a trap-handling routine executes, the program can sometimes be restarted, depending on how you set the environment variable COBRUNTIME. The COBOL compiler supports the following traps: Illegal Decimal Digit (Error 710). Illegal ASCII Digit (Error 711).
Debugging Your Program Table 7-3 gives the valid ASCII digits with which invalid unsigned ASCII digits are replaced if you specify the run-time error handling option M or N. Any invalid unsigned ASCII digit that does not appear in Table 7-3 is replaced by zero. Table 7-3.
Debugging Your Program Using Debug Debug, the MPE XL System Debugger, allows you to analyze your program's object code while it is executing. With Debug, you can do the following: Display data item values. Change data item values and continue program execution. Set breakpoints at statements. Set breakpoints at data items. You can cause the program to break when a speci ed data item changes value. This section is not a Debug tutorial.
Debugging Your Program This section does the following: Explains the symbol table, verb, and link maps. Gives an example of a chunked program and its maps. Gives an example of nested and concatenated programs and their maps. Explains how to get data and program o sets at run time. Explains how to nd subprogram parameters. Explains register meanings. Explains how to calculate the addresses of data items. Explains how to calculate code addresses. Explains how to debug trap errors with Debug.
Debugging Your Program Link Map A link map lists the following actual starting addresses, which you need in order to set breakpoints at statements and display data. A link map is one way to nd the addresses of chunk entry points and OWN and EXTERNAL data. The other way is to use the PROCLIST command when you execute your program under Debug. Starting addresses of chunks, if applicable. See \Maps Example for Chunked Program." Each chunk name that appears in the verb map is the starting address of a chunk.
Debugging Your Program Maps for Chunked Program For a large program, the executable code is in chunks. Each chunk is in a separate subspace, but they all reside in the same le. When reading a verb map and using Debug, code o sets are o set from the beginning of chunks. Chunk names are derived from the program-id , as explained in Chapter 4. See \Calculating Code Addresses" to determine how to nd code addresses of chunks. Example The following compiler listing for a chunked program includes a verb map.
Debugging Your Program PAGE 0002/COBTEXT NC101 STATEMENT OFFSETS Entry = nc101 STMT OFFSET STMT OFFSET STMT OFFSET STMT 261 262 263 264 265 266 267 268 . . .
Debugging Your Program PAGE 0011/COBTEXT NC101 COBOL ERRORS and WARNINGS COBOL ERRORS: LINE # ------ SEQ # ------ COL --- ERROR ----- SEV --- 00957 00973 00989 01005 096400 098000 099600 101200 80 80 80 80 050 050 050 050 W W W W TEXT OF MESSAGE --------------ARITHMETIC ARITHMETIC ARITHMETIC ARITHMETIC OVERFLOW OVERFLOW OVERFLOW OVERFLOW MAY MAY MAY MAY OCCUR. OCCUR. OCCUR. OCCUR. 0 ERRORS, 0 QUESTIONABLE, 4 WARNINGS DATA AREA IS 9FC BYTES. CPU TIME = 0:01:20. WALL TIME = 0:06:19.
Debugging Your Program The following shows a Link Editor session that displays the link map of the chunked program: :LINK $OLDPASS;MAP HP Link Editor/XL (HP30315A.02.27) Copyright Hewlett-Packard Co 1986 LinkEd> link $OLDPASS;MAP PROGRAM XL LIST CAPABILITIES NMHEAP SIZE NMSTACK SIZE VERSION : $OLDPASS : : BA, IA : : : 85082112 Sym Name ---$START$ _start nc101 $RECOVER_END $RECOVER_START $START$ $UNWIND_END $UNWIND_START _start nc101 nc101$001$ M$1 . . .
Debugging Your Program Example Maps for Nested and Concatenated Programs This compiler listing is for two concatenated programs, MAIN-P and CONCAT-P. The rst program, MAIN-P, contains a nested program, NESTED-P. The compiler appends the maps to the end of the listing of all three programs. First the symbol maps and cross reference appear, followed by the verb maps. Note that the nested program NESTED-P is compiled with $CONTROL DYNAMIC.
Debugging Your Program PAGE 0002/COBTEXT MAIN-P LINE# LVL SOURCE NAME SYMBOL TABLE MAP BASE OFFSET SIZE USAGE CATEGORY R O J BZ 00006 01 DUMMY-N DP+ N PAGE 0003/COBTEXT MAIN-P LINE# LVL SOURCE NAME SYMBOL TABLE MAP BASE OFFSET SIZE USAGE WORKING-STORAGE SECTION STORAGE LAYOUT FIRST TIME FLAG, etc. RUN TIME $ .
Debugging Your Program PAGE 0005/COBTEXT NESTED-P SYMBOL TABLE MAP LINE# LVL SOURCE NAME BASE OFFSET SIZE USAGE STORAGE LAYOUT FIRST TIME FLAG, etc. RUN TIME $ .
Debugging Your Program PAGE 0008/COBTEXT CONCAT-P STMT OFFSET STMT 8 1C 9 STATEMENT OFFSETS Entry = main_p OFFSET STMT OFFSET STMT OFFSET ... STATEMENT OFFSETS Entry = main_p$003$nested_p STMT OFFSET STMT OFFSET ... 1C PAGE 0009/COBTEXT CONCAT-P STMT OFFSET STMT OFFSET 19 60 20 60 PAGE 0010/COBTEXT CONCAT-P STMT OFFSET STMT OFFSET 33 48 34 48 21 22 E8 STATEMENT OFFSETS Entry = concat_p STMT OFFSET STMT OFFSET 0 ERRORS, 0 QUESTIONABLE, 0 WARNINGS DATA AREA IS 84 BYTES.
Debugging Your Program Subprogram Parameters Memory contains two copies of each set of subprogram parameters. The two copies allow multiple entry points. Parameters are stored in dynamically allocated memory and referenced through the stack pointer (SP, register 30) or the previous stack pointer (PSP). You can access one copy only if you are at a breakpoint at the entry point of the subprogram. The rst four parameters are in registers: Table 7-6.
Debugging Your Program Register Meanings The following registers have the following meanings, independent of COBOL: Table 7-7. Registers 0, 1, and 2 Register Meaning R0 Always zero. R1 Scratch register. R2 Last return address. The following registers are always present: Table 7-8. Registers 27, 30, and 31 Register 7-26 Contents R27 DP, the data pointer. R30 SP, the stack pointer. R31 Millicode return address. Millicode is special utility code for COBOL and other languages.
Debugging Your Program Calculating Addresses of Data Items The rst step in displaying or changing the value of a data item is to nd its address: 1. Obtain symbol table and link maps for your program. 2. On the symbol table map, nd the base and o set of the data item that you want to display or change. The base is DP, SP, EXT, OWN, or P nn , where nn is the parameter number. 3. If the base is DP (the address of the DATA DIVISION of the main program), then the address of the data item is DP+o set .
Debugging Your Program The following format of the PROCLIST command gives you starting o sets of all data areas associated with all programs in your program le. The global area of the outermost program (main) is shown as M$1, as $dp$, and as $global$. The COBOL EXTERNAL item EXT-GRADE is downshifted and the hyphen (\-") replaced with an underscore (\ "). EXTERNAL items have named storage associated with them at run time. The OWN data areas associated with a nested program follow the format M.
Debugging Your Program Calculating Code Addresses You must calculate code addresses in order to set breakpoints in Debug (refer to the MPE XL System Debug Reference Manual for breakpoint syntax). To calculate the code address of a speci c statement: 1. In the verb map, nd the o set for the statement. 2. If the portion of the verb map that lists the o set for the statement does not have \Chunk = name " in its heading, then the statement o set is: program o set + statement o set 3.
Debugging Your Program Debugging Trap Errors Debugging trap errors is easier if you have symbol table, verb, and link maps of your program. The trap error message contains the program counter (pc) address. In the link map, nd the value of the pc. The subprogram in which the trap error occurred is the symbol of type code with the greatest SYM VALUE not greater than the pc value. Subtract that SYM VALUE from the pc value to get the o set of the trap.
Debugging Your Program Illegal ASCII Digit In this example, a program with illegal ASCII digits is executed with the COBRUNTIME value A. The e ect of other COBRUNTIME values is explained after the example. Given the following compiled source program: 00001 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 000100$CONTROL MAP,VALIDATE 001000 IDENTIFICATION DIVISION. 002000 PROGRAM-ID. TRAP-ASCII-DIG. 003000 DATA DIVISION. 004000 WORKING-STORAGE SECTION.
Debugging Your Program When COBRUNTIME is not set (that is, when it has its default value) or when COBRUNTIME is set to A (Abort), and the program is compiled with the control option VALIDATE, this program produces the following information when run in session mode. (When run in a job stream, the output may look slightly di erent. When debugging a program, running it in a session is recommended.) :$OLDPASS Should produce illegal ASCII digit. Illegal ASCII digit (COBERR 711) Program file: $OLDPASS.H6OPT2.
Debugging Your Program The following example shows an illegal ASCII digit error with an invalid sign. The error occurs when attempting to display variables N4 and N4R. C PAGE 0001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 COBOL II/XL HP31500A.04.03 [85] TUE, JUL PM Copyright Hewlett-Packard CO. 1987 9, 1991, 5:18 001000$CONTROL VALIDATE 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. 001300 COBMAIN.
Debugging Your Program 10+10 Illegal ASCII digit (COBERR 711) Program file: $OLDPASS.USER2.COBOL74 Trap type = 00000200 (22,01), at pc = 000000B9.00005E07 invalid ascii digit (S->S) Source address = 4033A0BC, Source = '111' (hex) Source = '313131' DEBUG/XL A.47.01 HPDEBUG Intrinsic at: 678.00351270 cob_trap.print_message+$5c4 $$$$ Trap occurred at: cobmain+$1b4, at Stmt #20 PC=b9.00005e04 cobmain+$1b4 * 0) SP=4033a0f0 RP=b9.
Debugging Your Program Range Error These errors may occur when a subscript or index references an array out of bounds. Given the following compiled source program: 00001 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 10019 00020 00021 00022 001000$CONTROL BOUNDS,MAP 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. BOUNDSEXAMPLE. 001300* This program has a subscript out of bounds. 001400 DATA DIVISION. 001500 WORKING-STORAGE SECTION. 001600 01.
Debugging Your Program When COBRUNTIME is not set (that is, when it has its default value) or when COBRUNTIME is set to A (Abort), and the program is compiled with the control option BOUNDS, this program produces the following information when run in a session. (When run in a job stream, the output may look slightly di erent. When debugging a program, running it in a session is recommended.) :$OLDPASS SUBSCRIPT/INDEX/REFMOD/DEP-ON out of BOUNDS (COBERR 751) Program file: $OLDPASS.H6OPT2.
Debugging Your Program No Size Error The No Size Error trap sometimes occurs where it is not possible to specify ON SIZE ERROR, as in an expression in a relational condition. If the same expression were in a COMPUTE statement, the ON SIZE ERROR phrase would execute. In the following compiled source program, division by zero causes the ON SIZE ERROR trap: 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 001000 identification division. 001100 program-id. zerotrap.
Debugging Your Program PERFORM Stack Overflow Each program has a PERFORM stack, used to keep track of which paragraphs are executing and where to return after execution of a paragraph. This stack can over ow if your program has control- ow bugs, as the following example does. It has recursive PERFORM statements.
Debugging Your Program When COBRUNTIME is not set (that is, when it has its default value) or when COBRUNTIME is set to A (Abort), and the program is compiled with the control option BOUNDS, this program produces the following information when run in a session. (When run in a job stream, the output may look slightly di erent. When debugging a program, running it in a session is recommended.) :$OLDPASS Should give paragraph stack overflow. Paragraph stack overflow (COBERR 748) Program file: $OLDPASS.H6OPT2.
Debugging Your Program Invalid GO TO This example illustrates an invalid GO TO trap, which occurs at an unaltered GO TO statement: 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 001000$CONTROL BOUNDS 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID. TRAPGOTO. 001300 PROCEDURE DIVISION. 001400 TRAP-TEST.
Debugging Your Program Address Alignment Address alignment traps are caught by the Link Editor. You must link with PARMCHECK=0 AND purposely ignore the Link Editor warnings to cause one of these traps. This example illustrates parameter misalignment, where a parameter is passed to a COBOL subprogram that is not 32-bit aligned: 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 001000$CONTROL MAP 001100 IDENTIFICATION DIVISION. 001200 PROGRAM-ID.
Debugging Your Program Here is the compiled subprogram, called by the above main program: 00001 00003 00003 00004 00005 00006 00007 00008 00009 00010 00011 001000$CONTROL MAP,SUBPROGRAM,BOUNDS 001100$CONTROL OPTFEATURES=LINKALIGNED 001200 IDENTIFICATION DIVISION. 001300 PROGRAM-ID. TRAPSUB. 001400 DATA DIVISION. 001500 LINKAGE SECTION. 001600 01 XX PIC X. 001700 PROCEDURE DIVISION USING XX. 001800 P1. 001900 MOVE "**" TO XX. 002000 EXIT PROGRAM.
Debugging Your Program When COBRUNTIME is not set (that is, when it has its default value) or when COBRUNTIME is set to A (Abort), this program produces the following information when run in a session. (When run in a job stream, the output may look slightly di erent When debugging a program, running it in a session is recommended.) :ptrapm SHOULD PRODUCE ALIGNMENT TRAP (753) Address alignment error (COBERR 753) Program file: PTRAPM.H6OPT2.COBOL74 Trap type = 00200000 (10,00), at pc = 000004D0.
Debugging Your Program Invalid Decimal Data in NUMERIC Class Condition This example shows how you can force the NUMERIC class condition on packed decimal data to be true in certain cases where it would otherwise be false. By specifying I in column 9 of COBRUNTIME, any NUMERIC class condition on packed decimal data is true in the following cases: A signed value in an unsigned PACKED-DECIMAL eld. An unsigned value in a signed PACKED-DECIMAL eld. Any invalid sign nibble.
Debugging Your Program When this program is compiled and run either in Native Mode with column 9 of COBRUNTIME set to I, or in Compatibility Mode, it displays the following: DECIMAL-NO-SIGN DECIMAL-SIGN is DECIMAL-NO-SIGN DECIMAL-SIGN is is 123 +123 is NUMERIC. NUMERIC. Invalid sign still makes NUMERIC test true. The following diagram shows the contents of the single data item named by DECIMAL-NOSIGN and rede ned by DECIMAL-SIGN. The values shown are hexadecimal.
Debugging Your Program Traps with COBOL Functions In the following example, the parameter for the FACTORIAL function is out of range. 00001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 000100$control post85 001000 identification division. 001100 program-id. trap-fact. 001200 data division. 001300 working-storage section. 001400 01 n pic s9(18) comp. 001500 01 bad-value pic s999 comp value -1. 001600 procedure division. 001700 p1.
Debugging Your Program In the next example, for a function that uses a procedure in the Compiler Library, an invalid parameter is detected by the Compiler Library routine. The Compiler Library routine generates the math library error message and the COBOL trap handler provides the statement number of the source line that produced the trap. 00001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 000100$control post85 001000 identification division. 001100 program-id.
Debugging Your Program The next example shows an IEEE oating point error. 00001 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 001000$control post85 001100 identification division. 001200 program-id. trap-float-zero. 001300 data division. 001400 working-storage section. 001500 01 n pic s999v999 comp. 001600 01 bad-value pic s999 comp value zero. 001700 procedure division. 001800 p1.
Debugging Your Program Trace Traps Trace traps are \global" breakpoints that are easy to set up and use, providing a very useful tool for quickly isolating program problems within Debug. Trace traps are global in that they apply to all paragraphs and sections, entry and/or exit points. The COBOL compiler generates them within an object program, and once generated, they can be armed and used with Debug on MPE XL. To use trace traps with your program: 1.
Debugging Your Program If you type the underlined command in response to the Debug prompt, the program stops at every section and paragraph. Example. $nmdebug> TRAP LABELS ARM Note 7-50 The SYMDEBUG=TOOLSET control option signi cantly increases the amount of object code and execution time for your program, so use it only while you are debugging your program. When the program works, recompile it without SYMDEBUG.
Debugging Your Program Symbolic Debuggers The symbolic debuggers HP Symbolic Debugger/XL and HP TOOLSET/XL are more powerful and easier to use than Debug, the MPE XL System Debugger. Maps are unnecessary, commands are simple, and labeled function keys are available. If these debuggers are available on your system, you can use them to do the following: Reference data items by their names, instead of their addresses. Display data item values. Change data item values.
Debugging Your Program Compiler Limits The following compiler limits are maximum values that you cannot change. If your program exceeds them, the compiler prints internal error messages. You can work around some of these limits, as noted. Table 7-9. Compiler Limits Limited Entity Maximum Value Work-Around Value pairs per condition-name . 500 (A value pair is a literal , such as 3, or of the form literal THRU literal , such as 10 THRU 20 .
Debugging Your Program Table 7-9. Compiler Limits (continued) Limited Entity Maximum Value Work-Around Nonrede ned 01 and 77 data items in the LINKAGE SECTION. 255 Put separate data items into records in the subprogram and the calling program. PICTURE string. 30 characters. None. Call BY CONTENT. 64K bytes per call. Pass extra parameters by reference. Quali ers per quali ed data name. 50 None. Identi er. 30 characters (ANSI Standard). None. (Use a shorter name). Numeric PICTURE.
Index A address alignment trap, 7-41 addresses data item, 7-27 ADD statement enhancement, 2-8 alignment data, 4-6 parameter, 4-7 ALPHABETIC-LOWER class test, 2-9 ALPHABETIC-UPPER class test, 2-9 ALPHABET keyword, 2-21 ALTER statement nonobsolete alternative to, 2-19 American National Standards Institute (ANSI), 1-1 ANSI74 entry point, 2-1, 6-20 vs ANSI85, 6-1 ANSI'74 COBOL, 1-1 ANSI85 entry point, 2-1, 6-20 features, 2-1 incompatible features, 2-21 new features, 2-2 obsolete features, 2-17 ANSI'85 COBOL, 1
COBOL subprograms, 4-10 compile-time, 4-11 execution-time, 4-17 link-time, 4-15 load-time, 4-16 call by content, 4-8 CALL BY CONTENT, 2-9 call by reference, 4-8 call by value, 4-8 CALLINTRINSIC control option, 4-61, 6-9 call rules for compile-time bound subprograms, 4-13 CALL statement, 4-17 CANCEL statement, 2-22, 4-20 carriage control, 5-19 CCTL in ASSIGN clause, 4-54, 4-60 CHECKSYNTAX control option, 6-7 chunked program, maps example, 7-17 chunk names, 4-4 chunks names, 7-17 verb maps, 7-17 circular les,
options, 6-7 symbolic debugger, 7-51 using compiler listings, 7-2 debugging traps, 7-30 address alignment, 7-41 illegal digit, 7-31 invalid GO TO, 7-40 no size error, 7-37 PERFORM stack over ow, 7-38 range error, 7-35 trace traps, 7-49 debug module nonobsolete alternative to, 2-20 Debug system debugger, 1-3, 7-14 calculating code addresses, 7-29 calculating data item addresses, 7-27 debugging traps, 7-30 link map, 7-16 maps example, 7-17, 7-21 register meanings, 7-26 subprogram parameters, 7-25 symbol table
FORTRAN 77 functions, 4-25 subprograms, 4-25 FORTRAN subprograms EXTERNAL data items and les, 4-57 functions FORTRAN 77, 4-25 Pascal, 4-29 G generic keys, 5-35 GLOBAL data, 3-15 data items and les, 3-5 GLOBAL-and-EXTERNAL data items and les, 3-6 GLOBAL les CCTL in ASSIGN clause, 4-60 L in ASSIGN clause, 4-60 GLOBAL items, 4-60 SPECIAL-NAMES paragraph, 3-2 H hashing algorithms, 5-23 heuristics, 3-23 HP extensions, 3-34 HPSQL, 1-3 HP System Dictionary/XL. See System Dictionary/XL HP Toolset/XL.
libraries subprogram, 4-10 L in ASSIGN clause, 4-54, 4-60 LINES control option, 6-6 linking your program, 6-1, 6-18 link map, 7-16 link-time call binding, 4-15 LIST control option, 6-6 listing compiler, 7-2 options, 6-6 load-time call binding, 4-16 locality set names, 4-4 LOCKING control option, 6-17 LOCOFF control option, 6-6 LOCON control option, 6-6 logical les, 5-1, 5-5 associating with physical les, 5-42 variable records, 5-36 M MAP control option, 6-6 maps example chunked program, 7-17 concatenated p
number, 4-7 type, 4-7 parameter passing by content, 4-8 BY CONTENT, 2-9 by reference, 4-8 by value, 4-8 parameters alignment, 4-7 number, 4-7 type, 4-7 Pascal functions, 4-29 Pascal subprograms, 4-29 peephole optimization, 3-29 performance options, 6-5 PERFORM enhancements, 3-12 PERFORM stack over ow trap, 7-38 PERFORM statement VARYING . . .
TSAM le, 6-2 SPECIAL-NAMES paragraph, 3-2 SPL subprograms, 4-36 standard COBOL format, 6-4 standard conformance options, 6-14 STAT74 control option, 2-27, 6-9 status codes, 5-48 $STDIN le inputting source program through, 6-3 STDWARN control option, 6-14 STOP LITERAL statement nonobsolete alternative to, 2-19 STOP RUN statement, 2-22 structured programming, 3-1 COMMON clause, 3-5 CONTINUE statement, 3-7 END PROGRAM header, 3-2 EVALUATE statement, 3-7 explicit scope terminators, 3-9 GLOBAL data, 3-15 GLOBAL
X XCONTRAP example, 4-56 Index-8