Digital PDFs
Documents
Guest
Register
Log In
AA-5059A-TK
May 1979
536 pages
Original
18MB
view
download
Document:
COBOL-74 Language Manual Jan79
Order Number:
AA-5059A-TK
Revision:
0
Pages:
536
Original Filename:
AA-5059A-TK_COBOL-74_Language_Manual_Jan79.pdf
OCR Text
COBOL-74 Language Manual Order NUl1)ber AA-5059A-TK January 1979 This manual reflects the software of version 12 of the COBOL-74 compiler (CBL74), version 12 of the objecttime system (C740TS), and version 4A of SORT. To order additional copies of this document, contact the Software Distribution Center, Digital Equipment Corporation, Maynard, Massachusetts 01754 digital equipment corporation · maynard, massachusetts First Printing, January 1979 The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. The software described in this document is furnished under a license and may only be used or copied in accordance with the terms of such license. No responsibility is assumed for the use or reliability of software on equipment that is not supplied by DIGITAL or its affiliated companies. Copyright © 1979, by Digital Equipment Corporation The postage-prepaid READER'S COMMENTS form on the last page of this document requests the user's critical evaluation to assist us in preparing future documentation. The following are trademarks of Digital Equipment Corporation: DIGITAL DEC PDP DECUS UNIBUS COMPUTER LABS COMTEX DDT DECCOMM ASSIST-II DECsystem-IO DEC tape DIBOL EDUSYSTEM FLIP CHIP FOCAL INDAC LAB-8 DECSYSTF.M-20 RTS-8 3/79-14 MASSBtJS OMNIBUS OS/8 PHA RSTS RSX TYPESET-8 TYPESET-II TMS-II ITPS-IO CONTENTS Page PREFACE xii ACKNOWLEDGMENT xiii PART 1 INTRODUCTION TO THE COBOL-74 SYSTEM AND THE STRUCTURE OF THE MANUAL PART 2 COBOL-74 LANGUAGE REFERENCE MATERIAL CHAPTER 1 INTRODUCTION TO COBOL-74 LANGUAGE 1-1 1.1 1.1.1 1.1.1.1 1.1.1.2 1.1.1.3 1.1.2 1.2 1.2.1 1.2.3 1.2.3.1 1.2.3.2 1.2.4 1.2.4.1 1.2.4.2 1.2.5 1.3 1.3.1 1.3.2 1.3.2.1 1.3.2.2 1.4 1.4.1 SYMBOLS AND TERMS Symbols Underline Brackets and Braces The Ellipsis COBOL Terms ELEMENTS OF COBOL LANGUAGE Program Structure COBOL-74 Character Set Words Reserved Words User-Defined Words Literals Numeric Literals Alphanumeric Literals Separators SOURCE PROGRAM FORMAT Card-type Format Terminal-type Format With Line Numbers Without Line Numbers THE COBOL LIBRARY FACILITY The COpy Statement 1-1 1-1 1-2 1-2 1-2 1-3 1-3 1-3 1-4 1-5 1-5 1-9 1-10 1-10 1-11 1-11 1-13 1-14 1-15 1-15 1-16 1-19 1-19 CHAPTER 2 THE IDENTIFICATION DIVISION 2-1 CHAPTER 3 THE ENVIRONMENT DIVISION 3-1 3.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.1.10 ENVIRONMENT DIVISION CLAUSE FORMATS CONFIGURATION SECTION SOURCE-COMPUTER QBJECT-COMPUTER SPECIAL-NAMES INPUT-OUTPUT SECTION FILE-CONTROL SELECT RESERVE ORGANIZATION ACCESS MODE 3-2 3-2 3-:-3 3-4 3-6 3-9 3-10 3-14 3-16 3-17 3-19 1.2.2 iii CONTENTS (CONT.) Page 3.1.11 3..1.12 3.1.13 3.1.14 3.1.15 CHAPTER RECORD KEY RELATIVE KEY RECORDING MODE/DENSITY/PARITY FILE STATUS I-O-CONTROL 3-20 3-21 3-22 3-26 3-34 4 THE DATA DIVISION 4-1 4.1 4.1.1 4.1.2 4.1.3 4.2 4.3 4.4 4.5 4.6 4.6.1 4.7 4.8 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.6 4.9.7 4.9.8 4.9.9 4.9.10 FILE SECTION Record Descriptions Elementary Items and Group Items Level Numbers SCHEMA SECTION COMMUNICATION SECTION WORKING-STORAGE SECTION LINKAGE SECTION REPORT SECTION Format Of Report Section QUALIFICATION SUBSCRIPTING AND INDEXING DATA DIVISION CLAUSES File Description (FD) BLOCK CONTAINS CODE-SET DATA RECORD FD File-name LABEL RECORD RECORD CONTAINS REPORT SD File-name VALUE OF IDENTIFICATION/DATE-WRITTEN/USER-NUMBER DATA DESCRIPTION ENTRY BLANK WHEN ZERO Condition-name (level-88) Data-name/FILLER JUSTIFIED Level-number OCCURS PICTURE REDEFINES RENAMES (level-66) SIGN SYNCHRONIZED USAGE VALUE Report Description (RD) CODE CONTROL Report Group Description COLUMN NUMBER GROUP INDICATE LINAGE LINE NUMBER NEXT GROUP RESET 4-2 4-2 4-3 4-3 4-4 4-4 4-5 4-5 4-6 4-7 4-9 4-9 4-13 4-14 4-16 4-17 4-18 4-19 4-20 4-22 4-23 4-24 4.9.11 4.9.12 4.9.13 4.9.14 4.9.15 4.9.16 4.9.17 4.9.18 4.9.19 4.9.20 4.9.21 4.9.22 4.9.23 4.9.24 4.9.25 4.9.26 4.9.27 4.9.28 4.9.29 4.9.30 4.9.31 4.9.32 4.9.33 4.9.34 iv 4-25 4-29 4-31 4-32 4-34 4-35 4-37 4-38 4-40 4-54 4-56 4-58 4-60 4-62 4-68 4-70 4-72 4-73 4-74 4-77 4-78 4-79 4-81 4~83 4-84 CONTENTS (CONT.) Page 4.9.35 4.9.36 4.9.37 CHAPTER SOURCE SUM TYPE 4-85 4-86 4-87 5 THE PROCEDURE DIVISION 5.1 SYNTACTIC FORMAT OF THE PROCEDURE DIVISION Statements Sentences Paragraphs Sections SEQUENCE OF EXECUTION SEGMENTATION AND SECTION-NAME PRIORITY NUMBERS ARITHMETIC EXPRESSIONS Arithmetic Operators Formation and Evaluation Rules CONDITIONAL EXPRESSIONS Relation Condition Format of a Relation-Condition Relational Operators Comparison of Numeric Items Comparison of Nonnumeric Items Class Condition Format of a Class Condition Restrictions The ALPHABETIC Test The NUMERIC Test Condition-Name Condition Format of a Condition-Name Condition Sign Condition Format of a Sign Condition Logical Operators Formation and Evaluation Rules Combined and Negated Combined Conditions Abbreviated Combined Relation Conditions COMMON OPTIONS ASSOCIATED WITH THE ARITHMETIC VERBS The ROUNDED Option The SIZE ERROR Option THE CORRESPONDING OPTION DETERMINATION OF USAGE IN ARITHMETIC COMPUTATIONS PROCEDURE DIVISION VERB FORMATS ACCEPT ADD ALTER CALL C1\NCEL CLOSE COMPUTE DELETE 5.1.1 5.1.2 5.1.3 5.1.4 5.2 5.3 5.4 5.4.1 5.4.2 5.5 5.5.1 5.5.1.1 5.5.1.2 5.5.1.3 5.5.1.4 5.5.2 5.5.2.1 5.5.2.2 5.5.2.3 5.5.2.4 5.5.3 5.5.3.1 5.5.4 5.5.5.1 5.5.5 5.5.6 5.5.7 5.5.8 5.6 5.6.1 5.6.2 5.7 5.8 5.9 5.9.1 5.9.2 5.9.3 5.9.4 5.9.5 5.9.6 5.9.7 5.9.8 5.9.9 l)ISJ?_L~Y v 5-1 5-2 5-2 5-4 5-4 5-4 5-5 5-5 5-6 5-6 5-6 5-7 5-7 5-8 5-8 5-8 5-8 5-9 5-9 5-9 5-10 5-10 5-10 5-10 5-11 5-11 5-11 5-11 5-15 5-16 5-17 5-17 5-17 5-18 5-18 5-19 5-20 5-21 5-23 5-24 5-26 5-27 5-31 5-32 5-33 CONTENTS (CONT • ) Page 5.9.10 5.9.11 5.9.12 5.9.13 5.9.14 5.9.15 5.9.16 5.9.17 5.9.18 5.9.19 5.9.20 5.9.21 5.9.22 5.9.23 5.9.24 5.9.25 5.9.26 5.9.27 5.9.28 5.9.29 5.9.30 5.9.31 5.9.32 5.9.33 5.9.34 5.9.35 5.9.36 5.9.37 5.9.38 5.9.39 5.9.4,0 5.9.41 5.9.42 5.9.43 DIVIDE ENTER ENTRY EXIT EXIT PROGRAM FREE GENERATE GO TO GOBACK IF INITIATE INSPECT MERGE MOVE MULTIPLY OPEN PERFORM READ RELEASE RETAIN RETURN REWRITE SEARCH SET SORT START STOP STRING SUBTRACT TERMINATE TRACE UNSTRING USE WRITE 5-34 5-36 5-37 5-38 5-39 5-40 5-43 5-45 5-46 5-47 5-49 5-50 5-54 5-56 5-58 5-59 5-64 5-68 5-71 5-72 5-78 5-79 5-80 5-83 5-84 5-87 5-89 5-90 5-95 5-97 5-98 5-100 5-108 5-111 PART 3 COBOL-74 USAGE MATERIAL CHAPTER 6 COMPILER COMMAND STRINGS 6-1 CHAPTER 7 COBOL-74 UTILITY PROGRAMS 7-1 7.1 ISAM - INDEXED-SEQUENTIAL FILE MAINTENANCE PROGRAM Building an Indexed-Sequential File Maintaining an Indexed-Sequential File Packing an Indexed-Sequential File Ignoring Errors Reading and Writing Magnetic Tape Labels Indirect Commands Using Indexed-Sequential Files LIBARY - SOURCE LIBRARY MAINTENANCE PROGRAM Library File Format Invoking The Library Utility Command String Defaults LIBARY Switches 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.1.6 7.1.7 7.2 7.2.1 7.2.2 7.2.3 7.2.4 vi 7-2 7-4 7-7 7-9 7-10 7-11 7-12 7-13 7-15 7-15 7-15 7-17 7-18 CONTENTS (CONT.) Page 7.2.5 7.2.6 7.2.6.1 7.2.6.2 7.2.6.3 7.2.6.4 7.2.6.5 7.3 7.4.1 7.4.2 Running LIBARY LIBARY Commands Group Mode Commands Edit Mode Commands Edit Commands LIBARY-Directing. Commands Example of Command Usage COB DDT - PROGRAM FOR DEBUGGING COBOL PROGRAMS Loading and Starting COBDDT COBDDT Commands Obtaining Histograms of Program Behavior Initializing the Histogram Table Starting the Histogram Stopping the Histogram Obtaining Histogr~m Listing Using the Histogram Feature RERUN - PROGRAM TO RESTART COBOL-74 PROGRAMS Operating RERUN Examples of Using RERUN 8 FILE FORMATS 8-1 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.2.6.1 8.2.6.2 8.2.6.3 8.3 8.4 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 RECORDING MODES ASCII Recording Mode SIXBIT Recording Mode EBCDIC Recording Mode BINARY Recording Mode FILE FORMATS Fixed-Length ASCII Variable-Length ASCII Fixed-Length SIXBIT Variable-Length SIXBIT EBCDIC File Formats BINARY File Formats COBOL ASCII Mixed-Mode Binary COBOL SIXBIT Mixed-Mode Binary COBOL EBCDIC Mixed-Mode Binary FILE ORGANIZATION AND ACCESS SEQUENTIAL FILES RELATIVE FILES Sequential Access Of Relative Files Random Access Of Relative Files Dynamic Access Of Relative Files INDEXED-SEQUENTIAL FILES Data File Index File 8-1 8-1 8-2 8-2 8-3 8-3 8-4 8-5 8-8 8-10 8-12 8-19 8-20 8-21 8-22 8-23 8-23 8-23 8-24 8-25 8-25 8-27 8-27 8-28 9 SIMULTANEOUS UPDATE 9-1 9.1 9.1.1 9.1.2 9.1.3 9.1.4 9.1.4.1 9.1.4.2 PROGRAMMING CONSIDERATIONS The OPEN Statement The RETAIN Statement The FREE Statement Accessing Sequential Files Basic Reading Basic Writing 9-3 9-4 9-8 9-11 9-12 9-12 9-12 7.3.1 7.3.2 7.3.3 7.3.3.1 7.3.3.2 7.3.3.3 7.3.3.4 7.3.3.5 7.4 CHAPTER CHAPTER vii 7-18 7-;19 7-19 7-20 7-20 7-21 7-21 7-22 7-23 7-24 7-27 7-28 7-28 7-29 7-29 7-31 7-31 7-32 7-33 CONTENTS (CONT.) Page 9.1.4.3 9.1.4.4 9.1.5 9.1.6 Basic Updating Sophisticated Access to Sequential Files Accessing Relative Files Accessing Indexed-Sequential Files 9-13 9-13 9-16 9-17 CHAPTER 10 REPORT WRITER 10-1 CHAPTER 11 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS 11-1 11.1 11.1.1 11.1.2 11.2 11.2.1 11.2.1.1 11.2.1.2 11.2.2 11.2.3 11.2.4 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.3.5 11.3.6 PROGRAM SEGMENTS Section-Names and Segment Numbers Examples SUBPROGRAMS Inter-Program Communication The Calling Program The Called Subprogram Loading a Subprogram Structure Object Libraries and Searches Examples OVERLAYS When to Use Overlays Over1ayab1e COBOL Programs Defining Overlays The /SPACE Switch to LINK The CANCEL Statement Examples 11-1 11-1 11-2 11-3 11-4 11-4 11-5 11-6 11-6 11-7 11-8 11-8 11-8 11-9 11-11 11-13 11-14 12 CALLING NON-COBOL SUBPROGRAMS 12-1 12.1 12.2 CALLING FORTRAN SUBPROGRAMS CALLING MACRO SUBPROGRAMS 12-2 12-3 13 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13-1 HOW TO PROCEED WITH PROGRAM OPTIMIZATION Where to Begin What Tools are Available What Method or Procedure to Use Evaluating Performance Documentation LISTING THE TOOLS COBDDT The ENTRIES Column The CPU Column ELAPSED Column OVERHEAD USING THE CORRECT DATA TYPE DISPLAY Data Types EBCDIC ASCII SIXBIT COMPUTATIONAL 13-3 13-3 13-3 13-4 13-5 13-5 13-6 13-6 13-7 13-7 13-8 13-8 13-8 13-8 13-8 13-9 13-10 13-10 CHAPTER CHAPTER 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.1.5' 13.2 13.2.1 13.2.1.1 13.2.1.2 13.2.1.3 13.2.1.4 13.3 13.3.1 13.3.2 13.3.3 13.3.4 13.3.5 viii CONTENTS (CONT.) Page PART 13.4 13.4.1 13.4.2 13.4.3 13.5 13.5.1 13.5.2 13.5.3 13.5.4 13.5.5 13.5.6 13.5.7 13.5.8 DATA EFFICIENCIES Counter, Indexes, Subscripts File Storage Blocking Data EFFICIENT CODING CONVENTIONS Alignment Usage of Subscripts Incrementing Counters The PERFORM Statement Use of the INSPECT Statement Data Movement Ordering Statements Asking the Correct Question 4 APPENDIXES, GLOSSARY, INDEX APPENDIX A 13-10 13-11 13-11 13-11 13-12 13-12 13-12 13-13 13-13 13-14 13-14 13-15 13-15 DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 A-I APPENDIX B COBOL RESERVED WORDS B-1 APPENDIX C ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS C-l APPENDIX 0 ALTERNATE NUMERIC TEST D-l APPENDIX E DEFINING LOGICAL NAMES UNDER TOPS-20 E-l GLOSSARY Glossary-l INDEX Index-l FIGURES FIGURE 1-1 (a) l-2(a) l-3(a) 4-1 4-2 4-3 4-4 5-1 5-2 5-3 5-4 7-1 8-1 8-2 8-3 8-4 8-5 8-6 8-7 Card-type Format Terminal-type Format with Line Numbers Terminal-type Format without Line Numbers Direct Subscripting/Indexing Relative Subscripting/Indexing Qualified Direct Subscripting/Indexing Picture String Charcter Chart Order"of Evaluation of a Conditional Expression Order of~ Evaluation of a Compound-conditional Expression PERFORM Cycle Logic - Two Variables PERFORM Cycle Logic - Three Variables COBOL-74 ISAM File Environment ASCII Recording Mode SIXBIT Recording Mode EBCDIC Recording Mode EBCDIC Recording Mode - Industry-Compatible Binary Recording Mode Fixed-Length ASCII COBOL Fixed-Length ASCII ix 1-14 1-15 1-16 4-11 4-11 4-11 4-53 5-13 5-14 5-66 5-67 7-3 8-1 8-2 8-2 8-2 8-3 8-4 8-5 CONTENTS (CONT.) Page 8-8 8-9 8-10 8-11 8-12 8-13 8-14 8-15 8-16 8-17 8-18 8-19 8-20 8-21 8-22 8-23 8-24 8-25 8-26 8-27 9-1 9-2 9-3 9-4 9-5 9-6 9-7 11-1 13-1 Variable-Length ASCII COBOL Variable-Length ASCII Fixed-Length SIXBIT COBOL Fixed-Length SIXBIT Variable-Length SIXBIT COBOL Variable-Length SIXBIT Fixed-Length EBCDIC COBOL Fixed-Length EBCDIC Variable-Length EBCDIC COBOL Variable-Length EBCDIC COBOL Blocked Fixed-Length EBCDIC Blocked Variable-Length EBCDIC COBOL Blocked Variable-Length EBCDIC COBOL Standard Binary ana ASCI Mixed-Mode Binary COBOL Standard Binary and SIXBIT Mixed-Mode Binary COBOL Standard Binary and EBCDIC Mixed-Mod~ Binary Statments Used to Sequentially Access a Relative File lSAM Data File Structure Locating a Record in an Indexed-Sequential File ISAM Index File Structure The Problem of Buried Update The Problem of Deadly Embrace Projecting Resources For Simultaneous Update The OPEN Statement Competing For Program Access to Files The RETAIN Statement The FREE Statement Example of an Overlay Structure Sample COBDDT Histogram 8-6 8-7 8-8 8-9 8-10 8-12 8-13 8-13 8-14 8-15 8-16 8-19 8-20 8-21 8;..22 8-26 8-28 8-29 8-30 9-2 9-3 9-4 9-5 9-8 9-9 9-11 11-9 13-6 TABLES TABLE 3-1 3-2 3-3 4-1 5-1 5-2 5-3 5-4 6-1 C-l C-2 C-3 Recording Modes Monitor File Status Bits Monitor Error Codes Standard Label for Magtapes Procedure Verb and Statement Categories Types of Segments Conditions, Logical Operators, and Parentheses Combinations CLOSE Options and File Types COBOL Switch Summary ASCII and SIXBIT Collating Sequence and Conversion to EBCDIC ASCII to SIXBIT Conversion EBCDIC Collating Sequence and Conversion to ASCII x 3-25 3-30 3-31 4-21 5-3 5-5 5-15 5-30 6-3 C-l C-5 C-5 PREFACE This manual describes COBOL-74 as it has been implemented on the TOPS-IO and TOPS-20 operating systems. Part 1 of this manual outlines the topics to be covered in each chapter. Part 2 describes the COBOL-74 compiler and presents the vocabulary and syntax of the language. Part 3 provides the information necessary to use the COBOL system, including performance improvement, utilities, and various features of COBOL-74. Part 4 contains appended material. Several appendixes and a glossary of COBOL-74 terms have also been included. Appendix A is a list of differences between· COBOL-74 and COBOL-68. Appendix B contains a list of all COBOL-74 reserved words. Appendix C lists the character collating sequences. Appendix D describes an alternative form of numeric test which may be elected at system installation time. It is assumed that the reader has a knowledge of the COBOL language. This manual is intended primarily for reference and is not a tutorial guide for beginning COBOL programmers. Those wishing to learn the COBOL language are referred to the following books. Carl Feingold, Fundamentals of COBOL Programming (Dubuque, William C. Brown Company, 1977). Iowa, Daniel D. McCracken, A Simplified Guide to Structured Programming (New York, John Wiley and Sons, Inc., 1976). COBOL Daniel D. McCracken and Umberto Garbassi, A Guide to COBOL Programming, Second Edition (New York, John Wiley and Sons, Inc., 1970) • The COBOL programmer should be familiar with the operating system commands and ~he editing language for the system in question. For users of the TOPS-IO operating system, the manuals which contain this information are: • Operating System Commands Manual • TECO programmer's Reference Manual Other manuals which contain information programmers are: • Monitor Calls Manual • Hardware Reference Manual • LINK Reference Manual xi useful to TOPS-IO COBOL-74 For users of TOPS-20, the information concerning the operating system commands and the system editing language is contained in the following manuals: • DECSYSTEM-20 User's Guide • EDIT Reference Manual Other manuals which contain information programmers are: • Monitor Calls Reference Manual • Hardware Reference Manual • LINK Reference Manual xii useful to TOPS-20 COBOL-74 ACKNOWLEDGMENT COBOL is an industry language and is not the property of any company or group of companies, or of any organization or group of organizations. No warranty, expressed or implied, is made by any contributor or by the CODASYL Programming Language Committee as to the accuracy and functioning of the programming system and language. Moreover,. no responsibility is assumed by any contributor, or by the committee, in connection therewith. The authors and copyright holders of herein the copyrighted material used FLOW-MATIC (trademark of Sperry Rand Corporation), Programming for the Univac (R) I and II, Data Automation Systems copyrighted 1958, 1959 by Sperry Rand Corporation; IBM Commercial Translator Form No. by IBM; F 28-8013, copyrighted 1959 FACT, DSI 27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell have specifically authorized the use of this material, in whole or in part, in the COBOL specifications. Such authorization extends to the reproduction and use of COBOL specifications in programming manuals or similar publications. xiii INTRODUCTION TO THE COBOL-74 SYSTEM AND THE STRUCTURE OF THE MANUAL The typical COBOL program follows a fairly simple series of steps from the human-readable format in which it is written to the machine-readable format in which it is executed. The following flow chart shows the basic steps which all programs take. Introduction-l Library File (.LlB) created by LIBARY COBOL-74 COMPI·LER Compilation Listing (.LST) Relocatable (.REL) Object Module LINKER Executable Program (.EXE) USER PROGRAM C740TS I I 88 Simultaneous Update Report Writer MR-S.{)17·79 The program first sees the light of day as a source file which is either created with a text editor or entered into the system by some other means (for example, it could be punched into cards and loaded through a ca~d reader). This file is usually given a filename whose extension is .CBL, and it is identified in the flow chart by this extension. The COBOL-74 compiler then translates the source file into a relocatable object module. In order to do this, the compiler may sometimes copy text from user libraries which contain often-used pieces of code. These libraries, identified in the chart by the extension of .LIB, are created by the LIBARY utility. The output from the compiler, the relocatable object module, is usually given an Introduction-2 extension of .REL, and is identified by this extension in the flow chart. The compiler can optionally produce a file which contains the compilation listing of the source program. This file is identified by its extension, .LST. At this point the program is given to the system linker, which produces the executable version with the extension .EXE. (This manual does not contain any information on the system linker~ Users of TOPS-lO should refer to the LINK Reference Manual and the LOAD command in the Operating System Commands Manual for more information about LINK. Users of TOPS-20 should refer to the the LINK Reference Manual and the LOAD command in the DECSYSTEM-20 user's Guide.) The .EXE version of the program runs in conjunction with the object-time system, C740TS. Among other things, the object-time system handles I/O and calls routines from the COBOL-74 library to be used at runtime. The user program is now in a format which can be executed, but there is no guarantee that it will produce the correct results. Most programs must still be debugged after they compile error-free. The. COBOL-74 system provides an on-line debugging facility called COBDDT to assist the programmmer in finding out what the program is really doing. COBDDT runs along with the user program and the object-time system, and allows the steps which the program executes to be monitored by the programmer. Many COBOL programs use indexed files during their execution. These files are convenient for many applications. The COBOL-74 system provides a program, called ISAM, to create and maintain indexed files. There are times when the user program is running and the system operator has to shut down the system unexpectedly. Some programs are written to be restartable, but many are not. The RERUN utility is provided with COBOL-74 to help in this situation. RERUN can save enough information to allow the program to be restarted after the system is brought back up, even though no provision was made in the program for the restart. Thus, the COBOL-74 system, in conjunction with the operating system, provides complete facilities for the creation and execution of a COBOL program. The rules regarding the creation of a COBOL-74 program, and the syntax to be used in the program, are described in Part 2, COBOL-74 Language Reference Material. The individual units of the COBOL-74 system are enumerated below. 1. The Compiler The compiler copies text from user libraries and translates the COBOL-74 program into a relocatable object module. Running the COBOL-74 compiler is described in Part 3, Chapter 6. 2. The OTS The object-time system runs the COBOL-74 program and allows the program to use such facilities as simultaneous update and Report Writer. Information on the file formats which the OTS accepts may be found in Part 3, Chapter 8. The simu~taneous update facility is described in Part 3, Chapter 9, and Report Writer in Part 3, Chapter 10. Subprograms, segmentation and overlaying are covered in Part 3, Chapter 11. Chapter 12 of Part 3 contains information on calling non-COBOL subprograms. Introduction-3 3. The utilities The COBOL-74 utilities - LIBARY, COBDDT, RERUN and ISAM - are described in Part 3, Chapter 7. Information on the use of COBDDT in improving the performance of COBOL-74 programs may be found in Part 3, Chapter 13. Part 4 of this manual contains appended material which may be of interest to some users of COBOL-74. Appendix A presents a list of differences between DIGITAL's COBOL-68 and DIGITAL's COBOL-74. Appendix B is the list of COBOL-74 reserved words. Appendix C provides ASCII, SIXBIT, and EBCDIC collating sequences, along with conversion charts for these three codes. An alternate to the usual numeric test, which may be elected at the time of installation of COBOL-74, is described in Appendix D. Finally, Appendix E contains a short description of the process of defining a logical name for TOPS-20 users of the COBOL-74 utilities. Introduction-4 CHAPTER 1 INTRODUCTION TO COBOL-74 LANGUAGE This chapter describes the symbols, special terms, language elements, and source program formats acceptable to COBOL-74. The source language statements are discussed in subsequent chapters. NOTE In this manual the word COBOL refers to COBOL-74. Any documentation concernlng DECtapes can be ignored if your system does not have them. 1.1 SYMBOLS AND TERMS The symbols and terms used in the following chapters of this manual are necessary to describe the language or are commonly used COBOL terms. The single exception to this statement is the term BIS-compiler. This term refers to compiler implementations that compile COBOL-74 using the Business Instruction Set (BIS). All users of TOPS-20 get BIS code. Users of TOPS-lO who have a KS or KL central processing unit get BIS code as the default, but the compiler may be installed without the BIS option. TOPS-lO users who have a KI central processor will usually not get the BIS option on their compilers. The KI processor will not execute the BIS instructions; however, the KI will run the compiler which produces BIS code should there be a need for it (for more information, see the COBOL-74 Installation Procedures.) You can tell if your compiler is producing BIS code by checking a listing of a compiled program. If your compiler is producing the BIS instructions, the letters BIS will follow the version and edit numbers on top of the page. 1.1.1 Symbols The symbology used in this manual to illustrate the various COBOL statement formats is essentially the same as that used in other COBOL language manuals. Its basis is the system of symbols used in the American National Standard and developed by CODASYL. 1-1 INTRODUCTION TO COBOL-74 LANGUAGE 1.1.1.1 Underline - The underline is used to denote reserved key words. Key words (uppercase underlined words) are required when you ~se a function of which they are a part. The absence of an underline in an uppercase word denotes that the word is optional; you may use or omit the word at your discretion. NOTE Uppercase words, whether underlined not, must be spelled correctly. or 1.1.1.2 Brackets and Braces - When brackets, [], enclose a portion of a general format, they denote an optional portion that may be included or omitted as needed. When braces, {}, enclose a portion of a general format, you must select one of the options within the braces. Consider the following figure. [ MEMORY SIZE integer It ~~~~!CTERS JJ MODULES } The brackets indicate that the entire clause is optional. The braces indicate that a choice of one of the words vertically stacked within the braces must be specified. Wherever a choice is required, stacked either within brackets example. SYNCHRONIZED} [{ SYNC [LEFT RIGHT the possibilities are vertically or braces. Consider the following JJ The outside brackets indicate that the entire clause is optional. Th~ braces indicate that if the clause is used, a choice of a word vertically stacked within the braces must be made. The inside brackets indicate that you may optionally select a vertically stacked word within. NOTE When possibilities are vertically stacked between brackets, you have the option of overriding a default condition. The default condition is described in the general rules for the clause. 1.1.1.3 The Ellipsis - The ellipsis ( ••• ) indicates that you may repeat the item preceding it. The preceding item is usually enclosed either by brackets or braces to remove any ambiguity as to which item may be repeated. Consider the following example. [SAME [RECORD] AREA FOR file-name-l [file-name-2] ••• ] ••• The final ellipsis indicates that the entire clause, if used, may be repeated. The initial ellipsis indicates that the item file-name-2 may also be repeated within the clause. 1-2 INTRODUCTION TO COBOL-74 LANGUAGE 1.1.2 COBOL Terms The terms block, record, and item have special meanings when relation to a COBOL program. Term used in Meaning Block Signifies a logical grouping of records. This term commonly refers to a logical block of records on some storage medium. NOTE The term "block" as defined here does not refer to a "disk block", which is 128 words of storage space on a·disk. 1.2 1.2.1 Record Signifies a logical unit of information. In relation to a data file, a record is the largest unit of logical information that can be accessed and processed at a time. Records can be subdivided into fields or items. Item Signifies a logical field or group of fields within a record. A group item is one that is further broken down into subitems (for example, a group item called TAX might be broken down into subitems called FED-TAX and STATE-TAX). Subitems can be further broken down into other subitems. An item that has no subitems is called an elementary item. ELEMENTS OF COBOL LANGUAGE Program Structure A COBOL program consists of four divisions. Each division is made up of source language statements. Some statements are required in every program; most of them are optional. Division Meaning IDENTIFICATION DIVISION Identifies the source program. ENVIRONMENT DIVISION Describes the computer on which the source program is to be compiled, the computer on which the object program is to run, and certain relationships between program elements and hardware devices. DATA DIVISION Describes the data to be by the object program. PROCEDURE DIVISION Describes the actions performed on the data. 1-3 processed to be INTRODUCTION TO COBOL-74 LANGUAGE NOTE The COBOL-74 compiler will recognize source line numbers up to and including 8184. If your program (including library routines) exceeds this maximum, the compiler will start numbering again at 0001. Since this causes two or more lines to have a single line number, you should exercise caution when debugging your program. The cross-reference listing may be confusing. However, the compiler will generate correct code regardless of how many lines are in the program or how they are numbered in the cross-reference listing. 1.2.2 COBOL-74 Character Set Within a source program statement, except: all ASCII characters are valid 1. null, delete, and carriage return (which are ignored) 2. line feed, vertical tab, form feed, and the printer control characters (20(8) through 24(8», which mark the end of a source line 3. CTRL/Z (32(8», which marks the end-of-file The compiler translates the lowercase ASCII characters to characters except when they appear in nonnumeric literals. uppercase Of this character set, 37 characters (the digits 0 through 9, the 26 letters of the alphabet, and the hyphen) can be used by the programmer to form COBOL user-defined words, such as data-names, procedure-names, and identifiers. The remaining ASCII characters which are acceptable compiler are listed below. to the Punctuation characters include: f1 (space) II or I (quotation mark) (comma) (left parenthesis) (semicolon) (right paren,thesis) (per iod) (horizontal tab) 1-4 COBOL-74 INTRODUCTION TO COBOL-74 LANGUAGE Special editing characters include: + $ / (plus sign) * (check protection symbol) (minus sign) Z (zero suppression) (dollar sign) B (blank insertion) (comma) 0 (zero insertion) (decimal point) CR (credit) (slash) DB (debit) Special characters used in arithmetic expressions include: + * (addition) / (division) (subtraction) ** (exponentiation) (multiplication) t (exponentiation) Special characters used in conditional (IF) statements include: (equal) > (greater than) < (less than) NOTE These special characters will not necessarily be underlined when they appear in formats. For example, an underlined minus sign might easily be confused with an equal slgn. However, they are usually required items. You may not omit them, unless you are specifically told otherwise. 1.2.3 Words A COBOL word is a character string which has not more than 30 characters and is either a user-defined word or a reserved word. For COBOL-74, as for most COBOL compilers, a word may be either user-defined or reserved, but not both. 1.2.3.1 Reserved Words - A reserved word is a COBOL word that is one of a specific list that may be used in COBOL source programs as specified in the general formats. You cannot use a reserved word as a user-defined word; the two types are mutually exclusive. (See Appendix B for a complete list of COBOL reserved words). 1-5 INTRODUCTION TO COBOL-74 LANGUAGE There are six types of reserved words: 1. Key words A key wo~d is required when the format in which the word appears 1S used in a source program. Within each format, key words are uppercase and underlined. Consider the following example. COMPUTE identifier-l [ROUNDED] identifier-2 [ROUNDED]] .•• =arithmetic-expression [ ON SIZE ERROR imperative-statement] In this case, the words COMPUTE, ROUNDED, SIZE, and ERROR are key words. 2. Optional Words Within each format, uppercase words that are not underlined are optional words included for readability. You may use or omit these words indiscriminately. The presence or absence of an optional word does not alter the semantics of the COBOL program in which it appears. Consider the following example. LINAGE IS integer-l LINES [WITH FOOTING AT integer-2] [LINES AT TOP integer-3] In this case, the words IS, LINES, WITH, and AT are words. 3. optional Connectives There are three types of connectives: a. Qualifier connectives that associate a data-name, a condition-name, or a text-name with its qualifiers: OF, IN (See Section 4.7, Qualification.) An example of this type is COpy ACTREC OF COBLIB. b. Series connectives that link operands: separator comma, example is two or more consecutive separator semicolon. An GO TO PARTl, PART2, PART3 DEPENDING ON COUNTERI. c. Logical connectives that are used in the formation of the following conditions: AND, OR, AND NOT, OR NOT. An example is IF HOURS-WORKED IS GREATER THAN DEDUCTION-TIME PERFORM PRINT-CHECK. 4. ZERO AND NOT Figurative Constants A few specific constant values are used frequently and in enough different ways to make it useful to have names for them. The names given to them are called Figurative Constants. These names are reserved words and are listed below. 1-6 INTRODUCTION TO COBOL-74 LANGUAGE The values represented by figurative constants are generated by the compiler and referenced through the use of the reserved words given below. These words must not be bounded by quotation marks when used as figurative constants. The singular and plural forms of figurative constants are equivalent and may be used interchangeably to increase readability. The values which the compiler generates for you, reserved words that name them, are as follows: and the ZERO ZEROS ZEROES Represent the value '0', or one or more of the character '0', depending on context. SPACE SPACES Represent one or more of the character "space". HIGH-VALUE HIGH-VALUES Represent one or more of the character that has the highest ordinal position in the computer's collating sequence (in ASCII code, this is octal 177). LOW-VALUE LOW-VALUES Represent one or more of the character that has the lowest ordinal position in the computer's collating sequence (in ASCII this is octal 000). QUOTE QUOTES Represent one or more occurences of the quote character, usually'''' (double quote). ALL literal Represents one or more repetitions of the string of characters which compose the literal. The literal must be either an alphanumeric literal or a figurative constant other than ALL. When a figurative constant is used, the word ALL is redundant and is an option. You may use it for readability if you wish. Frequently a figurative constant represents a string of characters whose length is not explicitly stated. When this happens, the compiler determines the length of the string from context. The figurative constant may be associated with another data item by the context, as in the following statements: MOVE SPACES TO WORK-RECORD IF AMOUNT-OWED EQUALS ZERO PERFORM CLOSE-ACCOUNT Alternatively, the figurative constant may with no relation to any data item, as in: stand by itself DISPLAY "BALANCE IS" ZERO STRING DAY-CODE, SPACE, "_", SPACE, MONTH-CODE DELIMITED BY SIZE INTO DSPLY-DATE In cases where the figurative constant is associated with a data item, the compiler assumes that the string of characters represented by the figurative constant has the same number of characters as the associated data-item. In the case of the figurative constant ALL literal, the literal is repeated from left to right and truncated on the right, if necessary. 1-7 INTRODUCTION TO COBOL-74 LANGUAGE Thus, if WORK-RECORD in the above example contains 128 characters, the figurative constant SPACES represents a string of 128 spaces. If AMOUNT-OWED is an eight-character numeric field with two decimal places, ZERO represents the value 000000.00. In the following example: MOVE ALL "ABC" TO HOLD-AREA if HOLD-AREA is a ten-character contents after the MOVE will be alphanumeric field, its If you associate a JUSTIFIED clause with the data item, the character repetition and truncation will take place before any justification. When the figurative constant is not associated with a data item, as in the second set of examples above, the length of the character string is one character, or one occurrence of the literal in the case of ALL literal. This is true even if you use the plural form instead of the singular. That is, all of the following statements cause the same display: DISPLAY ZERO. DISPLAY ZEROS. DISPLAY ALL ZEROS. In each case, one zero will be displayed. A figurative constant may be used whenever a literal appears in a format. However, if the literal is restricted to numeric characters, the only figurative constants permitted are ZERO (ZEROS, ZEROES), LOW-VALUE (LOW-VALUES), and HIGH-VALUE (HIGH-VALUES). Each reserved word that is used to reference a figurative constant value is a distinct character string with the exception of the construction ALL literal, which is composed of two distinct character strings. 5. Special Registers COBOL-74 recognizes four reserved words as special registers: DAY, DATE, TIME, an9 LINAGE-COUNTER. All special registers have implied data descriptions of unsigned elementary integers. The lengths of DAY, DATE, and TIME are fixed; the length of LINAGE-COUNTER depends upon the file description statement that generates the register. DAY is five digits long. Its value represents the number the current day of the year. Its format is: YYDDD where YY is the year of the century, and DDD is the number of the day of the year. 1-8 of INTRODOCTION TO COBOL-74 LANGUAGE DATE is six digits long. date. Its format is: Its value represents the current YYMMDD where YY is the year of the century, MM is the number of the month, and 'DD is the number of the day. TIME is eight digits long. Its value represents the current elapsed time since midnight on a twenty-four-hour basis. Its format is:' HHMMSShh where HH is the hours, MM is the minutes, SS is the seconds, and hh is the 1/100ths of a second. DAY, DATE, and TIME may be accessed by ACCEPT statements in the Procedure Divisioh. See Section 5.9.1 for the correct format to use with the ACCEPT verb. The LINAGE-COUNTER special register is generated whenever the file description of a sequential file includes the LINAGE clause. The contents of a LINAGE-COUNTER represent the current line number within the current page of output. The contents of a LINAGE-COUNTER are updated automatically by WRITE statements referring to the associated sequential file. The LINAGE clause and LINAGE-COUNTER are fully explained in Section 4.9.31. 6. Special-Character Words The arithmetic operators +, -, *, I, **, A, and the relation characters <,), and = are special-character reserved words. 1.2.3.2 User-Defined Words - A user-defined word is a COBOL word which is supplied by the user to satisfy the format of a clause or statement. The characters which may be used to form user-defined words are the letters of the alphabet, the digits 0 through 9, and the hyphen. The hyphen may not be used as the first or last character in the user-defined word. There are 17 types of user-defined words: 1. alphabet-name 2. cd-name 3. condition-name 4. data-name 1-9 INTRODUCTION TO COBOL-74 LANGUAGE 5. file-name 6. index-name 7. level-number 8. library-name 9. mnemonic-name 10. paragraph-name 11. program-name 12. record-name 13. report-name 14. routine-name 15. section-name 16. segment-number 17. text-name Each of these user-defined word types is which appears at the end of this manual. 1.2.4 described in the Glossary Literals A literal is a character string whose value is determined by the ordered set of characters of which it is composed. You can also use a figurative constant as a literal. There are two types of literals: numeric and alphanumeric. 1.2.4.1 Numeric Literal - A numeric literal is a character string of from 1 to 20 characters selected from the digits 0 through 9, the plus sign, the minus sign, and the decimal point. The rules for the formation of numeric literals are as follows: 1. A literal must contain at least 1 digit and no more digits. than 2. A literal must not contain more than one sign character. If a sign is used, it must appear as the leftmost character of the literal. If the literal is unsigned, it is considered positive. 3. A literal must not contain more than one decimal point. The decimal point is treated as an assumed decimal point, and may appear anywhere within the literal except as the rightmost ,character. If the literal contains no decimal point, the literal is considered an integer. NOTE The word integer, appearing in a· general represents a nonnegative numeric literal decimal point. 1-10 format, with no 18 INTRODUCTION TO COBOL-74 LANGUAGE If a literal conforms to the rules for the formation of numeric literals but is enclosed in quotation marks, it is considered an alphanumeric literal and is treated as such by the compiler. 4. The value of a numeric literal is the algebraic quantity represented by the characters in the numeric literal. Every numeric literal is category numeric. (See Section 4.10.16, The PICTURE Clause.) The size of a numeric literal is equal to the number of digits specified by the user, including leading zeros, if any. 1.2.4.2 Alphanumeric Literals - An alphanumeric literal is a character string representing from 1 to 120 characters, delimited on both ends by quotation marks and consisting of any allowable character in the computer's character set. An opening quotation mark must be immediately preceded by a space or left parenthesis. A closing quotation mark must be immediately followed by one of the separators (space, comma, semicolon, or right parenthesis) or by the terminator, period. NOTE You may use either the single quote character (') or the double quote ("). Whichever one you use, you must be sure to pair them correctly - do not try to pair a single quote with a double quote or vice versa. To represent one quotation-mark character within an alphanumeric literal, two contiguous quotation marks must be used. The value of an alphanumeric literal in the object program is the string of characters itself, except that: 1. The delimiting quotation marks are excluded, and 2. Each embedded pair of contiguous quotation marks represents a single quotation mark character. All other punctuation alphanumeric literal, category alphanumeric. 1.2.5 characters are part of the value of the not separators. All alphanumeric literals are (See Section 4.9.18, The PICTURE Clause.) Separators A separator is a string of one or more rules for forming separators are: 1. punctuation characters. The Space a. Anywhere a space is used as a separator, space may be used. b. A space may immediately precede all separators except the closing quotation mark. Here the space is considered part of an alphanumeric literal, not a separator. 1-11 more than one INTRODUCTION TO COBOL-74 LANGUAGE c. 2. A space may immediately follow any separator except the open quotation mark. In this case, a following space is considered part of an alphanumeric literal, not a separator. Comma and Semicolon The punctuation characters, the comma and semicolon, are separators. You may insert these separators only where explicitly permitted by the general formats, by format punctuation rules, by statement and sentence definitions, or by source program format rules. 3. Right Parenthesis and Left Parenthesis Right parenthesis and left parenthesis are separators only when used in balanced pairs to delimit subscripts or indexes. 4. Quotation Marks Quotation marks may be used only in balanced pairs to delimit alphanumeric literals or in adjacent pairs to pass one quotation mark in an alphanumeric literal. (See note concerning quotation marks in Section 1.2.4.2, Alphanumeric Literals.) 5. Horizontal Tab The horizontal tab character is governed by the same rules that goverti the space character. It is normally used to vertically align statements or clauses on successive lines of the source program listing. The compiler, upon encountering a tab character, generates one or more space characters consistent with the tab character position in the source line. 6. Pseudo-text Delimiter Pseudo-text delimiters set off textual matter in the COpy statement from 'the rest of the sentence. Each delimiter consists of two contiguous equal signs (==). The opening pseudo-text qelimiter must be immediately preceded by a space; the closing delimiter must be immediately followed by one of the separators space, comma, semicolon, or period. These delimiters' may appear only in balanced pairs delimiting pseudo-text. NOTE There are certain rules for writing source programs which supersede these general rules. For a discussion of source program formats see Section 1.3. 1-12 INTRODUCTION TO COBOL-74 LANGUAGE 1.3 SOURCE PROGRAM FORMAT There are two basic types of source program formats in which you may write your COBOL-74 programs. These two types arise from the methods of entering the source program into the system. The first is conventional card-type format. You should use this type if you wish your COBOL-74 program to be compatible with other compilers. The second is the standard DEC format which is designed for easy use on terminals. This format is the one to us~ for those erograms which are to be entered into the system through a terminal using a text editor. The compiler will assume that the source program is written in terminal-type format unless the /S switch is included in the command string to the compiler (refer to Appendix C). Certain margins which begin the areas used for writing COBOL-74 statements are standard for source programs. The standard names for these margins are Margins L, A, B, and R. As you might expect, Margins Land R are the left and right marglns of the line, respectively. Margins A and B mark the beginning of two areas, Areas A and B. Area A is where all division-names, section-names, paragraph-names, and FD (File Description) entries must begin. All other entries must begin in Area B. Although the actual character position which marks each of these margins changes from format to format, the function of each area is the same; in other words, you must begin your division-names at Margin A no matter what format you use, no matter where Margin A happens to be placed in that format. NOTE These rules agree with the 1974 ANSI standard for source program formats. Programs written according to the rules will be more readable and transportable. The COBOL-74 compiler, however, does not do complete syntax checking to determine if you have followed all rules, and will not always issue an error message if you violate them. Thus, you are encouraged to conform to the rules to avoid unpredictable results. Some of the rules for using source program formats remain constant regardless of which format you use. These rules are given below. Refer to them for all types of formats. 1. Continuation Area - If you wish to split a word or literal across two lines, you must use this area to indicate your wish to the compiler. To do this, write the first line up to the point at which you wish to split it, then place a hyphen (-) in the continuation area of the next line and continue the second line beginning at or after Margin A. If you are splitting a word or numeric literal you may leave spaces between the last character in the first line and the end of the spurce statement area. (This area ends at the identification area, when it exists; otherwise it ends at Margin R.) However, if you wish to split an alphanumeric literal you must not leave spaces after the last character of the first line, since the compiler will assume that those spaces are part of the literal. If you wish only to continue a sentence on the next line without splitting any words, you may simply write the first line, then continue on the next line; do not use the continuation column for this purpose. 1-13 INTRODUCTION TO COBOL-74 LANGUAGE 2. Comment Lines - You may insert comment lines into your COBOL-74 program by using the continuation area. If the compiler finds an asterisk (*) in that area it will list the remainder of the line as a comment on the next line. If there is a slash (/) instead of an asterisk a new page will be started and the comment will be listed at the top of the new page. NOTE All formats may be used with any input medium. The names of the types of formats refer to their origins, not their uses. 1.3.1 Card-type Format You should use card-type format if you wish to compile your program under an operating system other than TOPS-lO or TOPS-20. Your program may be punched on an off-line card punch or created with an on-line text editor. This format uses card sequence numbers which must be created by the user. The layout of a line in this format is shown in Figure 1-1. The numbers refer to card columns or character positions. CARD·TYPE FORMAT 6 7 8 12 ~l r ~,' I L C B A 73 1 80 VI ~ MR-S-018-79 Figure 1-1 (a) Card-type Format In this format, Margin L is to the left of position 1 and Margin R is to the right of position 80. Margin A is between positions 7 and 8 and begins the area labeled A in the figure. Margin B is between positions 11 and 12 and begins the area labeled B. The following rules pertain to the use of this source format: 1. Line Numbers - These are placed in area L (positions 1 through 6) by the user who creates the file on a terminal or a card punch. 2. Debug Lines - You may insert debug lines into your program by putting a ~D" in the continuation area (column 7). The compiler will recognize it and print it on the source listing with the spacing similar to a comment line. 1-14 INTRODUCTION TO COBOL-74 LANGUAGE 3. Identification Area - This area is marked I in the figure (positions 73 through aD). These eight character positions may hold identifying information which can be composed of any eight characters. This information will be printed on the source listing, and can be used to identify the card deck (if the source code is in fact on cards). NOTE The card sequence numbers are not the same as the line numbers created by a line editor. The numbers supplied by an editor are not acceptable to COBOL-74 when you specify card-type format. The examples in Figure l-l(b} illustrate these rules. The first two .lines are simple statements, with a line number in area L, COBOL-74 statements in areas A and B, and the identification area containing the name of the program. The third line shows how the continuation column is used to split a word across two lines. Note that t~e word may be written right up to the end of area B. 1.3.2 Terminal-type Format If you are writing your program using a text editor and a terminal to input the source code, terminal-type format is your best choice. There are two types of terminal-oriented formats, one with line numbers and one without. Layouts and examples of each type are shown in the figures which follow. 1.3.2.1 With Line Numbers - This format is suitable if you use a line-oriented editor such as EDIT or SOS. The format is shown in figure 1-2(a). TERMINAL-TYPE FORMAT - WITH 6 7 LINE NUMBERS 12 8 I ~--~I~I~--~--~/',~{ 105 ______~ ~~~--~v~__~~-v--v-~----------------v~--------------~J L z c B A MR-S,819-79 Figure 1-2(a) Terminal-type Format with Line Numbers In this format, margin L is to the left of position 1 and margin R is to the right of position 105. Margin A is between positions 7 and a and begins the area labeled A. Margin B is between positions 11 and 12 and begins the area labeled B. 1-15 INTRODUCTION TO COBOL-74 LANGUAGE The following rules pertain to the use of this source format: 1. Line Numbers - These are placed in area L (positions 1 through 5) either by the line editor or by the user. If you are using an editor which supplies line numbers you must not add numbers yourself - one set is enough. 2. Position 6 - This position (marked Z in the figure) remains blank. The editor may insert a tab here for purposes of making your text more readable~ if so, the compiler will read the tab as a space. 3. Continuation Area - To use the continuation area, type -, *, , or / as the first character of the line. However, if you do not wish to use the continuation area, you may ignore it altogether - you do not need to type a space at the beginning of the line. If you do type a space as the first character of a line, the compiler will assume that you meant the space to be part of the line. 4. Debug Lines - Debug lines can be inserted in your program with this format if you type "\D" {backslash D) as the first two characters on the line. If you use "D" as in card-type format, the compiler will read the liD" as the first character of a word beginning in area A. The examples in figure l-2{b) illustrate the use of this format. The first two lines are simple COBOL-74 statements with the five-character line number in area L and areas Z and C blank. The third line shows how a word is split across two lines. Note that you may leave spaces between the last letter of the word and margin R without confusing the compiler. 1.3.2.2 without Line Numbers - If you decide to use a terminal to enter your program but your editor (such as TECO) does not supply line numbers (or you requested that. the edi tor remove th~m when you finished editing), this is the simplest format to use. The format is shown in figure l-3{a). TERMINAL-TYPE FORMAT - NO LINE NUMBERS o 105 5 ~~--------~r---------------~I ,~(----------------~ ~~--------~--------------~/ I~'------------------~ -v-~~,______--------~~~----""",,__~~ C A R MR-S'()20-79 Figure l-3(a) Terminal-type Format without Line Numbers In this format, margin L is to the left of position 0, if it exists, or position 1, if position a does not exist. Margin R is to the right of position 105. Margin A is to the left of position 1 and begins the area labeled A. Margin B is between positions 4 and 5 and begins the area labeled B. 1-16 INTRODUCTION TO COBOL-74 LANGUAGE The following rules pertains to the use of this source format: 1. Continuation Area - If you wish to use the continuation area, type the character you wish to enter (-, *, \, /) as the first character of the continued line. If the compiler finds one of these characters at the beginning of a line it will assume that the line has a position 0 - in other words, a continuation area. Otherwise, each line starts in position 1 and there is no position O. 2. Debug Lines - Debug lines may be inserted into the program. To do this type a "\D" (backslash D) as the first two characters on the line. The examples in Figure l-3(b) show this format's simplicity. The first two lines are the same simple COBOL-74 sentences as above. Note that the paragraph-name starts in the very first character position. The third line shows how to tell the compiler that the line you enter is a continuation (or a comment) line. The first half of the line is entered beginning in the first position of Area B, while the second half begins with a hyphen and continues from the second position. 1-17 T~ XA C~ T~ T~ XA C TG 00 10 00 PR olc ES s- n-A IX. 00 10 10 IMla VE ITH IS -P ER 10 OS -IT AX Te iliA X- pll 10. 00 10 2P 00 10 30 00 10 4P TA XA CC TG SIT RI NG MO ST -IR EC EN T- Mlv NIT H, SP AC E, "- , SP PC E, MO ~T -R EC EN T- OA Y , 11, ~iR OE LI 1M I !TE BY SI ZE IN TO 10 I SP LT AX ~C TG SP IA CE, IMO ST -R EC EN T- YE SP AC E, 'AY -~ At!" E. II II -- MR-5-021-79 Figure 1-1 (b) ....Z toi ~ o c:: (') 00 lPO 00 110 .... ....I (X) 00 120 00 1 3o - toi .... PR PC E~ s~ T~ x. M VE TH IS -P ER 10 o~ -T AX T TA X~ p~ 10. ~ ST RI NG 1M 0ST I-R EC EN :1'- MO NT H, ~p AC E, "- , SP IA CE , MO ~T -R ,-C EN T- O~ ~ , ~P AC E, "- , SP ACE,MO~!l-IRECENT-YEIAR DE IMITED BY ~IZE IN[O DISP~AY-DA~t. II II MR-S-022-79 Figure 1-2 (b) toi o (') o ttJ o t"t ....,I ~ t"t ~ Gl c:: >' Gl tzl PIR OC ES Ie:; - iTiA I~ • ~~Ie !~IE 1H IS -IF IE R110 10 " 1-11 IA ~ 10 ITIA ~- PA lie. SI1 !~ I NG itJ 0S1 -R Ele Efl 111-IMC IN 1 H, Isip Iplc E, "- SP A'c E, Mlc Sl -fR Ele EN 1- DA Y, SP lAC E , "111- IR ECE !~ 1 -~ lEA IR iD EIL IItJ IIT ED BIY IS I ZE IN ITO 01 SP IL A~- jeA IT E. II - J II Sip 'A e E, I~IOS MR-5-023-79 Figure 1-3 (b) INTRODUCTION TO COBOL-74 LANGUAGE 1.4 THE COBOL LIBRARY FACILITY You can use the COBOL Library Facility to copy part of your program from a COBOL source library at compile time. This can be useful if, for example, you need to describe a complex file to be used in several different programs, and you wish to write the file description only once. You can insert the file description into the library (for directions and further description see the COBOL-74 Usage Material, Part 3 of this manual), and whenever the description is needed you can simply copy it from the library into the program you are writing. The following statement is used to accomplish this. 1.4.1 The COpy Statement Function The COPY statement incorporates text from a COBOL library into a COBOL source program. (For a complete description of COBOL libraries, see the COBOL-74 Usage Material, Part 3 of this manual.) The COpy statement may also be used to replace specified text in the source text being copied. General Format COP Y t ext - n am e [ ~ REPLACING {~ q {1 1 i bra r y - n ame ] ==pseUdo_text-l==1 i?entifier-l llteral-l word-l BY ==pseUdo-text-2==l identifier-2 literal-2 word-2 J J 1 ... Technical Notes NOTE In the technical notes which follow, the term string-l is used to denote the character string which is used in place of pseudo-text-l, identifier-I, literal-I, or word-I. The term string-2 is similarly used. 1. If more than one COBOL library is available during compilation, text-name must be qualified by the library-name identifying the COBOL library in which the text associated with text-name resides. Within one COBOL library, each text-n'ame must be 1-19 unique~ INTRODUCTION TO COBOL-74 LANGUAGE ,2. The COpy statement must be preceded by a space and terminated by the separator period. The entire statement, including the period, will be removed when thel text is copied from the library. 3. String-l must not be null, nor may it consist solely of the character space(s), nor may it consist solely of comment lines. 4. String-2 may be nUll. 5. Character-strings within string-l and string-2 may be continued. However, both characters of a pseudo-text delimiter must be on the same line. 6. A COpy statement may occur in the source program anywhere a character-string or a separator may occur except that a COpy statement must not occur within a COpy statement. 7. The effect of processing a COpy statement is that the library text associated with text-name is copied into the source program, logically replacing the entire COpy statement, beginning with the reserved word COpy and ending with the punctuation character period, inclusive. The compilation of a source program containing COpy statements is logically equivalent to processing all COpy statements prior to the processing of the resulting source program. 8. If the REPLACING phrase is not specified, the library text is copied unchanged. If the REPLACING phrase is specified, the library text is copied and each properly matched occurrence of string-l in the library text is replaced by the corresponding string-2. 9. The comparison operation to determine text replacement occurs as follows: a. Any separator comma, semicolon, and/or space(s) preceding the leftmost library text-word is copied into the source program. Starting with the leftmost library text-word and the first string-l that was specified in the REPLACING phrase, the entire REPLACING phrase operand that precedes the reserved wora BY is compared to an equivalent number of contiguous library text-words. b. String-l matches the library text if, and only if, the ord~red sequence of text-words that forms string-l is equ~l, character for character, to the ordered sequence of library text-words. For purposes of matching, each occurrence of a separator comma or semicolon in string-l or in the library text is considered to be a single space except when string-l consists solely of either a separator comma or semicolon, in which case it participates in the match as a text-word. Each sequence of one or more space separators is considered to be a single'space. c. If no match occurs, the comparison is repeated with each next successive string-I, if any, in the REPLACING phrase until either a match is found or there is no next successive REPLACING operand. 1-20 INTRODUCTION TO COBOL-74 LANGUAGE 10. d. When all the REPLACING phrase operands have been compared and no match has occurred, the leftmost library text-word is copied into the source program. The next successive library text-word is then considered as the leftmost library text-word, and the comparison cycle starts again with the first string-l specified in the REPLACING phrase. e. Whenever a match occurs between string-l and the library text, the corresponding string-2 is placed into the source program. The library text-word immediately following the rightmost text-word that participated in the match is then considered as the leftmost library text-word. The comparison cycle starts again with the first string-l specified in the REPLACING phrase. f. The comparison operation continues until the rightmost text-word in the library text has either participated in a match or been considered as a leftmost library text-word and participated in a complete comparison cycle. When you use the REPLACING phrase, you must treat any picture strings in the library text as complete pieces of text. That is, if you wish to replace XiS in the picture string EXAMPLE-ITEM PICTURE IS XXX. with 9's, you must replace the entire PICTURE just the three XiS, with the form shown below: COpy EXAMPLE-TEXT FROM LIBARY XXX== BY ==PICTURE IS 999==. REPLACING clause, not ==PICTURE IS 11. For purposes of matching, a comment line which occurs in the library text and string-l is interpreted as a single space. Comment lines which appear in string-2 and library text are ~opied into the source program unchanged. 12. Debugging lines are permitted within library text and string-2. Debugging lines are not permitted within string-l~ text-words within a debugging line participate in the matching rules as if the '0' did not appear in the indicator area. If a COpy statement is specified on a debugging line, then the text that is the result of the processing of the COpy statement will also appear as though it were specified on debugging lines with the following exception: comment lines in library text will' appear as comment lines in the resultant source program. 13. The text produced as a result of the complete processing of a COpy statement must not contain a COpy statement. 14. The syntactic correctness of the library text cannot be independently determined. The syntactic correctness of the entire COBOL source program cannot be determined until all COpy statements have been completely processed. 1-21 INTRODUCTION TO COBOL-74 LANGUAGE 15. Library text must conform to the rules for COBOL source program format. {See Section 1.3.} You may copy text from a library without worrying about what format your program is in, however. 16. For purp?ses of compilation, text-words after replacement are placed ln the source program according to the rules for source program format. 1-22 CHAPTER 2 THE IDENTIFICATION DIVISION The Identification Division is required in every source program. It identifies the source program and the output from compilation. In addition, it may contain other documentary information such as the name of the program's author, the name of the installation, the dates on which the program was written and compiled, any special security restrictions, and any miscellaneous remarks. General Structure { t%ENTI FI CATION} DI VISION. program-name.J [PROGRAM-I D. comment-entry [ AUTHOR. J ... r=INSTALLATION. comment-entry .. J [DATE-WRITTEN. comment-entry ..J ~DATE-COMPILED. comment-entry [SECURITY. comment-entry ...J ...J Technical Notes 1. The Identification Division must begin with the reserved words IDENTIFICATION DIVISION followed by a period and a space. Note that in COBOL-74 the reserved word ID may be substituted for IDENTIFICATION in the division header. 2. The PROGRAM-IO paragraph contains the name identifying the program. The program-name may have up to six characters, and must contain only letters, digits, and the hyphen. It can be enclosed in quotation marks. The program-name cannot be a reserved word and must be unique. It cannot be the same as a section, paragraph, file, data, or subprogram name. This paragraph is optional. If it is not present, the name MAIN is assigned to the program. 2-1 THE IDENTIFICATION DIVISION 3. The remaining paragraphs are optional and, if used, may appear in any combination and in any order. A comment paragraph consists of any combination-of characters from the COBOL character set organized to conform to COBOL sentence' and paragraph format. All text appears as written on the output listing, except the DATE-COMPILED paragraph which will be replaced by the current date. Reserved words can be used in any comment ppragraph. 2-2 THE IDENTIFICATION DIVISION GENERAL FORMAT FOR IDENTIFICATION DIVISION { t%ENTIFICATION} DIVISION. [PROGRAM-I D. [ AUTHOR. program-name.J comment-entry J ... ~INSTALLATION. comment-entry .. .J ~DATE-WRITTEN. comment-entry .. ] ~DATE-COMPILED. comment-entry ...] [SECURITY. comment-entry ...J 2-3 CHAPTER 3 THE ENVIRONMENT DIVISION The Environment Division allows you to describe the particular computer configurations you wish to use for program compilation and execution. In this division you also specify the files and devices you will use for input and output. The clauses used to do these things are presented on the following pages. 3-1 THE ENVIRONMENT DIVISION CONFIGURATION SECTION 3.1 ENVIRONMENT DIVISION CLAUSE FORMATS 3.1.1 CONFIGURATION SECTION The Configuration Section allows you to describe the computers used for program compilation and execution, and to assign mnemonic-names for input/output devices. The Configuration Section consists of the section name (CONFIGURATION SECTION.) followed by one or more of the following paragraphs: SOURCE-COMPUTER. (See Section 3.1.2) OBJECT-COMPUTER. (See Section 3.1.3) SPECIAL-NAMES. (See Section 3.1.4) Technical Notes 1. This section is optional. 2. All commas and semicolons terminate the entire entry. 3-2 are optional. A period must THE ENVIRONMENT DIVISION SOURCE-COMPUTER 3.1.2 SOURCE-COMPUTER Function The SOURCE-COMPUTER paragraph describes program is to be compiled. the computer on which the General Format SOURCE-COMPUTER. computer-name [WITH DEBUGGING MODE] • Technical Notes 1. This paragraph is optional. 2. Computer-name must be one of the DECSYSTEM-20, PDP-lO, or PDP-integer-l. the range 1000 to 1099. 3. If the WITH DEBUGGING MODE clause is specified, all debugging lines are compiled. If it is not specified all debugging lines are treated as if they were comment lines. In either case all USE FOR DEBUGGING statements are compiled as if they were comments. This is because COBDDT accomplishes what is otherwise done with debugging statements. list DECsystem-lO, Integer-l must be in Examples SOURCE-COMPUTER. DECSYSTEM-l055. SOURCE-COMPUTER. DECSYSTEM-20 WITH DEBUGGING MODE. 3-3 THE ENVIRONMENT DIVISION OBJECf-COMPUTER 3.1.3 OBJECT-COMPUTER Function The OBJECT-COMPUTER paragraph describes program is to be executed. the computer on which the General Format OBJECT-COMPUTER. computer-name ~ WORDS ( [ MEMORY SIZE integer 1CHA'RACTERS MODULES , ~PROGRAM COLLATING SEQUENCE IS alPhabet-name~ ~SEGMENT-LIMIT ~ segment-number~ Technical Notes 1. This paragraph is optional. 2. Computer-name must. be one of the following: PDP-IO, PDP-integer-l, DECsystem-lO, or DECSYSTEM-20. Int~ger-l must be a number in the range 1000 through 1099. The number specified is for documentary purposes only and has no direct bearing on the object code generated" by the compiler. If the compiler was installed to take advantage of the KL central processing unit's Business Instruction Set (BIS), the BIS-code will be generated automatically. (See the COBOL-74 Installation Procedures.) 3. The optional MEMORY SIZE clause specifies the maximum memory size of SORT's work area during a SORT operation. If the MEMORY SIZE clause is omitted, 262,144 WORDS are assumed. If it appears, the following ranges are applicable. CHARACTERS Up to 1,572,864 (262,144 words x 6 characters/word) WORDS Up to 262,144 MODULES Up to 256 (1 module equals 1024 words) COBOL-74 presently ignores the MEMORY SIZE clause. SORT will use its default algorithms to determine the amount of memory needed to execute a sort. (Refer to the SORT User's Guide for more information.) 3-4 THE ENVIRONMENT DIVISION OBJECT-COMPUTER (Cont.) 4. The PROGRAM COLLATING SEQUENCE clause specifies a collating sequence for a program. When you use the PROGRAM COLLATING SEQUENCE clause the collating sequence is the one associated with alphabet-name. When you do not use the PROGRAM COLLATING SEQUENCE clause the collating sequence is ASCII. The program collating sequence determines: 1. the results of explicit comparisons relation-conditions and in condition-name conditions 2. the results of implicit comparisons in CONTROL clauses of report description entries 3. the order of records processed by SORT and MERGE statements which do not specify another collating sequence with the COLLATING SEQUENCE phrase 4. the values of the LOW-VALUE figurative constants HIGH-VALUE in and (See the alphabet-name IS clause in the SPECIAL-NAMES paragraph for information on how to associate a collating sequence with alphabet-name.) 5. If you use the SEGMENT-LIMIT clause, only those segments having segment numbers from a up to but not including the value of integer-3 are treated as resident segments of the program. Integer-3 must be a positive integer in the range 1 to 49. If you omit the SEGMENT-LIMIT clause, segments having segment numbers from a through 49 are considered as resident segments of the program (that is, SEGMENT-LIMIT IS 50 is assumed). More on segmentation can be found in Sections 5.3 and 11.1. 6. The DISPLAY clause is optional. If you include it in your program, the compiler will use the DISPLAY type you specify as the default in determining the recording mode for external files and for items described in the Data Division as DISPLAY. This allows you to change the default usage inside the program without using compiler switches. The effect of specifying DISPLAY IS DISPLAY-9 is the same as that of including a IX switch in the command string to the compiler. However, the IX switch will always override the DISPLAY clause. For example, if you include in your program the following statement DISPLAY IS DISPLAY-7 all items described in the Data Division as USAGE IS will be considered DISPLAY-7 items. Example DECSYSTEM-l077 MEMORY 50000 WORDS SEGMENT-LIMIT IS 35 PROGRAM COLLATING SEQUENCE IS NATIVE DISPLAY re DISPLAY-7. ~BJECT-COMPUTER. 3-5 DISPLAY THE ENVIRONMENT DIVISION SPECIAL-NAMES 3.1.4 SPECIAL-NAMES Function The SPECIAL-NAMES paragraph provides a means of assigning mnemonic names to input/output devices, code sets, and collating sequences. This paragraph may also define the character used as a currency slgn, and may specify the interchange of decimal point and comma functions in the program. General Format [SPECIAL-NAr.1ES. STANDARD-l NATIVE literal-l alphabet-name IS THROUGH} . { THRU llteral-2 [ ALSO ,1 iteral-3 [ALSO 1 iteral-4 ] literal-5 [ .J THROUGH} . { THRU llteral-6 [ ALSO literal-7 [ALSO literal-S] . .. ] r=literal-9 ~ mnemonic-name~ ~CURRENCY SIGN ~ literal-l0~ [DECIMAL-POINT Ii COMMA- ] .J Technical Notes 1. This paragraph is optional. 2. The reserved word CONSOLE refers to the user's terminal. The assigned mnemonic-name may be used with the ACCEPT and DISPLAY verbs in the Procedure Division to input data from and output data to the terminal. 3. The name CHANNEL refers to a channel on the line-printer control tape. m and n represent any integer from 1 to Sand refer to anyone of the eight channels on the tape. Control tape channels can be referred to in the. ADVANCING clause of the WRITE' verb in the Procedure Division to advance the paper form to the desired channel position. (Refer to the Hardware Reference Manual for a description of printer control ~apes.) For example, if the entry CHANNEL (1) IS TOP-OF-PAGE 3-6 THE ENVIRONMENT DIVISION SPECIAL-NAMES (Cont.) is included in this paragraph, the following procedure statement will print the line and then skip to the top of the next page. IF LINE-COUNT IS GREATER THAN 50 WRITE PRINT-RECORD BEFORE ADVANCING TOP-OF-PAGE. 4. The alphabet-name IS clause associates a user-specified name with a sequence of characters that may be used as a character code set, a collating sequence, or both. This character sequence may be either one of the two sequences provided by the compiler or a sequence specified by the user. A character code set is specified by referencing alphabet-name in the CODE-SET clause of a file description. When defining a character code set, the alphabet-name IS clause is restricted to STANDARD-I, NATIVE, ASCII, or EBCDIC. A collating sequence is specified by referencing alphabet-name either in the PROGRAM COLLATING SEQUENCE clause of the OBJECT-COMPUTER paragraph or in the COLLATING SEQUENCE phrase of a SORT or MERGE statement. When STANDARD-I, NATIVE, or ASCII appear in an alphabet-name IS clause, the character code set and collating sequence specified is ASCII. When EBCDIC appears in an alphabet-name IS clause, the character code set and collating sequence specified is EBCDIC. When the literal phrase appears in an alphabet-name IS clause, the literals define an ascending collating sequence in the order of their appearance in the phrase. Numeric literals represent the ordinal number of the character within the ASCII character set and must be in the range from 1 through 128. Nonnumeric literals in an alphabet-name IS clause represent themselves. If the literal contains multiple characters, they are assigned successive ascending positions within the collating sequence, starting with the leftmost character. Characters whose positions are not explicitly defined by the literal phrase are assigned positions higher than the specified characters and in their normal ASCII sequence. When you specify the THROUGH phrase, the set of contiguous ASCII characters beginning with the character specified by literal-l and ending with the character specified by literal-2 are assigned successive ascending positions in the collating sequence. The characters specified by a THROUGH phrase may be in either ascending or descending order. When you specify the ALSO phrase, the characters specified by literal-I, literal-3, literal-4, •.• , are all" assigned to the same position in the collating sequence. The highest character in the collating sequence, regardless of how it is specified, becomes the figurative constant HIGH-VALUE. If more than one character occupies this position, the last character specified becomes HIGH-VALUE. The lowest character in the collating sequence, regardless of how it is specified, becomes the figurative constant LOW-VALUE. If more than one character occupies this position, the first character specified becomes LOW-VALUE. 3-7 THE ENVIRONMENT DIVISION SPECIAL-NAMES (Cont.) 5. The clause literal-l IS mnemonic-name-5 specifies the CODE value for a particular report (refer to the CODE clause in Section 4.9.26). Literal-l must be an alphanumeric literal enclosed in quotation marks, and can be from 1 through 120 characters in length. 6. If you use the CURRENCY SIGN clause in the SPECIAL-NAMES paragraph, you· must use the literal you specify (instead of the $ character) in PICTURE clauses in the Data Division. For instance, if you wish to insert a currency sign at the front of a field which is to be printed on your report, you must use the literal you specified - not the $ character - as the editing symbol. This literal is limited to a single printable must not be one of the following characters: character and digits 0 through 9 alphabetic characters A, B, C, 0, P, R, S, V, X, Z special characters 7. * + - , . , ( ) " If you use the DECIMAL-POINT IS COMMA clause, then the functions of the comma and period are interchanged for all PICTURE clauses and numeric literals. Example SPECIAL-NAMES. CONSOLE IS MYTERM CHANNEL (1) IS TOP-OF-PAGE. 3-8 THE ENVIRONMENT DIVISION INPUT-OUTPUT SECTION 3.1.5 INPUT-OUTPUT SECTION The Input-Output Section names the files and exiernal media required by the object program and provides information required for transmitting and handling data during execution of the object program. This section consists of the section header (INPUT-OUTPUT SECTION.) followed by one or more of the following paragraphs: FILE-CONTROL. (See Section 3.1.6) I-O-CONTROL. (See Section 3.1.15) Technical Notes 1. This section is optional. 2. Each SELECT All semicolons and commas are optional. statement in the FILE-CONTROL paragraph must end with a period. The entire entry in the I-O-CONTROL paragraph must end with a period. 3-9 THE ENVIRONMENT DIVISION FILE-CONTROL 3.1.6 FILE-CONTROL Function The FILE-CONTROL paragraph names each file, identifies medium, and allows logical hardware assignments. the file General Format FORMAT 1: SELECT [OPTIONAL] fi 1e-name ASSIGN TO device-name-l . [ RESERVE lnteger-l [devi ce-name-2 ] II [AREA AREAS-!j ~ORGANIZATION IS SEQUENTIAL~ ~ACCESS MODE IS SEQUENTIAL~ RECORDING tODE IS ~YTE ASCI I SI XBIT BINARY MODE] -F-- V STAN DARD-ASCI I STAN DARD ASCI I FI LE-STATUS} { FI LE STATUS IS ~a.ta-name-5 data-name-l data-name-2 data-name-3 Gata-name-6 Gata-name-7 [itata-name-S 3-10 [:ata-name-4 1]]] J THE ENVIRONMENT DIVISION FILE-CONTROL (Cont.) FORMAT 2: SELECT file-name ~ ASSIGN TO 'device-name-l device-name-2 ] ~RESERVE integer-l [~~~:~~ ORGANIZATION IS RELATIVE RELATI VE KEY IS data-name-l (SEQUENTIAL [ ACCESS MODE IS )t {RANDOM } DYNAMI C RECORDING tODE IS ~YTE RELATI VE KEY IS data-name-l n U ASCI I S I XB IT BINARY MODE] -F-- V STANDARD-ASCI I STAN DARD AS ell FILE-STATUS { FI LE STATUS ft IS ~ata-name-5 data-name-l data-name-2 Gata-name-6 Gata-name-7 3-11 data-name-3 [:ata-name-4 [data_name-8JJ~ THE ENVIRONMENT DIVISION FILE-CONTROL (Cont.) FORMAT 3: SELECT fil e-name ASSIGN TO device-name-l [ devi ce-name-2 ] ... ~RESERVE integer-l [:~:~~S~ ORGANIZATION IS INDEXED L IACCESS MODE IS ~ ~!~~6~TIAL jn l U DYNAMIC RECORD KEY IS data-name-l RECORDING ~ODE ~YTE IS ASCII S I XB I T BINARY MODE] F '1 STAN DARD-AS CII STANDARD ASCII FI LE- STAT US } { FILE STATUS I S dat a - na me - 1 data-name-2 ~ata-name-5 ~ata-name-6 ~ata-name-7 3-12 data-name-3 [:ata-name_4 [data-name-a=LIIll THE ENVIRONMENT DIVISION FILE-CONTROL (Cont.) Technical Notes 1. This section is optional. 2. All semicolons and commas are optional. must end with a period. 3. The SELECT and ASSIGN statements must appear before any other clause shown, and the SELECT statement must precede the ASSIGN statement. Every file described in the Data Division must be named in a SELECT clause in the Environment Division. Thus, the following clause must be specified for every such file: SELECT file-name ASSIGN TO device-name. 4. The individual clauses are described on the in the order shown above. 3-13 Each SELECT following clause pages THE ENVIRONMENT DIVISION SELECT 3.1.7 SELECT Function The SELECT statement names each file that is to be described Data Division, and assigns each file to a particular device. in the General Format SELECT file-name ASSIGN TO device-name-l [ devi ce-name-2 ] Technical Notes 1. Each file described in the Data Division must be named once and only once as a file-name in a SELECT statement. Conversely, each file named in a SELECT statement must have a File Description entry in the Data Division. Each file-name must be unique within a program. 2. The key word OPTIONAL is required for input files that are not necessarily present each time the object program is run. When your program tries to open a file which you have declared to be OPTIONAL, the question IS file-name PRESENT? is typed on the operator's console and the operator responds with YES or NO. If the response is YES, the file is processed normally; if the response is NO, the first READ statement executed for that file will immediately take the AT END or INVALID KEY path. NOTE ISAM files may not be optional. They must be present at program start-up, even if only as dummy files. (Refer to the COBOL-74 Usage Material, Part 3 of this manual, for more information on ISAM.) 3. The ASSIGN clause specifies the device for a file. Device-names can be either physical device-names or logical device-names. Physical device-names are fixed mnemonic-names that refer to specific peripheral devices. When specified in an ASSIGN clause, a physical device-name assigns the associated file to that device. Physical device-names are described in the TOPS-IO Operating System Commands Manual and the TOPS-20 User's Guide. 3-14 THE ENVIRONMENT DIVISION SELECT (Cont.) Logical device-names are names created by the programmer. They can contain up to six characters, and can consist of any combination of letters and digits. At object execution time, each logical device-name must be assigned to a physical device by means of a monitor command (refer to the COBOL-74 Usage Material, Part 3 of this manual~ for an explanation of the commands). 4. You may assign more than one device to a file to avoid delay when switching from one reel or unit to the next. When you specify more than one device the object program automatically uses the next device, in a cyclic manner, when an end-of-reel condition is detected. This applies only to tape devices and SORT and ISAM files, and it is unconditional for tapes. For SORT/MERGE, any number of devices may be assigned. If the disks are specified generically, SORT/MERGE will use its internal algorithm to determine which physical devices to use. Otherwise, all devices specified will be used in a round-robin fashion. For ISAM files you may assign not more than two devices. 5. If the access mode is INDEXED and two devices are assigned, the first device is assumed to contain the index portion of the file and the second to contain the data portion of the file. If one device is specified, it is assumed to contain both the index portion and the data portion of the file. 6. For ISAM and random files, the devices must be random-access. Examples SELECT INFIL ASSIGN TO MTA1. SELECT SRTFIL ASSIGN TO DSK, DSK, DSK. 3-15 THE ENVIRONMENT DIVISION RESERVE 3.1.8 RESERVE Function The RESERVE clause allows you to specify the actual number of input/output buffer areas for the compiler to allocate to this file. General Format ~ESERVE integer-l [ AREAJO AREAS Technical Notes 1. If you specified the organization for this file as RELATIVE or INDEXED, this clause is ignored and only one buffer area is assigned. 2. If you did not specify RELATIVE or INDEXED organization, the integer specifies the number of buffer areas for the compiler to assign. 3. If you omit this clause for a sequential file, two areas will be assigned. 4. Integer-l does not have a maximum, but you may run out of available memory if you request too many areas res~rved. You may also make your program run slower if you request a large number of areas, since the program will be that much bigger. Example SELECT INFIL ASSIGN TO DSK RESERVE 1 AREA. 3-16 THE ENVIRONMENT DIVISION ORGANIZATION 3.1.9 ORGANIZATION Function The ORGANIZATION clause specifies the way in organized. General Format ORGANIZATION IS ! SEQUENTIAL RELATIVE INDEXED DEFERRED } {. CHECKPOINT OUTPUT which a file will be I Technical Notes 1. The ORGANIZATION clause indexed-sequential files. files. is It required for is ignored relative and for sequential 2. If ORGANIZATION IS SEQUENTIAL and the file is on a random-access device, records are obtained or placed sequentially. That is, the next logical record is made available from the file on a READ statement execution, and an output record is placed into the next available area on a WRITE statement execution. Thus sequential-access processing on a random-access device is functionally similar to the processing of a magnetic tape file. 3. If ORGANIZATION IS RELATIVE, the contents of the data item associated with the RELATIVE KEY specifies which record, relative to the beginning of the file, is made available by a READ statement, or where the record is to be placed by a WRITE statement " or which record is to be deleted by a DELETE statement, or which record will be replaced by a REWRITE statement. 4. If ORGANIZATION IS INDEXED, the contents of the data item associated with the RECORD KEY specifies which record is made available by a READ statement, or where the record is to be placed by a WRITE statement, or which record is to be deleted by a DELETE statement, or which record will be replaced by a REWRITE statement. 5. The DEFERRED OUTPUT option of the ORGANIZATION IS INDEXED clause causes the object-time system to output a block of an indexed-sequential file only when another block must be brought into memory. Normally, to ensure integrity for the file, a block is output every time a record is written, even if re'cords are written successively in the same block. When a file is opened for simultaneous update, the DEFERRED OUTPUT clause is ignored. Refer to the OPEN statement, Section 5.9.25. 3-17 THE ENVIRONMENT DIVISION ORGANIZATION (Cont.) 6. If you are using ISAM files sequentially, DEFERRED OUTPUT provides the advantage of running faster. However, your file is also more easily damaged if the system crashes. Thus, its use is advantageous if file integrity is not important. 7. If you use the ORGANIZATION IS INDEXED clause, you may also specify the CHECKPOINT OUTPUT option (instead of DEFERRED OUTPUT). If you specify this option, the object-time system will force the buffers to be written out, and all pointers internal to the file to be updated, after every WRITE statement. This will naturally make your program run much more slowly. However, it will also safeguard your file against system crashes, since the file will have been updated after the last WRITE before the crash. Example SELECT INFIL ASSIGN TO DSK, DSK ORGANIZATION IS INDEXED DEFERRED OUTPUT. 3-18 THE ENVIRONMENT DIVISION ACCESS MODE 3.1.10 ACCESS MODE Function The ACCESS MODE clause specifies the method used to access the file in question. General Format [ ACCESS MODE IS J) SEQUENTIAL ~ RANDOM ~ DYNAMIc ) Technica"l Notes 1. If you do not specify the ACCESS MODE clause, ACCESS MODE IS SEQUENTIAL is assumed regardless of the organization of the file. 2. If you specify ACCESS MODE IS DYNAMIC you may access the file either sequentially or randomly. 3. When you specify ACCESS MODE 'IS SEQUENTIAL, the records in your file are accessed in the sequence dictated by the file organization. Sequential files are accessed in the same order they are added to the file. Relative files are accessed in ascending relative record number order. Indexed files are accessed in ascending record key order. 4. If you choose random access mode, the relative key (for relative files) or the record key (for indexed files) indicates the record to be accessed. Example SELECT INFILE ASSIGN TO DSK ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS RECKEY. 3-19 THE ENVIRONMENT DIVISI(;)N RECORD KEY 3.1.11 RECORD REY Functian The RECORD KEY clause specifies the record in an indexed-sequential file that is to be read, written, deleted, or rewritten. General Format RECORD KEY IS data-name-l Technical Notes 1. The RECORD KEY clause is valid only for files whose access mode is INDEXED; it must be specified for those files (refer to the READ statement, Section 5.9.27). 2. You must define the RECORD KEY data-name as an item in the record area of the file to which it pertains. Though the RECORD KEY is described in only one of the records, it is assumed to occupy the same position in all records for that file. 3. The RECORD KEY is required to describe the location in the record area of the key for the file. The contents of the RECORD KEY data-item must be unique for each record in the file and cannot be equal to LOW-VALUES (refer to, the READ, WRITE, REWRITE, and DELETE statements in Section 5.9). Example SELECT INFIL ASSIGN TO DSK, DSK ORGANIZATION IS INDEXED RECORD KEY IS RECKEY. 3-20 THE ENVIRONMENT DIVISION RELATIVE KEY 3.1.12 RELATIVE KEY Function The RELATIVE KEY clause specifies which record is read or written in a random-access file. General Format RELATIVE KEY IS data-name-l Technical Notes 1. The RELATIVE KEY clause is valid only for a file whose organization is RELATIVE; it must be specified for this type of file. This clause cannot be used for a file whose organization is INDEXED or SEQUENTIAL. 2. The RELATIVE KEY data-name must be defined in the Data Division as a COMPUTATIONAL item of ten or fewer digits. The PICTURE can contain only the characters Sand 9 or their equivalent,. for example S9(10). Example SELECT INFIL ASSIGN TO DSK ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS RKEY. 3-21 THE ENVIRONMENT DIVISION RECORDING MODE/DENSITY/PARITY 3.1.13 RECORDING MODE/DENSITY/PARITY Function The RECORDING clause specifies the recording mode, tape parity for a magnetic tape file. density, and General Format RECORDING tODE IS ~YTE MOD~ ASCI I SIXBIT BINARY F V STAN DARD-AS CI I STAN DARD ASCI I Technical Notes 1. The RECORDING MODE clause allows the user to record data on the device in a format other than that used in memory. The following recording modes are acceptable. ASCII - The file will be read/written as ASCII records, five 7-bit characters per 36-bit ~ord. Bit 35 (the rightmost bit) is ignored. SIXBIT - The file will be read/written as SIXBIT records, six 6-bit characters per 36-bit word with record headers. BINARY - The file will be read/written as binary records, bits per word. F 36 - The file will be read/written as fixed-length EBCDIC records, four 9-bit characters per 36-bit word. However, for industry-compatible magnetic tape (9-track, with at least 800 bpi density), the file will be read/written with four 8-bit characters per 36-bit word. If more than one record description is given in the FD entry, the record length must be'the same for all of them. 3-22 THE ENVIRONMENT DIVISION RECORDING MODE/DENSITY/PARITY (Cont.) V - The file will be read/written as variable-length EBCDIC records, four 9-bit characters per 36-bit word with record and block headers. However, for industry-compatible magnetic tape (9-track, with at least 800 bpi density) , the file will be read/written with four 8-bit characters per 36-bit word. If a file whose recording mod~ is V is open for INPUT-OUTPUT and the user overwrites a record, the record being written must be the same size as the overwritten record. A file whose recording mode is V cannot be opened for simultaneous update. STANDARD-ASCII (STANDARD ASCII) The five 7-bit bytes in each word in memory are transferred to five 8-bit bytes on the tape and bit 35 is stored in bit 0 of ·the fifth byte on tape. The character set and the character encodings are the same as those of ASCII recording mode. This enables interchanges with other manufacturers' ASCII data files. The format of records for each recording Sections 8.1 and 8.2 of this manual. 2. mode is given in The recording mode of a file is determined by a number of factors besides the recording mode specified in the RECORDING MODE clause. These factors are: a. If the device can only accept ASCII data (for example, a line printer), the object-time system will always use ASCII as the recording mode no matter what recording mode is specified. b. If the ADVANCING or POSITIONING clause is included in the WRITE statement, the object-time system will always use ASCII as the recording mode no matter what recording mode is specified. c. If the file descriptor (FD) has a REPORT clause, the object-time system will always use ASCII as the recording mode no matter what recording mode is specified. d. The recording mode specified in the RECORDING MODE clause is compareQ to the USAGE clause for the record. Normally, the recording mode specified is used. However, if the recording mode is not specified, the default recording mode will depend on the usage mode. If neither the recording mode nor the usage mode is specified, and the /X switch is not included in the command string to the compiler, the default recording mode is SIXBIT. If the /X switch is present, the default recording mode is F. 3-23 THE ENVIRONMENT DIVISION RECORDING MODE/DENSITY/PARITY (Cont.) When the recording mode is not declared, it is inferred from the usage mode for the record according to the rules given above. However, the reverse is not true; that is, when the recording mode is declared and no usage mode is given for a record, the presence of the RECORDING MODE clause serves only to specify the recording mode of the file. The usage mode of the records in the file may default to another character set, with undesirable results (see the USAGE clause in Section 4.9.23). Table 3-1 shows the resulting recording mode when the recording mode declared in the RECORDING MODE clause is compared to the usage mode declared in the USAGE clause. 3. The DENSITY and PARITY clauses are valid only for magnetic tape and are ignored for all other devices. If the DENSITY clause is not present, tapes are recorded in the density standard for the installation. The density for a job can be modified by system commands which are described in the Operating System Commands Reference Manual for users of TOPS-lO, and in the TOPS-20 User's Guide for users of TOPS-20. Remember that not all drives will handle all densities. You should verify that the drive you plan to use will accept the density you specify. If the PARITY clause is omitted, ODD is assumed. Care must be taken when using even parity: if nulls are written into a file that is recorded in even parity, the file cannot be read properly. Nulls can be written into a file without a user being aware of them; that is, when SYNCHRONIZED data items appear in an item, the word preceding the word in which the item is synchronized could contain nulls. 4. If BYTE MODE is used, the exact number of bytes is written on the tape. (It does not round up to a word boundary.) This is only valid on magnetic tape, and applies only to users of TOPS-IO. Its purpose is to enable interchanges with other manufacturers' equipment. Example SELECT INFIL ASSIGN TO MTAI RECORDING MODE IS V DENSITY IS 800 PARITY IS ODD. 3-24 THE ENVIRONMENT DIVISION RECORDING MODE/DENSITY/PARITY (Cont.) Table 3-1 Recording Modes RECORDING MODE Clause USAGE Clause RECORDING MODE Actually Used none DISPLAY-6 SIXBIT none DISPLAY-7 ASCII none DISPLAY-9 EBCDIC none none SIXBIT (no IX) none none EBCDIC (IX) SIXBIT D~SPLAY-6 SIXBIT SIXBIT DISPLAY-7 SIXBIT SIXBIT DISPLAY-9 SIXBIT ASCII DISPLAY-6 ASCII ASCII DISPLAY-7 ASCII ASCII DISPLAY-9 ASCII F or V DISPLAY-6 EBCDIC F or V DISPLAY-7 EBCDIC F or V DISPLAY-9 EBCDIC BINARY DISPLAY-6 BINARY BINARY DISPLAY-7 BINARY BINARY DISPLAY-9 BINARY NOTE The object-time system automatically makes the conversions necessary to have ~he recording mode conform to the usage mode of the records. (These conversions may cause your program to run more slowly. ) 3-25 THE ENVIRONMENT DIVISION FILE STATUS 3.1.14 FILE STATUS Function The FILE STATUS clause specifies data-items into which the object-time system places values when an I/O error or warning message occurs on the file specified by the SELECT clause. A user-written USE procedure may then examine and alter these values as part of a recovery process. General Format FILE-STATUS} { FI LE STATUS IS ~ata-name-5 data-name-l Gata-name-6 data-name-2 ~ata-name-7 data-name-3 [:ata-name-4 [data_name-aJJJ] Technical Notes 1. Data-name-l is required if you specify this clause, but data-name-2 through data-name-8 are optional. If you specify fewer than eight data-names, the compiler assumes that the data-names are specified starting with data-name-l and continuing in order. Therefore, if you wish to specify data-name-8, you must also specify data-name-l through data-name-7. 3-2-6 THE ENVIRONMENT DIVISION FILE STATUS (Con t.) 2. You must define the data-names in the Working Storage Section of the Data Division in the following form. data-name-1 data-name-2 data-name-3 data-name-4 data-name-5 data-name-6 data-name-7 data-name-8 3. PIC 9(2). PIC 9(10). USAGE INDEX. PICX(9). USAGE INDEX. USAGE INDEX. PICX(30). USAGE INDEX. After a fatal I/O error, the FILE STATUS fo11bwing values. items contain the data-name-1 contains the file status. data-name-2 contains a 10-digit error number. data-name-3 contains the action code, which is set to zero. data-name-4 contains the VALUE OF ID. data-name-5 contains the current block number. data-name-6 contains the current record number. data-name-7 contains the file name. data-name-8 contains the file-table pointer. The file status, which is stored in data-name-1, is set to one of following 2-character codes. 00 10 22 23 24 30 34 the the I/O was successful. no next logical record; that is, there is no next record in the file. The AT END path is taken. duplicate key; that is, an attempt was made to write a record into a record position that is already occupied. The INVALID KEY path is taken. no record found on READ, REWRITE, DELETE; that is, when an indexed-sequential file was accessed, an empty record position was found. The INVALID KEY path is taken. boundary violation, that is, the random file's actual key violated the file limits. The INVALID KEY path is taken. permanent error; that is, a successful hardware operation cannot be done without a hardware error signal. permanent error; that is, more space on the media cannot be obtained to extend the file for output operations. The 10-character error number stored in data-name-2 has the form: ABCDEFGHIJ where the code has the meanings shown below. AB contains a value indicating the COBOL verb that caused the error. o 1 2 3 4 5 6 no COBOL verb error OPEN CLOSE WRITE REWRITE DELETE READ 3-27 THE ENVIRONMENT DIVISION FILE STATUS (Cont.) CD contains a value indicating the monitor call error. (UUO) that caused the o no UUO error 1 2 3 4 5 6 7 INPUT OUTPUT LOOKUP ENTER RENAME INIT FILOP EF contains a value indicating the type of file the error occurred. being accessed when o None of the following 1 2 3 4 ISAM index file ISAM data file a sequential file a random file G contains a value indicating the accessed when the error occurred. ISAM block type that was being o None of the following 1 2 3 4 ISAM statistics block ISAM SAT block ISAM index block ISAM data block HIJ contains a value indicating an error number on INPUT or OUTPUT. If CD is 0, HIJ contains an error number. The numbers and their meanings are listed below. Note that these are the same as the messages issued by LIBOL after an error or warning occurs. o None of the following 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 SYMBOLIC-KEY MUST NOT EQUAL LOW-VALUES 2 NO MORE INDEX LEVELS AVAILABLE INSUFFICIENT MEMORY WHILE ATTEMPTING TO SPLIT THE TOP INDEX BLOCK VERSION NUMBER DISCREPANCY ALLOCATION FAILURE - ALL BLOCKS ARE IN USE THE MAXIMUM RECORD SIZE MAY NOT BE EXCEEDED CANNOT EXPAND MEMORY WHILE SORT IS IN PROGRESS INSUFFICIENT MEMORY FOR BUFFER REQUIREMENTS BLOCKING-FACTOR DIFFERS BETWEEN INDEX FILE AND FILE-TABLE FILE CANNOT BE OPENED, ALREADY OPEN LOCKED FILE CANNOT BE OPENED FILE CANNOT BE OPENED SHARES BUFFER AREA WITH OPENED FILE FILE CANNOT BE OPENED DEVICE IS NOT AVAILABLE TO THIS JOB FILE CANNOT BE OPENED DEVICE IS ASSIGNED TO ANOTHER FILE FILE CANNOT BE OPENED DEVICE CANNOT INPUT/OUTPUT FILE CANNOT BE OPENED DEVICE CANNOT INPUT FILE CANNOT BE OPENED DEVICE CANNOT OUTPUT FILE CANNOT BE OPENED DEVICE IS NOT A DEVICE FILE CANNOT BE OPENED DIRECTORY DEVICE MUST HAVE STANDARD LABELS FILE CANNOT BE CLOSED BECAUSE IT IS NOT OPEN 3-28 THE ENVIRONMENT DIVISION FILE STATUS (Cont.) 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 FILE CANNOT BE CLOSED THE CLOSE "REEL" OPTION MAY NOT BE USED WITH A MULTI-FILE-TAPE FILE IS NOT OPEN FOR OUTPUT ZERO LENGTH RECORDS ARE ILLEGAL FILE CANNOT DO OUTPUT "AT END" PATH HAS BEEN TAKEN FILE CANNOT DO INPUT ENCOUNTERED AN "EOF" IN THE MIDDLE OF A RECORD FILE CANNOT DO INPUT RECORD-SEQUENCE-NUMBER n SHOULD BE m FILE CANNOT DO INPUT file-name ON device-name SHOULD BE REORGANIZED, THE TOP INDEX BLOCK WAS JUST SPLIT NOT USED EITHER THE ISAM FILE DOES NOT EXIST OR THE VALUE OF ID CHANGED DURING THE PROGRAM ATTEMPT TO DO I/O FROM A SUBROUTINE CALLED BY A NON RESIDENT SUBROUTINE. FILE CANNOT BE OPENED I/O CANNOT BE DONE FROM AN OVERLAY. FILE CANNOT BE OPENED READ AN "EOF" INSTEAD OF A LABEL CLOSE REEL IS LEGAL ONLY FOR MAGNETIC TAPE FILE IS NOT OPEN FOR INPUT NOT ENOUGH FREE MEMORY BETWEEN .JBFF AND OVERLAY AREA INSUFFICIENT MEMORY WHILE ATTEMPTING TO SPLIT THE TOP INDEX BLOCK STANDARD ASCII RECORDING MODE AND DENSITY OF 1600 BPI REQUIRE THE DEVICE TO BE A TU70 TAPOP. FAILED - UNABLE TO SET STANDARD-ASCII MODE GOT AN EOF IN MIDDLE OF BLOCK/RECORD DESCRIPTOR WORD BLOCK DESCRIPTOR WORD BYTE COUNT IS LESS THAN FIVE ERROR - GOT ANOTHER BUFFER INSTEAD OF "EOF" ERROR - RECORD EXTENDS BEYOND THE END OF THE LOGICAL BLOCK IT IS ILLEGAL TO CHANGE THE RECORD SIZE OF AN EBCDIC I/O RECORD THE TWO LOW-ORDER BYTES OF A BLOCK/RECORD DESCRIPTOR WORD MUST BE ZERO If CD is set to 1 or 2, HIJ contains the number of an I/O error status bit. The I/O error status bits, their mnemonics, and their meanings, are shown in Table 3-2. 3-29 THE ENVIRONMENT DIVISION FILE STATUS (Cont.) Table 3-2 Monitor File Status Bits Bit Mnemonic Meaning 18 IO. IMP Improper Mode. Attempt to write on a software write-locked file structure, or a software redundancy failure occurred. This bit is usually set by the monitor. The user cannot set this bit. 19 IO.DER Hardware device error. The disk unit is in error, rather than the data on the disk. However, data read into memory or written on the disk is probably incorrect. The user does not usually set this bit. 20 IO.DTE Hard data error. The data read or written has incorrect parity as detected by the hardware. The user's data is probably unrecoverable even after the device has been fixed. This bit is usually not set by the user. 21 IO.BKT Block too large. A disk data block is too large to fit into the buffer; or a block number is too large for the disk unit; or DSK has been filled; or the user's quota on the file structure has been exceeded. This bit is usually not set by the user. This error is also returned when the user tries to close a file that has open locks associated with it (via Enqueue/Dequeue). 22 IO.EOF End-of-file. The user program has requested data beyond the last block of the file with an IN or INPUT call; or USETI has specified a block beyond the last data block of the file. When IO.EOF is set, no data has been read into the buffer. This bit is usually not set by the user. 23 IO.ACT I/O Active. The disk is transmitting or receiving data. is always set by the monitor for use. 29 IO.WHD Write disk-pack headers. This is used in conjunction with the SUSET. monitor call to format a disk pack. (Not used in COBOL) 30 IO.SYN Synchronous mode I/O. Stop disk after every buffer is read or written. (Not used in COBOL) 31 Io.uwe User word count, supplied by each buffer. 32-35 IO.MOD Data mode of the device. the actively This bit its own user in THE ENVIRONMENT DIVISION FILE STATUS (Cont.) For the file status for Manual. each device, refer to the Monitor Calls If CO is set to 3, 4, 5, or 7, HIJ contains the error code for LOOKUP, ENTER, RENAME, or FILOP errors. "Table 3-3 gives these codes and their meanings. Table 3-3 Monitor Error Codes Explanation Code o File not found, illegal filename (0,*), filenames do not match, or RENAME after a LOOKUP failed. 1 UFO does not exist on specified file structures. (Incorrect project-programmer number) 2 Protection failure or directory full on DTA. 3 File being modified. 4 Filename already exists (RENAME) or filename is different (ENTER after LOOKUP) or requested supersede (on a non-superseding ENTER). 5 Illegal sequence of UUOs (RENAME with neither LOOKUP nor ENTER, or LOOKUP after ENTER). 6 1. 2. 3. Transmission, device, or data error. Hardware-detected device or data error detected while reading the UFO RIB or UFO data block. Software-detected data inconsistency error detected while reading the UFO RIB or file RIB. 7 Not a saved file. 10 Not enough memory. 11 Device not available. 12 No such device. 13 No 2-register relocation expected to occur) 14 No room on this file structure or quota exceeded (overdrawn quota not considered). 15 Write-lock structure. error. 16 Not enough monitor. table 3-31 (Not expected to occur) capability. Cannot space in (Not write on file free memory of THE ENVIRONMENT DIVISION FILE STATUS (Cont.) Table 3-3 (Cont.) Monitor Error Codes Code 4. Explanation 17 Partial allocation only. 20 Block not free on allocated position. 21 Cannot supersede an existing directory. 22 Cannot delete a nonempty expected to occur) 23 Subdirectory not found (some specified path was not found). 24 Search list empty (LOOKUP or ENTER was performed on generic device DSK and the search list is empty) ~ 25 Cannot create a SFD nested deeper than the maximum allowed level of nesting. (Not expected to occur) 26 No file structure in the job's search ~ist has both the no-create bit and the write-lock bit equal to zero and has the UFD or SFD specified by the default or explicit path (ENTER on generic device DSK only). 27 GETSEG from a locked low segment to a high segment which is not a dormant, active, or idle segment. (Segment not on the swapping space) (Not expected to occur) 30 Cannot update file. 31 Low segment overlaps expected to occur) 32 Not logged in. high directory. SFD segment. (Not in the (Not (Not expected to occur) The FILE STATUS items are the paths of communications between the object-time system and a USE procedure. A USE procedure specifies a recovery process executed when an error or warning occurs during an I/O operation. A USE procedure determines the error or warning type from the error-number placed into data-name-2 by the object-time system. Control returns to the object-time system at the conclusion of the USE procedure. The object-time system action is determined by the error number and by the contents of the action-code placed into data-name-3 by the USE procedure. If the action-code is set to 1, the object-time system ignores the error and continues the run. If the action-code is left set 3-32 THE ENVIRONMENT DIVISION FILE STATUS (Cont.) to 0, the object-time system issues an error message terminates the run. If the error-number is 17, object-time system continues the run independent of action-code setting. If the action-code is not 0 or 1, object-time system action is undefined. and the the the When the program comes to a normal termination and you have requested (by loading a "1" into the action-code) that errors be ignored, the object-time system issues the following message: %n ERRORS IGNORED 5. Refer to the USE statement in Section 5.9.42 for writing USE procedures. 6. If you did not specify the FILE STATUS statement, I/O error recovery processing cannot be performed. If you specify the FILE STATUS statement with only data-name-l included, you can examine the status of the file, but you cannot specify that the object-time system ignore the error because you cannot set the action code (data-name-3). You also cannot examine the error number (data-name-2). Example SELECT INFIL ASSIGN DSK, DSK ORGANIZATION IS INDEXED ACCESS MODE IS RANDOM RECORD KEY IS RECKEY RECORDING MODE IS ASCII FILE STATUS IS FILSTAT, ERRNUM, ACTCODE, VID, BLKNUM, RECNUM, FILNAM, FILPNTR. DATA DIVISION. WORKING-STORAGE SECTION. 77 FILSTAT PIC 9(2). 77 ERRNUM PIC 9(10). 77 ACTCODE INDEX. 77 VIP PIC X(9). 77 BLKNUM INDEX. 77 RECNUM INDEX. 77 FILNAM PIC X(30). 77 FILPNTR INDEX. 3-33 details of THE ENVIRONMENT DIVISION I-O-CONTROL 3.1.15 I-O-CONTROL Function The I-O-CONTROL paragraph specifies the points at which a RERUN DUMP is to be performed, the memory area that is to be shared by different files, and the location of files on a multiple-file reel. General Format [I - 0- CONTROL. [RERUN EVERY ~AME f l END DF {~m} I integer-l RECORDS J RECORD SORT [ SORT-MERGE OF fil e-name-l ] AREA FOR file-name-2 { fil e-name- 3 } .J ~ULTIPLE FILE TAPE CONTAINS file-name-4 [POSITION integer-3] ~ile-name-5 ~POSITION integer-~~ ... ~. ~ a rerun Technical Notes 1. This paragraph is optional. 2. The RERUN clause performed. specifies when dump is to be The dump is always written onto a disk file, using the program's low segment name as the filename, and an extension of CKP. If the program has no filename because it was neler saved, the program name (from the PROGRAM-ID paragraph in the Identification Division) is used as a filename, with the extension CKP. If you use the END OF UNIT option, a rerun dump is taken at the end of each input or output reel of the specified REEL file. If you use the integer-l RECORDS option, a rerun dump is taken whenever a number of logical records equal to a multiple of integer-l is either read or written for the file. 3-34 THE ENVIRONMENT DIVISION I-O-CO:NTROL (Cont.) A rerun dump is not taken if any files are open for input/output (updating), or if any file is open on a device other than magnetic tape, disk, line printer, or terminal, or if an indexed-sequential (ISAM) file is open. Therefore, do not attempt to have a rerun dump taken while a sort is in progress. Also, RERUN cannot be used if overlays are used or if files are open for simultaneous update. 3. The SAME AREA clause specifies that two or more files are to use the same area during processing; this overlapping applies to all buffer areas and the record area. However, unless the RECORD option is used, only one of the named files can be open at one time. If you specify the RECORD option, the files share only the record area (that is, the area in which the current logical record is processed). All of the files mentioned in the SAME RECORD AREA clause may be open at the same time. A logical record in the SAME RECORD AREA is considered to be a logical record of each opened output file whose name appears in the SAME RECORD AREA clause, as well as the most recently read input file whose name is specified. Since the various DISPLAY usages are represented differently in memory, you must keep track of the usage of the record in the SAME RECORD AREA. You may use the record in any way you would otherwise use it. However, you must be sure that you have a record of the expected usage in the SAME RECORD AREA. If, for example, you plan to use a DISPLAY~7 record in your processing, you must have a DISPLAY-7 record in the SAME RECORD AREA, not a DISPLAY-6 record. You will not get an error message if you attempt to use a DISPLAY-6 record as if it were DISPLAY-7. The SORT option is used for sort files. However, this option need not be specified because all sort files always use the same sort area. 4. The MULTIPLE FILE clause is required when several files share the same physical reel of tape. This clause is invalid for media other than magnetic tape. Regardless of the number of files on a single reel, only those files defined in the program may be listed. If all files residing on the tape are listed in consecutive order, the POSITION option need not be given. If any file on the tape is not listed, the POSITION option must be included; integer-2, integer-3, and so forth, specify the position of the file relative to the beginning of the tape. All files on the same reel of tape must be ASSIGNed to"the same device in the FILE-CONTROL paragraph. No more than one file on the same reel of tape can be open at one time. Example I-O-CONTROL. RERUN EVERY 300 RECORDS OF INFIL SAME RECORD AREA FOR INFIL, OUTFIL MULTIPLE FILE TAPE CONTAINS INFIL POSITION 4. 3-35 THIS PAGE INTENTIONALLY LEFT BLANK. THE ENVIRONMENT DIVISION VERB FORMATS THE ENVIRONMENT DIVISION GENERAL FORMAT FOR ENVIRONMENT DIVISION ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. computer-name [WITH DEBUGGING MODE] . OBJECT-COMPUTER. computer-name ~EMORY L SIZE integer !{~CTERS IIjJ MODULES ~PROGRAM COLLATING SEQUENCE IS alPhabet-name] ~SEGMENT-LIMIT ~ segment-number~ [SPECIAL-NM1ES. alphabet-name IS STAN DARD- 1 NATIVE literal-I THROUGH} . { THRU llteral-2 [ ALSO literal-3 [ALSO literal-4] literal-5 [ .J .J] THROUGH} . { THRU llteral-6 [ ALSO literal-7 [ALSO literal-S] r=literal-9 ~ mnemonic-name~ [CURRENCY SIGN l i literal-IO] [DECIMAL-POINT Ii COMMA] . ] 3-36 THE ENVIRONMENT DIVISION GENERAL FORMAT FOR ENVIRONMENT DIVISION ~INPUT-OUTPUT SECTION. FI LE- CONTROL. { fi 1e-control-entry } [I -0- CONTROL. [RERUN EVERY SAME [. RECORD j) END OF {REEL} UNIT ~ integer-l RECORDS J SORT [ SORT-MERGE I OF fil e-name-l ] AREA FOR file-name-2 {file-name-3} ~ULTI PLE FILE TAPE CONTAI NS fi 1e-name-4 [POSITION integer-3] [ril e-name-5 [POSITION integer-~ 3-37 ... J. JJ ... :] THE ENVIRONMENT DIVISION GENERAL FORMAT FOR ENVIRONMENT DIVISION FORMAT 1: SELECT [OPTIONAL] fi 1e-name ASSIGN TO device-name-l [devi ce-name-2 ] II [AREA AREAS~ . [ RESERVE lnteger-l ~ORGANIZATION IS SEQUENTIAL~ ~ACCESS MODE IS SEQUENTIAL ~ RECORDING tODE IS FI LE-STATUS} { FI LE STATUS ~YTE IS Gata-name-5 ASCI I SIXSIT BINARY MODE] F ~ STANDARD-ASCI I STANDARD ASCII data-name-l ~ata-name-6 data-name-2 data-name-3 Gata-name-7 [data-name-nJJ]] 3-38 [:ata_name-4 THE ENVIRONMENT DIVISION GEN~RAL FORMAT FOR ENViRONMENT DIVISION FORMAT 2: SELECT fil e-name ASSIGN TO ~ device-name-l device-name-2 ] ~RESERVE integer-l [~~~~~~ ORGANIZATION IS RELATIVE ( [ SEQUENTIAL ACCESS MODE IS {{ RANDOM } ~ DYNAMI C RECORDING tODE IS ~YTE MODE] RELATI VE KEY IS data-name-l RELATIVE KEY IS data-name-l n U ASCI I S I XB I T BI NARY F Ii STAN DARD-AS CI I STANDARD ASCII FILE-STATUS} { FILE STATUS IS data-name-l data-name-2 data-name-3 [:ata-name-4 ~ata-name-5 ~ata-name-6 ~ata-name-7 [ctata-name-8J~~ 3-39 THE ENVIRONMENT DIVISION GENERAL FORMAT FOR ENVIRONMENT DIVISION FORMAT 3: SELECT file-name ASSIGN TO device-name-l [ devi ce-name-2 ] ~RESERVE integer-I [:~~~~S~~ ORGANIZATION IS INDEXED L ~!~~6~TIAL In l IACCESS MODE IS ) U DYNAMIC RECORD KEY IS data-name-l RECORDING tODE IS ~YTE ASCI I S I XB I T BINARY MODE] F '{ STANDARD-ASCI I STANDARD ASCII ~~~ ~ ~ARITY t ENSITY IS }) 800 - - IS {ODD EVEN ~1600 FI LE-STATUS} { FI LE STATUS IS data-name-l ~ data-name-2 data-name-3 ~ata-name_4 ~ata-name-5 ~ata-name-6 ~ata-name-7 [data_name-8J~~:J 3-40 CHAPTER 4 THE DATA DIVISION The Data Division, which is required in every COBOL program, describes the characteristics of the data to be processed by the object program. This data can be divided into six major types: 1. Data contained in files, both input and output 2. Data contained in a database and accessed Base Management System 3. Data to be sent to or received from the Message System or the Transactional Processing System 4. Data which is used by the program in the process of executing (This data can be constant or variable, and may be stored as part of the program or computed by the program during its operation.) 5. Data in a subprogram that is passed from the program it calling 6. Data to be printed in a report, and the format used to such data print To handle these types of data, following sections: the Data Division through consists the Data Control of the 1. The File Section, which describes the characteristics and the data formats for each file processed by the object program 2. The Schema Section, which names the sub-schema and schema that link a program or subprogram to the Data Base Management System 3. The Communication Section, which defines the special data items that link a program or subprogram to the Message Control System (MeS-lO) or the Transactional Processing System (TPS-20) 4. The Working-Storage Section, which contains any fixed values and the working areas in which intermediate data can be stored 5. The Linkage Section, which describes the data in a subprogram that is available from a calling program 6. The Report Section, which describes the data and format of report 4-1 a THE DATA DIVISION Unused sections of the Data Division may be omitted. However, sections which are included must be in the following order: the FILE SECTION. SCHEMA SECTION. COMMUNICATION SECTION. WORKING-STORAGE SECTION. LINKAGE SECTION. REPORT SECTION. 4.1 FILE SECTION The File Section begins with the section-header FILE SECTION. If present, it must be the first section in the Data Division. In the File Section, the characteristics of each file to be processed are described by two types of entries, the file description and the record description. The first type of entry, the file description, describes the aspects of the file. These aspects include: file are physical 1. How the logical data records of the grouped into blocks on the file medium 2. The maximum length of a logical record, which 4095 characters 3. Whether or not the file contains header and trailer labels and, if so, whether the format of these labels is standard or nonstandard 4. The names of the records contained in the file 5. The names of any reports in the file cannot The second type of entry, the record description, describes formats of the logical records in the files. 4.1.1 physically the exceed data Record Descriptions Following the FD file-name entry for a file, or the SO file-name entry for a sort file, a record description is given for each different record format in the file. A record description consists of a set of data description entries which describe a particular logical record. Each data description entry consists of a level-number followed by a data-name (or FILLER) which is followed, as required, by a series of descriptive clauses. The general format of a data description entry can be found in Section.4.9.1l. A record description begins with a level-Ol entry: 01 data-name A complete record description may be as simple as 01 data-name PICTURE picture-string. or it may be more complex, where the Ol-level is followed by a long series of data description entries of varying hierarchies that describe various portions and subportions of the record. A Ol-level 4-2 THE DATA DIVISION data-name in the File Section cannot be explicitly redefined using the REDEFINES clause. However, because a file has only one record area, if more than one data-name is specified, they implicitly redefine the first data-name. 4.1.2 Elementary Items and Group Items The basic user-defined datum in a COBOL program is called an elementary item; it may be referenced directly only as a unit. An elementary item may combine with contiguous elementary items to form sets of data items called group items. Group items may combine with other group items and/or elementary items to form more inclusive group items. Thus, an elementary item may be contained within one or more group items, and a group item may contain more than one elementary item. 4.1.3 Level Numbers Level numbers indicate a hierarchy of data items. The highest level is 01, which signifies that the data item is a record within a file named in an FD clause (or is a contiguous area in the Working-Storage Section) . Level numbers of 02 through 49 indicate items that are subordinate to a Ol-level data item. For example, an employee record can be described in the following manner: 01 EMPLOYEE-RECORD. 02 NAME. 03 FIRST-NAME PICTURE IS A(6). 03 MIDDLE-INITIAL PICTURE IS A. 03 LAST-NAME PICTURE IS A(20). 02 BADGE-NUMBER PICTURE IS X(5). 02 SALARY-CLASS PICTURE IS X(2). within a record description, the level numbers indicate which items are contained within higher-level items. In the above example, the items that have a 03 level are subordinate to NAME, which has a 02 level, which is in turn subordinate to EMPLOYEE-RECORD, which has a 01 level. The example also shows elementary items (those that contain PICTURE clauses) contained within group items. In this example, EMPLOYEE-RECORD is a group item, NAME is a group item contained within a group item, and FIRST-NAME is an elementary item contained within the group item NAME. An item at 01 level is not required to be a group item; it may be an elementary item as long as it is referenced as a unit. For example: 01 EMPLOYEE-RECORD PICTURE IS X(34) . . shows the same record as above, but in this case the record is operated on as a single entity. Three other level numbers are available to the COBOL programmer: 66, and 88. always 77, Items with a level number of 77 are noncontiguous elementary data items that are defined only in the Working-Storage Section to define constant values or to store intermediate results. Defining a level-77 item is the equivalent of defining a level-Ol elementary item. Level-66 data items are specified portion of a those items that contain an explicitly record already defined, or even the whole 4-3 THE DATA DIVISION record. A data item with a level number of 66 is used in a RENAMES clause to regroup items within a record. After a record is described, a level-66 item RENAMES a portion of that record. The level-66 data item can be a regrouping of the whole record, a group within the record, or a combination of group and elementary items. For example: 01 EMPLOYEE-RECORD 02 NAME 03 FIRST-NAME .•• 03 MIDDLE-INITIAL ••. 03 LAST-NAME .•• 02 BADGE-NO •.• 02 SALARY-CLASS ••• 66 PERSONNEL-REC RENAMES NAME THRU BADGE-NO. 66 PAY-REC RENAMES LAST-NAME THRU SALARY-CLASS. When the level-66 item PAY-REC is referenced, the items LAST-NAME, BADGE-NO, and SALARY-CLASS are referenced as a unit. The programmer can thus regroup portions of a record for differing purposes. Level-88 items are condition-names that cause a value or a range of values to be associated with a data item. The condition-name may then be used in place of the relation condition in conditional expressions in the Procedure Division. For example: 03 BADGE-NO •.• 88 FIRST-BADGE VALUE IS A0001. 88 LAST-BADGE VALUE IS Z9999. In a comparison, the following statements would then be equivalent: Conditional Variable Condition-Name IF BADGE-NO IS EQUAL TO A0001 ... IF BADGE-NO IS EQUAL TO Z9999 .•. 4.2 IF FIRST-BADGE •.• IF LAST-BADGE .•. SCHEMA SECTION In the Schema Section, either an INVOKE statement or an ACCESS statement specifies the names of the sub-schema and schema to be processed. The Schema Section begins with the section-header SCHEMA must follow the File Section, if present. If the installation does not include DBMS, the Schema be used. SECTION Section A description of the contents of the Schema Section will be the Data Base System Programmer's Procedures Manual. 4.3 and cannot found in COMMUNICATION SECTION The Communication Section contains the definitions of input and output communication-description entries. CD entries define records called CD records which contain special data items used to link the program to the Message Control System for users of TOPS-10 or the Transactional Processing System for users of TOPS-20. 4-4 THE DATA DIVISION The Communication Section begins with the section-header COMMUNICATION SECTION and must follow the File Section and precede the Report Section. The Communication Section must also follow the Schema Section if both are present. If your TOPS-IO installation does not include MCS, or your TOPS-20 installation does not have TPS, the Communication Section cannot be used. Details of the Communication Section entries will be found in the Message Control System programmer's Procedures Manual for users of TOPS-lO, and the Transactional Processing System Programmer's Procedures Manual for users of TOPS-20. 4.4 WORKING-STORAGE SECTION The Working-Storage Section defines (1) data that is stored when the object program is loaded, and (2) areas used for intermediate results. The Working-Storage Section is similar to the File Section, except that the Working-.Storage Section can contain level-77 items and cannot contain FD, SD, RD, CD, or SCHEMA entries. The Working-Storage· Section WORKING-STORAGE SECTION. begins with the section-header The maximum size of a record in Working Storage is 4095 characters. 4.5 LINKAGE SECTION The Linkage Section describes data available from a calling program and can appear only in a subprogram. The structure is the same as that of the Working-Storage Section with the following restrictions: 1. The VALUE clauses can only be used in condition-name entries. 2. The data-names used in the VALUE OF IDENTIFICATION (or ID), the VALUE OF DATE-WRITTEN, and the VALUE OF USER NUMBER cannot appear in this section. 3. The OCCURS clause with the DEPENDING phrase cannot be defined in this section. 4. The RECORD KEY and RELATIVE KEY data items cannot be in this section. defined Data described in the Linkage Section of a subprogram is not allocated storage space. Instead, at link-time, the LINK program sequentially equates the Linkage Section identifiers (listed in the USING clause of the ENTRY statement within the subprogram or in the USING clause of the Procedure Division beader within the subprogram) to the calling program identifiers (listed in the USING clause of the CALL statement within the calling program). Thus, when the Procedure Division of a subprogram executes, references to the Linkage Section data refer instead to the calling program data. 4-5 THE DATA DIVISION Thus: CALLING PROGRAM CALLED PROGRAM DATA DIVISION. FILE SECTION. FD •.. 01 MAIN •.. 02 MAINl .. . 02 MAIN2 .. . DATA DIVISION. FILE SECTION. LINKAGE SECTION. 01 SUB .•• 02 SUBl ... 02 SUB2 ..• PROCEDURE DIVISION. PROCEDURE DIVISION. ENTRY ENTRPT USING SUB, SUBl, SUB2. CALL ENTRPT USING MAIN, MAINl, MAIN2. EXIT PROGRAM. The identifier MAIN is defined in the File Section of the calling the identifier SUB is defined in the Linkage Section of the called program. When the Procedure Division of the called program executes, references to SUB refer instead to MAIN, references to SUBI refer to MAINl, and so on through the list. See the COBOL-74 Usage Material, Part 3 of this manual, for more information about subprograms. program~ Each 01- or 77-level item in the Linkage Section must have a unique name because it cannot be qualified. Also, each 01- and 77-level item must correspond to a word-aligned item of the same size or larger in the calling program. Word-aligned items start at the beginning of a computer word. All 01- and 77-level items fulfill this requirement; any items that do not can be made to do so by means of the SYNCHRONIZED LEFT statement. 4.6 REPORT SECTION The Report Section defines reports by describing the physical appearance of the particular format and data rather than by specifying the procedure used to produce the report. The data for a report can be read from a file or another part of the program or can be summed within the Report Section. The format of the report is given in the record description and report group entries in the Report Section. The Report Section begins with the section-header REPORT SECTION, and must follow the File Section, the Working-Storage Section and the I,.inkage Section. 4-6 THE DATA DIVISION A r , 'i.O.ol Format Of Report .... _ _ .&...!_i:)t::\";~.1.UI1 The Report Section contains the descriptions of one and the report groups that make up each report. or more reports Report groups are the basic elements of a report. Each report group is divided into report lines, which are in turn divided into fields. The report groups that can appear in a report are: REPORT HEADING printed once at the beginning REPORT FOOTING printed once at the end PAGE HEADING printed at the beginning of each page PAGE FOOTING printed at the end of each page DETAIL printed for each set of report data CONTROL HEADING printed at the beginning of each detail report group when a control break occurs CONTROL FOOTING printed at the end of each detail group when a control break occurs report The detail report groups contain the data items that constitute the report. Data items within a detail group can be designated by the programmer as controls. These control items are in descending order of rank from final, through major, intermediate, to minor. Each time a control item changes, a control break is said to occur; the control footings for the detail group are printed, and control headings for the next detail group are printed before the next detail group is printed. A FINAL control break occurs twice during the generation of a report, before the first detail line is printed and after the last detail line is printed. The most major control break happens least often and the most minor control break happens most often. If the most minor control field breaks, the control footing for that control field is generated, and the control heading for the next detail group for that control is generated. If a more major control field breaks, the control footings for all fields more minor than that which broke are generated, starting with the most minor and continuing up to the control footing for the control that broke. The control headings are then printed starting with the control field that broke and continuing through the most minor control field. An example of a skeleton report follows. 4-7 THE DATA DIVISION REPORT HEADING PAGE HEADING CONTROL HEADING (FINAL) CONTROL HEADING (MAJOR) CONTROL HEADING (MINOR) DETAIL GROUP CONTROL FOOTING (MINOR) CONTROL HEADING (MINOR) DETAIL GROUP CONTROL FOOTING CONTROL FOOTING CONTROL HEADING CONTROL HEADING DETAIL GROUP (MINOR) (MAJOR) (MAJOR) (MINOR) CONTROL FOOTING (MINOR) CONTROL FOOTING (MAJOR) CONTROL FOOTING (FINAL) PAGE FOOTING REPORT FOOTING (control break occurred) (control break occurred) (control break occurred) Within a report file, more than one report can be written. If more than one report is written in a file, the names of all the reports must be specified in the REPORTS clause of the file description entry, and a unique code must be specified for each report by means of the CODE clause in the Report Description of each report. The code must also be identified in the SPECIAL-NAMES section of the Environment Division. To print one of the reports within a report file, you enter the filename and the code of the desired report into the print queue using the PRINT command and specifying the code with the REPORT switch, as follows: PRINT file-specifier/REPORT:code Only the first 12 characters of the code will be accepted in the PRINT command string. Included in the description of a report are the number of lines on a report page, where headings should begin on the page, where footings should end, the column on the page where each item in a rep6rt group should be placed, and the number of lines which should be left between report groups. To cause a report to be printed, in addition to specifying its format and data in the Data Division, you must include certain verbs in the Procedure Division. These verbs are: INITIATE, which initializes the report and sets sum counters to zero; GENERATE, which causes report groups to be generated on specified control breaks; and TERMINATE, which ends the report. An additional statement, USE BEFORE REPORTING, causes programmer-specified procedure to be performed before a report group is produced. 4-8 THE DATA DIVISION A "'7 "'J:. I QUALIFICATION Any data item that is to be referenced must be uniquely identified. This unique identification can be achieved by the assignment of a unique name to each item. However, in many applications this is tedious and inconvenient (1) because of the large number of names required, and (2) because items containing the same type of information in different records would have different names. Therefore, qualification is introduced to allow similar items and certain records to have identical names. Qualification means giving enough information about the item to specify it uniquely. In COBOL, this information is the name of the group items containing it, in order of increasing inclusiveness. It is not necessary to name each group containing it, but only enough groups so that no other item with the same name as the original item could be identically qualified. It is also unnecessary to name each successively higher group containing the item until a unique qualification is made. Any set of names that uniquely describe the item is sufficient. Example: 01 02 RECORD-2. RECORD-I. 01 ITEM-I. ITEM-2. 02 SUB-ITEM. SUB-ITEM. 03 03 ·FIELD PIC X. FIELD PIC X. 04 04 FIELD in the left-hand example can be referenced uniquely the following ways: in any of FIELD OF SUB-ITEM OF ITEM-I OF RECORD-I. FIELD OF SUB-ITEM OF ITEM-I. FIELD OF SUB-ITEM IN RECORD-I. FIELD IN ITEM-l OF RECORD-I. FIELD IN RECORD-I. FIELD IN ITEM-I. The connectives interchangeably. OF and IN are equivalent and may be used The only data items which need to have unique names are level-77 items a~d records not associated with files, since they are not contained in any higher level data structure. Records associated with files may be qualified by the file name, as may any item contained within the record. File names must be unique. Level-66 items may be qualified only (1) by the name of the record with which they are associated and (2) by the name of any file with which that record is associated. 4.8 SUBSCRIPTING AND INDEXING It may sometimes be more convenient for you to specify a set of data values as a table rather than assign a name to each element of the set. A table (or array) is a set of homogeneous items stored together in memory for use by the program. You define the table elements in the program by specifying an OCCURS clause in the description of a data item. The data item thus defined represents not one item but a set of items having the identical format. Subscripting and indexing are used to refer to one of the elements of the set. In DIGITAL COBOL-74, subscripting and indexing are identical in use and can be 4-9 THE DATA DIVISION used interchangeably. However, the manner in which they are defined differs. Subscripting is defined simply by the fact that an item has an OCCURS clause in its description. For example, 01 RATE-TABLE. 02 VOLUME OCCURS 25 TIMES. describes VOLUME as 25 elements of RATE-TABLE. If you wish to refer to one of the elements of this set you must qualify the data-name with a subscript. Thus, VOLUME(lO) is the tenth element (or occurrence) of VOLUME. A subscript can be either an integer or a data-name to which an integer value has been assigned. Thus, when DIST has been assigned to value 10, VOLUME(DIST) is the same as VOLUME (10) . To specify indexing you must add the INDEXED BY option to clause. Thus, 01 the OCCURS RATE-TABLE. 02 VOLUME OCCURS 25 TIMES INDEXED BY IND. defines VOLUME as 25 elements of the table and defines IND as the index by which each element of the table can be indexed; that is, VOLUME (IND) is an element in the table. The index-name IND is treated exactly like the data-name DIST because the compiler recognizes an index-name as being exactly the same as a data-name. An item defined ,as an index in an OCCURS clause has an implicit usage of INDEX, and is equivalent to a data item that is declared USAGE INDEX. However, this usage is included in DIGITAL COBOL for compatibility with other comRilers because an item whose usage is INDEX (implicit or explicit) is treated as if its usage were COMPUTATIONAL. In fact, a data-name that is used as a subscript can be explicitly declared as USAGE INDEX; it will be treated as a COMPUTATIONAL data item by the compiler. COBOL-74 tables can be one, two, or three dimensions. The number of dimensions is defined by the number of subscripts or indexes required to refer to an individual item. For example, C(l,3) represents the item located in the first row and third column of 2-dimensional table which is defined by the Data Division entries a 01 TABLEA. 02 ROW OCCURS 20 TIMES. 03 COLUMN OCCURS 5 TIMES. The subscript/index must be enclosed in parentheses and must appear immediately after the terminal space that follows the data-name. Multiple subscripts/indexes are separated by a comma or by a space. No spaces can appear immediately following the left parenthesis or immediately preceding the right parenthesis. When referring to elements in multi-dimensional tables, subscript/indexes are written from left to right in the order of major (subscript/index varying least rapidly), intermediate, and minor (subscript/index varying most rapidly). The major index corresponds to the item written with the smallest level-number, that is, the most inclusive item. As an illustration, consider a table having a major element occurring 10 times, an intermediate element occurring 5 times within each occurrence of the major element, and a minor element occurring 3 times within each intermediate element. The last major element of the table is referred to by the subscript form (10,1,1), while the final element of the table is referred to by (10,5,3). 4-10 THE DATA DIVISION There are two forms of sUbscripting/indexing: direct and relative. Direct subscripting/indexing means that the subscript/index refers directly to the desired element. Relative subscripting/indexing means that the element of the table is referred to indirectly by a subscript/index to which an integer is added or subtracted. The form for direct subscript/indexing is shown in Figure 4-1. data-name (I subs cri pt index I [I ,.s ubs cri pt , index I] ... ) Figure 4-1 Direct Subscripting/Ipdexing In relative subscripting/indexing, the subscript/index is followed by the operator plus (+) or minus (-) followed by an unsigned integer numeric literal all enclosed in the parentheses immediately following the terminal space of the data-name. The form for relative subscripting/indexing is shown in Figure 4-2. data-name ~ ubscript } ({ lndex integer ,subscript [{ , index integer J ... ) Figure 4-2 Relative Subscripting/Indexing When you use relative subscripting/indexing, the element of the table that you refer to is not the one to which the subscript/index refers, but the element to which the subscript/index plus or minus the integer refers. That is, if the item VOLUME (IND + 2) is specified, and IND is set at 3, the fifth occurrence of VOLUME is referred to, not the third. However, the value of the subscript/index is not changed by relative subscripting/indexing; the value of IND remains 3. When you need to qualify a table element for uniqueness, you should use the format for direct subscripting/indexing shown in Figure 4-3. data-name [I ~~ I data-na~-l J ... (I ~ubscript I [I lndex ,subscript ,index Figure 4-3 Qualified Direct Subscripting/Indexing 4-11 IJ ) ... THE DATA DIVISION For example, to refer to ANAME in the following sample: 01 ARECI. 02 AGROUPl OCCURS 5. 03 ASUBGROUPI OCCURS 10. 04 ANAME PIC XeS) OCCURS 20. you could specify the following: ANAME OF ASUBGROUPI OF AGROUPI OF ARECI (I,J,4) NOTE Subscripts may not be subscripted. 4-12 THE DATA DIVISION 4.9 DATA DIVISION CLAUSES The clauses which make up the Data Division are presented in the following pages. The function, syntax, and details of each clause are described, and the general format of the clause i s ' included. The clauses are presented in the order in which they appear in the general formats at the end of this chapter, that is, in the order in which they occur in the Data Division. The formats of some clauses contain other clauses. When this is the case each clause which is subordinate is described separately on succeeding pages. 4-13 THE DATA DIVISION FILE DESCRIPTION (FD) 4.9.1 File Description (FD) Function The File Description (FO) furnishes information concerning the physical structure, identification, and record names pertaining to a given file. General Format DATA DIVISION. [FI LE SECTION. [FD fil e-name ~LOCK CONTAINS [i nteger-l T'U integer-2 RECORD(S) { CHARACTERS ~RECORD CONTAINS Qnteger-3 TO] integer-4 CHARACTER~ LABEL RE.'CORD IS } { RECORDS ARE 11 ill L-- U IVALUE OF I STANDARD OMITTED record-name-l IDENTIFICATION I }O ~ IS {d~ta-name-l}~ J llteral-l ~ fllusER-NUMBER IS {. data-name-3 tJ 1 iteral-3 J lrDATE-WRITTEN IS {d~ta-name-2 llteral-2 UL Ir~ATA {RECORD IS } data-name-4 RECORDS ARE l-- ILINAGE IS {~ata-name-6 t nteger-5 f 1 LINES [data-name-5J ~WITH FOOTING AT .. J ~ata-name-7 { lnteger-6 D U D~ ~ata-name-8}] l'UNES AT BOTTOM { ~ata-name-9 LILINES AT -TOP .{ lnteger-7 nteger-8 f!J 1 [CODE-SET IS al phabet-name ] [ REPORT IS } report-name-l { REPORTS ARE G-eport-name-~ 4-14 .. -] THE DATA DIVISION FILE DESCRIPTION (FD) (Cont.) ASCI I SI XBIT BINARY RECORDING L V STANDARD-ASCI I STANDARD ASCII The clauses shown in the General Format appear in on the following pages. alphabetical order Technical Notes 1. An FD entry must be present for each file-name selected the FILE-CONTROL paragraph of the Environment Division. 2. All semicolons and commas are optional. must terminate with a period. 3. The clauses may appear Description entry. 4. The ability to place the RECORDING MODE clause in the FD has been provided for compatibility with other manufacturers. If you specify the RECORDING MODE clause for a file in the FO, you cannot also specify it in the File-Control paragraph for that file in the Environment Division. Also, if you wish to use the RECORDING DENSITY and RECORDING PARITY clauses, you must put them in the File-Control paragraph in the Environment Division, even if the RECORDING MODE clause is in the FD. The description of the RECORDING MODE clause can be found in Section 3.1.13. 5. The maximum number of files that can be open at one time is 16. ISAM files count as two files: one index (.IDX) file and one data (.IDA) file. in 4-15 any order The entire FD within the in entry File THE DATA DIVISION BLOCK CONTAINS 4.9.2 BLOCK CONTAINS Function The BLOCK CONTAINS clause specifies the size of a logical block. 'General Format ~lOCK CONTAINS [i nteger-l TQ] i nteger-2 RECORD( S) }~ { CHARACTERS iJ Technical Notes 1. If you do not include this clause, or if you specify that integer-2 is zero, the file will not be organized into logical blocks when it is written. Rather, all records will be placed in the file with no empty space. The file is then considered to be "unblocked ll or "blocked zero". 2. If you use the CHARACTERS option, you specify the logical block SIze in terms, of the number of character posi tions required to contain the record. If the recording mode is ASCII (that is, all records for the file are described, explicitly or implicitly, as USAGE DISPLAY-7), the compiler assumes that the size is specified in terms of ASCII characters. If the recording mode is SIXBIT (that is, the records for the file are all described, explictly or implicitly, as DISPLAY-6), the compiler assumes that the size is specified in terms of SIXBIT characters. If the recording mode is F or V (that is, the data is recorded on the medium as EBCDIC characters), the compiler assumes that the size is specified in terms of EBCDIC characters, either fixed- or variable-length. When variable-length EBCDIC records are used (that is, the recording mode is V), the number of records in a block is also variable. If the blocking factor is not zero, the number of records in a block is determined by dividing the block size in characters by the number of characters in the longest record as specified by the FD statement. For example, if the FD statement specifies a maximum record length of 248 characters and the BLOCK CONTAINS 2400 CHARACTERS clause is used, the number of records in a block will be 9. 3. Integer-l and integer-2 must be positive integers. If you specify only integer-2, it represents the exact size of the logical block. If you specify both integer-l and integer-2, integer-l is ignored and integer-2 is used as the blocking factor. 4. Files whose organizations are RELATIVE or INDEXED must have a nonzero blocking factor. 4-16 THE DATA DIVISION CODE-SET 4.9.3 CODE-SET FUNCTION The CODE-SET clause specifies the character code set uSed to represent data on the external media. General Format [CODE-SET IS al phabet-name J Technical Notes 1. When you specify the CODE-SET clause for a file, you must describe all data in that file as USAGE IS DISPLAY. You must also describe any signed numeric data with the SIGN IS SEPARATE clause. 2. The alphabet-name clause referenced by must not specify the literal phrase. the CODE-SET 3. You may specify the CODE-SET clause residing on mass storage media. only for 4. The CODE-SET clause is included only for compatability, since ASCII is the only alphabet-name allowed, and ASCII is also the default. 5. If you include the CODE-SET clause, alphabet-name specifies the character code convention used to represent data on the external media. It also specifies the algorithm for converting the character codes on the external media from or to the native character codes. This code conversion occurs during the execution of an input or output operation. 6. If you omit the CODE-SET clause, the ASCII character assumed for data on the external media. 4-17 clause files set not is THE DATA DIVISION DATA RECORD 4.9.4 DATA RECORD Function The DATA RECORD clause associated file. cross-references the record-name with its FD entry General Format IrL!ATA {RECORD IS t RECORDS AREf data-name-4 [data-name-5J ... ] Technical Notes 1. This clause is Qptional because all records in the are assumed to be data records. 2. All records within a file share the same area. 3. All record-names must be specified in Ol-level data entries subordinate to this FD entry. The presence of more than one such record-name indicates that the file contains more than one type of data record. These records may have different descriptions. The order in which they are listed is not significant. 4-18 THE DATA DIVISION FD File-name 4.9.5 FD File-name Function The FD file-name clause identifies the file to which this description entry and the subsequent record descriptions relate. file General Format [JFo file-name~ Technical Notes 1. This entry must begin each file description. 2. The file-name must appear in a SELECT statement File-Control paragraph of the Environment Division. 4-19 in the THE DATA DIVISION LABEL RECORD 4.9.6 LABEL RECORD Function The LABEL RECORD clause specifies whether or not labels are present on the file and, if they are, identifies the format of the labels. General Format ~ RECORD IS } STANDARD ) OMITTED { RECORDS ARE ( record-name-l I Technical Notes 1. If you omit assumed. the clause, LABEL RECORDS ARE STANDARD is 2. You should use the OMITTED option when the file has no header or trailer labels. 3. You should use the STANDARD option when the file has header and trailer labels that conform to the standard format. If the file you are describing is on disk or DECtape, you must either specify LABEL RECORDS ARE STANDARD, or omit the clause altogether allowing the default to take over. See the VALUE OF IDENTIFICATION clause for the association between the label and the filename on disk or DECtape. The standard label for DECtape and disk is the directory block used by the monitor. For magnetic tape, if the file is recorded in SIXBIT, the standard label 1S 78 SIXBIT characters in length and is written in a separate physical record from the data. If the recording mode is ASCII, the label contains 78 ASCII characters, plus carriage return and line feed, for a total of 80 characters. Table 4-1 shows the contents of each character in a standard label for nonrandom-access devices. Magnetic tapes are the only devices with ending labels. Each ending label is preceded by and followed by an end-of-file mark. 4. Files whose recording mode is F or V (fixed- or variablelength EBCDIC) must have LABELS RECORDS ARE OMITTED if they are on magnetic tape. If they are on disk or DECtape, they are assumed to have DECsystern-lO standard labels. 4-20 THE DATA DIVISION LABEL RECORD (Cont.) 5. If PULSAR is running on your TOPS-10 system, you must perform a MOUNT to get a tape. PULSAR writes labels in a different format from the label format explained here. (Refer to the reference material provided with PULSAR for more information.) PULSAR labeling depends on the type of labeling you specify at MOUNT time. It is recommended that you make the LABEL RECORD clause and the value specified for the /LABELS: switch on the mount agree. LABEL RECORDS can have two values: STANDARD and OMITTED. These values have the following equivalents in PULSAR labeling: /LABELS:STANDARD; /LABELS:NONE. You must specify the PULSAR label on the mount and the COBOL label in your program. If you use STANDARD in your program, that /LABELS:STANDARD in PULSAR. is equivalent to If you use OMITTED in your program, /LABELS:NONE in PULSAR. is equivalent to that Table 4-1 Standard Label for Magtapes Contents Characters 1-4 HDRI = Beginning File EOFI = Ending file EOVI = Ending reel 5-13 Value of identification 14-21 Always spaces 22-27 Not used 28-31 Reel number; 32-41 Not used 42-47 Creation date; two characters each year, month, and day, respectively 48-78 Not used 79-80 Carriage-return/line-feed if file is ASCII (Note that this is on the label only; it is not kept internally. ) the first reel is always 0001 4-21 for the THE DATA DIVISION RECORD CONTAINS 4.9.7 RECORD CONTAINS Function The RECORD CONTAINS clause specifies the size of the data the file to which it refers. records in General Format [RECORD CONTAINS Qnteger-3 TO] integer-4 CHARACTER~ Technical Notes 1. Since the record description entry completely defines the size of the data re~ord, this clause is never required. However, if you use it, it replaces the record description entry in setting the size of the record. 2. Integer-l and integer-2 must be positive integers. Integer-2 may n.ot be less than the size of the largest record but cannot exceed 4095, which is the limit on the size of a record. Integer-2, if specified, must be larger than integer-I. 3. The data record size is equal to the number positions required to contain the record. 4-22 of character THE DATA DIVISION REPORT 4.9.8 REPORT Function The REPORT clause specifies the name of each report that is associated with the file. General Format [ REPORT IS } { REPORTS ARE report-name-l ~eport-name-~ .J Technical Notes 1. This clause is optional; it is used only when Report-Writer statements cause output to be written on the file. 2. Report-name-l and report-name-2 must be the names Descriptor items in the Report Section. 3. If you use this clause, you may omit the data record description because the name of the data record is not referred to directly in the Procedure Division. When the data record description is omitted, the compiler automatically assumes a l32-character record. 4-23 of Report THE DATA DIVISION SD File-name 4.9.9 SD File-name Function The SD file-name clause identifies the sort file to which this description entry and the subsequent record description relate. file General Format [SD fil e-name [RECORD CONTAINS [i nteger-l TOJ "~DATA {RECORD RECORDS ISARE } [record-descri ption-entry} i nteger-2 ~ata-name-2J data-name-l 00 CHARACTER~ 00'] oJ 00 oJ Technical Notes 1. The SD entry must begin each sort file description. 2. The file-name must appear in a SELECT statement FILE-CONTROL paragraph of the Environment Division. 3. The DATA RECORD and RECORD CONTAINS descriptive clauses allowed. 4-24 clauses are in the the only THE DATA DIVISION VALUE OF iDENTiFiCATiON/DATE-WRITTEN!USER-NUMBER 4.9.10 VALUE OF IDENTIFICATION/DATE-WRITTEN!USER-NUMBER Function The VALUE OF IDENTIFICATION clause provides specific data for an item within the label records associated with a file. The VALUE OF DATE-WRITTEN clause specifies a date which the file label must contain to be processed by the program. The VALUE OF USER-NUMBER clause provides a project-programmer number to be checked against the file label before processing. General Format data-name-3 { 1 i te ra 1 - 3 (lJ fJ Technical Notes 1. ID may be substituted for IDENTIFICATION. 2. The VALUE OF IDENTIFICATION clause is required only if label records are standard; it is ignored in all other cases. The VALUE OF DATE-WRITTEN and the VALUE OF USER-NUMBER are always optional. 3. The three clauses can be written in any order, but of each can be specified for a file. 4.. IDENTIFICATION represents the file-name and extension of a file with standard labels. If a data-name is specified, it must be associated with a DISPLAY, DISPLAY-6, DISPLAY-7, or DISPLAY-9 data item nine characters in length. If a literal is specified, it must be a nonnumeric literal nine characters in length. The first six characters are taken as the file-name, and last three characters are taken as the extension. The programmer must provide spaces as required to conform to this convention. The period which the system prints between the file-name and the extension must not be included in the VALUE OF IDENTIFICATION clause. 4-25 only one THE DATA DIVISION VALUE OF IDENTIFICATION/DATE-WRITTEN/USER-NUMBER (Cont.) Examples: a. VALUE OF IDENTIFICATION IS "COST TST" b. VALUE OF IDENTIFICATION IS FILE-I-NAME (WORKING-STORAGE SECTION.) 77-FILE-I-NAME PICTURE IS X(9). 5. DATE-WRITTEN represents the date that a file (with STANDARD labels) was written. If a data-name is specified, it must be associated with a DISPLAY, DISPLAY-6, DISPLAY-7 or DISPLAY-9 data item six characters in length. If a literal is specified, it must be a nonnumeric literal six characters in length. The first two characters are taken as year, the next two as month, and the last two as day. The DATE-WRITTEN clause is ignored when the file is OPENed for output; instead, the current date is used. Examples: a. VALUE OF IDENTIFICATION IS "RANDOMXYZ", 760112 DATE-WRITTEN IS b. VALUE OF IDENTIFICATION IS "DATA FILE-I-DATE DATE-WRITTEN IS " (WORKING-STORAGE SECTION.) 77 FILE-I-DATE PICTURE IS 9(6). 6. USER-NUMBER represents the project-programmer number of the owner of a disk file; it is ignored for all other devices. Data-name-3 must be a COMPUTATIONAL item of 10 or fewer digits in which the project-programmer number is stored. Literal-3 and literal-4 are numeric literals of six or fewer digits that are treated as octal. Literal-3 is the project number and literal-4 is the programmer number. 7. For input files the VALUEs specified are checked against the file when it is opened. ISAM files are checked as soon as your program is run. For output files, the VALUE OF IDENTIFICATION is written when the file is opened. If the specified values do not match a file on the selected medium, a run-time error message is issued. 8. If the access mode is INDEXED and data-name-l is used in the VALUE OF IDENTIFICATION clause, data-name-l must contain the tilename and extension of the index-file for the indexed-sequential file being referenced. The contents of data-name-l may not be altered during program execution. You need not specify the identification for the data file of an indexed-sequential file because this identification is stored in the index file. 4-26 THE DATA DIVISION VALUE OF IDENTIFICATIONjDATE-WRITTEN!USER=NUMBER (Cont.) 9. If data-name-3 is used to represent the project-programmer number, you must be aware that the value of data-name-3 is treated as decimal, even though the project-programmer number is octal. The data-name-3 value will be translated from decimal to binary by the COBOL conversion routine. Thus, the project-programmer will not be accurate unless you provide a conversion routine in your program to convert your octal project-programmer number to its decimal equivalent so that it will be converted to the correct binary number. The following example is a suggested method for performing the conversion. 77 77 77 77 01 USAGE COMPo PIC 9, ERR-FLAG USAGE COMPo HALF-NUM, PIC S9,(7) , USAGE COMPo OCTAL-PPN, PIC S9 (10) , DIGIT, PIC 9. PP-NUMBER. 02 PROJ-NUMBER, PIC 9 (6) . 02 PROG-NUMBER, PIC 9 (6) . 02 EITHER-NUM, PIC 9(6). 02 X REDEFINES EITHER-NUM. 03 PP-DIGIT, PIC 9, OCCURS 6 TIMES, INDEXED BY I. ACCEPT PROJ-NUMBER, PROG-NUMBER. SET ERR-FLAG TO ZERO. MOVE PROJ-NUMBER TO EITHER-NUM. MOVE ZERO TO HALF-NUM. PERFORM CONVERT VARYING I FROM 1 BY 1 UNTIL 1>6. IF ERR-FLAG IS NOT = 0 GO TO OCTAL-ERROR. COMPUTEOCTAL-PPN = HALF NUM * 262144. MOVE PROG-NUMBER TO EITHER-NUM. MOVE ZERO TO HALF-NUM. PERFORM CONVERT VARYING I FROM 1 BY 1 UNTIL 1>6. IF ERR-FLAG IS NOT = 0 GO TO OCTAL-ERROR. COMPUTE OCTAL-PPN = OCTAL-PPN + HALF-NUM. CONVERT. IF PP-DIGIT (I) = 8 OR 9, SET ERR-FLAG UP BY 1. COMPUTE HALF-NUM = 8 *HALF-NUM + PP-DIGIT (I). * * THIS ROUTINE INVALID FOR PROJECT NUMBERS LARGER THAN 77777. 4-27 THE DATA DIVISION 'VALUE OF IDENTIFICATION/DATE-WRITTEN/USER-NUMBER (Cont.) If the access mode is INDEXED and data-name-3 is used to represent the project-programmer number, the following rules must be observed: 10. a. Data-name-3 must have a value that is the decimal equivalent of an octal project-programmer number, and that project-programmer number m,ust contain a file with the name used in the VALUE OF IDENTIFICATION clause. b. Data-name-3 may be altered during program execution if all files referenced have identical parameters. c. If several files will be read through the same File Description, data-name-3, should point to the file with the largest number of levels of index (this is usually the largest file). None of the data-names in the VALUE OF clauses can appear the Linkage Section. 4-28 only in THE DATA DIVISION D.A.T,,4,. DESCRIPTION ENTRY 4.9.11 DATA DESCRIPTION ENTRY Function A data description entry describes a particular item of data. General Format FORMAT 1: 1 evel-number data-name-l} { FILLER [REDEFINES data-name-2 ] [ PI ClURE .} IS character-stnng . ] { PIC COMPUTATIONAL cm~p USAGE IS COMPUTATIONAL-l COMP-l COM'PITfATIONAL-3 COMP-3 DISPLAY DISPLAY-6 DISPLAY-7 DISPLAY-9 INDEX DAfABASE-KEY DBKEY 'OCCURS {~nteger-l TO integer-2 TIMES DEPENDING ON data-name-3} L-,nteger-2 TIMES [{ ~~~~~~~~~G} KEY IS data-name-4 [}ata-name-u ~INDEXED BY index-name-l C=index-name-2~ [{ ~HRONIZED} [~~~~TJJ [{:ll FlED }{ ~~~~T D 4-29 ... ~~ .. .J THE DATA DIVISION DATA DESCRIPTION ENTRY (Cont.) FORMAT 2: 66 data-name-1 RENAMES data-name-2 ~{ ~UGH} data-name-3~ FORMAT 3: 88 condition-name VALUE IS } { VALUES ARE 1itera 1-1 [{ ~UGH} 1itera 1-~ The clauses shown in the General Format appear in alphabetical order along with the other Data Division clauses on the following pages. Technical Notes 1. Each data description entry must be terminated by All semicolons and commas are optional. 2. The clauses may appear in any order, with one exception: the REDEFINES clause, when used, must immediately follow the data-name being redefined. 3. The VALUE clause must not appear in a data description entry which also contains an OCCURS clause, or in an entry which is subordinate to an entry containing an OCCURS clause. The latter part of this rule does not apply to condition-name (level-SS) entries. 4. The PICTURE clause must be specified for every elementary item, except a USAGE INDEX, COMP-I item, DATABASE-KEY, or DBKEY. 5. The clauses SYNCHRONIZED, PICTURE, JUSTIFIED, and BLANK ZERO can be specified only at the elementary level. 4-30 a period. WHEN THE DATA DIVISION , BLANK WHEN ZERO 4.9.12 BLANK WHEN ZERO Function The BLANK WHEN ZERO clause causes the blanking of value is zero. an item when its General Format []LANK WHEN ZERO] Technical Notes 1. When the BLANK WHEN ZERO option is used and the item is zero, the item is set to blanks. 2. BLANK WHEN ZERO can be specified only at the elementary level and only for numeric or numeric-edited items whose usage is DISPLAY-6, DISPLAY-7, or DISPLAY-9. 3. An asterisk used as a zero suppression symbol in a PICTURE clause may not appear in the same entry with the BLANK WHEN ZERO clause. More comprehensive editing features are available in the PICTURE clause. 4. When the BLANK WHEN ZERO clause is used for an elementary item whose PICTURE is numeric, the category of the item is considered to be numeric-edited. 4-31 THE DATA DIVISION Condition-name (level-88) 4.9.13 Condition-name (level-SS) Function The condition-name (level-88) entry assigns a name to a value or range of values of the associated data item. General Format VALUE IS } { VALUES ARE 88 condition-name [iteral-3 D =UGH} lite al-l r rJ{ 1iteral-~ lJ THROUGH} THRU literal-4] Technical Notes 1. Each condition-name requires a separate level-88 entry. This entry contains the name assigned to the condition, and the value or values associated with that condition. Condition-name entries must immediately follow the data description entry with which the condition-name is to be associated. 2. A condition-name entry can be associated with any or group item except 3. 4. a. another condition-name entry, or b. a level-66 item. elementary Some examples of possible level-88 entries are given below. a. 05 B-FIELD PICTURE IS 99. 88 Bl VALUE IS 3. 88 B2 VALUES ARE 50 THRU 69. 88 B3 VALUES ARE 20, 25, 28, 31 THRU 37. 88 B4 VALUES ARE 70 THRU 75, 80 THRU 85, 90 THRU 95. b. 02 C-FIELD PICTURE IS XXX. 88 C-YES VALUE IS "YES". 88 C-NO VALUE IS liND ". The data item with which the condition-name is associated is called a conditional variable. A conditional variab~e may be used to qualify any of its condition-names. If references to a conditional variable require iQdexing, subscripting, or qualification, then reference to its associated condition-names also require the same combination of indexing, subcripting, or qualification. 4-32 THE DATA DIVISION Condition-name (level 88) (Cont.) Q 5. A condition-name is used in conditional expressions as an abbreviation for the related condition. Thus, if the above Data Division entries (Note c) are used, the statements in each pair below are functionally equivalent. Relational Expression 6. Condition-Name a. IF 8-FIELD IS EQUAL TO 3 •.•• IF 81 ..•• b. IF 8-FIELD IS GREATER THAN 49 AND LESS THAN 70 .••• IF B2 •••• c. IF 8-FIELD IS EQUAL TO 20 OR EQUAL TO 25 OR EQUAL TO 28 OR GREATER THAN 30 AND 1 LESS THAN 38 ..•• IF B3 •••• d. IF 8-FIELD IS GREATER THAN 69 AND LESS THAN 76 OR GREATER THAN 79 AND LESS THAN 86 OR GREATER THAN 89 AND LESS THAN 96 •••• IF B4 .... e. IF C-FIELD IS EQUAL TO "YES" •. IF C-YES Litera1-1 must always be less than 1iteral-2, and 1iteral-3 less than 1iteral-4. The values given must always be within the range allowed by the format given for the conditional variable. For example, any condition-name values given for a conditional variable with a PICTURE of 999 must be in the range of 000 to 999. 4-33 THE DATA DIVISION Data-name/FILLER 4.9.14 Data-name/FILLER Function A data-name specifies the name of the data being described. The FILLER specifies an unreferenced portion of the logical record. word General Format level-number da ta- name-I} { FI LLER Technical Notes 1. A data-name or the word FILLER must immediately level-number in,each data description entry. 2. A data-name must be composed of a combination of the characters A through Z,'O through 9, and the hyphen. It must contain at least one alphabetic character and must not exceed 30 characters in length. It must not duplicate a COBOL reserved word. Refer to Section 1.2.3.2, User-Defined Words, for further information. 3. The key word FILLER is used to name an unreferenced item in a record (that is, an item to which the programmer has no reason for assigning a unique name). A FILLER item cannot, under any circumstances, be referenced directly in a Procedure Division statement. However, it may be indirectly referenced by referring to a group-level item of which the FILLER item is a part. FILLER can be used at any level, including· the 01 level. 4-34 follow the THE DATA DIVISION JUSTIFIED 4.9.15 JUSTIFIED Function The JUSTIFIED clause specifies nonstandard positioning of data a receiving data item. within General Format RIGHT}~ JUSTI FlED} { [{ JUST LEFT U Technical Notes 1. The JUSTIFIED clause cannot be specified at a group level, or for numeric or edited items. If neither RIGHT nor LEFT is specified, RIGHT is assumed. 2. An item subordinate to one containing a VALUE be JUSTIFIED. clause cannot 3. DISPLAY, DISPLAY-6, DISPLAY-7 JUSTIFIED. items can 4. The standard rules for positioning data within an data item are as follows: a. and DISPLAY-9 be elementary The receiving data item is described as numeric or numeric-edited (see definition in Notes 7 and 10 under the PICTURE clause, Section 4.9.18.) A numeric or numeric-edited item is justified according to the following rules, thus the JUSTIFIED clause cannot be used. The data is aligned by decimal point and is moved to the receiving character positions with zero fill or truncation on either end as required. If an assumed decimal point is not explicitly specified, the data item is treated as if it had an assumed decimal point immediately following its rightmost character, and the sending data is aligned according to this decimal point. b. The receiving data item is described as alphanumeric or alphabetic (see definition in Notes 6 and 8 under the PICTURE clause, Section 4.9.18). The data is moved to the receiving character positions and aligned at the leftmost character position with space fill or truncation at the right end as required. 4-35 THE DATA DIVISION JUSTIFIED (Cont.) 5. When a receiving item is described positioning occurs as in 4a above. as JUSTIFIED LEFT, 6. When a receiving data item is described with the JUSTIFIED RIGHT clause and is larger than the sending data item, the data is aligned at the rightmost character position in the receiving item with space fill at the left end. When a receiving data item is described with the JUSTIFIED RIGHT clause and is smaller than the sending data item, the data is aligned at the rightmost character position in the receiving item with truncation at the left end. Examples are given below. 03 ITEM-A PICTURE IS X(8) VALUE IS "ABCDEFGH". 03 ITEM-B PICTURE IS X(4) VALUE IS "WXYZ". 03 ITEM-C PICTURE IS X(6). 03 ITEM-D PICTURE IS X(6). JUSTIFIED RIGHT. Procedure Division statement Contents of Receiving Field MOVE ITEM-A TO ITEM-C,. AIBlclDIE F MOVE ITEM-A TO ITEM-D. CIDIEIFIG H MOVE ITEM-B TO ITEM-C. WIXIYIZI~ MOVE ITEM-B TO ITEM-D. ~I~IWIXIY Z 4-36 ~ THE DATA DIVISION 4.9.16 Level-number Function The level-number shows the hierarchy of data within a logical record. In addition, special level-numbers are used for condition-names (level-88), noncontiguous Working-Storage items (level-77), and the RENAMES clause (level-66). General Format level-number data-name-l} { FILLER Technical Notes 1. A level-number is required as the first element in each description entry. 2. Level-numbers may be placed anywhere on the source or after margin A. 3. Level-number 88 is described under "condition-name (level-88)", Section 4.9.13, and level-number 66 is described under "RENAMES (level-66)", Section 4.9.20. 4. A further description of level-numbers and data hierarchy can be found in the introduction to this chapter. 4-37 line, data at THE DATA DIVISION OCCURS 4.9.17 OCCURS Function The OCCURS clause eliminates the need for separate entries for repeated data, and supplies information required for the application of subscripts and indexes. General Format 'OCCURS ~----- {~nteger-l TO i nteger-2 TI MES DEPENDI NG ON data-name-3 } ] lnteger-2 TIMES Technical Notes 1. This clause cannot be specified in a data description entry that has a 66 or 88 level-number, or in one that contains a VALUE clause. 2. The OCCURS clause is used to define tables or other homogeneous sets of repeated data. Whenever this clause is used, the associated data-name and any subordinate data-names must always be subscripted or indexed when used in all Procedure Division statements. 3. All clauses given in a data description that includes OCCURS clause apply to each repetition of the item. 4. The integers must be positive. If integer-l is specified, it must have a value less than integer-2. No value of a subscript can exceed integer-2; in addition, if the DEPENDING option is specified, no subscript can exceed the value of data-name-l at the time of subscripting. 5. The value of data-name-l is the count of the number of occurrences of the item described by the OCCURS clause; its value must not exceed integer-2. 6. If the DEPENDING option is specified, the integer-l TO phrase must be included. The DEPENDING option must immediately follow TIMES. Data-name-l must be a positive integer, and for efficiency should be either USAGE INDEX or USAGE COMP. It cannot be subcripted, and if the clause appears in the Linkage Section, data-name-l must be either USAGE INDEX or USAGE COMP. 7. The KEY IS option indicates that you have sorted the repeated data into either ascending or descending order according to the values associated with data-name-2, data-name-3, and so forth. The data-names are listed in order of decreasing significance. Note that you must sort the data - it will not be sorted automatically. 4-38 an THE DATA DIVISION OCCURS (Cont.) 8. Data-name-2 must be either the name of the entry containing the OCCURS clause, or the name of an entry subordinate to the entry containing the OCCURS clause. Data-name-3, etc., must be the name of an entry subordinate to the group item that is the subject of this entry. 9. An index-name defined in a OCCURS clause must not be defined elsewhere; its appearance in the INDEXED option is its only definition. There can be no items of the same name defined elsewhere. The USAGE of each index-name is assumed to be INDEX. 10. Subscripting and indexing are described in Section 4.8. 11. The entire record containing the OCCURS clause must not exceed 32,767 characters in size; that is, if the record were completely full of data, the number of characters required to contain the record would have to be less than or equal to 32,767. 4-39 THE DATA DIVISION PICTURE 4.9.18 PICTURE Function The PICTURE clause describes the general characteristics requirements of an elementary item. and editing General Format PI CTURE ..} IS character-stnng . ] [ { PIC Technical Notes 1. A PICTURE clause may be specified only for an elementary data item. It may not be used with an item described as USAGE INDEX, CaMP-I, or DATABASE-KEY (DBKEY). 2. PIC may be substituted for PICTURE in the format. 3. A picture string consists of certain allowable combinations of characters in the COBOL character set used as symbols. These symbols are as follows: a. Symbols representing data characters 9 represents a numeric character (0 through 9) A represents an alphabetic character (A through Z, tab, and space) X represents an alphanumeric character (any allowable character) b. Symbols representing arithmetic signs and assumed decimal point positioning V represents the position of the assumed decimal point P represents an assumed decimal point scaling position S represents the presence of an arithmetic sign c. Symbols representing zero suppression operations Z represents standard zero suppression (replacement of leading zeros by spaces) * represents check protection (replacement of leading zeros by asterisks) d. Symbols representing insertion characters $ represents a dollar sign (this SigIl floats from left to right and replaces the rightmost leading zero when more than One $ appears)l 1 If the CURRENCY SIGN IS clause appears in the SPECIAL-NAMES paragraph, the symbol specified by the literal must be used in all ~nstances in place of the $. 4-40 THE DATA DIVISION PICTURE (Cont.) , represents • represents B represents o represents / represents e. an insertion comma l an actual decimal point l an insertion blank an insertion zero an insertion slash Symbols representing editing sign-control symbols + represents an editing plus sign - represents an editing minus sign CR represents an editing Credit symbol DB represents an editing Debit symbol The plus and minus signs (+ and -) float when more than one appear, and replace the rightmost leading zeroes. f. 4. Consecutive repetitions of a picture symbol can be abbreviated to the symbol followed by (n), where n indicates the number of occurrences. However, some editing symbols may not be used more than once in a data item: "S", "V", ".11, ItCR", and "DB". A maximum number of 30 symbols can appear in a picture string. Note that the number of symbols in a picture string and the size of the item represented are not necessarily the same. There are two reasons for this discrepancy. First, the abbreviated form for indicating consecutive repetitions of a symbol may result in fewer symbols in the picture string than character positions in the item being described. For example, a data item having 40 alphanumeric character positions can be described by a picture string of only 5 symbols: PICTURE IS X(40). The second reason is that some symbols are not counted when calculating the size of the data item being described. These symbols include the V (assumed decimal point), P (decimal point scaling position), and S (arithmetic sign); these symbols, with one exception, do not represent actual physical character positions within the data item. The exception involves the use of the SIGN IS SEPARATE clause, which causes the S (arithmetic sign) to take up a character position. If the clause is omitted, the character-string S999V99 represents a 5-position data item. However, if the SIGN IS SEPARATE clause is included, the character-string would represent a 6-position item. Other size restrictions for numeric and numeric-edited are given under the appropriate headings below. 5. items There are five categories of data that can be described with a PICTURE clause: alphabetic, numeric, alphanumeric, alphanumeric-edited, and num~ric-edited. A description of each category is given in the notes below. 1 If the DECIMAL-POINT IS COMMA clause appears in the SPECIAL-NAMES paragraph, the function of the comma and decimal point is reversed. 4-41 THE DATA DIVISION PICTURE (Cont.) 6. 7. Definition of an Alphabetic Item a. Its picture string may contain only the symbol A or B. b. It may contain only the 26 letters of the space. alphabet and Its picture string may contain only the symbols 9, P, and V. It must contain at least one 9. S, Definition of a Numeric Item a. The picture positions. b. S. 9. 10. the string must have from 1 to 18 It may contain only operational sign. the digits 0 through 9 digit and an Definition of an Alphanumeric Item a. Its picture string can consist of all Xs, or a combination of the symbols A, X, and 9 (except all 9s or all As). The item is treated as if the character-string contained all xs. b. It,s contents can be any combination of characters the complete character set (see Section 1.2.2). from Definition of an Alphanumeric-Edited Item a. Its picture string can consist of any combination of As, Xs, or 9s (it must contain at least one A or one X), plus at least one of the symbols B, 0 or I. b. Its contents can be any combination the complete character set. of characters from Definition of a Numeric-Edited Item a. Its picture string must contain following editing symbols: at least one of the , . * + - 0 B CR DB $ It may also contain the symbols 9, V, or P. If you use the CURRENCY SIGN IS clause, the new currency sign you specify replaces the $ in the above list. The allowable sequences are determined by certain editing rules for each symbol and can be found in Note 11. The picture positions. b. string must digit from 1 to IS The contents can be any combination through 9 and the editing characters. of the digits 4-42 have 0 THE DATA DIVISION PICTURE (Cont.) 11. The symbols used to define the category of an elementary item and their functions are as follows: A Each A in the picture string represents a character position which can contain only a letter of the alphabet or a space. B Each B in the picture string represents a character position into which a space character will be inserted during editing. Examples: (A-FLD contains the value 092469) B-FLD picture string Result MOVE A-FLD TO B-FLD 99B99B99 1019111121411116191 MOVE A-FLD TO B-FLD 9999BBBB 101912141111111111111 Also see Note 15, Simple Insertion Editing. PEach P in the picture string indicates an assumed decimal point scaling position and is used to specify the location of an assumed decimal poin~ when the point is outside the positions defined for the item. Ps are not counted in the size of the d~ta item. They are counted in determining the maximum number of digit positions (18) allowed in numeric-edited items or numeric items. Ps can appear only to the left or right of the picture string and must appear together. The assumed decimal point is assumed to be to the left of the string of ?s if the Ps are at the left end of the picture string and to the right of the string of Ps if the Ps are at the right end of the picture string. If the V symbol is used in this case, it must appear in either of those positions; in either case, it is redundant. Examples: PPP9999 (or VPPP9999) defines a data item of four character positions whose contents will be treated as .000nnnn during any decimal point alignment operation (such as in a MOVE or ADD). 9PPP (or 9PPPV) defines a data item of one character position whose contents will be treated as nOaa during any decimal point alignment operation. S An S in a picture string indicates that the item has an operational sign and will retain the sign of any data stored in it. The S must be written as the leftmost character in the picture string. If S is not included, all data will be stored in the item as an absolute value and will be treated as positive in all operations. The S symbol is not counted in the size ~f the data item unless the SIGN IS SEPARATE clause is included, in which case it occupies one character position. 4-43 THE DATA DIVISION PICTURE (Cont.) V A V in a picture string indicates the location of the assumed decimal point and may appear only once in a picture string. The V does not represent a physical character position and is not counted in the size of the data item. If the assumed decimal point position is at the right of the rightmost character position of the item, the V is redundant (that is, 9999 is functionally equivalent to 9999V). X Each X in a picture string represents a character position which can contain any allowable character from the complete character set. Z Each Z in a picture string represents the leftmost leading numeric character positions in which leading zeros are to be replaced by spaces. Each Z is counted in the size of the item. * Each * in a picture string represents the leftmost leading numeric character positions in which leading zeros are to be replaced by *. Each * is counted in the size of the item. Examples: (A-FLD contains the value 00305) B-FLD picture string Result MOVE A-FLD TO B-FLD 999999 01 0 1 0 1 3 0 5 MOVE A-FLD TO B-FLD ZZ9999 l11l11013 0 5 MOVE A-FLD TO B-FL~ ZZZZZZ l11l11l113 0 5 MOVE A-FLD TO B-FLD ZZZZ.ZZ Il1 310 151. 0 0 Also see Note 19, Zero Suppression Editing. 9 Each 9 in a picture string represents a character position which can contain a digit. Each 9 is counted in the size of the item. o Each 0 in a picture string represents a character position into which a zero will be inserted. It is counted in the size of the item. The 0 symbol works in the same manner as the B symbol. Each , in a picture string represents a position into which a comma will be inserted. is counted in the size of the item. / character The comma Each / in a picture string represents a character position into w~ich the slash will be inserted. The slash is counted in the size of the item. 4-44 THE DATA DIVISION PICTURE (Cont.) Examples: (A-FLO contains 362577) Result B-FLO picture string MOVE A-FLO TO B-FLO 9,999,999 MOVE A-FLO TO B-FLO z,zzz,zzz \01,\3\61 2[,1 517171 I~1~1316121' \5\71 7\ Also see Note 15, Simple Insertion Editing. A • (period) in a picture string is an editing symbol that represents an actual decimal point. It is used for decimal point alignment and also indicates where a period (.) is to be inserted. This symbol is counted in the size of the item. Only one • may appear in a picture string. Examples: (A-FLO contains 3526 99)1 A B-FLO picture string Result MOVE A-FLO TO B-FLO 99,999.99 MOVE A-FLO TO B-FLO ZZ,ZZZ.ZZ MOVE A-FLO TO B-FLO 99999.9999 10131,1512161.1919\ 1~131 ,1512161.19191 10131512161.191910101 5.9.23, See Note 4 under the MOVE clause, Section for clarification of the rule governing the third example. a Also see Note 16, Special Insertion Editing. ~Rl OB Each of these symbols is used as an editing sign-control symbol. When used, they represent the character position(s) into which the editing sign-control symbol will be placed. Only one of these symbols can appear in a character-string. The + and - symbols can appear either at the beginning or at the end of a picture string. The CR and OB symbols can appear only at the end of a picture string. + The character position containing this symbol will contain a + if the sending field either was unsigned (absolute) or had a positive operational sign; it will contain a if the sending field had a negative operational sign. The character position containing this symbol will contain a space if the sending field either was unsigned (absolute) or had a positive operational sign; it will contain a if the sending field had a negative operational sign. 1 The caret ( ~ ) symbol is used to assumed decimal point. 4-45 indicate the location of the THE DATA DIVISION PICTURE (Cont.) Each of these symbols requires two character positions. CR} OB The character positions containing either of these symbols will contain spaces if the sending field either was unsigned (absolute) or had a positive operational sign; they will contain the symbol specified if the sending field had a negative operational sign. Examples: .3456~5) 1 (A-FLD contains 345625, B-FLO contains ;0., C-FLO picture string Result MOVE A-FLO TO C-FLO 9999.99BCR 1 3141s161 .1 2 15 ~I~I~I MOVE B-FLO TO C-FLO 9999.99BCR 13141s161·121s MOVE A-FLO TO C-FLO +9999.99 \+131 4 s 6 1·12 S MOVE B-FLO TO C-FLO +9999.99 1-1 3 4 S 6 · 2 S MOVE A-FLO TO C-FLO -9999.99 I~ 3 4 S 6 · 2 S MOVE B-FLO TO C-FLO -9999.99 1- 3 4 S 6 MOVE A-FLO TO C-FLO 9999.990B MOVE B-FLO TO C-FLO 9999.990B MOVE B-FLO TO C-FLO $9999.99+ ~ ci RI II ·2S 3 4 S 6 · 2 sl~I~1 3 4 sl6 · 2 slolBI 1$ 3 4\s16 · 2 sl-I Also see Note 17, Fixed Inserting Editing. The + and can also be used to perform floating insertion editing, a combination of zero suppression and symbol insertion. Floating insertion editing is indicated by the occurrence of two or more consecutive + or - symbols at the beginning of the picture string. The total number of significant positions in the editing field must be at least one greater than the number of significant digits in the data to be edited. The floating + or - moves from left to right through any high-order zeros until a decimal point or the picture character 9 is encountered. (In order for floating to go past decimal point, all numeric positions of the item must be represented by the floating insertion symbol.) The caret ( ~ ) symbol is used to assumed decimal point. 4-46 indicate the location of the THE DATA DIVISION PICTURE (Cont.) Examples: (A-FLO contains 00S6",2S; contains B-FLD -00S6}S) C-FLO picture string Result MOVE A-FLD TO C-FLD ++999.99 I~\+\O S 6 .\2\S 1 MOVE B-FLD TO C-FLD ++++9.99 MOVE ZERO TO C-FLD ++999.99 I~I~I- S 6 ·1 2 IS \ 1~1+10 0 0 .10101 MOVE ZERO TO C-FLD +++++.++ I~I~\~ ~ 6 ~16\~\ MOVE A-FLO TO C-FLD --999.99 \6 6\0\S 6\.\2\S\ MOVE B-FLD TO C-FLD --999.99 16 MOVE ZERO TO C-FLD ---99.99 \6 61 ~ 10 01 .1 010 I MOVE ZERO TO C-FLD -------- 16 -lois 61·\2\sl 61~16 ~I~I~I I Also see Note 18, Floating Insertion Editing. Note that the + and - symbols are distinct from the S (operational sign) symbol. Normally, the + and - symbols are used to describe display items that are to appear on some printed report; they provide visual sign indication and cannot be used with items appearing as operands in arithmetic statements. $ A $ (or the symbol specified by the CURRENCY SIGN clause in the SPECIAL-NAMES paragraph) represents the character position into which a $ (or the currency symbol) is to be placed. This symbol is counted in the size of the item. Example: (A-FLO contains 34S6JS) B-FLO character-string Result MOVE A-FLO TO B-FLD $9,999.99 \$\31,\4ISI6\.17\S\ MOVE A-FLD TO B-FLD $999,999.99 1$10\0\31,\4\516\.\7\S\ Also see Note 17, Fixed Insertion Editing. The $ symbol can also be used to perform floating insertion editing. Floating insertion editing is indicated by the occurrence of two or more consecutive $ symbols at the beginning of the character string. The total number of significant positions in the editing field must be at least one greater than the number of significant digits in the data to be edited. The floating $ symbol floats from left to right through any high-order zeros until a decimal point or the picture character 9 is encountered. 4-47 THE DATA DIVISION PICTURE (Cont.) Examples: (A-FLD contains 005625) Result B-FLD picture string MOVE A-FLD TO B-FLD $$9,999.99 I bl $1 0 I, 10 15 16 .1 2 15 MOVE A-FLD TO B-FLD $$$,$$$.99 Ibl blbllll$1516 .1 2 1 5 MOVE ZERO TO B-FLD $$$,999.99 Iblblbl$IOIOlo MOVE ZERO TO B-FLD $$$,$$$.$$ [Alb(bJbllllblll blill b .1 0 10 Also see Note 18, Floating Insertion Editing. 12. There are two general methods of performing PICTURE clause: a. insertion, or b. suppression and replacement. editing in the There are four types of insertion editing available: a. Simple insertion b. Special insertion c. Fixed insertion d. Floating insertion There are two types of suppression and replacement editing: 13. a. Zero suppression and replacement with spaces b. Zero suppression and replacement with asterisks The type of editing that may be performed upon depends on the category to which the item belongs. Category Type of Editing Allowed Alphabetic Simple insertion: Numeric None Alphanumeric None Alphanumeric-edited Simple insertion: Numeric-edited an item B only 0, Band / All (except for the restriction given in Note 14) 4-48 THE DATA DIVISION PICTURE (Cont.) 14. Floating insertion editing and zero suppression/replacement editing are mutually exclusive in a PICTURE clause. Only one type of replacement can be used with zero suppression in a PICTURE clause. 15. Simple Insertion Editing (, B 0 /) The , (comma), B (space), 0 (zero), and / (slash or stroke) constitute those editing symbols used in simple insertion editing. These insertion characters represent the character position in the item into which the character will be inserted. These symbols are counted in the size of the item. 16. Special Insertion Editing (.) The • (decimal point) symbol is used in special insertion editing. In addition to its use as an insertion character, it also represents the position of the decimal point for decimal point alignment. This symbol is counted in the size of the item. The symbols . and V (assumed decimal point) are mutually exclusive in a PICTURE clause. Since the . cannot be the last symbol in the character-string, it must be immediately followed by one of the line-ending characters, either space or carriage return. 17. Fixed Insertion Editing ($ + - CR DB) The currency symbol ($) and the editing sign control characters (+ CR DB) constitute the characters used ln fixed insertion editing. Only one $ and one of the editing sign control characters can be used in a PICTURE character-string. When the symbols CR or DB are used, they represent two character positions in determining the size of the item. The symbols + or - when used must be the leftmo$t or rightmost character positions to be counted in the size of the item. The $ when used must be the leftmost character position to' be counted in the size of the item, except that it can be preceded by a + or symbol. A fixed insertion editing character appears in the same character position in the edited item as it occupied in the PICTURE character-string. When the $ is used as a floating insertion editing character, the picture string must contain at least one $ more than the maximum number of significant digits in the item to be edited. If you use a comma and the $ simultaneously for editing, there must always be at least two $ to the left of the comma because one $ will always be printed; there is no place for a significant digit to the left of the comma if you have used only one $. (If the i tern has a picture of $, $$$ then no digit will ever appear to the left of the comma; a $ will always be there.) A comma is omitted only when what appears to its left consists only of zeroes. (With the picture string $,$$$ the comma is never omitted.) 4-49 THE DATA DIVISION PICTURE (Cont.) Editing sign control symbols produce the following depending on the value of the data being edited. Editing Symbol in PICTURE character-string 18. results Result Data positive Data Negative + + - - space - CR 2 spaces CR DB 2 spaces DB Floating Insertion Editing ($$ ++ --) The $ and the editing sign control symbols + and floating insertion editing characters and are exclusive in a given PICTURE string. are the mutually Floating insertion editing is indicated in a PICTURE character-string by using a string of at least two of the allowable insertion characters to represent the leftmost numerip character positions into which the insertion characters can be floated. Any of the simple insertion characters embedded in the string of floating insertion characters or to the immediate right of this string are part of the floating string. In a PICTURE character-string, there are representing floating insertion editing: only two ways of a. Representing any two or more of the leading numeric character positions on the left of the decimal point by the insertion character. The result is that a single insertion character will be placed in the character position immediately preceding the leftmost nonzero digit of the data being edited or in the character position immediately preceding the decimal point, or in the character position represented by the rightmost insertion character, whichever is encountered first. b. Representing all numeric character positions in character-string by the insertion character. If value is not zero, the result is the same as when insertioi character appears only to the left of decimal point. If the value is zero, the entire item set to spaces. the the the the is A picture string containing floating insertion characters must contain at least one more floating insertion character than the maximum number of significant digits in the item to be edited. For example, a data field containing five significant digit positions requires an editing field of at least six significant positions. ,All floating insertion characters are counted in the size 'of the item. 4-50 THE DATA DIVISION PICTURE (Cont.) 19. Zero suppression Editing (Z *) The suppression of leading zeros and commas in a data field is indicated by the use of the Z or the * symbol in a picture string. These symbols are mutually exclusive in a given picture string. Each suppression symbol is counted in the size of the item. If a Z is used, the replacement character is a space. If an * is used, the replacement character is an * Zero suppression and replacement is indicated by a string of one or more Zs or *s to represent the leading numeric character positions which are to be replaced when the associated character position in the data contains a leading zero. Any of the simple insertion characters embedded in this string of zero suppression symbols or to the immediate right of this string are part of the string. If the zero suppression symbols appear only to the left of the decimal point, any leading zero in the data that corresponds to a zero suppression symbol in the string is replaced by the replacement character. Suppression terminates at the first nonzero digit in the data represented by the suppression symbol in the string or at the decimal point, whichever is encountered first. If all numeric character positions in the picture string are represented by the suppression symbol and the value of the data is not zero, the result is the same as if the suppression characters were only to the left of the decimal point. If the value is zero, the entire item (including any sign) will be set tb the replacement character (with the exception of the decimal point if the suppresson symbol is an *) • The * and the clause BLANK WHEN ZERO may not same entry. 4-51 appear in the THE DATA DIVISION PICTURE (Cont.) Example: (A-FLD contains 023456, B-FLD contains 001200) R-FLD PICTURE String Result of MOVE MOVE A-FLD TO R-FLD ****.** *234.56 MOVE B-FLD TO R-FLD **12.00 (1) MOVE B-FLD TO R-FLD xxxx.xx zzzz.zz zzzz.zz MOVE ZERO TO R-FLD ****.** ****.** (2) MOVE ZERO TO R-FLD ZZZZ.ZZ D.D.D.D.D.D.D. MOVE ZERO TO R-FLD +****.** *****.** (4) MOVE ZERO TO R-FLD +ZZZZ.ZZ D.D.D.D.D.D.D.D. (5) MOVE A-FLD TO R-FLD 234.56 (l) 12.00 (3) (1) Zero supression does not take place to the right of the decimal point. (2) Decimal point is not suppressed. (3) Decimal point is replaced by a space. (4) Plus sign ( +') is replaced by a space. (5) Both sign and decimal point are replaced by space. 20. The symbols + - * Z and $ when used as floating replacement characters are mutually exclusive within a given picture string. 21. Figure 4-4 shows the order of precedence of the various picture string symbols. Each "Y" on the chart indicates that the symbol in the top row directly above can precede the symbol at the left of the row in which the "Y" appears. { }indicate that the symbols are mutually exclusive. The P and the fixed insertion + and - appear twice. P9, +9, and -9 represent the case where these symbols to the left of any numeric positions in the string. appear 9P, 9+, and 9- represent the case where these symbols to the right of any numeric positions in the string. appear The Z, *, and the floating ++, --, and $$ also appear twice. Z., *., $$., and --. represent the case where these appear before the decimal point position • symbols . z, .*, .$$, .++, and .-- represent the case where symbols appear following the decimal point position. these 4-52 THE DATA DIVISION PICTURE (Cont.) FIXED INSERTION z o Z ~~ f~:} $ Y Y Y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y y 0 , B Y Y Y 0 y y , y y w V") (+~ B i= 0::: OTHER -~ A X +9J -9 P9 9P S V Ir++.} :~~} {:J l:} Il-. 9 y Y $$. .$$ y Y Cl t9~ u: 9w X Y Y Y Y Y Y Y Y Y Y Y ~~ Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y $ Y Y Y A X Y Y Y P9 Y Y Y Y Y Y Y y y y y y y y y y y y y V Y Y Y Y Y Y Y Y Y Y Y Y Y ~:.J y y y y y t:} y y y y y y 9 Y Y y y y y y y y y y y y 9P S ~ UJ :c I- o C~} y [~~ y $$. y y y .$$ y y y y y y y y y y y y y y y y y y y y y y y y y y y y y MR-S-024- 79 Figure 4-4 Picture String Character Chart 4-53 THE DATA DIVISION REDEFINES 4.9.19 REDEFINES Function The REDEFINES clause allows the same memory area to two or more data items. be allocated to General Format [REDEFINES data-name-2 ] Technical Notes 1. The REDEFINES clause, data-name-l. 2. The level-numbe~s of the data-name-l and data-name-2 must identical. 3. This clause must not be used for level-number 66 or 88 items. Also, it must not be used for level-Ol entries in the File Section: implicit redefinition is provided by specifying more than one data-name in the DATA RECORDS ARE clause in the FD. However, the REDEFINES clause may be used to redefine an item whose picture contains the OCCURS clause. 4. When the level-number of the data-names is other than level-Ol, the storage area for data-name-2 should be of the same size as data-name-l. FILLER items may be used to comply with this rule. 5. The REDEFINES entry must describing data-name-2. 6. The redefinition entries cannot contain VALUE clauses. 7. Data-name-2 must not be qualified. 8. The following example illustrates the use of the REDEFINES entry. The entries shown cause AREA-A and AREA-B to occupy the same area in memory. 03 03 when used, must immediately immediately follow AREA-A USAGE DISPLAY-6. 04 FIELD-l PICTURE IS X(7). 04 FIELD-2 PICTURE IS A(l3) • 04 FIELD-3. 05 SUBFIELD-l PICTURE IS S999V99 USAGE IS COMPo 05 SUBFIELD-2 PICTURE IS S999V99 USAGE IS COMPo AREA-B REDEFINES AREA-A USAGE DISPLAY-6. 04 FIELD-A PICTURE IS X(22). 04 FIELD-B PICTURE IS X(S). 04 FILLER PICTURE IS X(9). 4-54 the follow be entries THE DATA DIVISION REDEFINES (Cont.) Note how the length of each area is calculated so that AREA-B can be defined so that its size is equal to that of AREA-A. AREA-A: FIELD-l 7 FIELD-2 13 FIELD-3 4 SUBFIELD-l 6 SUBFIELD-l 6 Total 6-bit characters 36 AREA-B: FIELD-A 22 FIELD-B 5 FILLER 9 Total 6-bit characters 36 4-55 6-bit characters (DISPLAY-6 assumed) 6-bit characters (DISPLAY-6 assumed) (not used 6-bit characters because COMP items must start at a new word boundary) (COMP items 6-bit characters occupy one word, or six 6-bit character positions) (COMP items 6-bit characters occupy one word, or six 6-bit character positions) (DISPLAY-6 6-bit characters assumed) (DISPLAY-6 6-bit characters assumed) (needed to 6-bit characters make AREA-B size equal to AREA-A) THE DATA DIVISION RENAMES (level-66) 4.9.20 RENAMES (level-66) Function The RENAMES clause permits alternate, possibly overlapping, of elementary items. groupings General Format 66 data-name-l RENAMES data-name-2 ~{ ~UGH} data-name-3~ Technical Notes 1. All RENAMES entries associated with items in,a given record must immediately follow the last data description entry for that record . . 01 data-name-a (data description entries) 01 (level-66 entries associated with this logical record) data-name-b. 2. Data-name-l cannot be used as a qualifier, and can be qualified only by the names of the level-Ol or FD entries associated with it. 3. The words THRU and THROUGH are equivalent. 4. Data-name-2 and data-name-3 must be the names of items in the associated logical record and cannot be the same data-name. Neither data-name-2 nor data-name-3 can have a level-number of 01, 66, 77, or 88. Neither of these data-names can have an OCCURS clause in its data description entry, nor be subordinate to an item that has an OCCURS clause in its data description entry. Data-name-2 must precede data-name-3 in the record description, and data-name-3 cannot be subordinate to data-name-2. If there is any associated redefinition (REDEFINES), the ending point of data-name-3 must logically follow the beginning point of data-name-2. When data-name-3 is specified, data-name-l is a group item that includes all elementary items starting with data-name-2 (if data-name-2 is an elementary item) or the first elementary item in data-name-2 (if data-name-2 is a group item) and concluding with data-name-3 (or the last elementary item in data-name-3) • 4-56 THE DATA DIVISION RENAMES (ievel-66) (Cont.) If data-name-3 is not specified, data-name-2 can be either a group item or an elementary item. If it is a group item, data-name-l is treated as a group item and includes all elementary items in data-name-2; if data-name-2 is an elementary item, data-name-l is treated as an elementary item with the same descriptive clauses. 5. The following examples illustrate entry. 01 the use of the RECORD-NAME. 02 FIRST-PART. 03 PART-A. 04 FIELD-l PICTURE IS 04 FIELD-2 PICTURE IS 04 FIELD-3 PICTURE IS 03 PART-B. 04 FIELD-4 PICTURE IS 04 FIELD-S. 05 FIELD-SA PICTURE IS 05 FIELD-58 PICTURE IS 03 SECOND-PART. 03 PART-C. 04 FIELD-6 PICTURE IS .•• 04 FIELD-7 PICTURE IS .•• 66 SUBPART RENAMES PART-B THRU PART-C. 66 SUBPARTI RENAMES FIELD-3 THRU SECOND-PART. 66 SUBPART2 RENAMES FIELD-SB THRU FIELD-7. 66 AMOUNT RENAMES FIELD-7. 4-57 RENAMES THE DATA DIVISION SIGN 4.9.21 SIGN Function The SIGN clause specifies the position and the mode of of the operational sign. representation General Format Technical Notes 1. The optional SIGN clause, if present, specifies the position and the mode of representation of the operational sign for the numeric data description entry to which it applies, or for each numeric data description entry subordinate to the group to which it applies. The SIGN clause applies only to numeric data description entries whose PICTURE contains the character S; the S indicates the presence of an' operational sign. However, it does not indicate the representation or the position of the sign. 2. The numeric data description entries to which the SIGN clause applies must be described as USAGE IS DISPLAY. 3. At most one SIGN clause may apply to any given description entry. 4. If the CODE-SET clause is specified, any signed numeric data description entries associated with that file description entry must be described with the SIGN IS SEPARATE clause. 5. A numeric data description entry whose PICTURE contains the character S, but to which no optional SIGN clause applies, has an operational sign which is associated with the trailing digit position of the elementary item. 6. If the optional SEPARATE CHARACTER phrase is not present, the following rules apply: numeric data a. The operational sign will be presumed to be with the trailing digit position of the numeric data item. b. The letter ~ in a PICTURE character-string is not counted in determining the size of the item (in terms of standard data format characters). 4-58 associated elementary THE DATA DIVISION SIGN (Cont.) 7. 8. If the optional SEPARATE CHARACTER following rules apply: phrase is present, the a. There is no default condition for the operational sign in this case. You may specify the SEPARATE CHARACTER phrase only when either LEADING or TRAILING is also specified. b. The letter S in a PICTURE character-string is counted in determining the size of the item (in terms of standard data format characters). c. The operational signs for positive and negative are the standard data format characters + and -, respectively. d. The various possiblities for the SIGN and SEPARATE CHARACTER clauses are illustrated below: (value is -Ill) Options SIXBIT Representation none SIGN LEADING SIGN TRAILING SIGN LEADING SEPARATE SIGN TRAILING SEPARATE 0000001lJ ]00000111 0000001lJ -000000111 000000111- Every numeric data description entry whose PICTURE contains the character S is a signed numeric data description entry. If a SIGN clause applies to such an entry and conversion is necessary for purposes of computation or comparisons, conversion takes place automatically. 4-59 THE DATA DIVISION SYNCHRONIZED 4.9.22 SYNCHRONIZED Function The SYNCHRONIZED clause specifies the positioning item within a computer word (or words). of an elementary General Format SYNCHRONIZED} [ { SYNC JD LEFT [ RIGHT ~ Technical Notes 1. This clause can appear only in the elementary item. data description 2. This clause is optional. SYNCHRONIZED LEFT. omit it 3. This clause specifies that the item being defined is to be placed in an integral number of computer words and that it is to begin or end at a computer word boundary. No other adjacent fields are to occupy these words. The unused positions, however, must be counted when calculating: 4. If group you to which this the of an default is a. the size of any belongs, and elementary item b. the computer memory allocation when the item appears as the object of a REDEFINES clause. However, when a SYNCHRONIZED item is referenced, the original size of the item (as indicated by the PICTURE clause) is used in determining such things as truncation, justification, and overflow. SYNCHRONIZED LEFT or SYNC LEFT specifies that the item is to be positioned in such a way that it will begin at the left boundary of a computer word. SYNCHRONIZED RIGHT or SYNC RIGHT specifies that the item is to be positioned in such a way that it will terminate at the right boundary of a computer word. 5. When the SYNCHRONIZED clause is specified for an item within the scope of an OCCURS clause, each occurrence of the item is SYNCHRONIZED. 6. Any FILLER required to position the item as specified will be automatically generated by the compiler. The content of this FILLER is indeterminate. 4-60 THE DATA DIVISION SYNCHRONIZED (Cont.) 7. COMP(UTATIONAL), COMP(UTATIONAL)-l, and INDEX items are always implicitly SYNCHRONIZED RIGHT, and therefore cannot be SYNCHRONIZED LEFT. 8. An item subordinate to one containing a VALUE be SYNCHRONIZED. 9. Only DISPLAY, DISPLAY-6, DISPLAY-7, items can be SYNCHRONIZED. 4-61 clause DISPLAY-9, or cannot COMP-3 THE DATA DIVISION USAGE 4.9.23 USAGE Function The USAGE clause specifies the format storage. of a data item in computer 1. This clause specifies the manner in represented within computer memory. which a data 2. The USAGE clause can be written at any level. If it is written at a group level, it applies to each elementary item in the group. The USAGE clause of an elementary item cannot contradict the USAGE clause of a group to which the item belongs. General Format COMPUTATIONAL cm~p COMPUTATIONAL-l COMP-l CQMi5'ITf ATI ONAL- 3 COMP-3 USAGE IS DISPLAy DISPLAY-6 DISPLAY-7 DISPLAY-9 INDEX DATABASE-KEY DBKEY Technical Notes item is The recording mode of a file determines how the data is recorded on the external medium. The recording mode may be inferred from the usage mode of the data records, but the reverse is never true. The usage of a data record is never inferred from the declared recording mode of the file. The implied USAGE of a group item is DISPLAY-7 if the first elementary item subordinate to it is declared as DISPLAY-7, or DISPLAY-9 if the first elementary item subordinate to it is declared as either DISPLAY-9 or COMP-3; otherwise, its USAGE is DISPLAY-6. However, if the Ix switch is included in the compiler command string, the default USAGE is DISPLAY-9. Usages of DISPLAY-6, DISPLAY-7, and DISPLAY-9/COMP-3 cannot be mixed. However, USAGES of COMP, COMP-I and INDEX can be mixed with the aforementioned usages. 3. All group items are treated as DISPLAY-6, DISPLAY-7, or DISPLAY-9. such item is 4,096 characters. 4-62 DISPLAY items, either The maximum size for any THE DATA DIVISION USAGE (Cont.) 4. COMPUTATIONAL (COMP) a. COMP is equivalent to COMPUTATIONAL. b. A COMPUTATIONAL item represents a value to be used in computations and must be numeric. Its picture string can contain only the symbols: 9 S V P. Its value is represented as a binary number with an assumed decimal point. c. If a group item is described as COMPUTATIONAL, the elementary items in the group are COMPUTATIONAL. However, the group itself is not COMPUTATIONAL and cannot be used as an operand in arithmetic computations. See Note 3 above. d. COMPUTATIONAL items of 10 or fewer decimal positions will be SYNCHRONIZED RIGHT in one computer word. Computational items of more than 10 decimal positions will be SYNCHRONIZED RIGHT in two full computer words. The maximum size of a COMP item is 18 digits. e. The following illustrations COMPUTATIONAL item. give the format of a tr---- sign Io I I-WORD COMPUTATIONAL ITEM 35 t--- sign Io I E I o I 5. 35 not used 2-WORD COMPUTATIONAL ITEM 35 COMPUTATIONAL-l (COMP-l) a. COMP-l is equivalent to COMPUTATIONAL-I. b. A COMPUTATIONAL-l item can contain a value, in floating point format, to be used in computations. It must be numeric. A COMP-l item must not have a PICTURE. c. If a group item is described as COMPUTATIONAL-I, the elementary items within the group are COMPUTATIONAL-I. However, the group item itself is not COMPUTATIONAL-l and cannot be used as an operand in arithmetic computations. See Note 3 above. d. COMPUTATIONAL-l items will be SYNCHRONIZED computer word. 4-63 in one full THE DATA DIVISION USAGE (Cont.) e. The following illustration COMPUTATIONAL-l item. the format of a sign f II hinary exponent 0 6. gives mantissi.l 9 35 COMPUTATIONAL-3 (COMP-3) a. COMP-3 is equivalent to COMPUTATIONAL-3. b. A COMP-3 item's picture string can contain only the symbols 9, S, V, P. Its value 1S represented as a packed decimal number with an assumed decimal point. c. If a group item is declared as COMP-3 the elementary items in the group are COMP-3.However, the group item itself is not COMP-3 and cannot be used as an operand in arithmetic computations. See Note 3 above. d. The maximum size of a COMP-3 item is 18 decimal digits . • The following illustration gives the format of a COMP-3 item. Note that bits 0, 9, 18 and 27 of the word are not used. e. I 0 4 ~ 89 13 I 17 18 22 SYNCHRONIZED I 2627 or 35 SYNCHRONIZED f. COMP-3 items may be RIGHT. g. COMP-3 items may share a computer word with other COMP-3 items or with DISPLAY-9 items. However, COMP-3 items will always begin at one of the following bit positions in a word: 1, 10, 19, 28. h. .The actual size of a COMP-3 item in memory is at least four bits larger and may be nine bits larger than the number of character positions because the sign is! stored in the last four bits of the item and the item is stored right justified on a nine-bit byte boundary. i. The octal values 12, 14, and 16 represent plus signs and the octal values 13 and 15 represent minus signs. The octal value 17 represents the nonprinting plus sign. Although octal 12, 14 and 16 represent plus signs, the sign given to the positive result of any arithmetic operation will be 14. Similarly, the minus sign given to the negative result of any arithmetic operation will be 15. 4-64 LEFT 31 THE DATA DIVISION USAGE (Cont.) The nonprinting plus sign is actually an absolute value indicator. Any positive or negative number which is moved into an item with this sign will receive this sign. In arithmetic computations and numeric editing operations, items containing the nonprinting plus sign are treated as positive. 7. DISPLAY a. 8. DISPLAY-6 a. DISPLAY is equivalent to DISPLAY-6 when the Ix switch not given in the compiler command string. b. A DISPLAY-6 item represents a string of 6-bit characters. Its picture string may contain any picture symbols. Refer to Appendix C for the SIXBIT collating sequence. c. DISPLAY-6 items may be SYNCHRONIZED LEFT or SYNCHRONIZED RIGHT, as desired. Otherwise, they may share a computer word with other DISPLAY-6 items. d. The illustration below given the format word. o e. 9. DISPLAY is equivalent to DISPLAY-6. However, you may change DISPLAY to be DISPLAY-7 or 9 with the DISPLAY IS clause. You may also cause the compiler to consider all DISPLAY items to be DISPLAY-9 by using the IX switch when compiling your program. 6 12 24 18 of a is DlSPLAY-6 35 30 If the IX switch has not been included in the compiler command string, and the USAGE clause is omitted for an elementary item, its USAGE is assumed to be DISPLAY-6. DISPLAY-7 a. A DISPLAY-7 item represents a string of 7-bit ASCII characters. Its picture string may contain any picture symbols. b. DISPLAY-7 items can be SYNCHRONIZED LEFT or SYNCHRONIZED RIGHT, as desired; otherwise, they may share a computer word with other items. If the item is SYNCHRONIZED RIGHT, the last character of the item will end in bit 34 of a computer word. c. Bit 35 of a word represented used. in d. The maximum characters. DISPLAY-7 length of 4-65 a this format is never item is 4,096 THE DATA DIVISION USAGE (Cont.) e. The illustration below gives the format word. o 10. 7 DISPLAY-7 3S 28 21 a DISPLAY-9 a. DISPLAY is equivalent to DISPLAY-9 when the Ix switch included in the command string to the compiler. b. A c. DISPLAY-9 items may be SYNCHRONIZED LEFT or SYNCHRONIZED RIGHT as desired; otherwise, they may share a computer word with ather DISPLAY-9 or COMP-3 items. If the item is SYNCHRONIZED RIGHT, the last character of the item will end in bit 35 of a computer word. d. The maximum characters. e. The illustration below gives the format of a DISPLAY-9 item. Note that bits 0, 9, 18, and 27 are not used. DISPLAY-9 characters. symbol. I I o 89 f. 11. 14 of is a string of EBCDIC item represents Its picture string may contain any picture length of a DISPLAY-9 I item is I 1718 4,096 3S 2627 If the USAGE clause is omitted for an elementary item and the IX switch has been included in the compiler command string, its USAGE is assumed to be DISPLAY-9 • INDEX a. An elementary item described as USAGE INDEX is called an index data-item. It is treated as a COMP item with PICTURE S9(5) and can be used as a COMP item. b. An index data-item must not have a PICTURE. c. If a group item is described as INDEX, the elementary items within the group are treated as INDEX. However, the group item itself is not INDEX and cannot be used as an operand in arithmetic statements. 'd. Index data items and index-names (defined in the clause by the INDEXED BY option) are equivalent. e. If an index-name ,is defined cannot be defined elsewhere. 4-66 in an OCCURS OCCURS clause, it THE DATA DIVISION USAGE (Con t.) 12. DATABASE-KEY DATABASE-KEY and interchangeable. b. An item described as USAGE DATABASE-KEY is treated as a COMP item with PICTURE S9{lO) and can be used as a COMP item. c. The item with USAGE DATABASE-KEY must not have a PICTURE. d. An item with USAGE DATABASE-KEY is primarily used in programs accessing data bases through the TOPS-IO Data Base Management System (DBMS-IO), or the TOPS-20 Data Base Management System (DBMS-20). This item can be used to store the value of a data base key. All data base keys are assigned by DBMS and you cannot change them. Refer to the DBMS-IO Programmer's Procedures Manual for more information about DBMS-IO, or the DBMS-20 programmer's Procedures Manual for DBMS-20. DBKEY 4-67 are equivalent and a. THE DATA DIVISION VALUE 4.9.24 VALUE Function The VALUE clause defines the initial value of Working-Storage and the values associated with condition-names (level-88). items, General Format Format 1: [VALUE IS literal] Format 2: f VALUE IS } [ 1 VALOIs ARE [ literal-3 literal-l [THRU [THRU literal-2 ] literal-4] ] ... J Technical Notes 1. Format 2 can be specified only for level-88 items. 2. The words THRU and THROUGH are equivalent. 3. In the File Section and the Linkage Section, the VALUE clause can be used only with level-88 items. In the Working-Storage Section, it can be used at all levels except level-66. It must not be stated in a data description entry that contains an OCCURS clause or that is subordinate to an entry containing an OCCURS clause. Also, it must not be stated in an entry that, contains a REDEFINES clause or that is subordinate to an entry that contains a REDEFINES clause. 4. If the VALUE clause is used at a group level, the literal must be a figurative constant or a nonnumeric literal. The group item is initialized to this value without consideration for the individual elementary or group items contained within this group. No VALUE' clauses can appear at subordinate levels within the group. 5. If no VALUE clause appears for a Working-Storage initial value of the item is unpredictable. 6. More information concerning Format 2 can be Condition-name (Level-88) in Section 4.9.13. 4-68 item, found the under THE DATA DIVISION VALUE (Cont.) 7. 8. The VALUE clause must not conflict with other clauses in the data description entry or in the data description entries within the hierarchy of the item. The following rules apply: a. If the category of an item is numeric, all literals in the VALUE clause must be numeric. All literals in a VALUE clause must have a value within the range of values indicated by the PICTURE clause; for example, an item with PICTURE PPP9 may have only the values in the range .0000 through .0009. b. If the category of the item is alphabetic or alphanumeric, all literals in the VALUE clause must be nonnumeric literals. The literal will be aligned according to the normal alignmen~ rules (see the JUSTIFIED clause, Section 4.9.15) except that the number of characters in the literal must not exceed the size of the item. c. If the category of an item is numeric-edited or alphanumeric-edited, no editing of the value is performed in the VALUE clause. d. The USAGE of the literal agrees with the USAGE of the item. Thus, if the item has USAGE DISPLAY-6, the literal also has USAGE DISPLAY-6 and its value must contain legal SIXSIT characters. The figurative constants SPACE (S), ZERO(E) (8), QUOTE (8) , LOW-VALUE (8) , and HIGH-VALUE (8) may be substituted for a literal. If the item is numeric, only ZERO(E) (8), LOW-VALUE (8) , and HIGH-VALUE(8) are allowed. 4-69 THE DATA DIVISION Report Description (RD) 4.9.25 Report Description (RD) Function The Report Description furnishes information concerning structure for a report. the physical General Format RD report-name [CODE mnemonic-name ] CONTROL IS CONTROLS ARE [ PAGE FINAL identifier-l [identifier-21 FINAL identifier-l [identifier-21 I{ I J LIMIT I S integer-l 1J LINE LI NES integer-2J [FIRST DETAIL 1 LIMITS ARE [ HEADING [ LAST DETAI L integer-4] [FOOTING ] ... } I integer-3 ] inte ger-5]] .'- Technical Notes appearance of the optional clauses is 1. The order of immaterial. 2. A fixed data-name PAGE-COUNTER is automatically generated for each RD entry. Its function is to contain the current page number of a report. It is a COMPUTATIONAL item; its size is equal to the size of the largest field that refers to it in a SOURCE clause. The contents of the PAGE-COUNTER are set to 1 by the INITIATE statement. 3. The fixed data-name LINE-COUNTER is automatically generated for each RD entry. Its function is to contain the current line number within a report page. It i s a COMPUTATIONAL item; its size is based on the number of lines specified in the PAGE-LIMIT clause. 4-70 THE DATA DIVISION Report Description (RD) (Cont.) 4. PAGE-COUNTER or LINE-COUNTER may be referenced as if it were any data-name. It must be qualified by the report-name if more than one RD entry is present in the program. 5. Each of the above clauses appears in this chapter separately, in alphabetical order. 4-71 THE DATA DIVISION CODE 4.9.26 CODE Function The CODE clause defines a unique string of one or more characters that is affixed to each line of the report. General Format ~CODE mnemonic-name~ Technical Notes 1. This clause is necessary only if more than one report be written in a single file. is to 2. Mnemonic-name is defined in the SPECIAL-NAMES paragraph the Environment Division, described in Section 3.1.4. of 3. The character string represented by mnemonic-name is affixed to the beginning of each report line, and is used to uniquely define the lines of separate reports written in one file. 4. The number of characters represented by mnemonic-name must be the same for the codes of all reports in the same file. 4-72 THE DATA DIVISION CONTROL 4.9.27 CONTROL Function The CONTROL clause indicates the identifiers that control the printing of totals in the report. General Format IS} lrf{2 CONTROL CONTROLS ARE FINAL identifier-l [identifier-2]", { FINAL identifier-l [identifier-2] u Technical Notes 1. The CONTROL clause is required when CONTROL CONTROL FOOTING report groups are specified. 2. The identifiers specify the control hierarchy for this report. They are listed in order from major to minor; FINAL is the highest level of control, identifier-l is the major control, identifier-2 is the intermediate control, etc. The last identifier specified is the minor control. 3. Identifiers must be defined in the File or Working-Storage Section of the Data Division. They cannot be subscripted or indexed. 4-73 HEADING or THE DATA DIVISION Report Group Description 4.9.28 Report Group Description Function The Report Group Description entry specifies the format of a particular report group. characteristics General Format Format 1 01 [ dat a - n arne -1 ] NUMBER IS integer-1 }] PLUS integer-2 { NEXT PAGE NEXT GROUP IS integer-3 PLUS in teger-4 { NEXT PAGE [ LI NE [ }] REPORT HEADING RH PAGE HEADING PH {CONTROL -CH TYPE IS HEADING } { identifier-1 } FINAL DETAIL Qf {~~NTROL FOOTING } { ~~~~~ifier-2 } PAGE FOOTING PF REPORT FOOTING RF DISPLAY [ [USAGE IS] DISpLAv-6 { DISPLAY-7 DISPLAY-9 4-74 and THE DATA DIVISION Report Group Description (Con t.) Format 2 level-number [data-name-l ] [BLANK WHEN ZERO ] [COLUMN NUMBER [GROUP [I [I integer-I] INDICATE] ) RIGHT ] JUSTIFIED JUST [LINE IS NUMBER PICTURE PIC [RESET ON IS { integer-2 PLUS integer-3 NEXT PAGE ) IS character-string ] I i de nt if i er -1 ) ] FINAL SOURCE IS identifier-2 SUM identifier-3 [identifier-4] { VALUE IS literal-l I] [ I [USAGE }] IS ] DISPLAY DISPLAY-6 DISPLAY-7 DISPLAY-9 -=- 4-75 [UPON data-name-2]} THE DATA DIVISION Report Group Description (Cont.) Technical Notes 1. Except for the data-name, which when present must immediately follow the level-number, the clauses may be written in any order. 2. In order for a report group to be referred to by a Division statement, it must have a data-name. 3. All elementary items must have both a PICTURE clause and of the clauses SOURCE, SUM, or VALUE. 4. For a detailed description of the BLANK WHEN ZERO, JUSTIFIED, PICTURE, VALUE, and USAGE clauses, see the pages following the Data Description Entry, which is Section 4.9.11. 5. The data-name need not appear in an entry unless it is re,ferred to by a GENERATE or USE statement, or reference is made to the SUM counter. 6. If the Ol-level item is elementary, the clauses in Format may be used in addition to the clauses in Format 1. 7. The remaining clauses following pages. are 4-76 described in detail Procedure on one 2 the THE DATA DIVISION COLUMN NUMBER 4.9.29 COLUMN NUMBER Function The COLUMN NUMBER clause indicates the column on the printed page in which the high-order (leftmost) character of an item will be printed. General Format [}OLUMN NUMBER IS i nteger-l] Technical Notes 1. Integer must have a positive value less than 512. 2. This clause is valid only for an elementary item. 3. Within a report group and a particular LINE NUMBER specification, COLUMN NUMBER entries must be indicated from left to right. 4. If the COLUMN NUMBER clause is omitted, the elementary item, though included in the description, is suppressed when the report group is produced at object time. 4-77 THE DATA DIVISION GROUP INDICATE 4.9.30 GROUP INDICATE Function The GROUP INDICATE clause indicates that this elementary item is to be produced only on the first occurrence of the item after any CONTROL or PAGE breaks. General Format [GROUP INDI CATE] Technical Notes 1. This clause can only be used at the elementary level within a TYPE DETAIL report group. 2. A GROUP INDICATEd item is presented in the first detail line of a, report after any control breaks and after any page breaks; it is suppressed at all other times. 4-78 THE DATA DIVISION LINAGE 4.9.31 LINAGE Function The LINAGE clause specifies the size of a logical page in terms of number of lines. It can also specify the size of the top and bottom margins on the logical page and the line number, within the page body, at which the footing area begins. General Format L--- IUNAGE IS {~ata-name-6} lnteger-5 LINES ~WITH FOOTING AT ILLINES AT -TOP {~ata-name-8}] ILLINES AT BOTTOM lnteger-7 ~ata-name-7 { lnteger-6 r U nlJ { ~ata-name-9 U 1 nteger-8 Technical Notes 1. The logical page size is the sum of the values referenced by each phrase except the FOOTING phrase. (There is no necessary relationship between the size of the logical page and the size of a physical page.) If the LINES AT TOP or LINES AT BOTTOM phrases are not specified, the values for these functions are zero. 2. Data-name-l, data-name-2, data-name-3 and data-name-4 must reference elementary unsigned numeric integer data items. The value of integer-l must be greater than zero: the value of integer-2 must not be greater than integer-I: the value of integer-3 and integer-4 may be zero. 3. The number of lines on the logical page is equal to the value of integer-l or the data item referenced by data-name-l. The page body is that part of the logical page in which lines can be written and/or spaced. 4. The line number within the page body at which the footing area begins is equal to the value of integer-2 or the data item referenced by data-name-2. The value must not be greater than the value of integer-I, or the data item referenced by data-name-l. The footing area is the area of the logical page between the line represented by the value of integer-2 (or the data item referenced by data-name-2) and the line represented by the value of integer-l (or the data item referenced by data-name-l) inclusive. 5. The number of lines that constitute the top margin on the logical page is equal to the value of integer-3 or the data item referenced by data-name-3. 4-79 THE DATA DIVISION LINAGE (Cont.) 6. The number of lines that constitute the bottom margin on the logical page is equal to the value of integer-4 or the data item referenced by data-name-4. 7. When an OPEN statement with the OUTPUT option is executed, all of the data-names or integers you have specified will refer to the areas and positions of the first logical page. When a WRITE statement with the ADVANCING PAGE options is executed, or when a page overflow condition occurs, the data-names or integers you have specified will refer to the next logical page. 8. The presence of a LINAGE clause in the FD entry for a file causes the compiler to generate a LINAGE-COUNTER. The value in the LINAGE-COUNTER at any given time represents the line number at which the device is positioned within the current page body. The rules governing the LINAGE-COUNTER are as follows: a. The compiler supplies a separate LINAGE-COUNTER for each file described in the File Section whose file description entry contains a LINAGE clause. b. You may reference LINAGE-COUNTER, but you may not modify it, with Procedure Division statements. Since more than one LINAGE-COUNTER may exist in a program, you must qualify LINAGE-COUNTER by file-name when- necessary. c. During the execution of a WRITE statement, LINAGE-COUNTER is automatically modified according to qow and whether you have specified the ADVANCING clause, as follows: d. 9. 1) When you specify the ADVANCING PAGE phrase of the WRITE statement, the LINAGE-COUNTER is automatically reset to one (I). 2) When you specify the ADVANCING identifier-2 or integer phrase of the WRITE statement, the LINAGE-COUNTER is incremented by integer or the value of the data item referenced by identifier-2. 3) When you omit the ADVANCING phrase of the WRITE statement, the LINAGE-COUNTER is incremented by the value one (I). 4) For each of the succeeding logical pages, the value of LINAGE-COUNTER is automatically reset to one (I) when the device is repositioned to the first line that can be written on. When an OPEN statement is executed, the LINAGE-COUNTER associated with that file is initialized to one (I). Each logical page is contiguous additional spacing provided. 4-80 to the next, with no THE DATA DIVISION LINE NUMBER 4.9.32 LINE NUMBER Function The LINE NUMBER clause indicates the absolute or relative line entry in reference to the page or the previous entry. General Format GINE NUMBER IS { i nteger-l PLUS integer-2 NEXT PAGE number 0 -- -- Technical Notes 1. Integer-l and integer-2 must be positive integers with values less than 512. Integer-l must be within the range specified by the PAGE LIMITS clause in the RD entry. 2. The LINE NUMBER clause must be given for each report line of a report group, and must be specified at or before the first elementary item that contains a COLUMN clause of each report line. If an item does not contain a COLUMN clause and the LINE NUMBER clause is specified for it, no printing will be done, but the LINE NUMBER clause will cause vertical spacing to be done. 3. If a LINE NUMBER clause is specified for an item, all entries following that item, up to but not including the next item with a LINE NUMBER clause, are presented on the same line. 4. A LINE NUMBER at a subordinate level LINE NUMBER at a group level. 5. Integer-1 indicates that the current line is to be at that line number. 6. PLUS integer-2 indicates that the LINE-COUNTER is to be incremented by the value of integer-2, and that the current line is to be presented on the line specified by the new value of the LINE-COUNTER. 4-81 may not contradict a presented THE DATA DIVISION LINE NUMBER (Cont.) 7. NEXT PAGE is used to indicate an automatic skip to the next page before the current line is presented. If there is no PAGE-LIMIT clause, there will only be a skip to the top of the next page. However, if there is a PAGE-LIMIT clause, after skipping to the next page, the Report writer will then space as follows. Type of Line Space To Detail, control heading, control footing First detail line Report heading, report footing, page heading Heading line Page footing Footing line 4-82 THE DATA DIVISION NEXT GROUP 4.9.33 NEXT GROUP Function The NEXT GROUP clause specifies the spacing last line of the report group. condition following the General Format NEXT GROUP integer-l } PLUS i nteger-2 NEXT PAGE . Technical Notes 1. The NEXT GROUP clause may appear only at the 01 report group. 2. Integer-l and integer-2 must be positive integers with values less than 512. Integer-l cannot exceed the number of lines specified by the PAGE LIMIT clause. 3. Integer-l indicates a line number to which is set after the group is presented. 4. PLUS integer-2 indicates a relative line number that increments the LINE-COUNTER by the value of integer-2 after the group is presented. Integer-2 is the number of lines skipped following the last line of the report group. 5. NEXT PAGE indicates an automatic skip to the next page the group is presented. 4-83 the level of a LINE-COUNTER after THE DATA DIVISION RESET 4.9.34 RESET Function 'fhe RESET clause indicates the CONTROL data-item that causes counter to be reset to zero on a control break. the SUM. General Format RESET ON -- .1 FINAL identifier-I) Technical Notes 1. Identifier must be one of the identifiers associated with the CONTROL clause in the RD entry. 2. The RESET clause may be used only in conjunction with clause at a CONTROL FOOTING elementary level. 3. Identifier must be a higher level (more major) control identifier than the control identifier associated with this report group. 4. After a TYPE CONTROL FOOTING report group is presented, the sum counters associated with that group are automatically set to zero, unless an explicit RESE~ clause directs that the counter be cleared at a higher level. 4-84 a SUM THE DATA DIVISION SOURCE 4.9.35 SOURCE Function The SOURCE clause indicates the source of the data for a report item. General Format SOURCE IS identifier Technical Notes 1. The SOURCE clause can only be given at the elementary level. 2. Identifier must reference an item that appears in the File or Working-Storage Section. 3. The identifier cannot be subscripted or indexed. 4. When the report group is presented, the contents of report item are replaced by the contents of identifier. 4-85 this THE DATA DIVISION SUM 4.9.36 SUM Function The SUM clause indicates the items to be summed to produce the of data for a report item. source General Format SUM identifier-l [identifier-2 ] [UPON data-name-l ] Techn'ical Notes 1. A SUM clause may appear only in a TYPE CONTROL FOOTING report group. 2. Each identifier must indicate a SOURCE item in a TYPE DETAIL report group, or a SUM counter in a TYPE CONTROL FOOTING report group. 3. If the SUM counter is referred to by a Procedure Division or Report Section statement, a data-name must be specified for the item. The data-name then represents the summation counter automatically generated by the Report Writer; that data-name does not represent the report group item itself. 4. A summation counter is incremented just before the presentation of the identifiers. Any editing of the SUM counters is done only when the sum item is presented; at all other times it is treated as a numeric item. 5. If higher-level report groups are indicated in the control hierarchy, each lower level that is figured into the sum is summed into the higher level before each lower level is reset: that is, counters are rolled forward prior to the reset operation. 6. The UPON option is required to obtain selective summation for a particular data item that is named as a SOURCE item in two or more TYPE DETAIL report groups. Identifier-l and identifier-2 must be SOURCE data items in data-name-l; data-name-l must be the name of a TYPE DETAIL report group. 7. When the UPON option is used, summation occurs only when a GENERATE statement references data-name-l. It does not occur during summary reporting (refer to the GENERATE statement, Section 5.9.16.) 8. The identifiers cannot be subscripted or indexed. 4-86 THE DATA DIVISION TYPE 4.9.37 TYPE Function The TYPE clause specifies the particular type of report group that is described by this entry and indicates the time when the report group is generated. General Format REPORT HEADING RH PAGE HEAD I NG I TYPE IS I identifier-n ) PH CONTROL HEADING ) CH FINAL DETAIL DE J CONTROL FOOTING) J identifier-n ) - l CF l FINAL PAGE FOOTING PF REPORT FOOTING RF Technical Notes 1. RH is an abbreviation for REPORT HEADING. PH is an abbreviation for PAGE HEADING. CH is an abbreviation for CONTROL HEADING. DE is an abbreviation for DETAIL. CF is an abbreviation for CONTROL FOOTING. PF is an abbreviation for PAGE FOOTING. RF is an abbreviation for REPORT FOOTING. 2. If the report group is described as TYPE DETAIL, the GENERATE statement in the Procedure Division directs the Report Writer to produce the named report group. 3. The REPORT HEADING entry indicates a report group that is produced only once at the beginning of a report, during the execution of the first GENERATE statement. There may be only one report group of this type in a report. 4. The PAGE HEADING entry indicates a report group that is automatically produced at the beginning of each page of the report. There may be only one report group of this type in a report. 5. The CONTROL HEADING entry indicates a report group that is produced at the beginning of a control group for a designated identifier. In the case of FINAL, it is produced once before the first control group during the execution of the first GENERATE statement. There may be only one report group of this type for each identifier and for FINAL. 4-87 THE DATA DIVISION TYPE (Cont.) 6. The CONTROL FOOTING entry indicates a report group that is produced at the end of a control group for a designated identifier, or that is produced only once at the termination of a report in the case of FINAL. There may be only one report group of this type for each identifier and for FINAL. In order to produce any CONTROL FOOTING report groups, a control break must occur. 7. The PAGE FOOTING entry indicates a report group that is automatically produced at the bottom of each page of the report. There may be only one report group of this type in a report. 8. The REPORT FOOTING entry indicates a report group that is produced only once, at the termination of a report. There may be only one report group of this type in a report. 9. Each identifier, as well as identifiers associated with entry. 4-88 FINAL, must the CONTROL be one of the clause in the RD THE DATA DIVISION GENERAL FORMAT FOR DATA DIVISION DATA DIVISION. [rILE SECTION. [}D fil e-name tl ~LOCK CONTAINS [i nteger-l TQ] integer-2 RECORD(S) { CHARACTERS [RECORD CONTAINS Qnteger-3 TOJ i nteger-4 CHARACTER~ LABEL fJ RECORD IS } ~ STANDARD ) OMITTED ( { RECORDS ARE { record-name-l, l L-- Ul.Q IVALUE OFfJ'IDENTIFICATION} IS {d~ta-name-l}~ llteral-l ~ j d~ta-name-2 }fllusER-NUMBER IS { da t a - na me - 3 {l ] literal-3 fJ lIDATE-WRITTEN IS tllteral-2 UL IrL!ATA {RECORD IS } data-name-4 RECORDS ARE l-- ILINAGE "IS {?ata-name-6} 1 nteger-5 LINES [data-name-5J ~ITH FOOTING AT .. J ?ata-name-7 { 1 n teger-6 r.u nl ILINES AT TOP {?ata-name-8 l] I LINES AT BOTTOM { nteger-8 U L - lnteger-7 L J data-name-9 1 [CODE-SET IS al phabet-name ] [ {~g~~is I!RE l report-name-l Geport-name-~ ASCI I SIXBIT BINARY \ RECORDING L V STAN DARD-ASCI I STANDARD ASCII 4-89 .. .] THE DATA DIVISION GENERAL FORMAT FOR DATA DIVISION [so file-name [RECORD CONTAINS [integer-l TO] integer-2 CHARACTERs] ~ {RECORD IS } data-name-l ~OATA RECORDS ARE ITrecord-ctescri pt i on-entry I ~ata-name-2J J ...J ... C:WORKING-STORAGE SECTION. J 77-1 evel-descri pti on-entry] ... [ record-description-entry C:LINKAGE SECTION. \77-1 eve1-descri pti on-entry] ~ecord-descriPtion-entry ] ... ~OMMUNICATION SECTION. J .. J ~ommunication-description-entry [!ecord-description-entry] .. 4-90 .J THE DATA DIVISION GENERAL FORMAT FOR DATA DIVISION REPORT SECTION. RD report-name [CODE mnemonic-name ] CONTROL IS I {;~~~tifier-l [identifier-2] ... }] ARE [ 1 CONTROLS FINAL identifier-l [identifier-2] ... [ PAGE I. lnteger-l LINE \J LINES integer-2J [FIRST DETAIL LIMIT IS LHlITS ARE [ HEADING [ LAST DETA I L {record-descr; pt; on-entry} i nte ger-4] [FOOT! NG ••• ] ••• ] 4-91 I integer-3 ] i nteger-5 ] ] "- THE DATA DIVISION GENERAL FORMAT FOR DATA DESCRIPTION ENTRY FORMAT 1: level-number data-name-l } { FI LLER [REDEFINES data-name-2 ] [ {~TURE } IS character-string] COMPUTATIONAL cm~p USAGE IS COMPUTATIONAL-l COMP-l COMPOTATI ONAL - 3 COMP-3 DISPLAY DISPLAY-6 DISPLAY-7 DISPLAY-9 INDEX BATABAS[- KEY DBKEY [[SIGN IS] { ~~~~~~~G } [SEPARATE CHARACTE~ 'OCCURS {~nteger-l TO integer-2 TIMES DEPENDING ON data-name-3 } L-nteger-2 TIMES 1 ASCENDING } [ { DESCEN DI NG KEY IS data-name-4 [INDEXED BY index-name-l [data-name-~ [ i ndex-name-2] [{~HRONIZED} [~~~~TJJ [{ :fIFIED }{ ~~~T D []LANK WHEN ZERO] ~ALUE IS literall 4-92 . J] . .J THE DATA DIVISION GENERAL FORMAT FOR DATA DESCRIPTION ENTRY FORMAT 2: 66 data-name-l RENAMES data-name-2 ~{ ~UGH} data-name-3~ FORMAT 3: VALUE IS { { VALUES ARE) 88 condition-name [iteral-3 a =UGH} ~{ THROUGH} l 1"t era 1-1 ~ THRU literal-4] 4-93 1iteral-2] THE DATA DIVISION GENERAL FORMAT FOR REPORT GROUP DESCRIPTION ENTRY Format 1 01 [ da t a - name - 1 ] LI NE NU~1BER IS { ~~0~ge~~ieger-2 }] NEXT PAGE NEXT GROUP [ IS [ integer-3 PLUSinteger-4 { NEXT PAGE }] REPORT HEADING RH PAGE HEADING PH {CONTROL -CH TYPE IS HEADING} { identifier-I} FINAL DETAIL DE {CONTROL -CF FOOTI NG } { i dent i fi er-2 } FINAL PAGE FOOTING PF REPORT FOOTING RF DISPLAY DISPlAY-6 DISPLAY-7 DISPLAY-9 THE DATA DIVISION GENERAL FORMAT FOR REPORT GROUP DESCRIPTION ENTRY Format 2 leve l-number [ data-name-l ] [BLANK WHEN ZERO] [COLUMN NUMBER [GROUP integer-I] INDICATE] ) RIGHT ] [ { JUSTIFIED JUST [LINE IS NUMBER IS { integer-2 PLUS integer-3 NEXT PAGE [ { PICTURE ) IS character-string ] [RESET { identifier-I) ] FINAL PIC ON SOURCE IS identifier-2 SUM identifier-3 [identifier-4] { VALUE IS literal-l [ [USAGE IS] I mmb I]...:... DISPLAY-9 4-95 }] [UPON data-name-2)} CHAPTER 5 THE PROCEDURE DIVISION The Procedure Division specifies the processing to be performed on the files and file data described in the Environment and Data Divisions. The Procedure Division contains a series of COBOL procedure statements which describe the processing to be done. Statements, sentences, paragraphs, and sections are described in Section 5.1. Sections are optional and permit a group of consecutive paragraphs to be referenced by a single procedure-name; sections can also be used for segmentation purposes (see Section 5.3, Segmentation). If any section appears in the Procedure Division, then all paragraphs must appear within a section. The first entry in the Procedure Division of a source program must be the division-header. The next entry must be either the DECLARATIVES header (see the USE statement, Section 5.9.42), or a paragraph-name or section-name. PROCEDURE DIVISION ~SJNG data-name-J ~ata-name-2J ..J [DECLARATI VES. { section-name SECTION [segment-number]. [!aragraPh-name. [sentence] ... ] declarative-sentence ... } END DECLARATIVES~ { sect ion-name SECTION li.egment-n umber] ~aragraPh-name . [sentence] Only in a subprogram DIVISION header. can ... ] } USING clauses appear in the PROCEDURE When a program-name is specified in a CALL statement in a calling program, control is transferred to the beginning of the executable code in the subprogram (that is, the Procedure Division). The identifiers in the USING clause indicate those data items in the called program that may reference data items in the calling program. The order of identifiers in the CALL statement of the calling program and in the PROCEDURE DIVISION header of the called program is critical. The items in the USING clauses are related by their corresponding positions, not by name. Corresponding identifiers refer to a single set of data that is available to both the calling and the called programs. 5-1 THE PROCEDURE DIVISION The number of identifiers in the USING clause in the PROCEDURE DIVISION header must be less than or equal to the number of identifiers in the USING clause in the CALL statement in the calling program. 5.1 SYNTACTIC FORMAT OF THE PROCEDURE DIVISION The Piocedure Division consists of a series of procedure statements grouped into sentences, paragraphs, and sections. By grouping the statements in this manner, reference can be made to them via a procedure-name (that is, a paragraph-name or a section-name). The order in which procedure statements are executed can be controlled by using the sequence-control verbs ALTER, GO TO, and PERFORM. 5.1.1 Statements Statements fall into three categories: imperative, conditional, and compiler-directing, depending upon the verb used. Verbs, in turn, are also classified into certain categories. These categories and their relationship to the three statement categories are given in Table 5-1. 5-2 THE PROCEDURE DIVISION Table 5-1 Procedure Verb and Statement Categories Verb Category Statement Category ADD COMPUTE DIVIDE MULTIPLY SUBTRACT INSPECT ARITHMETIC IMPERATIVE ALTER CALL ENTER ENTRY EXIT PROGRAM GOBACK GO TO PERFORM STOP SEQUENCE-CONTROL IMPERATIVE ACCEPT INSPECT MOVE SET STRING UNSTRING DATA MOVEMENT IMPERATIVE CANCEL FREE INSPECT MERGE RELEASE RETAIN RETURN SEARCH SORT TRACE MISCELLANEOUS IMPERATIVE GENERATE INITIATE TERMINATE REPORT IMPERATIVE ACCEPT CLOSE DELETE DISPLAY OPEN READ REWRITE WRITE 1-0 IMPERATIVE IF CONDITIONAL CONDITIONAL COpy ENTER USE COMPILER-DIRECTING COMPILER-DIRECTING Verb 5-3 THE PROCEDURE DIVISION 5.1.2 Sentences A statement or sequence of statements terminated by a period forms a sentence. Sentences are classified into the sd~e three categories as statements. An imperative sentence consists solely of one or more imperative statements. Except for imperative sentences containing one of the sequence-control verbs, control passes to the next procedural sentence following execution of the imperative sentence. If a GO TO or STOP RUN statement is present in an imperative sentence~ it must be the last statement in the sentence. A conditional sentence performs some test and, on the basis of the results of that test, determines whether a "true" or a "false" path should be taken. A conditional sentence is one that contains the conditional verb (IF) or one of the option clauses ON SIZE ERROR (used with arithmetic verbs), AT END (used with the READ verb), or INVALID KEY (used with the READ verb for mass storage devices). A compiler-directing sentence consists of a single compiler-directing statement. Compiler-directing sentences are used to indicate the end point of a PERFORM loop (EXIT), to copy library entries (COPY), and to specify procedures for input-output errors (USE). Generally, compiler-directing sentences generate no object-program coding. 5.1.3 Paragraphs A single sentence or a group of sequential sentences can be assigned a paragraph-name for reference. The paragraph-name must begin in Area A (see Section 1.3, Source Program Format) and terminate with a period. The first sentence of the paragraph can begin after the space following this period or it can begin on the next line, beginning in Area B. A paragraph-name must be unique within its section, but need not be unique within the program. A non-unique paragraph-name must be qualified by its section-name except when it is referenced from within its own section. 5.1.4 Sections A single paragraph or a group of sequential paragraphs can be assigned a section-name for reference. The section-name must begin in Area A and be followed by the word SECTION followed by a priority number, if desired, followed by a terminating period. section-name SECTION nne If the section-name is in the Declaratives portion, it may not have a priority number. A USE statement may appear following the terminating space after the period. The section-name applies to all paragraphs following it until section-header is encountered. another All section-names must be unique within a program. Sections are optional within the Procedure Division, but if a Declaratives portion is used there must be a named section immediately following the END DECLARATIVES statement. 5-4 THE PROCEDURE DIVISION When a section-name is referenced, the word SECTION is not allowed the reference. 5.2 in SEQUENCE OF EXECUTION In the absence of sequence-control verbs, sentences are executed consecutively within paragraphs, paragraphs are executed consecutively within sections, and sections are executed consecutively within the Procedure Division (with the exception of sections within the Declaratives portion, which are executed individually when the related condition occurs). 5.3 SEGMENTATION AND SECTION-NAME PRIORITY NUMBERS COBOL source programs can be written to enable certain portions of the Procedure Division code to share the same memory area at object run time, thus decreasing the amount of memory required to run the object program. The method used to achieve this reduction is called segmentation. Segmentation consists of dividing the Procedure Division sections into logically related groupings called segments. You can define a segment by assigning the same priority-number (a priority-number follows the word SECTION in the section-header, and can be in the range 00 through 99) to all the sections you wish included in that segment; these sections need not appear consecutively in the source program. Segments are classified into three groups, depending upon their priority-number. These three groups are described in Table 5-2. Table 5-2 Types of Segments Priority Number Type None, or 00 up to SEGMENT-LIMIT minus I Resident Segment This segment is always resident in memory and is never overlaid. SEGMENT-LIMIT up to 49 Nonresident; ALTERed GO TOs retained These segments are nonresident and are brought into memory when needed. Any ALTERed GO TOs retain their most recently set values. 50 through 99 Nonresldent; ALTERed GO TOs reset These segments are also nonresident and are brought into memory when needed. Any ALTERed GO TOs do not retain their latest values, but are reset to their original setting each time the segment is reloaded into memory. Description 5-5 THE PROCEDURE DIVISION In addition to the resident segment, all data areas described in the Data Division are resident at all times. Thus, memory can be thought of as being divided into two parts: 1. A resident area, in which resident segment, and reside 2. A nonresident area, equal to the size of the largest nonresident segment, into which each nonresident segment is read when needed. Since each nonresident segment reads into the same memory area, any previous nonresident segment in that area is overlaid and must be brought in again when it is to be executed again. all data areas and the The resident segment should consist of those sections that constitute the main portion of the processing. Infrequently used sections can be allocated to the nonresident segments. 5.4 ARITHMETIC EXPRESSIONS An arithmetic expression is an identifier of a numeric elementary item, or a numeric literal, or such identifiers and literals separated by arithmetic operators. Algebraic negation can be indicated by a unary minus symbol. Arithmetic Operators 5.4.1 There are five arithmetic operators that may be used in arithmetic expressions. They are represented by specific character symbols that must be preceded by a space and followed by a space. Arithmetic Operator + * ** / 5.4.2 Meaning Addition or unary plus Subtraction or unary minus Multiplication Division Exponentiation Exponentiation Formation and Evaluation Rules The following rules for information and evaluation apply to arithmetic expressions. 1. Parentheses specify the order in which elements within an arithroetic expression are to be evaluated. Expressions within parentheses are evaluated first. Within a nest of parentheses, the evaluation proceeds from the elements within the innermost pair of parentheses to the outermost pair of parentheses. When parentheses are not used, or parenthesized expressions are at the same level of inclusiveness, the following hierarchal order of operations is implied: 5-6 THE PROCEDURE DIVISION First: then then and then unary +, unary ** and ~ * and / + and - (exponentiation) (multiplication and division) (addition and subtraction) 2. When the order of a sequence of operations on the same hierarchal level (for example, a sequence of + and operations) is not completely specified by use of parentheses, the order of operations is from left to right. 3. An arithmetic expression may begin with one of the following: (- + variable and may end only with one of the following: ) variable 4. 5.5 There must be a one-to-one correspondence between left and right parentheses ln an arithmetic expression; each left parenthesis must precede its corresponding right 'parenthesis. CONDITIONAL EXPRESSIONS A conditional expression causes the object program to select between alternate paths (called the true path and the false path) of control depending upon the truth value of a test. Conditional expressions can be used in conditional (IF) statements and in PERFORM statements (formate 3 and 4). A conditional expression can be one of the following types: Relation condition Class condition Condition-name condition Sign condition (greater than, equal to, less than) (numeric or alphabetic) (level-aa condition-names) (positive, negative, zero) Each of these types is discussed below. 5.5.1 Relation Condition A relation condition causes a comparison of two operands, each of which may be an identifier, a literal, a figurati~e constant, or an arithmetic expression. Comparison of two numerlC operands is permitted regardless of their formats as described by their respective USAGE clauses. Comparison of two operands is permitted if each is DISPLAY-6, DISPLAY-7, or DISPLAY-9. A numeric-edited operand may not be compared to a numeric operand. An alphanumeric operand may not be compared to a numeric operand unless the alphanumeric operand contains no characters other than numeric digits. For example, the statement: IF NUM < "2". is permissible but the statement: IF NUM is not. < "2.0". THE PROCEDURE DIVISION I 5.5.1.1 Format of a Relation-Condition - The relation condition is I identifier-l literal-l arithmetic-express ion-l figurative-constant-l . relatlonal-operator general identifier-2 literal-2 arithmetic-expression-2 figurative-constant-2 format for a I I The first operand is called the subject of the condition; the second operand is called the object of the condition. Either the subject or the object must be an identifier or an arithmetic expression. 5.5.1.2 Relational Operators - Relational operators specify the type of comparison to be made in the relation condition. Relational operators must be preceded by a space and followed by a space. Meaning Relational Operator IS [NOT] GREATER THAN IS [NOT] > THAN Greater than, not greater than IS [NOT] LESS THAN IS [NOT] < THAN Less than, not less than IS [NOT] EQUAL (EQUALS) TO IS [NOT] = TO Equal to, not equal to 5.5.1.3 Comparison of Numeric Items - A comparison between two numeric items determines that the algebraic value of one item is less than, equal to, or greater than the algebraic value of the other item. The length of the operands is not significant. Zero is considered a unique value; +0 and -0 are equal. Unsigned operands are considered positive. Blanks and tabs are ignored when a numeric item is compared to zero. Since blanks and tabs make an item nonnumeric, a true zero condition may be established by a nonnumeric test followed by a comparison with zero. 5.5.1.4 Comparison of Nonnumeric Items - For operands whose category is nonnumeric (or where one operand is numeric and the other is nonnumeric), a comparison results in the determination that one of the operands is less than, equal to, or greater than the other operand with respect to a specified collating sequence of characters (see Appendix C). The size'of an operand is the total number of characters in the operand. Blanks and tabs are not ,ignored when a nonnumeric item is compared to ZERO. The presence of either blanks, tabs, or both in the operand will cause the test result to be NOT EQUAL. There are three cases to consider: operands of equal size, of unequal size, and operands with differing justification. 5-8 operands THE PROCEDURE DIVISION 1. Operands of equal size - If the operands are of equal size,· characters in corresponding character positions of the two operands are compared, starting at the higher-order (leftmost) end and continuing through the low-order end. If all pairs of characters compare equally through the last pair, the operands are considered to be equal. If they do not all compare equally, the first pair of unequal characters encountered is compared to determine their relative position in the collating sequence. The operand containing the character that is positioned higher in the collating sequence is considered to be the greater operand. 2. Operands of unequal size - If the operands are of unequal size, the comparison of characters proceeds from the high-order end to the low-order end until either a. A pair of unequal characters is encountered, or b. One of the operands has no more characters to compare. encountered, If a pair of unequal characters is comparison is determined in the manner described equal-sized operands. the for If the end of one of the operands is encountered before unequal characters are encountered, this shorter operand is considered to be less than the longer operand unless the remaining characters in the longer operand are spaces, in which case the two operands are considered equal. 3. 5.5.2 If one operand is right-justified and the other is left-justified, they are compared just as they appear in the record. That is, PICTURE XXX, VALUE "BII and PICTURE XXX, VALUE liB II , JUSTIFIED RIGHT are not equal because'the first appears in the record 'as B and the second as B. Class Condition The class condition tests the contents of an alphabetic or wholly numeric. 5.5.2.1 Format of a Class Condition i de n t i fie r IS I item for being wholly ALPHABETIC) NUt~ERI C 5.5.2.2 Restrictions - The item named by identifier must be described, implicitly or explicitly, as DISPLAY, DISPLAY-6, DISPLAY-7, or DISPLAY-9. The NUMERIC test cannot be applied to an item described as alphabetic. The ALPHABETIC test cannot be applied to an item described as numeric. A compiler diagnostic will result if either of the two previously mentioned tests are attempted. 5-9 THE PROCEDURE DIVISION 5.5.2.3 The ALPHABETIC Test - The ALPHABETIC test result is true when the item consists of characters from the alphabet (A through Z) and the space or tab. 5.5.2.4 The NUMERIC Test - The NUMERIC test result is true under following conditions: the 1. For nonnumeric and unsigned numeric items, each character must be a digit (0 through 9). No signs are permitted. Spaces and tabs cause the test result to be false. 2. For signed numeric items, the sign must have one of the four following representations: a leading graphic sign ("+" or "-"), a trailing graphic sign, a leading embedded sign, or a trailing embedded sign. All other characters must be digits. Spaces or tabs cause the test result to be false. NOTE An alternative form of NUMERIC test, which causes leading and trailing blanks and tabs to be ,ignored, may be selected by a switch setting during system installation. This alternative form is described in Appendix De 5.5.3 Condition-Name Condition In a condition-name condition, a conditional variable is tested to determine whether or not its value is equal to one of the values associated with a condition-name (level-88). 5.5.3.1 Format of a Condition-Name Condition - The general format for a condition-name is ~NOTJ condition-name If the condition-name is associated with a range of values, then the conditional variable is tested to determine whether or not its value falls within this range, including the end values. The rules for comparing a conditional variable with a condition-name value are the same as those specified for relation conditions. The result of the test is true if one of the values associated with the condition-name equals the value of its associated conditional variable. 5-10 THE PROCEDURE DIVISION 5.5.4 Sign Condition 'The sign condition determines whether or not the algebraic value of numeric operand is less than, greater than, or equal to zero. 5.5.5.1 Format of a Sign Condition - The general format condition follows. { identifier arithmetic-expression } IS [NOT] { POSITIVE NEGATIVE ZERO for a a sign } The POSITIVE test result is true if the identifier or arithmetic-expression is algebraically greater than zero. The NEGATIVE test result is true if the identifier or arithmetic-expression is algebraically less than zero. The ZERO test result is true if the identifier or arithmetic-expression is equal to zero or contains all spaces, all tabs, or a combination of spaces and tabs. However, any spaces or tabs will make an item nonnumeric. 5.5.5 Logical Operators The interpretation of any of the above conditions is reversed by preceding the condition with the logical operator NOT. Any of the above types of conditions can be combined by either of two logical operators. A logical operator must be preceded by a space and followed by a space. 5.5.6 Logical Operator Meaning OR Entire condition is true if either or both of the simple conditions are true. AND Entire condition is true if both of the simple 'conditions are true. NOT Entire condition is true simple condition is false. if the Formation and Evaluation Rules A conditional expression can be composed of either a simple-condition or a compound-condition. A simple-condition is one that performs a single test. A compound-condition is one that contains a string of simple-conditions connected by the logical operators AND and/or OR. A compound-condition can contain any combination of types of conditional expressions (relational, class, condition-name, and sign). 5-11 THE PROCEDURE DIVISION The evaluation rules for conditions are analogous to those given for arithmetic expressions, except that the following hierarchy applies: "arithmetic-expressions all relational operators NOT AND OR Parentheses may be used either to improve readability or to override the effects of the hierarchy given above. Each set of conditions within a pair of parentheses is reduced to a single condition. When this is accomplished, reductions which cross parentheses are done. You may use parentheses in arithmetic expressions to specify the order in which elements are to be evaluated. Expressions within parentheses are evaluated first~ within nested parentheses, evaluation proceeds from the least inclusive set to the most inclusive set. In the absence of parentheses or when parenthesized expressions are at the same level of inclusiveness, the following hierarchical order of execution is implied: 1st 2nd 3rd 4th - Unary plus and minus Exponentiation Multiplication and division Addition and subtraction NOTE The" precedence of unary minus over exponentiation is different from algebraic notation, and from some other programming languages. If the data-names A and B have the values 3 and 2 respectively, then the COBOL statement COMPUTE C= - A ** B yields C as 9 (not -9 as in algebra). Examples 1. Using parentheses for ease of reading The following expression A = B OR C > D AND F NEGATIVE" can be parenthesized for effect as shown below. (A = B) OR (C IS NEGATIVE) < G AND H IS ALPHABETIC readability without OR I changing > D AND F < G AND H IS ALPHABETIC) OR IS its (I If all the conditions within any of the three sets of parentheses are true, then the entire conditional expression is true. Figure 5-1 illustrates the effect of this statement order of evaluation. 5-12 and the THE PROCEDURE DIVISION >---------------------------------~~~ True MR-S-025-79 Figure 5-1 Order of Evaluation of a Conditional Expression 2. Using parentheses to override normal order of evaluation To illustrate this usage, a compound-conditional is shown in three forms in Figure 5-2, each accompanied by a flow diagram showing the result of each. 5-13 THE PROCEDURE DIVISION Fl = F2 AND F3 '" F4 OR F5 = F6 AND F7 = F8 Fl = F2 AND (F3 = F4 OR F5 = F6 AND F7 = F8) >---------r--------~~ False Path False True False True Fl=F2 AND ((F3 = F4 OR F5 = F6) AND F7 = F8) >------------r--.----.c ~:~~e False MR-5-026-79 Figure 5-2 Order of Evaluation of a Compound-conditional Expression 5-14 THE PROCEDURE DIVISION 5.5.7 Combined and Negated Combined Conditions A combined condition results from connecting conditions with one of the logical operators 'AND' or 'OR'. The general format of a combined condition follows: condition { { ~~D } condition} "Condition" may be one of the following: 1. A simple condition 2. A negated simple condition 3. A combined condition 4. A negated combined condition: that is, the 'NOT' logical operator followed by a combined condition enclosed within parentheses. 5. Combinations of the above, specified according to the rules summarized in Table 5-3 Combinations of Conditions, Logical Operators, and Parentheses. Although parentheses need never be used when either 'AND' or 'OR' (but not both) is used exclusively in a combined condition, parentheses may be used to effect a final truth value when a mixture of 'AND', 'OR' and 'NOT' is used. (See Table 5-3 Combinations of Conditions, Logical Operators, and Parentheses.) Table 5-3 indicates the ways in which conditions and logical operators may be combined and parenthesized. There must be a one-to-one correspondence between left and right parentheses so that each left parenthesis occurs to the left of its corresponding right parenthesis. Table 5-3 Conditions, Logical Operators, and Parentheses Combinations In a left-to-right sequence of elements: Location in conditional expression First Last Element, when not first, may be immediately preceded by only: simplecondition Yes Yes OR, NOT, AND, OR or AND No No simple-condition, NOT Yes No OR, AND, ( Yes No OR, NOT, AND, Given the following element ( ) Element, when not last, may be immediately followed by only: OR, AND, simple-condition, NOT, ( simple-condition, ( simple~condition, ( NOT, ) No Yes simple-condition, 5-15 ) ) ( OR, AND, ) ( THE PROCEDURE DIVISION Thus, the element pair 'OR NOT' is permissible while the pair 'NOT OR' is not permissible; 'NOT' is permissible while 'NOT NOT' is not permissible. 5.5.8 Abbreviated Combined Relation Conditions Simple or negated simple relation conditions can be combined with logical connectives in a consecutive sequence. When a succeeding relation condition contains a subject or subject and relational operator that is common with the preceding relation condition, and no parentheses are used within such a consecutive sequence, then any relation condition except the first may be abbreviated by one of the following: 1. The omission of the subject of the relation condition 2. The omission of the subject and relational relation condition operator of the The format for an abbreviated combined relation condition follows: rel ation-condition {{ ~~D} e NOT] G-el ati ona l-operato~ object } Within a sequence of relation conditions both of the above forms of abbreviation may be used. The effect of using such abbreviations is as if the last preceding stated subject were inserted in place of the omitted subject, and the last stated relational operator were inserted in place of the omitted relational operator. The result of such implied insertion must comply with the rules of Table 5-3, Combinations of Coriditions, Logical Operators, and Parentheses. This insertion of an omitted subject and/or relational operator terminates once a complete simple condition is encountered within a complex condition. The interpretation ~pplied to the use of the word abbreviated combined relation condition is as follows: 'NOT' in an 1. If the word immediately following 'NOT' is 'GREATER', I ) ' , 'LESS', '<I, 'EQUAL', or '=', then the 'NOT' participates as part of the relational operator; otherwise 2. The 'NOT' is interpreted as a logical operator and, therefore, the implied insertion of subject or relational operator results in a negated relation condition. Some examples of abbreviated combined ~nd negated conditions and expanded equivalents follow. Abbreviated Combined Relation Condition combined relation Expanded Equivalent a ) b AND NOT < c OR d «a) b} AND (a NOT < c)} OR (a NOT < d) a NOT EQUAL b OR c (a NOT EQUAL b) OR (a NOT EQUAL c) NOT a = b OR c (NOT (a = b}) OR (a = c) 5-16 THE PROCEDURE DIVISION NOT (a GREATER b OR < c) NOT «a GREATER b) OR (a < c)) NOT (a NOT > bAND c AND NOT d) NOT ««a NOT> b) AND (a NOT> c)) AND (NOT (a NOT> d)))) 5.6 COMMON OPTIONS ASSOCIATED WITH THE ARITHMETIC VERBS Associated with the five arithmetic verbs (ADD, COMPUTE, DIVIDE, the ROUNDED option and the MULTIPLY, and SUBTRACT) are two options: SIZE ERROR option. These two options are described here to avoid the necessity of including their descriptions with each of the arithmetic verbs. 5.6.1 The ROUNDED Option If the ROUNDED option is specified, the absolute value of the item is increased by 1 if the leftmost truncated digit is greater than or equal to 5. Example: value: resultant-identifier picture: stored result without ROUNDED option: stored result with ROUNDED option: 567~8756 999V99 567A87 When the low-order positions in a resultant-identifier are represented by the symbol P in "the PICTURE associated with the resultant-identifier, rounding or truncation occurs relative to the rightmost integer position for which storage is allocated. Example: resultant-identifier picture: stored result without ROUNDED option: stored result with ROUNDED option: 5.6.2 value: 99PP 5388 53 54 The SIZE ERROR Option If, after decimal point alignment, the number of signitlcant digits in the result of an arithmetic operation is greater than the number of integer positions provided in the result-identifier, a size error condition occurs. Division by zero always causes a size error condition. The size error condition applies to both the intermediate results and the final result of an arithmetic operation. If the ROUNDED option is specified, rounding takes place before checking for size error. When such a size error does occur, the subsequent action depends upon whether or not the SIZE ERROR option is specified. If the SIZE ERROR is not specified and a size error condition the value of the resultant-identifier is unpredictable, additional actiqn is taken. occurs, and no If SIZE ERROR is specified, and a size error condition occurs, then the values of the resultant-identiiier(s) affected by the size errors 5-17 THE PROCEDURE DIVISION are not altered. Values for resultant-identifier(s) for which no size error condition occurs are unaffected by size errors that occur for other resultant-identifier(s). After completion of the execution of the arithmetic operation, the statement(s) after SIZE ERROR is executed. Example ADD A TO B ON SIZE ERROR GO TO OVERFLW A: 954 B: PICTURE IS 999; VALUE 954. Result: The contents of B are left unchanged and control is transferred to the paragraph or section named OVERFLW 5.7 THE CORRESPONDING OPTION The CORRESPONDING option is arithmetic verbs (ADD and verb. used in the formats of two of the SUBTRACT) ano in the format of the MOVE For the purpose of this discussion, del) and d(2) represent identifiers that refer to group items. A pair of data items, one from del) and one from d(2), correspond if the following conditions exist: 1. A data item in del) and a data item in d(2) have the same data-name and the same qualification up to, but not including, del) and d(2). 2. Both of the data items are elementary numeric data the case of an ADD or SUBTRACT statement CORRESPONDING option. 3. Neither del) nor d(2) may be data items with level-number 66, 77, or 88. 4. Each data item subordinate to del) or d(2) that contains a RENAMES, a REDEFINES or an OtCURS clause is ignored. However, del) and d(2) may have REDEFINES or OCCURS clauses or be subordinate to data items with REDEFINES or OCCURS clauses. items in with the See the sections ADD, MOVE, and SUBTRACT for information on the specific formats and results of the use of the CORRESPONDING option. 5.8 DETERMINATION OF USAGE IN ARITHMETIC COMPUTATIONS If a programmer describes a numeric field as having USAGE DISPLAY-6, DISPLAY-9, or COMP-3, the compiler converts this data to fixed-point binary when performing arithmetic computations with it. If the field contain~ 10 or fewer digits, it is converted to single-precision fixed-point binary. Conversion to double-precision fixed-point binary is performed if the field contains more than 10 digits_ A field described as COMPUTATIONAL (or INDEX) is fixed-point binary, and single-precision for 10 or fewer digits, double-precision for more than 10 digits. A field de~cribed as COMPUTATIONAL-l is single precision floating-point binary. DISPLAY-7~ When any arithmetic computation is performed, the arithmetic usage (single-precision fixed-point, double-precision fixed-point, or floating-point) used for each operation is determined from the usages of the two operands of the computation. If either operand is 5-18 THE PROCEDURE DIVISION floating-point, the operation is performed in floating-point arithmetic. If neither operand is floating-point, but one operand is double-precision fixed-point, the operation is performed in double-precision fixed-point arithmetic. Otherwise, the operation is performed in single-precision fixed-point arithmetic. If both operands are constants, the operation IS performed in single- or double-precision fixed-point arithmetic, as appropriate. If any nonnumeric characters appear in the DISPLAY-6, DISPLAY-7, or DISPLAY-9 field that is to be converted, the compiler attempts to convert them to binary; however, in many cases, undefined results can occur. When DISPLAY-6, DISPLAY-7, and DISPLAY-9 characters are converted to binary, the following rules apply. o through 9 need no conversion. A through I are converted to 1 through 9. ? , [, { are converted to J through R o. are converted to 1 through 9, and the field is made negative if they are found in the high-order or low-order digit, unless an explicit sign is present. :,!,],} are converted to 0, and the field is made negative if it is found in the high-order or low-order digit unless an explicit sign is present. Nulls are ignored. Leading spaces and tabs are ignored. + and - are treated as sign characters. Scanning of a field proceeds from left to right, stopping when one the following conditions is met: 1. The entire field has been scanned. 2. A trailing space, tab, plus, or minus is seen. If both leading and trailing signs appear in the field, sign will be ignored. 5.9 of the trailing the following PROCEDURE DIVISION VERB FORMATS The format of each Procedure Division verb is given on pages. The verbs are presented in alphabetical order. The word "identifier" is a data-name followed, as required, by qualification, subscripts, and/or indexes necessary to make data-name unique. 5-19 any the THE PROCEDURE DIVISION ACCEPT 5.9.1 ACCEPT Function The ACCEPT statement causes low-volume data to be read from the user's terminal. General Format ACCEPT identifier-l identifier-2 ... ~fROM mnemonic-name~ DATE I ACCEPT identifier FROM)~ DAY l TIME Technical Notes 1. The ACCEPT statement causes the next set of data available from the terminal to replace the contents of the items named by identifier-I, identifier-2, • . • . 2. If the FROM appear in paragraph. 3. When the data to be read for one or more ACCEPT statements is numeric, a comma (,), space, or tab is used as a delimiter separating the data items. 4. When the data to be read for one or more ACCEPT statements is alphanumeric, each data item is delimited by.a line-feed, altmode, form-feed, or vertical tab. 5. The ACCEPT statement will read a maximum of into each identifier. 6. The ACCEPT statement places characters into an alphanumeric item from left to right, filling any remaining characters of the item with blanks up to a maximum of 1023 positions. 7. If an alphanumeric item is longer than 1023 characters, only the leftmost 1023 characters are replaced or blanked; the remaining characters of the item are not altered. option is specified, the mnemonic-name must the CONSOLE IS clause of the SPECIAL-NAMES 5-20 1023 characters THE PROCEDURE DIVISION ADD 5.9.2 ADD Function The ADD statement computes the sum of two or more numeric operands and stores the result. General Format ADD {i denti fi er-l literal-l [identifier-n ADD - i dent i fi er-2] [ literal-2 [ROUNOE~ .•. {i~enti fier-l } llteral-l TO identifier-m QOUNDE~ [ON SI ZE ERROR i mperati ve-statemen~ i denti fi er-2} [i denti fi er-3] { literal-2 literal-3 GIVING identifier-m [ROUNOE~ ~dentifier-n [}OUNOEO~ [ON SIZE ERROR i mperati ve-s tatementJ AD[} {CORRESPONDING}- identifier-l TO identifier-2 rROUNDED] CORR L:: [ON SIZE ERROR imperative-statement] Technical Notes 1. Each ADD st~tement must contain at least two operands (that is, an addend and an augend). In formats 1 and 2, each identifier must refer to an elementary numeric item, except that identifiers appearing to the right of the word GIVING may refer to numeric-edited items. In format 3, each identifier must refer to a group item. Each literal must be a numeric constant ZERO is permitted. 2. literal; the figurative The composite of all operands (that is, the data item resulting from the superimposition of all operands aligned by decimal point) must not contain more than 19 decimal digits for the standard compiler and not more than 36 digits for the BIS-compiler. In either case, a maximum of 18 digits can be stored in the receiving field. (See Section 1.1 for a definition of the BIS-compiler.) 5-21 THE PROCEDURE DIVISION ADD (Cont.) 3. Format 1 causes the values of the operands preceding the word TO to be algebraically summed. The resultant sum is then added to the current value of identifier-m and this result replaces the current value in identifier-me If other identifiers follow, the same process is repeated for each of them. 4. Format 2 causes the values of the operands preceding the word GIVING to be algebraically summed. The resultant sum then replaces the current contents of identifier-me If other identifiers follow, their contents are also replaced by this resultant sum. The current values of identifier-m, identifier-n,... do not enter into the arithmetic computation. 5. Format 3 causes the data items in the group item associated with identifier-l to be added to the current value of the corresponding data items associated with identifier-2, and each result replaces the value of the corresponding data-items associated with identifier-2. The criteria used to determine whether two items are corresponding are descr ibed in Section ,5. 7, The CORRESPONDING Option. 6. The ROUNDED and SIZE ERROR options are d~scribed in Section 5.6, Common.Options Associated with Arithmetic Verbs. 5-22 THE PROCEDURE DIVISION 5.9.3 ALTER Function The ALTER statement statements. changes the object of one or more GO TO General Format ALTER procedure-name-l TO ~ROCEED TO] procedure-name-2 ~procedure-name-3 TO [fROCEED TO~ procedure-name-4 ] Technical Notes 1. During execution of the object program, the ALTER statement modifies the GO TO statement in the paragraph named procedure-name-l, procedure-name-3, ••• replacing the object of the GO TO by procedure-name-2, procedure-name-4, ••• , respectively. 2. Each procedure-name-l, procedure-name-3, •••• must be the name of a paragraph that contains nothing but a single GO TO statement without the DEPENDING option. 3. Each procedure-name-2, procedure-name-4, ••• must be the name, of a paragraph or section within the Procedure Divisio~. 4. A GO TO statement in a section whose priority is greater than Jr equal to 50 must not be referred to by an ALTER statement in a section with a different priority. 5. An ALTER statement in a procedure not in the DECLARATIVES portion of the program may not reference a procedure name within the DECLARATIVESi conversely, an ALTER statement within the DECLARATIVES may not reference a procedure-name not in the DECLARATIVES. 6. Restrictions similar to those in Note 5 also apply to the input procedures and to the output procedures associated with SORT and MERGE verbs. 7. For program segments with priorities of 50 and greater, the changes made by ALTER statements will be lost when segments are overlaid. 5-23 THE PROCEDURE DIVISION CALL 5.9.4 CALL Function The CALL statement is used to transfer control to a subprogram. General Format CALL r. identifier-I} program-name L!S ING data-name-l entry-name [data-name-2] 1 .. J ~ON OVERFLOW imperative-statemen~ Technical Notes 1. Program-name is a one to six character name (PROGRAM-ID) of the subprogram to be called. Entry-name is a one to six character name of an entry point in the subprogram. Either name can be enclosed in quotation marks, but can contain only letters and digits. 2. If the program-name is used, the entry point will be beginning of the executable code in the subprogram. 3. Called programs can call other subprograms, but a called program cannot call, either directly or indirectly, any part of itself or the program that called it. 4. The number of operands in the USING clause of the CALL statement must be greater than or equal to the number of operands in the ENTRY Statement or PROCEDURE DIVISION header in the subprogram. 5. Each of the operands in the USING clause may be any item defined in the File, Working-Storage, or Linkage section of the calling program. However, these items must be word-aligned; that is, they must begin on a word boundary. 01- and 77-level items are always word-aligned. Any other item can be word-aligned by means of the SYNCHRONIZED LEFT clause. 6. The identifiers in the USING clause indicate those data items in the calling program that may be referenced (or whose subordinate parts may be referenced) in the called program. The order of the identifiers in the CALL statement in the calling program and in the PROCEDURE DIVISION header or ENTRY statement of the calling program is critical. The items in the USING clause are related by their corresponding positions, not by name. Corresponding identifiers refer to a single set of data that is available to both the calling and called programs. 5-24 at the THE PROCEDURE DIVISION CALL (Cont.) 7. The first time a called program is entered, its state is that of a fresh copy. Subsequently, if the subprogram is not in a LINK overlay, its state when entered is exactly as it was left after the last exit from it. That is, all internal variables, altered GO TOs, and the like are exactly as they were left. However, external data (that is, data described in the Linkage Section) may have been changed since the last exit. If the subprogram is in a LINK overlay and it is entered again, its state is exactly as it was left after the last exit from it provided that the subprogram has not been cancelled or overlaid. If the subprogram has been cancelled or overlaid, its state is that of a fresh copy. 8. 9. The CALL identifier clause conditions are met: works only when, the following a. There is only one subprogram per overlay. b. Each subprogram has only one entry point. c. The overlay name is the same as the subprogram name. Refer to the COBOL-74 Usage Material, Part 3 of this for more information on subprograms. 5-25 manual, THE PROCEDURE DIVISION CANCEL 5.9.5 CANCEL Function The CANCEL statement releases programs named in the clause. the memory areas occupied QY the General Format CANCEL {identifier-I} subprogram-l i denti fi er-2] [ subprogram-2 Technical Notes 1. The CANCEL statement can be used either to reload a segment of a segmented COBOL program or to cancel a subprogram that has been loaded into an overlay link by LINK. (Refer to the COBOL-74 Usage Material, Part 3 of this manual, for information,on specifying LINK overlays and on subprograms.) Note 2 describes the first case while the remaining notes describe the second. 2. When you cancel a segment of a program you cause the object-time system to read your .EXE file and copy an initialized version of the segment into memory. 3. After a subprogram has been cancelled, a subsequent call to the subprogram will cause a freshly initialized copy to be brought into memory. 4. Cancellation of a subprogram causes the entire link in it resides and all lower-level links to be cancelled. 5. A subprogram in the root link or higher in the current overlay structure cannot be cancelled. If an attempt is made to do so, the CANCEL statement will be ignored and a warning message issued at runtime. 6. A subprogram cannot cancel itself or any subprogram that resides in an overlay link with it. An attempt to do either will result in the CANCEL statement being ignored and a warning message issued at runtime. 7. Cancellation of a subprogram higher in the current calling sequence is also an illegal operation. But, if the subprogram being cancelled is in a lower-level link and higher in the calling sequence, it could be cancelled without being detected as an error. This would cause the return from the program to reach an undef~ned location. 5-26 which THE PROCEDURE DIVISION CLOSE 5.9.6 CLOSE Function The CLOSE statement terminates the files, reels, or units. processing of input and output General Format CLOSE file-name-l o~~i~ ~ {WITH FOR fi 1 e··name-2 U~~i~ B{ WITH FOR CLOSE fil e-name-l rO LOCKREWIND}} DELETE REMOVAL ro LOCKREWIND}} DELETE REMOVAL I!ITH LOCK] ~i1 e-name-2 [WITH LOCK]] Technical Notes 1. Each filename must appear as the subject of an the File Section of the Data Division. 2. The DELETE option applies only to disk and DEC tape files. If this option is included, the file will be deleted from the device. 3. The REEL, UNIT, and NO REWIND options apply only to tape files; UNIT is synonymous with REEL. 4. The FOR REMOVAL option unloads magnetic tape. The file cannot be re-open~d without intervention by the operator. 5. For' the purpose of showing the effect of various CLOSE options as applied to the various storage media, all input, output, and input-output files are divided into the following three mutually exclusive categories: a. NON-REEL FD entry in magnetic A file whose device is such that the concepts of REWIND, REEL, or UNIT have no meaning. This category includes files residing on disk, punched cards, paper tape, line printer, and terminal. 5-27 THE PROCEDURE DIVISION CLOSE (Cont.) b. SINGLE REEL A file that is entirely contained on one reel or unit. c. MULTI-REEL A file that may be contained on more than one reel or unit. The results of each CLOSE option for each of the above types of files are summarized in Table 5-4. The definitions for the symbols used in this table are given below. Where the definition depends upon whether th~ file is an input or output file, alternate definitions are given; otherwise, the single definition given applies to both input and output files. Codes Used in Table 5-4 A Any subsequent reels of this file will not be processed. B The current reel is not rewound. C Standard CLOSE File Procedure is followed: INPUT and 1-0 Files An input file is considered to be at the end-of-file if the imperative-statement in the AT END clause of a READ for the file has been executed, and no CLOSE statement for the file has been executed. OUTPUT Files If LABEL RECORDS are STANDARD, an ending created and written on the output medium. label is D The current reel is rewound and unloaded. E Any attempt to subsequently OPEN this file will result in an error message being typed and the run terminated. F Standard CLOSE REEL Procedure is followed: INPUT Files 1. If the file is assigned next device specified the current device. specified, the first curr"ent device. to more than one device, the in the ASSIGN clause becomes If no other device is device mentioned becomes the 2. The standard beginning reel performed for the new reel. label procedure is procedure is OUTPUT and 1-0 Files 1. The standard performed. ending 5-28 reel label THE PROCEDURE DIVISION CWSE (Cont.) 2. If the file is assigned to more than one device, the devices are swapped. A halt occurs to allow the operator to mount an available reel. 3. The standard performed. beginning reel label procedure is G The tape is rewound. H The file is deleted from the device. However, if the file is a sequential file on disk that is open for output in supersede mode, the original file will remain intact (that is, the originaL file will not be superseded nor deleted). X Illegal. This is an illegal option and a file type. combination of a CLOSE 6. If a file is OPENed but not CLOSEd before the STOP RUN statement is executed, the file will be automatically CLOSEd. Any records still retained by a RETAIN statement will automatically be freed by a CLOSE statement. 7. If the file has been specified with an OPTIONAL clause in the File-Control Paragraph of the Environment Division and the file was not present for this run, the CLOSE has no effect. 8. If a CLOSE statement without the REEL or UNIT option has been executed for a file, a READ, WRITE, or CLOSE statement for that file must not be executed until another OPEN for that file has been executed. 5-29 THE PROCEDURE DIVISION CWSE (Cont.) Table 5-4 CLOSE Options and File Types CLOSE Options File Type NON-REEL SINGLE REEL/UNIT MULTI-REEL CLOSE C C,G C,G,A CLOSE WITH LOCK C,E C,G,E C,G,E,A CLOSE WITH NO REWIND X C,B C,B,A CLOSE REEL X X F,G CLOSE REEL WITH LOCK X X F,D X X F,D,G CLOSE REEL WITH NO REWIND X X F,B CLOSE WITH DELETE C,H X X CLOSE REEL FOR REMOVAL 5-30 THE PROCEDURE DIVISION COMPUTE 5.9.7 COMPUTE Function The COMPUTE statement assigns to a data item the value of a data item, literal, or arithmetic expression. numeric General Format COMPUTE identifier-l [ROUNDED] j IS EQUAL TO ~ I :QUAL5 i denti fi er-2 li~eral. O . arlthmetlc-expresslon f arithmeti c-express i on } U [JOUNDEDJ [ON 51 ZE ERROR imperati ve-statemeniJ Technical Notes 1. The COMPUTE statement allows you to combine arithmetic operations without the restrictions on the composite of operands and/or recelvlng data items imposed by the arithmetic statements ADD, SUBTRACT, MULTIPLY, and DIVIDE. If the composite operand exceeds 19 decimal digits, the composite is converted to COMP-l format. This will lead, however, to a loss of precision. 2. Identifier-l must numeric-edited item. 3. Identifier-2 must be an elementary numeric item. must be a numeric literal. be an elementary numeric or Literal-2 The identifier-2 and literal-l options provide a method for setting the value of identifier-l equal to identifier-2 or literal-I. 4. The rules for forming arithmetic expressions and the order of evaluation are given in Section 5.4, Arithmetic Expressions. 5. The ROUNDED and SIZE ERROR options are described in Section 5.6, Common Options Associated with the Arithmetic Verbs. 5-31 THE PROCEDURE DIVISION DELETE 5.9.8 DELETE Function The DELETE statement removes a specified record from organization is RELATIVE or INDEXED. a file whose 1. Record-name must be a record associated with a organization is RELATIVE or INDEXED. file whose 2. When the DELETE statement is executed, the object-time system removes from the file the record which has a key equal in value to the RELATIVE KEY (for relative files) or the RECORD KEY (for indexed files). If no such record exists, the statement(s) associated with the INVALID KEY clause is executed. 3. At the time that the DELETE statement is executed, the file must be open for OUTPUT or INPUT-OUTPUT. 4. The INVALID KEY clause must not be specified for a DELETE statement that references a file that is in sequential-access mode. It must be specified for a DELETE statement that references a file that is not in sequential-access mode, and for which no USE procedure is specified. 5. For files in the sequential-access mode, the last input-output statement executed for file-name prior to the execution of the DELETE statement must have been a successfully executed READ statement. The OTS logically removes from the file the record that was accessed by that READ statement. 6. The execution of a DELETE statement does not affect the current record pointer or the contents of the record area associated with file-name. The execution of the DELETE statement causes updating of the value of any specified FILE STATUS data item associated with file-name. General Format DELETE file-name RECORD [jNVALID KEY imperative-statement] Technical Notes 5-32 THE PROCEDURE DIVISION DISPLAY 5.9.9 DISPLAY Function The DISPLAY statement causes low-volume data to be user's terminal. written to the General Format ~i?entifier-2·riJ ... r~UPON mnemonic-nam~~ !wITH NO ADVANCING! ~ ~ DISPLAY {i?entifier-l} llteral-l ~11teral-2 Technical Notes 1. The contents of each operand are terminal in the order listed. 2. Each of the literals can be numeric or nonnumeric, or one of the figurative constants. If a figurative constant is specified as one of the operands, only a single occurrence of that constant is written on the device. 3. The mnemonic-name must appear in the CONSOLE clause in Special-Names paragraph of the Environment Division. 4. If WITH NO ADVANCING is specified, the terminal does not Qdvance to the next line. Thus, printing or type-in can continue on the same line. If you do not specify the WITH NO ADVANCING clause, the terminal will advance to the next line after printing the text of the DISPLAY statement. 5-33 written on the user's the THE PROCEDURE DIVISION DIVIDE 5.9.10 DIVIDE Function The DIVIDE statement divides one numeric item into others and sets the value of specified data item(s) equal to the quotient and the remainder. General Format DIVI DE { ; 1~~~! i~ ~r-l} INTO i dentifi er-2 [i denti fier-3 [lOUNDEDJ] i dent i fi er-l } { 1i tera 1-1 DIVIDE INTO -- tdenti fier-4 [ROUNDEr[]] identifier-I} { 1itera1-1 DIVIDE BY ~entifier-4 [ROUNDEq:lJ identi fier-l} { 1itera1-1 DIVIDE REMAINDER i dent i fi er-4 identifier-I} { 1itera1-1 REMAINDER identifier-4 INTO -- '" [!OUNDEDJ [ON 51 ZE ERROR imperative-statement] {i~entifier-2} 11teral-2 GIVING identifier-3 'ROUNDED' LJ U [ON SIZE ERROR imperative-statemen!J i denti fi er-2 } { 1iteral-2 GIVING identifier-3 [JROUNDE~ II ~N SIZE ERROR imperative-statemen~ {i~entifier-2} 11teral-2 GIVING identifier-3 UOUNDEDI U \IN SIZE ERROR i mperat i ve-statemenu BY - i denti fi er-2 } { 1iteral-2 GIVING identifier-3 [JROUNDE~ ill C=ON SIZE ERROR imperative-statemen~ Tecnnical Notes 1. In all formats which include the INTO keyword, identifier-l is the divisor and identifier-2 is the 9ividend. In formats which include the BY 'keyword, identifier-l is the dividend and identifier-2 the divisor. In formats 1 and 2, the resulting quotient replaces the value of identifier-2. In format~ 3 and 4, the resulting quotient replaces the value of identifier-3 and any data items which follow identifier-3. 5-34 THE PROCEDURE DIVISION DIV1DE (Cont.) 2. Each DIVIDE statement must contain two operands (that is, a dividend and a divisor) • Both of these operands (identifier-l and identifier-2) must refer to elementary numeric items. Identifier-3 may be an elementary numeric or numeric-edited item. Each literal-lor literal-2 must be a numeric literal. Identifier-4 may be an elementary numeric or numeric-edited item. 3. The ROUNDED and SIZE ERROR options are described in Section 5.6, Common Options Associated with Arithmetic Verbs. 4. If the REMAINDER clause is used, the replaces the value of identifier-4. 5. The data item resulting from the divide operation (that is, the sum of the digits in the dividend and the digits in the fractional part of the divisor) must not contain more than 20 decimal digits for the non-BIS compiler and not more than 36 digits for the BIS-compiler. In either case, a maximum of 18 digits can be stored in the receiving field. (See Section 1.1 for a definition of the BIS-compiler.) 6. The remainder is checked for a size error after the quotient is checked, whether or not the quotient has a size error. If either the quotient or the remainder has a size error, the object-time system follows the procedure described in Section 5.6, Common Options Associated with Arithmetic Verbs. 7. The ROUNDED option does not apply remainder is always truncated. 5-35 to resulting the remainder remainder; the THE PROCEDURE DIVISION ENTER 5.9.11 ENTER Function The ENTER statement allows the execution of MACRO subroutines in conjunction with the COBOL program. and FORTRAN General Format ENTER MACRO ) FORTRAN ~ COBOL , 1 ~SING t ~ identifier-l literal-l procedure-name-l I ~ ~~ i denti fi er-2 literal-2 ~ procedure-name-2 ) Technical Notes 1. MACRO refers to MACRO-IO or MACRO-20 assembly language FORTRAN to the TOPS-IO or the TOPS-20 FORTRAN language. 2. The program-name can be enclosed in quotation marks. 3. The ENTER statement generates a subroutine call and specifies the address where the items associated with the USING clause are located. (Refer to the COBOL-74 Usage Material, Part 3 of this manual, for more information on the ENTER statement.) 4. ENTER COBOL is equivalent to CALL. 5-36 and THE PROCEDURE DIVISION ENTRY 5.9.12 ENTRY Function The ENTRY statement establishes an entry point in a subprogram. General Format ENTRY ent ry- name [us I NG i den t ifi e r-l 0 dent ifi er-:[] •. J. Technical Notes 1. The ENTRY statement can only be used in a subprogram. 2. Control is passed to the entry point by a CALL statement in a calling program. 3. Entry-name is a one to six character name that can contain only letters and digits. It can, however, be enclosed in quotation marks. This name must not be the same as any other entry-name or PROGRAM-ID in any program with which the subprogram containing it is loaded. 4. The identifiers listed in the USING clause must be defined as 01or 77-level i~ems in the Linkage Section of the subprogram containing the ENTRY statement. 5. The number of operands in the USING clause of an ENTRY statement must be less than or equal to the number of ENTRY operands in any CALL statement referencing that statement. 6. The identifiers in the USING clause indicate those data items in the called program that may reference data items in the calling program. The order of identifiers in the CALL statement in the calling program and in the ENTRY statement in the called program is critical. The items in the USING clauses are related by their corresponding positions, not by name. Corresponding identifiers refer to a single set of data that is available to both the calling and called programs. 7. At runtime, ENTRY statements are specific calls to them. 8. Refer to the COBOL-74 Usage Material, Part 3 of this for more information on subprograms. 5-37 ignored unless there are manual, THE PROCEDURE DIVISION EXIT 5.9.13 EXIT Function The EXIT statement provides a common end point routines executed by a PERFORM or USE statement. for a series of General Format paragraph-name. EXIT. Technical Notes 1. EXIT must be the only sentence in the paragraph. 2. The EXIT statement may be used at the end of a section in the Declaratives, or to provide an end point for a series of paragraphs that are performed. When you use EXIT at the end of the range of a PERFORM or USE, you can provide a variety of exits from the performed procedure by making" each point at which an exit is required a transfer to the EXIT paragraph. However, unless EXIT is specified as the end of the range of a PERFORM or USE or is placed as the last paragraph in the range of a PERFORM or USE, it is ignored. Example: PERFORM TAX-ROUTINE THROUGH EXIT-RTE. TAX-ROUTINE. IF TOTAL-TAX IS EQUAL TO OR GREATER THAN TAX-LIMIT GO TO EXIT-RTE. MULTIPLy .•••• DEDUCTION-RTE. IF NO-OF-DEPENDENTS IS EQUAL TO ZERO GO TO EXIT-RTE. MULTIPLY NO-OF-DEPENDENTS BY DEP-DEDUCT •••• EXIT:"RTE. EXIT. 3~ If control reaches an EXIT statement and no associated PERFORM or USE statement is active or if EXIT is not the last paragraph in the range of a PERFORM or USE statement even if the PERFORM or USE statem'ent is active, control passes through the EXIT paragraph to "the first statement of the next paragraph. 5-38 THE PROCEDURE DIVISION EXIT PROGRAM 5.9.14 EXIT PROGRAM Function The EXIT PROGRAM statement is used to return control from a subprogram to its calling program. General Format Technical Notes 1. EXIT PROGRAM can only appear in a subprogram. 2. When an EXIT PROGRAM statement is executed, control is returned to the calling program at the statement immediately following the CALL statement. 3. If an EXIT PROGRAM statement is encountered in a subprogram that is operating as a main program, it is i.gnored. 4. Refer to the COBOL-74 Usage Material, Part 3 of this for more information on subprograms. 5-39 manual, THE PROCEDURE DIVISION FREE 5.9.15 FREE Function The FREE statement explicitly frees records that have been retained in a RETAIN statement. General Format identifier-1 1i tera 1-1 RECORD fi1e-name-1 { EVERY RECORD FREE RECORD [KEY [ file-name-2 { J identifier-2 1 1iteral-2 EVERY RECORD EVERY RECORD [NOT RETAINED statement-l [statement-21 ... ] ~ Technical Notes 1. Filename-I, filename-2 ••• are the names of files containing records that have been retained. Thus, they are files that have been opened for simultaneous update. 2. Identifier-l, identifier-2... and literal-I, literal-2 ••• specify the value of a key. This key refers to the record to be freed in the file. 3. Statement-I, statement-2 ••• 4. The FREE statement is needed to explicitly free records that have not been implicitly freed by an I/O statement. This could occur when the RETAIN statement contains the UNTIL FREED phrase, when an I/O statement is not issued after the RETAIN statement, or when the FOR clause of the RETAIN statement specifies ANY VERB. Refer to the RETAIN statement, Section 5.9.29, for a description of its function and syntax. 5-40 are any valid COBOL statements. THE PROCEDURE DIVISION FREE (Cont.) 5. The EVERY RECORD phrase is used to free all records or to free all records retained in a specific file. 6. The NOT RETAINED phrase specifies the COBOL statements to be executed . when one or more records to be freed are not currently retained. If the NOT RETAINED phrase is not included and the records to be freed are not currently retained, the program proceeds and you are not notified of the possible error. 7. When an EVERY RECORD phrase is used, the statements in the NOT RETAINED phrase are executed only if no records are currently retained or only if no records are currently retained in the specified file. 8. If the FREE statement includes a file that was not opened for simultaneous update, the NOT RETAINED statements, if present,· are executed. Otherwise, the program continues and you are not notified of the error. 9. You can mix records from sequential, relative, indexed-sequential files in the same FREE statement. 10. All records of a file are freed automatically when the file is closed including those records that were retained with an UNTIL FREED clause in the RETAIN statement. 11. The record to be freed, whether or not the KEY phrase is specified, depends on the organization of the fil~. Each organization is described separately below. a. retained and Sequential Files If the KEY phrase is specified, the value of the key refers to the record with that value in the RETAIN statement. That is, a KEY value of 6 in the FREE statement frees the record defined with a KEY value of 6 in the RETAIN statement. If the KEY phrase is not specified, the record freed is that record defined with a KEY value of 0 in the RETAIN statement. The value of a key can 'be specified by any identifier, which can be subscripted and/or qualified, provided that its USAGE is COMPUTATIONAL or INDEX. The value of the key can also be specified by a positive integer numeric literal containing ten or fewer digits. b. Random Files If the KEY phrase is specified, the value of the key refers to the record with that value in the RETAIN statement. For example, a KEY value of 0 in the FREE statement frees the record defined with a KEY value of 0 in the RETAIN statement. If the KEY phrase is not specified, the record freed that record defined by the ACTUAL KEY of the file. 5-41 is THE PROCEDURE DIVISION FREE (Cont.) The value of a key can be specified by any identifier, which can be subscripted and/or qualified, provided that its USAGE is COMPUTATIONAL or INDEX. The value of a key can also be specified by a positive integer numeric literal containing ten or fewer digits. c. Indexed-Sequential Files If the KEY phrase is specified, its value refers to the record with that value in the RETAIN statement. That is, a key identified with a value of "ABC" in the FREE statement frees the record identified as "ABC" in the RETAIN statement. If LOW-VALUES is used as the value of the key, it refers to the next record after the current record, which is not necessarily the record identified by LOW-VALUES in the RETAIN statement. This is because the current record is changed by an I/O statement and LOW-VALUES always refers to the record following the current record. The value specified in the KEY phrase must normally be an identifier that, specifies a field that agrees with the RECORD KEY defined for the file in size, class, usage, and number of decimal places. However, if the RECORD KEY of the file is USAGE COMPUTATIONAL or INDEX, a positive integer' numeric literal of ten or fewer digits can be used as the value~n the KEY phrase. If the KEY phrase is not specified, the record freed is that record defined by the RECORD KEY of the file. If the RECORD KEY contains LOW-VALUES, it refers to the next record after the current record, which is not necessarily the record specified by LOW-VALUES in the RETAIN statement. This is because the current record is changed by an I/O statement and LOW-VALUES refers to the record following the current record. Examples Sequential File RETAIN HISTORY KEY 0 FOR READ-WRITE UNTIL FREED, HISTORY KEY 1 FOR READ-WRITE UNTIL FREED, HISTORY KEY 2 FOR READ-WRITE. READ HISTORY, AT END STOP RUN. FREE HISTORY EVERY RECORD. Random File RETAIN PART KEY 0 FOR ANY VERB. READ P~RT, INVALID KEY GO TO ERR. WRITE ~ARTREC. FREE PARK KEY O. Indexed-Sequential File MOVE "'B" TO RECORD-KEY. RETAIN LETTERS FOR READ. FREE LETTERS. 5-42 THE PROCEDURE DIVISION GENERATE 5.9.16 GENERATE Function The GENERATE statement causes the Report-Writer to execute all automatic report operations, and, if required, to produce one or more report groups. General Format GENERATE data-name } { report-name Technical Notes 1. If identifier is the name of a TYPE DETAIL report group, the GENERATE statement performs all the automatic report operations, and produces an output detail report group on the output file. This is called detailed reporting. 2. If the identifier is the name of an RD entry, the GENERATE statement performs all the automatic report operations, but does not produce an output detail report group. This is called summary reporting. 3. A GENERATE operations: 4. statement performs the following automatic a. It steps and tests the LINE-COUNTER and/or PAGE-COUNTER to produce, if necessary, any PAGE FOOTING and PAGE HEADING report groups. b. It recognizes any specified control breaks to produce appropriate CONTROL FOOTING and CONTROL HEADING report groups, and resets appropriate summation counters. c. It accumulates into the summation counters all identifiers. d. It executes any routines defined by a USE statement. e. In detailed reporting, it produces group. the specified detailed report During the execution of the first GENERATE statement for report, the following groups, if specified, are produced: a. Report Heading b. Page Heading c. All Control Headings, in the order major to minor d. The detail report group, in detailed reporting 5-43 a THE PROCEDURE DIVISION GENERATE (Cont.) 5. Data is moved to the data item in the Report Group Description Entry according to the same rules for movement described for the MOVE statement. 6. A GENERATE statement for a particular report may not be executed until an INITIATE statement has been executed for that report. In addition, if a TERMINATE statement has been executed for that report, a GENERATE statement may not be executed until an intervening INITIATE statement is executed for the report. 5-44 THE PROCEDURE DIVISION GO TO 5.9.17 GO TO Function The GO TO statement causes control to be transferred from one part the Procedure Division to another. of General Format GO TO [procedure-name-l] GO TO procedure-name-l ~procedure-name-2J procedure-name-n DEPENDING ON identifier Technical Notes 1. Each procedure-name is the name of a paragraph or section the Procedure Division of the program. 2. Format 1 causes transfer of control to the specified procedure-name, or to some other procedure-name if the GO TO has been previously altered. In order to be alterable, format 1 must appear as sentence in a paragraph. the in first If procedure-name-l is not specified, the GO TO must be alterable and an associated ALTER statement must be executed prior to executing this GO TO. When this form of GO TO appears in an imperative sentence, it must appear as the last or only statement in the sentence. 3. Format 2 causes transfer 'of control to procedure-name-l, procedure-name-2,... or procedure-name-n depending on whether the value of the identifier is 1, 2, or n, respectively. The identifier must refer to an elementary numeric item having no positions to the right of the decimal point. The item may not be USAGE COMPUTATIONAL-I. If the value of the identifier is other than the positive integers 1, 2, •.. or n, the GO TO statement is by-passed. 5-45 THE PROCEDURE DIVISION GOBACK 5.9~l8 GOBACK Function The GOBACK statement is used in a subprogram to return control to calling program. the General Format GOBACK. Technical Notes 1. The GOBACK statement can only be used in subprograms. 2. When control reaches 'a GOBACK statement, control is returned to the calling program at the statement immediately following the CALL statement. 3. If a GOBACK statement is encountered in a subprogram that is operating as a main program, it is treated as a STOP RUN statement. 4. Refer to the COBOL-74 Usage Material, Part 3 of this for more information on subprograms. 5-46 manual, THE PROCEDURE DIVISION 5.9.19 IF Function The IF statement causes a conditional expression to be evaluated and subsequent operations to be determined as a result of this evaluation. General Format } IE condition {statement-l NEXT SENTENCE statement-2 }] {NEXT SENTENCE Technical Notes 1. Conditional expressions are discussed in Section 5.5 in chapter. this 2. The subsequent action of the program is determined by whether the conditional expression is true or false. a. If the conditional expression is true and statement-l and any following statements are given, statement-l and any following statements are executed and, provided that they do not contain a GO TO or STOP RUN, control passes to the next sentence. If the conditional expression is true and NEXT SENTENCE is given, control passes to the next sentence. b. If the conditional expression is false and statement-3 and any following statements are given, statement-3 and any following statements are executed and, provided that they do not contain a GO TO or STOP RUN, control passes to the next sentence. If the conditional expression is false and either ELSE NEXT SENTENCE is given or the entire ELSE clause is omitted, control passes to the next sentence. 3. The length of compared data-items in the conditional expression of an IF statement is limited to 2047 characters. 4. Statement-I, statement-2, statement-3, and statement-4 may include any statement or sequence of statements, including other IF statements. IF statements included within other IF statements are nested. Nested IF statements are paired IF and ELSE combinations and may continue up to 12 levels deep. Each ELSE encountered is paired with the nearest preceding IF not already paired with an ELSE. The pairing process begins with the innermost IF .•. ELSE pair and proceeds outw~rds. 5-47 THE PROCEDURE DIVISION IF (Cont.) Example: (c=conditionis=statement) ,...L1 1 i I I IF col IF c-2 s-2 ELSE IF c-3 s-3 ELSE s4 ELSE s-5, L' , MR-8-027-79 5-48 THE PROCEDURE DIVISION INITIATE 5.9.20 INITIATE Function The INITIATE statement is used to initialize report is produced. all counters before a General Format INITIATE report-name-l [report-name- 2] Technical Notes 1. Each report-name must be defined by an RD entry in the Report Section of the Data Division. 2. The INITIATE statement resets all data-name contain SUM clauses associated with a report. 3. The PAGE-COUNTER is set to 1 during the execution of an INITIATE statement. If a different starting value for the PAGE-COUNTER is desired, it may be reset following the INITIATE statement before the execution of the first GENERATE statement. 4. The LINE-COUNTER is set to 0 during execution of the INITIATE statement. 5. The INITIATE statement does not open the file with which the report is associated. An OPEN statement must be executed prior to the execution of the INITIATE statement. 6. A second INITIATE statement for a particular report-name may not be executed until a TERMINATE statement for that report-name is executed. 5-49 entries that THE PROCEDURE DIVISION INSPECT 5.9.21 INSPECT Function The INSPECT statement counts, replaces, or counts and replaces the number of occurrences of a given character or groups of characters in a data item. General Format INSPECT identifier-l TALLYING {i denti fi er-4 11 } {i ~enti fi er-3}}IJBEFORE} {{~~~DING} llteral-l IJAFTER INITIAL literal-2 fJ .,. CHARACTERS {i denti fi er-2 FOR!~ I . .. INSPECT identifier-l REPLACING CHARACTERS BY {i~entifier-6} ~BEFORE} llteral-4 LlAFTER ~;.;..;;....;.;~~ - INITIAL {i~entifier-7}] J llteral-5 ]1 I J ~enti fi er-5} ---BY {illteral-4 ~enti fi er-6} ~{BEFORE} INITIAL {literal-5 identifier-7 f.l ... { ~~~DING} {{illteral-3 ( ~AFTER { FIRST • .. INSPECT identifier-l TALLYING { ALL } identifier-2 FOR {{{ LEADING CHARACTERS identifier-3}} [JBEFORE} literal-l lAFTER INITIAL identifier-4}J} •.• {literal-2 I . .• REPLACING C,HARACTERS BY ~--- ( {i ~enti fi er-6} llteral-4 jt {~~~DING} }{i~entifier-5} ~ { llteral-3 BEFORE} [{AFTER BY --- INITIAL {~~~~;!f~,~r-7}] {identifier-6} [{ BEFORE} AFTER literal-4 INITIAL I {identifier-7}]) literal-5 ;. . . . . . . Technical Notes (The Lollowing rules apply to Formats 1, 2 and 3: 1. Each literal must be nonnumeric and constant except ALL. 2. The usage of all identifiers must be DISPLAY, implicitly or explicitly. Identifier-l must reference either a group item or any category of elementary item. Identifier-3 ••• identifier-n must reference either an elementary, alphabetic, alphanumeric or numeric item. 5-50 may be any figurative J THE PROCEDURE DIVISION INSPECT (Cont.) The following rules apply to Format 1: 3. Identifier-2 must reference an elementary numeric data name. If either literal-lor literal-2 is a figurative constant, it refers to an implicit one-character data item. 4. The contents of the data item referenced by identifier-2 is not initialized by the execution of the INSPECT statement. 5. The rules for tallying are as follows: a. If the ALL phrase is specified, the contents of the data item referenced by identifier-2 is incremented by one (1) for each occurrence of literal-l matched within the contents of the data item referenced by identifier-I. b. If the LEADING phrase is specified, the contents of the data item referenced by identifier-2 is incremented by one (1) for each contiguous occurrence of literal-l matched within the contents of the data item referenced by identifier-I, provided that the leftmost such occurrence is at the point where comparison began in the first comparison cycle in which literal-l was eligible to participate. c. If the CHARACTERS phrase is specified, the contents of the data item referenced by identifier-2 is incremented by one (1) for each character matched, within the contents of the data item referenced by identifier-I. The following rules apply to Format 2: 6. The size of the data referenced by literal-4 or identifier-6 must be equal to the size of the data referenced by literal-3 or identifier-5. When a figurative constant IS used as literal-4, the size of the figurative constant is equal to the size of literal-3 or the size of the data item referenced by identifier-5. 7. When the CHARACTERS phrase is used, literal-4, literal-5, or the size of the data item referenced by identifier-6 or identifier-7 must be one character in length. 8. When a figurative constant is used as literal-3, the data referenced by literal-4 or identifier-6 must be one character in length. 9. The required words ALL, LEADING and FIRST are adjectives that apply to each succeeding BY phrase until the next adjective appears. 10. The following rules for replacement are as follows: a. When the CHARACTERS phrase is specified, each character matched in the contents of the data item referenced by identifier-l is replaced by literal-4. b. When the adjective ALL is specified, each occurrence of literal-3 matched in the contents of the data item referenced by identifier-l is replaced by literal-4. 5-51 THE PROCEDURE DIVISION ,INSPECT (Cont.) c. When the adjective LEADING is specified, each contiguous occurrence of literal-3 matched in the contents of the data item referenced by identifier-l is replaced by literal-4, provided that the leftmost occurrence is at the point where comparison began in the first comparison cycle in which literal-3 was eligible to participate. d. When the adjective FIRST is specified, the leftmost occurrence of literal-3 matched within the contents of the data item referenced by identifier-l is replaced by literal-4. The following rules apply to Format 3: 11. Identifier-2 must reference an elementary numeric data item. 12. If either literal-lor literal-2 is a figurative constant, the figurative constant refers to an implicit one-character data item. 13. The size of the data referenced by literal-4 or identifier-6 must be equal to the size of the data referenced by literal-3 or identifier-5. When a figurative constant is used as literal-4, the size of the figurative constant is equal to the size of literal-3 or the size of the data item referenced by identifier-5. 14. When the CHARACTERS phrase is used, literal-4, literal-5, or the size of the data item referenced by identifier-6 or identifier-7 must be one character in length. 15. When a figurative constant is used as literal-3, the data referenced by literal-4 or identifier-6 must be one character in length. 16. A Format 3 INSPECT statement is interpreted and executed as though two successive INSPECT statements specifying the same identifier-l had been written with one statement being a Format 1 statement with TALLYING phrases identical to those specified in the Format 3 statement, and the other statement being a Format 2 statement with REPLACING phrases identical to those specified in the Format 3 statement. The general rules given for matching and counting apply to the Format 1 statement and the general rules given for matching and replacing apply to the Format 2 statement. 5-52 THE PROCEOURE OIVISION INSPECT (Cont.) Examples The field TXT-FLO contains "PSYCHOANALYSIS". INSPECT TXT-FLO INITIAL "A". TALLYING COUNTER-l FOR CHARACTERS BEFORE COUNTER-l contains 6 INSPECT TXT-FLO REPLACING "A" BY "X" BEFORE INITIAL "N". TXT-FLO ends with "PSYCHOXNALYSIS" INSPECT TXT-FLO TALLYING COUNTER-l FOR INITIAL "S", REPLACING ALL "S" BY HZ". TXT-FLO ends with "PZYCHOANALYZIZ" COUNTER-l contains 12 5-53 CHARACTERS AFTER THE PROCEDURE DIVISION MERGE 5.9.22 MERGE Function The MERGE statement combines two or more identically sequenced files on a set of specified keys. During the MERGE process records are made available, in merged order, to an output procedure or to an output file. General Format MERGE [WITH SEQUENCE CHECK] file-name-l ON - {ASCENDING} DESCENDING KEY data-name-l ON {ASCENDING} DESCENDING KEY data-name-3 [ ~COLLATING SEQUENCE IS alPhabet-name~ USING file-name-2 j l file-name-3 [file-name-4] 0 UTPUT PROCE DURE ISs ect i on - name-l [n~:~UGH} sect i on-n ame-2] [ [ data-name-2] data - name-4] . J. l GIVING file-name-5 Technical Notes 1. File-name-l must be described in an SD file description entry in the Data Division. Each data-name must represent data items described in records associated with file-name-l. Note that file-name-l is actually a dummy file whose file description applies to all the files to be merged. However, file-name-2, file-name-3, file-name-4, and file-name-5 are real files. File-name-2, file-name-~, and fil~-name-4 are the files to be merged, and file-name-5 is the file into which the merged records will be written. 2. File-name-2, file-name-3, file-name-4, and file-name-5 must be described in an FD file description, not an SD file description. All records associated with file-name-2, file-name-3, and file-name-4 must be large enough to contain all the KEY data-names. 3. The data-names following the word KEY are listed in order of decreasing significance without regard to how they are divided into KEY clauses. 4. The data-names may be qualified but not subscripted. 5-54 THE PROCEDURE DIVISION MERGE (Cont.) 5. MERGE statements may appear anywhere in the Procedure Division except in the DECLARATIVES portion or in an INPUT or OUTPUT PROCEDURE associated with a SORT, or an OUTPUT PROCEDURE associated with another MERGE. 6. When the ASCENDING clause is used, the input files must be in sequence from the lowest values to the highest values; when the DESCENDING clause is used, the input files must be in sequence from the highest values to the lowest values. 7. The OUTPUT PROCEDURE, if present, must consist of one or more sections or paragraphs that appear contiguously in the source program and do not form a part of any INPUT- PROCEDURE. The OUTPUT PROCEDURE must contain at least one RETURN statement in order to make MERGEd records available for processing. 8. ALTER, GO, and PERFORM statements in the OUTPUT PROCEDURE may not refer to procedure-names outside the OUTPUT PROCEDURE in which they appear. 9. If you specify an OUTPUT PROCEDURE, it is performed by the MERGE statement. You must observe all rules relating to the range of a PERFORM. 10. If WITH SEQUENCE CHECK is present then the input files are checked to make sure that the records are in sequence with respect to the merge keys (that is, that the files were presorted.) A warning message is glven for each record out of order. 11. If you specify the GIVING option, all the merged records in file-name-l are automatically transferred to file-name-5. File-name-5 must not be open when the MERGE statem~nt is executed. Any USE PROCEDURES associated with file-name-5 will be executed as appropriate. The GIVING option is equivalent to the following OUTPUT PROCEDURE: L4. OPEN OUTPUT file-name-5. L5. RETURN sort-file INTO record-name-5; WRITE record-name-5. GO TO L5. L6. CLOSE file-name-5. AT END GO TO L6. Refer to the SORT/MERGE User's Guide for more information MERGE. 5-55 on THE PROCEDURE DIVISION MOVE 5.9.23 MOVE Function The MOVE statement transfers data in accordance with editing, from one data area to one or more data areas. the rules of General Format identifier-I} MOVE { 1 i tera 1 MOVE {CORRESPONDING} CORR TO i dent i fi er-2 [ i dentifi er-3] identifier-I TO identifier-2 Technical Notes 1. CORR may be interchanged with CORRESPONDING. 2. Identifier-l (or literal-I) represents the data to be moved and is called the sending item. Identifier-2, identifier-3, represent the receiving data items. 3. In format 1, the data contained in identifier-lor literal-l is moved first to identifier-2, then to identifier-3, etc. In format 2, data items within the group item associated with identifier-l are moved to corresponding data items within the group item associated with identifier-2. The results are the same as if you had referred to each pair of corresponding identifiers in separate MOVE statements. The criteria used to determine whether two items are corresponding are described in Section 5.7, The CORRESPONDING Option. 4. The following rules apply to both group and elementary items; a group item is treated as a single field. a. A numeric-edited, alphanumeric-edited, or alphabetic data item must not be moved to a numeric or numeric-edited data item. b. A numeric or numeric-edited item must not be moved to alphabetic data item. c. A numeric item whose implicit decimal point is not immediately to the right of the least significant digit must not be moved to an alphanumeric or alphanumeric-edited item. d. All other moves are legal. 5-56 an THE PROCEDURE DIVISION MOVE (Cont.) 5. The following rules apply to all legal moves. a. 6. When an alphanumeric, alphanumeric edited, or item is the receiving item: alphabetic 1. If the size of the sending field is greater than the size of the receiving field, the least significant (rightmost) characters are truncated if the receiving field is not described by a JUSTIFIED RIGHT clause; the most significant (leftmost) characters are truncated if the receiving field is described as JUSTIFIED RIGHT. 2. If the size of the sending field is less than the size of the receiving field, spaces are placed in the remaining rightmost characters of the receiving field if the recelvlng field is not described by Q JUSTIFIED RIGHT clause; spaces are placed in the remalnlng leftmost characters of the receiving field if the receiving field is described by a JUSTIFIED RIGHT clause. 3. If the sizes of the sending and receiving field are equal, no truncation or filling with spaces takes place. b. When a numeric or numeric-edited item is the receiving item, the sending and receiving fields are aligned by decimal point. If the sending field is not numeric, the decimal point is assumed to be on the right. Any necessary zero filling takes place before editing. If the recelv1ng item has no operational sign, the absolute value of the sending item is stored. If the receiving item has fewer digits to the left or right of the decimal point than does the sending item, the excess digits are truncated. If the sending item contains any nonnumeric characters, the result is unpredictable. c. Any necessary conversion of data from one form of internal representation to another is performed automatically during the move, along with any editing specified by the PICTURE of the receiving item. Any move that is not an elementary move (that is, neither the sending or receiving items are elementary items) is called a group move. A group move is treated as if it were an alphanumeric-to-alphanumeric elementary move except that there is no conversion of data from one form of internal representation to another. In other words, the individual data descriptions o~ the items within the sending group item and the receiving group item are completely ignored and both items are treated as though they were described by a PICTURE IS X(n) clause, where n is the number of character positions in the particular item. 5-57 THE PROCEDURE DIVISION MULTIPLY 5.9.24 MULTIPLY Function The MULTIPLY statement causes numeric data items to be multiplied sets the values of data items equal to the results. and General Format MUl TIPl Y {; 1~~;! i~ ~r-l} .!!.y i dentifi er-2 [ROUN OED] [i denti fier-3 [ROUNDED]] MULTIPLY {identifier-I} BY literal-I -- [ON SIZE ERROR imperative-statement] {identif-ler-2} liter.al-2 [identi fier-4 [ROUNDED]] ... GIVING identifier-3 [ROUNDED] [ON SIZE ERROR imperative-statement] Technical Notes 1. Each MULTIPLY statement must contain at least two operands (a multiplicand and a multiplier). Each identifier must refer to an elementary numeric item, except that identifier-3 in format 2 may refer to either a numeric or a numeric-edited item. Each literal must be a numeric literal; the figurative constant ZERO is permitted. 2. Format 1 causes the value of identifier-lor literal-l to be multiplied by the value of identifier-2. The resultant product replaces the value of identifier-2. The same process happens again, with identifier-3 replacing identifier-2, then identifier-4 replacing identifier-3, until all multipliers have been used. 3. Format 2 causes the value of identifier-lor literal-l to be multiplied by the value of identifier-2 or literal-2. The resultant product is stored in identifier-3, identifier-4, and so on. 4. The ROUNDED and SIZE ERROR options are described in Section 5.6, Common Options Associated with Arithmetic Verbs. 5~ Despite the possiblity of sequential multiplication taking place, there can never be more than two operands in use at one time. The total number of digits in both opera~ds must not be more than 18 decimal digits for the st~ndard compiler and not more than 36 digits for the BIS-compiler. In either case, a maximum of 18 digits can be stored in the receiving field. (S,ee Section 1.1 for a defini tion of the BIS-compiler.) 5-58 THE PROCEDURE DIVISION OPEN 5.9.25 OPEN Function The OPEN statement initiates the processing of files and, where necessary, performs the checking and writing of labels. It also specifies your covenants for opening a file for simultaneous update. General Format INPUT } . [ REVERSED flle-name-l WITH NO REWIND { OUTPUT [. flle-name-2 t ~~~~ITE I } { i~~UT-OUTPUT} file-name-3 FOR [ WRITE DELETE ) [ REVERSED ~JITH NO REWIND t l~ ~~~~ITE AND ANYVE RB WRITE DELETE ALLOWING OTHERS -- I~~~~ITE READ REWRITE NONE [ ALLOWING OTHERS WRITE DELETE I A:NYVE RB [ UNAVAILABLE statement-l [ 0 statement-2 ] . o. I ~~~~ITE oj] ] WRITE DELETE ANY VERB . 00 READ )] REWRITE ( WRITE ) ... { DELETE ANYVERB REWRITE }[ } READ FOR {WRITE AND DELETE [ ANYVERB o' ~ WRITE llANO DELETE ANY VERB OPEN [ EXTEND ] fi 1ename- 5 [fil ename-6 ] (] ANYVf RB [ [ file-name-4 JJ ] 5-59 ~ If READ AND INONE REWRITE WRITE DELETE ANYVERB II 1 .. 0 THE PROCEDURE DIVISION OPEN (Cont.) Technical Notes 1. The OPEN statement must be executed for a file prior to the execution of any I/O verbs, such as READ, WRITE, DELETE, REWRITE, SEEK, or CLOSE. 2. A second OPEN statement for a file cannot be executed to the execution of a CLOSE statement for that file. 3. An OPEN statement does not obtain or release the first record of a file. A READ statement must be executed to obtain the first record (or a WRITE statement must be executed to release the first record). 4. The maximum number of files that can be opened at a time is 16. When indexed-sequential files are being used, each indexed-sequential file is treated as two files: the index file and the data file. If the program is segmented, one less file can be open; similarly, if the RERUN option is being used, one less file can be open. The key word INPUT, OUTPUT, INPUT-OUTPUT, or 1-0 applies to each subsequent filename until another such key word is encountered or until the end of the OPEN statement is reached. 5. The NO REWIND option has meaning only for magtape files and is ignored for all other devices. If the NO REWIND clause is not specified for a tape file, the tape is rewound to the beginning of the tape. 6. If a file has been described with LABEL RECORDS ARE STANDARD, standard label checking or label writing is performed. If a file has been described as LABEL RECORDS ARE OMITTED, no label checking or writinq is performed. 7. If an INPUT file is described as OPTIONAL (in the FILE-CONTROL paragraph), the object-time system will type the message prior IS file-name PRESENT? and wait for the operator to type YES or NO. If he types NO, the first READ statement for this file causes the imperative-statement at the AT END or INVALID KEY clause to be executed. 8. The 1-0 or INPUT-OUTPUT options permit the opening of a file on a random-access device for both input and output processing. When the 1-0 option is specified, the execution of the OPEN statement causes the standard beginning label procedures to be executed. If the file does not exist when it is opened for INPUT-OUTPUT, an empty file is created. 9. A file is opened for simultaneous update if the ALLOWING OTHERS clause is present in the OPEN statement. It must be opened in 1-0 mode and cannot have a recording mode of V (variable-length EBCDIC). 5-60 THE PROCEDURE DIVISION OPEN (Cont.) ° 10. If the first user of a file opens it for simultaneous update, all subsequent users of the file must also open it for simultaneous update or for input only. If the file is currently open for simultaneous update, any subsequent users attempting to open the file for output or I-O will be denied access to the file. If the first user of a file opens it for output or I-O only and subsequent users attempt to open that file for simultaneous update, the simultaneous update users will be denied access to the file until the first user closes it. 11. After the keyword FOR, you must give one or more verbs that you intend to execute while you have your file open. You can only execute those verbs that you have specified. Following the keywords ALLOWING OTHERS, you must give one or more verbs that you will allow other users to execute when they open the file. You can also specify that others not be allowed to· execute any verbs when they open the file. Specification of ANY VERB means that all verbs legal for the file are permissible. If the ALLOWING OTHERS cloause is not present, the file is not opened for simultaneous update. 12. Once you have opened at least one file for simultaneous update, you cannot open any other files for simultaneous update until all files you previously opened for simultaneous update are closed. Thus, all files that must be open concurrently for simultaneous update must be opened in the same OPEN statement. However, files that are not to be . opened for simultaneous update can be opened at any time. 13. Files can be opened for INPUT, OUPUT, and just INPUT-OUTPUT (that is, not for simultaneous update) in the same OPEN statement as files opened for simultaneous update. 14. When more than one file is to be opened in one OPEN statement and at least one of the files is to be opened for simultaneous update, no files will be opened if the simultaneous update file cannot be opened. Simultaneous update files cannot be opened if they are not available in the modes specified by both the FOR and ALLOWING clauses. If the files cannot be opened for this reason, your program is suspended until all files are available, unless the UNAVAILABLE clause is specified. If the UNAVAILABLE clause is specified and one or 'more simul taneous update files are unavailable, control passes to the UNAVAILABLE clause. Note that the availability of the simultaneous update files is always checked before any files are opened. After the simultaneous update files are checked for availability, the files are opened. A failure during the actual opening process on any of the files will not cause the UNAVAILABLE path to be taken, but will cause an error to be returned. You can choose to ignore the error by using the FILE STATUS clause in the Environment Division (see Section 3.1.14, FILE STATUS) • 15. Any valid COBOL statements (including OPEN) can the UNAVAILABLE clause. 5-61 be used in THE PROCEDURE DIVISION OPEN (Cont.) 16. If a user program wishes to open a file for simultaneous update and the file is not available to it, the open request is queued for the file on a first-come/first-served basis. However, if a user program wishes to open more than one file for simultaneous update and at least one of the files is not available, the program is queued for those files that are available as well as the ones that are not available. This is because the program cannot open one file without opening all files in the same OPEN request. The requests for files remain in the queue for the files until all of the files are available. 17. A user pr~gram that violates its simultaneous update covenants 1S aborted. That is, if the program opens a file for READ and then issues a WRITE statement for that file, the program will be aborted. 18. Once a file is open for simultaneous update, you must issue a RETAIN statement before you execute any I/O on that file. Refer to the RETAIN statement, Section 5.9.29. 19. The EXTEND option may be specified only by users of TOPS-IO. 20. When the EXTEND phrase is specified, the OPEN statement positions ~he file immediately following the last logical record of that file. Subsequent WRITE statements referencing the file will add records to the file as though the file had been opened with the OUTPUT phrase. 21. When the EXTEND phrase is specified and the LABEL RECORDS clause indicates label records are present, the execution of the OPEN statement includes the following steps: a. The beginning file labels are processed only in the of a single reel file. b. The beginning reel labels on the last existing reel are processed as though the file was being opened with the INPUT phrase. c. The existing ending file labels are processed as though the file is being opened with the INPUT phrase. These labels are then deleted. d. Processing then proceeds as though opened with the OUTPUT phrase. 22. The REVERSED option may only be used on TU45 and TU70 tape drives. If you specify this option for a file, the file will be opened and the tape positioned at the end of the file. A READ statement will cause the final block of the file to be grabbed by the monitor. This can be slightly tricky because the record which is actually made available to you is the first record of the last block, which may not be the last record. For e~ample~ if your file is blocked 2, the r~cord made available by the READ statement will be the next to last record in the file, not the last one. 5-62 the file had case been THE PROCEDURE DIVISION OPEN (Cont.) Examples OPEN INPUT INFIL. OPEN 1-0 TRANSACTION FOR READ AND WRITE, ALLOWING OTHERS READ AND WRITE. OPEN OUTPUT LOG, LIST, INPUT-OUTPUT MASTER FOR READ AND REWRITE, OTHERS ANY DET FOR READ, OTHERS READ AND WRITE, ACCOUNT FOR ANY OTHERS NONE, INPUT DAILY WITH NO REWIND. 5-63 THE PROCEDURE DIVISION PERFORM 5.9.26 PERFORM Function The PERFORM statement is used to depart from the normal sequence of execution in order to execute one or more procedures and then return control to the normal sequence. General Format PERFORM procedure-name-l [ { i~~~UGH } procedure-name-2 ] PERFORM procedure-name-l [ { THROUGH THRU } TIMES } procedure-name-2 ] {identifier-l i nteger-l } procedure-name-2 ] UNTIL condition-l PERFORM procedure-name-l [ {THROUGH THRU } procedure-name-2 ] PERFORM procedure-name-l [ { THROUGH THRU VARYING BY f {~dentifier-2} FROM 1 ndex-name-l -tdentifi er-4} literal-3 dentifi er-3} index-name-2 literal-I UNTIL condition-l dent ifi er- 5} index-name-3 FROM r BY {identi fier-7} literal-4 UNTIL condition-2 [AFTER t denti fi er-a} index-name-5 FROM i denti fi er-9 index-name-6 literal-5 BY {i dentifi er-IO} literal-6 UNTIL condition-3 [ AFTER t dentifi er-6} index-name-4 literal-3 5-64 JJ THE PROCEDURE DIVISION PERFORM (Cont.) Technical Notes 1. Each procedure-name is the name of a section or paragraph in the Procedure Division. Each identifier must refer to a numeric elementary item described in the Data Division. Each literal must be either a numeric literal or the figurative constant ZERO. 2. When the PERFORM statement is executed, control is transferred to the first statement of procedure-name-l. An automatic return to the statement following the PERFORM The procedures executed statement is established as follows. constitute the range of the PERFORM. a. If procedure-name-l is a paragraph-name and procedure-name-2 is not specified, the return is after the last statement of procedure-name-l. b. If procedure-name-l is a section-name and procedure-name-2 is not specified, the return is after the last statement in the last paragraph in procedure-name-l. c. If procedure-name-2 is a paragraph-name, the after the last statement in that paragraph. d. If procedure-name-2 is a section-name, the return is after the last statement in the last paragraph of that section. return is 3. There is no relationship between procedure-name-l and procedure-name-2, except that the sequence of operations beginning at procedure-name-l must eventually end with the execution of procedure-name-2 in order to effect the return at the end of procedure-name-2. Any number of GO TO and/or PERFORM statements may occur between procedure-name-l and procedure-name-2. 4. If control passes to these procedures by means other than a PERFORM statement, control passes through the return point to the following statement as though no return mechanism were present. 5. No PERFORM statement may terminate until all PERFORM statements that it has executed have terminated. A PERFORM statement may be executed which terminates at the same procedure-name as another active PERFORM. 6. Format 1 causes the PERFORM range to be executed once, followed by a return to the statement immediately following the PERFORM. 5-65 THE PROCEDURE DIVISION PERFORM(Cont.) 7. Format 2 causes the PERFORM range to be executed the number of times specified by identifier-lor integer-I. The value of identifier-lor integer-l must not be negative; it may be zero. Once the PERFORM statement has been initialized, any modification to the contents of identifier-l has no effect on the number of times the range is executed. 8. Format 3 causes the PERFORM range to be executed until the condition specified in the UNTIL clause is true. If this condi tion _is true at the time the PERFORM statement is initialized, the range is not executed. Conditions are explained in Section 5.5, Conditional Expressions. 9. Format 4 is used to augment the value of one or more identifiers during the execution of a PERFORM statement. In format 4, when only one identifier is varied, identifier-l is set equal to identifier-2 or literal-2 when the PERFORM statement is initialized. If the condition specified is determined to 'be false at this point, the PERFORM range is executed once. Then the value of identifier-l is augmented by identifier-3 or literal-3 and the rest of the_condition is done again. This cycle continues until condition-l is true; at this point, control passes to the statement following the PERFORM statement. If condition-l is true at tbe beginning of the execution of the PERFORM, control immediately passes to the statement following the PERFORM. The flow chart in Figure 5-3 illustrates the logic PERFORM cycle when two identifiers are varied. of ENTRANCE • Set identifier-2 and identifier-5 to current F ROM values t True Condition-1 ~ False True Condition-2 ! t False Execute procedure-name-1 THRU procedure-name-2 -------, . Exit Set identifier-5 to its current F ROM value • • Augment identifier-5 with current BY value Augment identifier-2 with current BY value J Figure 5-3 PERFORM Cycle Logic - Two Variables 5-66 MR-S-028-79 the THE PROCEDURE DIVISION PERFORM (Cont.) The flow chart in Figure 5-4 illustrates the logic of the PERFORM cycle when three identifiers are varied. ENTRANCE + Set identifier-2, identifier-5, identifier-8 to current FROM values , Condition-l t t True ! False Execute procedure-name-l TH RU procedurename-2 i-- True False Condition-3 • Exit False Condition-2 ~ True Set identifier-8 to its current FROM value + t Augment identifier-8 with current BY value Augment identifier-5 with current BY value Set identifier-5 to its current FROM value Augment identifier-2 with current BY value I MR·S-059·79 Figure 5-4 PERFORM Cycle Logic - Three Variables 10. When a procedure-name in a segment with a priority number greater than 49 is referred to by a PERFORM statement contained in a segment with a different priority number, the segment referred to is made available in its initial state (that is, with all alterable GO TOs set to their initial setting) for each execution of the PERFORM statement. 11. A PERFORM statement in a section not in the DECLARATIVES may have as its range procedures wholly contained within the DECLARATIVESi however, a PERFORM statement in a section within the DECLARATIVES may not have any non-DECLARATIVE procedures within its range. 12. A PERFORM statement within an INPUT or OUTPUT PROCEDURE associated with a SORT or MERGE verb may not have within its range any procedures outside of that INPUT or OUTPUT PROCEDURE. 5-67 THE PROCEDURE DIVISION READ 5.9.27 READ Function The READ statement makes available a logical record from an input file and allows performance of a specified imperative statement when end-of-file or invalid key is detected. General Format READ fi 1 e-name [NEXT] RECORD [INTO i denti fi erJ [AT END imperative-statement] READ file-name RECORD [INTO identifier] [INVALID KEY imperative-statement] READ fil e-name RECORD [INTO i denti fi erJ [KEY IS data-name] [INVALID KEY imperative-statement] Technical Notes 1. An OPEN INPUT or OPEN 1-0 statement must be executed for the file prior to execution of the first READ statement for that file. 2. The AT END clause is valid only for those files whose organization is SEQUENTIAL (explicitly or implicitly). For those files, the AT END phrase must be specified if no applicable USE procedure is specified for file-name. The INVALID KEY clause is valid only for access mode is RANDOM or DYNAMIC. those files whose For files whose organization is RELATIVE or INDEXED, the INVALID KEY phrase or the AT END phrase must be specified if no applicable USE procedure is specified for file-name. If an end-of-file condition is encountered during the execution o'f a READ statement for a sequential file, any statements specified in the AT END clause are executed, and no logical record is made available. The logical end-of-file depends upon the type of device on which the file resides (users of TOPS-IO should see the Monitor Calls Manual, and users of TOPS-20 should see the Monitor Calls Reference Manual). After execution of the imperative-statement(s) in the AT END clause, no further READ statements can be executed for that file without first executing a CLOSE statement followed by an OPEN statement for the file. 5-68 THE PROCEDURE DIVISION READ (Cont.) When a READ statement is executed for a file whose organization is RELATIVE, the object-time system makes available the record whose relative record number is equal to the contents of the data item named in the RELATIVE KEY phrase. If no such record exists, the INVALID KEY statements are executed and no record is made available. For relative files whose access mode is DYNAMIC, the NEXT phrase must be specified if you wish to read the file sequentially. If you specify the NEXT phrase the record made available will be the next logical record after the one most recently read, unless there has not been a READ statement since the last OPEN or START statement. If this is the case, the record made available is the first record, in the case of OPEN, or the record specified in the START statement, whether the EQUAL, GREATER THAN, or NOT LESS THAN option is used. When a READ statement is executed for a file whose" organization is INDEXED, a search of the file is made to find the record that has a key equal to the contents of the RECORD KEY associated with the file. If that record is found, it is moved to the record area for the file; if it is not found, the statements associated with the INVALID KEY clause are executed, and no record is made available. When a READ NEXT statement is executed for a file whose organization is INDEXED, the first logical record having a key higher than the last record processed (by a READ, WRITE, REWRITE, or DELETE statement) is made available. The next higher key is used regardless of whether or not the previous I/O operation caused the INVALID KEY path to be taken. If a START statement was the last" reference to the file, the record made available is the one specified in the START statement, or the first of the specified range. That is, if your program contains the following sentence: START MYFILE KEY IS GREATER THAN MIN-KEY INVALID TO DISPLAY-ERROR KEY GO the record made available to your program is the first logical record with a key value greater than MIN-KEY. If no such record exists (that is, you have reached end-of-file), the INVALID KEY statements are executed, and no record is made available. If the file has been opened but no READ, WRITE, REWRITE, DELETE or START statement has been executed, the first record of the file is made available. 3. If a file described by an OPTIONAL clause is not present, the imperative-statement(s) in the AT END or INVALID KEY clause is executed on the first READ for that file. Any specified USE procedures are not performed. 4. If logical end-of-reel is recognized during execution of READ statement, the following operations are carried out. a a. The reel is rewound. b. If the file is assigned to more than one device, the devices are advanced. The previous reel is rewound and th~ next reel is initialized. 5-69 > THE PROCEDURE DIVISION READ (Cont.) c. The standard beginning label procedure is executed. d. The first data record on the new reel is made available. 5. If a file consists of more than one type of logical record, these records automatically share the same storage area. This is equivalent to an implied REDEFINE for the record area. Only information in the current record is accessible. 6. If the INTO identifier option is specified, the READ statement is then equivalent to a READ without the INTO option, followed by a MOVE of the record area associated with the filename to identifier. 5-70 THE PROCEDURE DIVISION RELEASE 5.9.28 RELEASE Function The RELEASE statement transfers records to the initial sort operation. phase of the General Format RELEASE record-name [FROM ; dent; f; erJ Technical Notes 1. A RELEASE statement may be used only in an input procedure associated with a SORT or MERGE statement for a file whose SD description contains record-name. 2. If the FROM option is used, the contents of identifier are moved to record-name, then the contents of record-name are released to the sort ~ubroutines. 3. After the RELEASE statement is executed, record-name 'may no longer be available. 5-71 the contents of THE PROCEDURE DIVISION RETAIN 5.9.29 RETAIN Function The RETAIN statement specifies your intent to access records in a file that is open for simultaneous update. General Format f RECORD RETAIN fil e-name-l {1identifier-I}] i tera 1-1 [KEY l {NEXT RECORD FOR { READ REWRI TE READ- REW RI TE } DELETE WRITE ANY VERB fil e-name-2 ! RECORD [UNTI L FREED ] [KEY { i~~~;! i~~r-2} NEXT RECORD FOR ~~C~ITE ~~~~T~EWRI TE } [ UNTI L FREE 0 J ... { WRITE ANY VERB [UNAVAILABLE statement-l [statement-2 ] ... ] 5-72 ] I one or more THE PROCEDURE DIVISION RETAiN (Cont.) Technical Notes Filename-I, filename-2 ... must be the names previously opened for simultaneous update. 2. literal-I, Identifier-I, identifier-2 .•. and literal-2 •.. specify keys that refer to records in the file. 3. Statement-I, statement-2 ... 4. The RETAIN statement must be given before any record is accessed in a file opened for simultaneous update. If it is given for a file not open for simultaneous update, the program will be terminated. 5. The RETAIN statement does not cause any change in the record area or any change in the positioning in the file. You must explicitly issue I/O statements for these changes to be performed. Thus, the RETAIN statement will not cause an end-of-file condition. 6. The action performed by any I/O operation is logically the same as if the file were not opened for simultaneous update. That is, a sequential file is always read/written/rewritten sequentially; the RELATIVE KEY is examined to determine the record to be read/written/rewritten/deleted in a relative file; and the RECORD KEY is examined to determine the record to be read/written/rewritten/deleted in an indexed-sequential file. The only difference is that a check is made to ascertain that the record has been retained. Thus, retaining a record does not cause that record to become the current record of the file. Only I/O operations can cause a record to become the current record of the file. 7. You can retain nonexistent records in a file, but you will receive an error if you attempt to perform I/O on these nonexistent records. 8. It is possible to mix requests for records from random, and indexed-sequential files in the statement. 9. When you retain a record for READ, other users are also allowed to read that record, but cannot perform any other form of I/O on that record (WRITE, REWRITE, or DELETE). When you retain a record for any use other than READ, all other users are banned completely from accessing that record. 10. The statement included in the FOR clause in the RETAIN statement must agree with at least one statement in the FOR clause in the OPEN statement for the file. If ANY VERB is specified in the FOR clause in the RETAIN statement, the file must have been explicitly opened for ANY VERB. 5-73 of files 1. are any valid COBOL statements. sequential, same RETAIN THE PROCEDURE DIVISION RETAIN (Cont.) 11. The record or records named in the RETAIN statement are automatically freed upon execution of the statement or statements (except ANY VERB) in the FOR clause of the RETAIN statement. If you do not issue an I/O statement for the record, or if the UNTIL FREED phrase is used, you must explicitly free the record with the FREE statement. If a record is not freed, you cannot retain any more records in any of your files open for simultaneous update. 12. The UNTIL FREED phrase allows you to retain several logically related records for processing without their being freed automatically by the I/O statements. Instead, the records are retained until they are explicitly freed by means of the FREE statement. 13. The KEY phrase allows you to specify a particular to specify more than one record in a file. 14. All records to be retained concurrently, whether in one or several files, must be retained in the same RETAIN statement. Once records in any file have been retained, no other records in any open file can be retained until the currently retained records have all been freed. This rule prevents a deadly embrace situation. record or NOTE Deadly embrace occurs when two users make conflicting demands upon a file resource and neither is willing or able to yield to the other. The result is that both programs hang or stall waiting for the resource to become available. 15. When attempting to retain records, the program will be suspended if anyone of the records is not available. If you wish the program to perform other processing, rather than be suspended, you can include an UNAVAILABLE phrase in the RETAIN statement. Any valid COBOL statement can be used in the UNAVAILABLE phrase. 16. Use of the RETAIN statement differs according to the organization of the file. Each type of file is described separately below. 17. Sequential files a. Records in a sequential file can be retained for READ, WRITE, READ-REWRITE, or ANY VERB. For sequential files ANY VERB means READ, WRITE, and REWRITE. 5-74 THE PROCEDURE DIVISION RETAIN (Cont.) b. When the KEY phrase is specified, KEY 0 refers to the next record in the file. The next record in the file depends on the last I/O operation performed (READ, WRITE, or REWRITE) and the I/O operation for which the record is to be retained. If the last record was written, the next record to be retained for READ, WRITE, or READ-REWRITE is defined to be the one following the record just written. Similarly, if the last record was read, the next record to be retained for READ is defined to be the one following the one just read. However, the next record to be retained for REWRITE is defined to be the record just read. c. Subsequent KEY values (1, 2, 3 •.• ), refer to records relative to the record designated by a KEY value of O. d. If the KEY phrase is not included, the record retained is always the record designated by a KEY value of O. e. The value of a key can be specified by any identifier. The identifier must be numeric, and can be subscripted or qualified or both. Its USAGE should be COMPUTATIONAL or INDEX for the sake of efficiency. The value of the key can also be specified by a positive integer numeric literal containing ten or fewer digits. f. It is recommended that, when performing simultaneous updating on sequential files, you retain several records at a time so that the input/output overhead will be reduced. If records are retained singly, each record must be brought into memory from the device (even if it is already in memory) so that you have the latest copy of the record. When you free a record (either implicitly or explicitly), you must write the record out to the device so that other users have access to the latest copy of that record. Ekample OPEN INPUT-OUTPUT HISTORY FOR READ AND REWRITE ALLOWING OTHERS READ AND REWRITE RETAIN HISTORY KEY 0 FOR READ-REWRITE UNTIL FREED, HISTORY KEY 1 FOR READ-REWRITE UNTIL FREED, HISTORY KEY 2 FOR READ-REWRITE; READ HISTORY, AT END STOP RUN. 18. Relative files a. Records in a relative file can only be retained for READ, WRITE, READ-REWRITE, or ANY VERB. For relative files, ANY VERB means READ, WRITE, and READ-REWRITE. 5-75 THE PROCEDURE DIVISION RETAIN (Cont.) b. When the KEY phrase is specified, the value of the key designates a specific record in the file, just as the RELATIVE KEY of the file does. Thus, record 1 is always the first record in the file. If you specify the NEXT option, however, the record retained is the next sequential record in the file. The next record in the file depends on the last I/O operation performed (READ, REWRITE or WRITE) and the I/O operation for which the record is to be retained. If the last record was written, the next record to be retained for READ, WRITE, or READ-REWRITE is defined to be the one following the record just written. Similarly, if the last record was read, the next record to be retained for READ is defined to be the one following the record just read. However, the next record to be retained for REWRITE is defined to be the record just read. Note that the next record actually read or written depends on the value of the RELATIVE KEY, not on the record specified in the RETAIN statement. c. If you wish to read/rewrite the file sequentially, you should select the NEXT option in the RETAIN statement, and use the READ NEXT syntax so that you are performing I/O on the same records that you are retaining. If you wish to read/rewrite the file randomly, you should set the RELATIVE KEY to the desired record and either use the same value in the KEY in the RETAIN statement or use no KEY value in the RETAIN statement. d. If the KEY phrase is not specified, the value used for the key is taken from the RELATIVE KEY specified for the file. e. The value of a key can be specified by any identifier. The identifier must be numeric, and may be subscripted or qualified or both. For the sake of efficiency, its USAGE should be COMPUTATIONAL or INDEX. The value of the key can also be specified by a positive integer numeric literal containing ten or fewer digits. Example OPEN 1-0 PART FOR READ AND REWRITE ALLOWING OTHERS NONE. MOVE 64 TOPART-ACTUAL-KEY RETAIN PART FOR READ. READ PART, INVALID KEY GO TO ERR. RETAIN PART KEY 0 FOR REWRITE, PART KEY 35 FOR READ AND REWRITE. REWRITE PARTREC. MOVE 35 TO PART-ACTUAL-KEY. READ PART, INVALID KEY GO TO ERR. REWRITE PARTREC. 5-76 THE PROCEDURE DIVISION RETAIN (Con t.) 19. Indexed-sequential files a. Records in an indexed-sequential file can be retained for READ, WRITE, REWRITE, DELETE, READ-REWRITE, and ANY VERB. For indexed-sequential files, ANY VERB means READ, WRITE, REWRITE, DELETE, and READ-REWRITE. b. When the KEY phrase is specified, the value of the key refers to a specific record in the file, just as the RECORD KEY does. c. The value specified in the KEY phrase must normally be an identifier that specifies a field that agrees with the RECORD KEY defined for the file in size, class, usage, and number of decimal places. However, if the RECORD KEY of the file is numeric, a positive numeric literal of ten or fewer digits can be used as the value in the KEY phrase •. For the sake of efficiency the key should be USAGE COMPUTATIONAL or INDEX. d. If the KEY phrase is not specified, the value used for the key is taken from the current RECORD KEY for the file. e. If NEXT is specified, the record retained is that following the last record referenced in the same RETAIN statement or by a READ, WRITE, REWRITE, or DELETE statement. Example OPEN 1-0 LETTERS FOR READ ALLOWING OTHERS READ AND REWRITE. MOVE "B" TO RECORD KEY. RETAIN LETTERS FOR READ. READ LETTERS INVALID KEY GO TO ERRS. 5-77 THE PR0CEDURE DIVISION RETURN 5.9.30 RETURN Function The RETURN statement obtains sorted records from the output phase of a SORT or MERGE operation. General Format RETURN file-name RECORD [INTO identifier] AT END imperative-statement Technical Notes 1. File-name must be described by an SD file descriptor. 2. A RETURN statement may be used only in an output procedure associated with a SORT or MERGE statement for file-name. 3. If the INTO phrase is specified, the current record is moved from the record area associated with file-name to identifier. 4. The AT END path is automatically taken when there are no more records to be returned. After executing the statement(s) in the AT END clause, no RETURN statements may be executed until another SORT or MERGE is executed. 5-78 THE PROCEDURE DIVISION REWRITE 5.9.31 REWRITE Function The REWRITE statement replaces an already existing record in a file. General Format REWRITE record-name [FROM identi fieCJ [INVALID KEY imperative-statement] Technical Notes 1. Record-name must be a record associated organization is RELATIVE or INDEXED. with a file whose 2. When the REWRITE statement is executed, a record in the file is located whose key value is equal to the contents of the RECORD KEY associated with the file, and the contents of the record are then replaced with the contents of record-name. If no such record exists in the file, the statement(s) associated with the INVALID KEY clause is executed. 3. At the time'the REWRITE statement is executed, the file be open for OUTPUT or INPUT-OUTPUT. 4. If the FROM option is used, the statement is equivalent to: must MOVE identifier TO record-name REWRITE record-name (without the FROM option) 5. The INVALID KEY phrase must not be specified for a REWRITE statement that references a file in sequential mode. This is because a REWRITE may only be done on a file in sequential-access mode after a successful READ statement is executed. 6. The INVALID KEY phrase must be specified in the REWRITE statement for files in the random- or dynamic-access mode for which an appropriate USE procedure is not specified. 5-79 THE PROCEDURE DIVISION SEARCH 5.9.32 SEARCH Function The SEARCH statement is used to condition exists. search a table until a specified General Format S~ARCH identifier-l [ VARYING WHEN condition-l [ WHEN condition-2 }l identifier-2 r .. ] { index-name-l ~ ~T END lmperatlve-statement-l imperative-statement-2 } { NEXT SENTENCE imperative-statement-3 }] ... { NEXT SENTENCE SEARCH ALL identifier-l [AT END imperative-statement-l] f data-name-l {~~ EQUAL TO} {identifier-3 literal-l WHEN ) ~ condition-name-l [AND } } arithmetic-expression-l data-name-2 {IS EQUAL TO} {i denti fi er-4 }} IS = literal-2 { condition-name-2 arithmetic-expression-2 J imperati ve-statement-2 } { NEXT SENTENCE Technical Notes 1. If any of the optional clauses are present, they must in the order shown. 2. Identifier-l must not be subscripted or indexed, but its description must contain an OCCURS clause with an INDEXED BY option. In format 2, identifier-l must also contain a KEY option in its OCCURS clause. 3. Identifier-2 must be an index, or an elementary numeric with no places to the right of the decimal point. 5-80 appear item THE PROCEDURE DIVISION SEARCH (Cont.) 4. In format 1, condition-I, condition-2, condition described in Section 5.5. etc., can be any 5. In format 2, condition-l must consist of a relation condition incorporating the EQUAL TO or equal sign, or a condition-name condition where the VALUE clause contains only a single literal, or a compound condition consisting of two or more such simple conditions connected by AND. A data-name that appears in the KEY clause of identifier-l must appear as the subject or object of a test, or be the name of the data-item with which the tested condition-name is associated. However, all preceding data-names in the KEY clause must also be included within condition-I. 6. If the AT END clause is not present, AT END NEXT SENTENCE assumed. is 7. If the VARYING option is not specified, the first index specified in the INDEXED BY option for identifier-l is used. If the VARYING option is used and identifier-2 is the name of an item specified in the INDEXED BY option for identifier-I, then identifier-2 is used as the index. If identifier-2 is not specified in the INDEXED BY option for identifier-I, the first index-name in the INDEXED BY option is used as the index, and identifier-2 will contain the value of the index at each step of the search. 8. If format 1 of the SEARCH verb is used, a serial type of search takes place, starting with the current index setting. If, at the start of execution of the SEARCH statement, the index contains a value that is not positive or is greater than allowed (greater than the number of occurrences or greater than any DEP~NDING item), the statement(s) specified in the AT END statement is executed. If, at the start of execution of the SEARCH statement, the index is within the allowed range of values, the WHEN conditions are evaluated one at a time. If any condition is true, the associated statement(s) is executed. If no condition is true, the index is incremented by 1, and the search operation is executed again. The contents of the index are always left as they were when the search is terminated, either by a WHEN condition, or the AT END condition. 9. If format 2 of the SEARCH verb is used, a binary search takes place. All the keys in the table must be in order (ascending or descending) and all the elements in the table must be filled. It is up to you to ensure that the keys associated with the table are in order and the table filled. If the keys are not in order, or if there are empty elements in the table being searched, the SEARCH may take the AT END path even if the key being searched for is there. If the table is not going to be filled, using the DEPENDING ON clause with OCCURS effectively shortens the table. 5-81 THE PROCEDURE DIVISION SEARCH (Cont.) The initial contents of the index are ignored; instead, the table is examined until the WHEN condition is satisfied (in which case statement-3 and any following statements are executed) or until the entire table is examined (in which case the AT END statement(s) is executed). When the search is terminated, the contents of the index reflect the occurrence number of the entry that satisfied the WHEN condition if it was satisfied, or is arbitrary if it was not satisfied. 10. In either format, after any WHEN or AT END statement(s) is executed, control is transferred to NEXT SENTENCE unless that statement contained a GO TO. 11. If identifier-l is a data item subordinate to a data item that contains an OCCURS clause (that is, this is a multidimensional table), only the index associated with identifier-l is modified during the search. To search an entire multidimensional table, the SEARCH statement must be executed several times. Example 01 TABLE. 02 TABLI OCCURS 200 TIMES INDEXED BY I, ASCENDING KEYS A, B. 03 A, PICTURE XXX. 03 FOO, PICTURE X(20). 03 B, PICTURE 9(4). 03 DES, PICTURE X(40). 03 AM, PICTURE S9(5)V99. SEARCH ALL TABLl, AT END GO TO WHAT-HAPPENDED; WHEN A(I) = "XYZ" AND B(I) = 350 GO TO GO-ONE. 5-82 THE PROCEDURE DIVISION SET 5.9.33 SET Function The SET statement allows a data-item to be or set to a value. incremented, decremented, General Format SET {identifier-l index-name-l SET index-name-4 [i denti fi er-2 ] [index-name-2 ] [i ndex-name-5] } TO ... identifier-3} { ~ndex-name-3 1 nteger-l UP BY } {i denti fi er-4 } { DOWN BY integer-2 Technical Notes 1. All identifiers must be numeric elementary items described without any positions to the right of the assumed decimal point. 2. All literals must be integers, ZERO. 3. The SET statement causes identifier-I, identifier-2,... to be set (TO), incremented (UP BY), or .decremented (DOWN BY) the value of identifier-3 or literal-I. 5-83 or the figurative constant THE PROCEDURE DIVISION SORT 5.9.34 SORT Function The SORT statement orders a file or files of records according to contents of the user-specified keys within each sorted record. the General Format SORT file-name-l ON {ASCENDING} DESCENDING KEY data-name-l [ data-name-2] ASCENDING } { DESCENDING KEY data-name-3 [ data-name-4] . J. [COLLATING SEQUENCE IS alPhabet-name] INPUT PROCEDURE IS section-name-l { USING file-name-2 j THROUGH} [{ THRU sect i on-name-2] } [file-name-3] OUTPUT PROCEDURE IS section-name-3 [{ THROUGH} THRU section-name-4] I {GIVING file-name-4 Technical Notes 1. File-name-l must be described in an SD file description entry in the Data Division. Each data-name must represent data items described in records associated with file-name-l. 2. File-name-2, file-name-3, and file-name-4 must be described in an FD file description. All records associated with these files must be large eno~gh to contain all of the KEY data-names. You can use any number of input files with a SORT statement. 3. The data-names following the word KEY are listed in order of decreasing significance without regard to how they are organized in the SD record description. 4. The data-names may be qualified but not subscripted. 5. SORT statements may appear anywhere in the Procedure Division except in the DECLARATIVES portion or in an input or output procedure associated with a sort, or an output procedure associated with a merge. 5-84 THE PROCEDURE DIVISION SORT (Cont.) 6. When the ASCENDING clause is used, the sorted sequence is from the lowest value to the highest value; when a DESCENDING clause is used, the sorted sequence is from the highest value to the lowest value. 7. The input procedure, if present, must consist of one or more sections or paragraphs that appear contiguously in the program and do not form a part of any output procedure. The input procedure must contain at least one RELEASE statement in order to transfer records to the sort subroutine. 8. The output procedure, if present, must consist of one or more sections or paragraphs that appear contiguously in a source program and do not form a part of any input procedure. The output procedure must contain at least one RETURN statement in order to make sorted records available for processing. 9. ALTER, GO and PERFORM statements in the input procedure are not permitted to refer to procedure-names outside the input procedure; similarly, ALTER, GO and PERFORM statements in the output procedure. are not permitted to refer to procedure-names outside the output procedure. 10. If an input or output procedure is specified, those procedures are PERFORMED by the SORT statement, and all rules relating to the range of a PERFORM must be observed. 11. If the USING option is specified, all records in file-name-2, file-name-3, ... , are automatically transferred to the SORT subroutine. File-name-2, file-name-3, ... , must not be open when the SORT statement is executed. Any USE PROCEDUREs associated with file-name-2, file-name-3, ... , will be executed as appropriate. The USING option is equivalent to the following INPUT PROCEDURE: Ll. L2. L3. 12. OPEN INPUT file-name-2 READ file-name-2 INTO sort-record; L3. RELEASE sort-record. GO TO L2. CLOSE file-name-2. AT END GO TO If the GIVING option is specified, all the sorted records in file-name-l are automatically transferred to file-name-4. File-name-4 must not be open when the SORT statement is executed. Any USE PROCEDURES associated with file-name-4 will be executed as appropriate. The GIVING option is equivalent to the following OUTPUT PROCEDURE: L4. L5. L6. OPEN OUTPUT file-name-4. RETURN sort-file INTO record-name-4;AT END GO TO L6. WRITE record-name-4. GO TO L5. CLOSE file-name-4. 5-85 THE PROCEDURE DIVISION SORT (Cont.) 13. An ISAM file cannot be sorted directly standalone SORT. using the non-COBOL ISAM files are by definition a sorted set. In designing the file you should use the order in which the file will be most often accessed. If you wish to access it in a different order, write a program with an input procedure that reads the ISAM file. The input procedure can release records to the sort. You can read the file in two ways - sequentially using READ NEXT, or randomly by selecting the desired record and inserting the key value in the RECORD KEY. Usually, reading the file sequentially and allowing SORT to order the records is much faster. If you wish to use an ISAM file as output, you must have an empty ISAM file for output, return records from the sort and write them into the new ISAM file. 14. 15. The collating sequence for the comparison of the specified nonnumeric key data items is determined in the following order: a. First, the collating sequence COLLATING SEQUENCE phrase, if statement. established by the specified, in the SORT b. Second, the collating sequence established as the program collating sequence. Refer to the SORT User's Guide for more information on SORT. 5-86 THE PROCEDURE DIVISION 5.9.35 START Function The START statement provides for logical positioning within 'a relative or indexed file, for subsequent sequential retrieval of records. General Format START file-name IS EQUAL } IS - - TO IS GREATER THAN IS ) { IS NOT LESS THAN IS NOT ( data-name [INVALID KEY imperative-statement] Technical Rules 1. File-name must be the name dynamic access. sequential or 2. Data-name may be qualified. 3. The INVALID KEY phrase must be the data item specified if applicable USE procedure is specified for file-name. no 4. The file associated with file-name must be open in the INPUT or 1-0 mode at the time the START statement is executed. 5. If you omit the KEY phrase, you imply the phrase IS EQUAL TO data-name, where data-name refers to the RECORD KEY of an indexed file or the RELATIVE KEY of a relative file. 6. If the file associated with file-name is a relative file, and you include data-name, data-name must be the data item specified in the RELATIVE KEY phrase of the file control entry. If the file is an indexed one and you include data-name, data-name must be either the data item specified as the record key, or an "approximate key". An "approximate key" is a part of a key, whose leftmost character position is the same position as the leftmost position of the RECORD KEY but which is not the entire key. Suppose, for example, you have an ISAM file whose key is of the form YY-MM-DD-XX 5-87 of a file with THE PROCEDURE DIVISION START (Cont.) where YY is the year, MM the month, DO the day, and XX the charge sequence number. If you wished to begin pr~essing the file at the first record of July 1978, you could write the following code: SELECT CHARGE-FILE ASSIGN TO DSK ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS CHG-REC-KEY. MOVE "78-07-" TO CHG-REC-KEY. START CHARGE-FILE KEY IS GREATER THAN CHG-REC-KEY, INVALID KEY GO TO ERR-RTN. The effect of this would be to find the first record in the file whose key collates higher than 78-07- and then position the record pointer in front of that record. If you specified NOT LESS THAN instead of GREATER THAN the pointer would be positioned in front of the record whose key is 78-07-~~~~~ if such a record existed; otherwise the pointer would be positioned as in the actual example. Note that only indexed files may use the "approximate key", and that the leftmost positions of the record key and the "approximate key" must be the same character position in the record, not simply contain the same character. 7. If the comparison is not satisfied by any record in the file, the INVALID KEY condition exists, the execution of the START statement is unsuccessful, and your logical position in the file is undefined. When this is the case, the imperative-statements following the INVALID KEY phrase are executed. 8. The execution of the START statement causes the value of the FILE STATUS data item, if any, associated with file-name to be updated. 5-88 THE PROCEDURE DIVISION STOP 5.9.36 STOP Function The STOP statement halts the object program. General Format RUN } { literal Technical Notes 1. The literal may be numeric or figurative constant except ALL. nonnumeric or may be any 2. If the literal is numeric, it must be an unsigned integer. 3. If the literal option is used, the literal is displayed on the user's terminal. The literal may be a figurative constant; in this case, a single character is displayed. The program waits for the operator to type CONTINUE Following receipt of this message, the program execution at the statement following the STOP. 4. continues If the RUN option is used, all files currently open closed, and execution of the program is terminated. 5-89 are THE PROCEDURE DIVISION STRING 5.9.37 STRING Function The STRING statement is used to concatenate the partial contents of several data items into a single data item. or complete General Format STRING {i ~ent i fi er--l} [i ~enti fi er-2J llteral-l ( i dent i fi e r- 3 DELIMITED BY 11teral-2 DELIMITED BY ~literal-3 {SIZE ~enti l ( , l] i fi er-6 llteral-6 ( \ i!1I , ... INTO identifier-7 [WITH POINTER identifier-8] [ON OVERFLOW imperative-statement] Technical Notes 1. Source Items a. The data items referenced by identifier-I, identifier-2, •.. are called source data items. b. A numeric source item is moved (according to the rules for numeric transfers) to an intermediate unsigned numeric data item of the same size as the source whose USAGE is the same as that of identifier-7 , and then it is treated as alphanumeric. c. If subsc~ipting or indexing is needed to identify a source data item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of that particular source item are used. d. Literal-I; literal-2 •.• Source literals must alphanumeric figurative modifier. e. If a source literal is a figurative constant, it refers to a single-character literal of the specified type. 5-90 are called source literals. be alphanumeric literals or constants without the ALL THE PROCEDURE DIVISION STRING (Cont.) 2. Delimiter Items a. Each series of source items specified in the STRING statement must be followed by a DELIMITED BY phrase. This phrase specifies the delimiter condition to be associated with each source item in that series. b. The data items referenced by identifier-3 identifier-6 are called delimiter data items. c. A numeric delimiter item is moved (according to the rules for numeric transfers) to an intermediate unsigned numeric data item of the same size as the delimiter whose USAGE is the same as that of identifier-7 and then treated as alphanumeric. d. If subscripting or indexing is needed to identify a delimiter data item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of the source item corresponding to that particular delimiter item are used. e. Literal-3 and literal-6 are called delimiter literals. Delimiter literals must be alphanumeric literals or alphanumeric figurative constants without the ALL modifier. f. If a delimiter literal is a figurative constant, it refers 'to a single-character literal of the specified type. g. If a delimiter data item or a delimiter literal is specified, either the content of the data item during the execution of the STRING statement or the value of the literal is the delimiter string for each source item corresponding to that delimiter item. and In this case, the delimiter condition for each of the corresponding source items is the first occurrence in the source item of a character string that matches the delimiter string. If there is not such character string in the source item, the delimiter condition is the rightmost boundary of that source item. NOTE Two character strings match if, and only if, they are of equal length and each character of the first string is equivalent, according to the rules for code conversion, to the corresponding character of the second string. h. If the DELIMITED BY SIZE phrase is specified, the only condition for each of the corrsponding source items is the rightmost boundary of the source item. delimit~r 5-91 THE PROCEDURE DIVISION STRING (Cont.) 3. 4. 5. Destination a. The data item referenced by identifier-7 is called the destination. The destination must be an unedited alphanumeric data item. It cannot be justified (that is, the JUSTIFIED clause cannot be used for this item). b. If subscripting or indexing is needed to identify the destination, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the execution of the STRING statement are used. Pointer a. The data item referenced by identifier-8 is called the pointer. The pointer must be an unedited integer data item of sufficient size to contain a value one greater that the size of the destination. b. The pointer destination. c. If subscripting or indexing is needed to identify the pointer, the values of the required subscripts and/or indexes and the depending items, if any, prior to the execution of the STRING statement are used. d. If the POINTER phrase is specified, the pointer is directly available to you. It must be initialized before the execution of the STRING statement to a value greater than zero and not greater than the size of the destination. e. If the POINTER phrase is not specified, the STRING statement is always executed as if you have specified a pointer and set the initial value to 1. In this case, the pointer is not directly available to you. f. The STRING statement is executed as if the initial value of the pointer were stored in a temporary location. This temporary location is used as the pointer during the execution of the STRING statement. The value in this temporary location is stored in the real pointer item before any subscripting is done and at the end of execution of the STRING statement. serves as a character index for the Execution a. When the STRING statement is executed, each source item in turn, starting with the first source item specified, is transferred to the destination character by character, beginning at the leftmost character position of the source item and continuing to the right, until the delimiter condition corresponding to that source item has been encountered or the destination has been filled. 5-92 THE PROCEDURE DIVISION STRING (Cont.) b. If a delimiter item was specified for a source item and a string of characters is found in the source item matching the delimiter string, all characters of the source item preceding the matching string are used in the transfer to the destination, but none of the characters that are in the matching string and no characters following it in the source item are used in the transfer. c. If no delimiter item was specified for a source item or no string of characters is found in the source item matching the delimiter string, all characters of the source item are used in the transfer to the destination. d. During the execution of the STRING statement, characters are transferred to the destination from the source items as if the destination were a table of single-character data items indexed by the pointer, which is automatically incremented after each character transfer. e. The first character transferred is stored in the character position of the destination indicated by the initial value of the pointer. The nth character transferred is stored in the character position indicated by the initial value of the pointer plus n-l. f. The transfer of characters ends when one of the following conditions occur. These conditions are specifically checked for in the order stated. 1. The initial value of the pointer is not a positive integer less than or equal to the size of the destination. 2. All appropriate characters of all source been transferred to the destination. 3. A character has been transferred to the last character position of the destination, though not all appropriate characters of all source items have been transferred. items have g. If the transfer of characters to the destination is terminated because of condition 2 of note f, those character positions of the destination to which characters were not transferred, if any, will retain the values they contained before the execution of the STRING statement. That is, remaining character positions in the destination are not space-filled. h. After the transfer of characters to the destination has ended, the pointer is set to a value one greater than the ordinal number of the last character position of the destination to which data was transferred. If no data was transferred to the destination, the pointer is unchanged. 5-93 THE PROCEDURE DIVISION STRING (Cont.) 6. Overflow a. If the transfer of characters to the destination is terminated because of either condition 1 or condition 2 of note f, the STRING statement is considered to have caused an overflow. b. If the ON OVERFLOW phrase is not specified, after the execution of the STRING statement, regardless of whether or not there was an overflow, control passes to the point in the program immediately following the STRING statement. c. If the ON OVERFLOW phrase is specified, after the transfer of characters has ended and the pointer has been set to the appropriate value, the flow of control of the program depends on whether or not there was an overflow. 1. If an overflow did not occur, control passes to the point in the program corresponding to the end of the sentence containing the STRING statement (following all the statements in the ON OVERFLOW phrase). 2. If an overflow did occur, control passes to the point in the program corresponding to the beginning of statement-I. 5-94 THE PROCEDURE DIVISION SUBTRACT 5.9.38 SUBTRACT Function The SUBTRACT statement is used to subtract one" or the sum of two or more, numeric items from one or more numeric items and set the values of one or more items to the result. General Format SUBTRACT ~identifier-lt~ [identifier-2] literal-2 tliteral-l [:identifier-n [ROUNDED]:] SUBTRACT ... ~ llteral-2 [ ROUNDED ] [ON SIZE ERROR imperative-statement] {i~entifier-lt [i~entifier-il llteral-l FRm~ identifier-m J i denti fi er-m} {1 i tera l-m GIVING identifier-n [ROUNDED] [identifier-o [ROUNDED]] ... ~ON SIZE error imperative-statement] SUBTRACT {=ESPONDING} i dentifi er-l FROM i dentifi er-2 [ROUNDED] [ON SIZE ERROR imperative-statement] Technical Notes 1. Each SUBTRACT statement must contain at least two operands (that is, a subtrahend and a minuend). In formats 1 and 2, each identifier must refer to an elementary numeric item, except that identifiers to the right of the word GIVING may refer to numeric edited items. In format 3, each identifier must refer to a group item. Each literal must be a constant ZERO. numeric literal or the figurative 2. The composite of all operands (that is, the data item resulting from the superimposition of all operands aligned by decimal point) must not contain more than 18 decimal digits for the standard compiler and not more than 36 digits for the BIS-compiler. In either case, a maximum of 18 digits can be stored in the receiving field. (See Section 1.1 for a definition of the BIS-compiler.) J. Format 1 c~uses the values of the operands preceding the word FROM to be added together, and this sum to be subtracted from the values of identifier-m, identifier-n, and so forth. 5-95 THE PROCEDURE DIVISION SUBTRACT (Cont.) 4. Format 2 causes the values of the operands preceding the word FROM to be added together, the sum subtracted from identifier-m or literal-m, and the result stored as the new values of identifier-n, identifier-p, and so forth. The current values of identifier-n, identifier-p, and so forth, do not enter into the computation. 5. Format 3 causes the data items in the group item associated with identifier-l to be subtracted from and stored into corresponding data items in the group item associated with identifier-2. The criteria used to determine whether two items are corresponding are described in Section 5.7, The CORRESPONDING Option. 6. The ROUNDED and SIZE ERROR options are described in Section 5.6, Common Options Associated with Arithmetic Verbs. 5-96 THE PROCEDURE DIVISION TE~~INATE 5.9.39 TERMINATE Function The TERMINATE statement ends the processing of a report. General Format TERMINATE report-name-l [report-name-2~ Technical Notes 1. Each report-name must be defined by an RD entry in the Report Section of the Data Division. 2. All control footings associated with the report are produced as if a control break had occurred at the highest level. In addition, the last PAGE FOOTING and any REPORT FOOTING report groups are produced. 3. A second TERMINATE statement for a particular report may not be executed until another INITIATE statement is executed for that report. 4. The TERMINATE statement does not close the file associated with the report; a CLOSE statement must be executed after the TERMINATE statement is executed. 5-97 THE PROCEDURE DIVISION TRACE 5.9.40 TRACE Function The TRACE statement causes the complier to trace paragraphs or to stop tracing paragraphs. When a paragraph is traced, its name, enclosed in angle brackets «», is typed each time that the paragraph is entered. General Format Technical Notes 1. The TRACE statement works with the COBDDT utility to help you debug your COBOL-74 program. 2. The compiler generates trace calls for each paragraph in the program if the IP switch is not included in the command string. If the IP switch is included in the command string, the trace calls are not generated. 3. Although the compiler generates trace calls when the IP switch is not present, tracing is not performed unless the user includes the TRACE ON statement in his program. 4. The TRACE ON statement causes all ensuing paragraphs to be traced; that is, their names, enclosed in angle brackets «», are typed each time they are entered. Tracing continues until either the end of program is reached or a TRACE OFF statement is encountered. 5. The TRACE OFF statement stops tracing of all ensuing paragraphs until either the end of program is reached or a TRACE ON statement is encountered. 6. When compiling for a production run, you should include the IP switch in the command string so that trace calls will not be generated and TRACE statements in the program will be ignored. The following example shows paragraphs with TRACE OFF and TRACE ON statements included. 5-98 THE PROCEDURE DIVISION TRACE (Cont.) PROCEDURE DIVISION. PARA. TRACE ON. PARB. TRACE OFF. PARCo TRACE ON. PARD~ Paragraph PARB and PARD are traced. Paragraph PARC is not traced because the TRACE OFF statement is included immediately before it. If the IP switch is included in the command string when, this program is compiled, the TRACE statements will be ignored and trace calls will not be generated. 5-99 THE PROCEDURE DIVISION UNSTRING 5.9.41 UNSTRING Function The UNSTRING statement is used to split a single data item (for example, a text string) into several parts, depending on the occurrence of specified delimiters, and to store the parts into separate data items where they may be more easily accessed by the COBOL program. General Format UNSTRING identifier-I [DELIMITED BY [ -ALL] {i?entifier-2} llteral-I OR [ALL] ?enti fi er-3}] ... - - {illteral-2 [- J INTO identifier-4 [DELIMITER IN identifier-5][COUNT IN identifier-6] [i dentifi er-7 [DELIMITER IN i dentifi er-a] [COUNT IN i denti fi er-g]] [WITH POINTER identifier-IO][TALLYING IN identifier-II] [ON OVERFLOW imperative-statement] Technical Notes 1. 2. Source Items a. The data item referenced by identifier-l is called the source item. The source item must be a DISPLAY-6, DISPLAY-7, or DISPLAY-9 data item. A numeric source item is moved to an intermediate unsigned numeric data item of the same size according to the rules for numeric transfers and then is treated as alphanumeric. b. If subscripting or indexing is needed to identify the source, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the execution of the UNSTRING statement are used. Destination Items a. The data items referenced by identifier-4, identifier-7, •.• , are called destination items. Destination items can be any kind of data items. b. If subscripting or indexing is needed to identify a destination item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of data to that destination item are used. 5-100 THE PROCEDURE DIVISION UNSTRING (Cont.) 3. 4. Delimiter Items a. The data items referenced by identifier-2, identifier-3, .•. , are called delimiter data items. b. A numeric delimiter item is moved (according to the rules for numeric transfers) to an intermediate unsigned numeric data item of the same size as the delimiter whose USAGE is the same as that of identifier-l and then is treated as alphanumeric. c. If subscripting or indexing is needed to identify a delimiter data item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of data to each successive destination item are used. d. Literal-I, literal-2, ... , are called delimiter literals. Delimiter literals must be alphanumeric literals or alphanumric figurative constants without the ALL modifier. e. If a delimiter literal is a figurative constant, it refers to a single-character literal of the specified type. f. If a delimiter data item or a delimiter literal is specified, the contents of the data item or the value of the literal is a delimiter string for the source. g. If more than one delimiter item is specified, the delimiter items are separated by the connective OR. In this case, the several delimiter strings are ordered by the order in which the delimiter items specifying them occur in the UNSTRING statement. h. If the ALL phrase is specified with a delimiter item, the delimiter string which that item specifies is considered to consist of as many occurrences of that simple delimiter string as can be found contiguously stored in the source. i. A delimiter condition is an occurrence in the source of a character string, not contained in the portion of the source that has already been scanned, that matched one of the delimiter strings, or the rightmost boundary of the source. Delimiter Storage Items a. A DELIMITER IN phrase may be specified DELIMITED BY phrase is specified. if the b. The data items referenced by identifier-5 identifier-8 are called delimiter storage items. and c. If subscripting or indexing is needed to identify a delimiter storage item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of data to the destination item corresponding to that delimiter storage item are used. 5-101 only THE PROCEDURE DIVISION UNSTRING (Cont.) 5. Count Storage Items a. A COUNT IN phrase may be specified only if the BY phrase is specified. DELIMITED b. The data items referenced by identifier-6 and identifier-9 are called count storage items. Count storage items must be unedited integer data items of sufficient size to contain a value equal to the size of the source. c. If subscripting or indexing is needed to identify a count storage item, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the transfer of data to the destination item corresponding to that count storage item are used. d. A count storage item is used to store the number of characters of the source that were examined during the execution of the UNSTRING statement and approved for transfer to the destination corresponding to that count storage item. NOTE This'is not necessarily the same as the number of characters that were actually transferred, because the destination may be too small to hold all that were approved for transfer. 6. Pointer a. The data item referenced by identifier-IO is called the pointer. The pointer must be an unedited integer data item of sufficient size to contain a value one greater than the size of the source. b. The pointer serves as a character index for the source. c. If subscripting or indexing is needed to identify the pointer, 'the values of the required subscripts and/or indexes and the depending items, if any, just prior to the execution of the UNSTRING statement are used. d. If the POINTER phrase is specified, the pointer is directly available to you. It must be initialized before the execution of the UNSTRING statement to a value greater than zero and not greater than the size of the source. e. If the POINTER phrase is not specified, the UNSTRING statement is always executed as if you have specified a pointer and set the initial value to 1. In this case, however, the pointer is not directly available to you. 5-102 THE PROCEDURE DIVISION UNSTRING (Cont.) 7. 8. Destination Counter a. The data item referenced by identifier-II is called the destination counter. The destination counter must be an unedited integer data item of sufficient size to contain a value equal to the number of destination items specified in the UNSTRING statement. b. The destination counter is used to store the number of destination items to which data was transferred by the execution of the UNSTRING statement. c. If subscripting or indexing is needed to identify the destination counter, the values of the required subscripts and/or indexes and the depending items, if any, just prior to the execution of the UNSTRING statement are used. d. If the TALLYING phrase is specified, the destination counter is directly available to you, and it must be initialized before the execution of the UNSTRING statement. e. If the TALLYING phrase is not specified, the UNSTRING statement is always executed as if you had specified a destination counter and set the initial value to O. In this case, the destination counter is not directly available to you. Execution a. The execution of the UNSTRING statement is an interactive process. There is one iteration for each destination item specified in the UNSTRING statement, starting with the first destination item specified and continuing in order through the series of destination items. However, the iteration process will be stopped after all the data in the source has been used, even if not all destination items have been used. During execution of the UNSTRING statement, the pointer and an increment to be added to the destination counter are kept in temporary locations. At the start of execution of the UNSTRING statement, the real pointer is stored in the temporary pointer and the temporary destination count is set to zero. When it becomes necessary to move these items to the real pointer and real destination items, the internal pointer is moved into the real pointer, the internal destination counter is added to the real destination counter, and the internal destination counter is set to zero again. b. Each iteration of the process involved in the execution of the UNSTRING statement consists of the following steps: 1. Select a set of characters from the source. 2. If ~he destination it~m, delimiter storage item, or count storage item is subscripted, store the internal pointer into the real pointer item and update the real destination counter. 5-103 THE PROCEDURE DIVISION UNSTRING (Cont.) 3. Move a representation of these characters destination item for that iteration. 4. Move some characters to the delimiter storage item corresponding to that destination item, if one is specified. 5. Set the count storage item corresponding destination item, if one is specified. 6. Advance the internal pointer position in the source. 7. Increment the internal destination counter. to to to indicate the that a new c. During the execution of the UNSTRING statement, the source is treated as if it were a table of single-character data items indexed by the pointer. The character position of the source indicated by the pointer, during each iteration of the UNSTRING process, is called the pointer-indicated position for that interation. Only the pointer-indicated position for an iteration and those source character positions to its right are used during that iteration. Character positions to the left of that position are not involved in that iteration in any way. d. During each iteration of the UNSTRING process, a scan of the source is done to determine which characters of the source will be selected as the character set to be moved to the appropriate destination item. This scan begins at the pointer-indicated position and continues to the right in the source. e. When the source is scanned, certain conditions are detected depending on whether or not the DELIMITED BY phrase is specified. 1. 2. If the DELIMITED BY phrase is specified, the scan ends when either of the following conditions occurs. a. A string of contiguous characters in the source that matches one of the delimiter strings is found. b. The rightmost boundary of the source is found. When the DELIMITED BY phrase is not specified, the scan ends when either of the following conditions occurs. a. A number of characters sufficient fill the destination is found. to completely b. The rightmost boundary of the source is found. When the scan ends, the set of characters to be moved the destination item is then known. 5-104 to THE PROCEDURE DIVISION UNSTRING (Cont.) f. The source scan proceeds in one of two ways~depending whether or not the DELIMITED BY phrase is specified. 1. 2. g. If the DELIMITED BY phrase proceeds as follows: is specified, the on scan a. Each character position of the source, starting at the pointer-indicated position and continuing to the right, is first checked to see if any source character-string beginning at that position matches the delimiter-string specified by the first delimiter item in the UNSTRING statement. If such a string is found, condition a of Note el is satisfied. b. If no such string is found, the same character position is then checked to see if any source character-string beginning at that position matches the second specified delimiter-string. This process is repeated using each succeSSlve delimiter-string until either condition a of Note el is satisfied or all specified delimiters have been tried. c. If condition a of Note el is not satisfied for the source character position under consideration and one of the specified delimiter-strings, that character position is then selected as part of the source to be moved to the current destination item. d. The above process continues until no more source character positions remain (condition b of Note el) • If the DELIMITED BY phrase is not specified, the source scan proceeds until one of the following conditions occurs. a. Enough successive character positions of the source have been selected to entirely fill the destination item (conditon a of Note e2). b. No more source character (Condition b of Note e2). positions remain During each iteration of the UNSTRING process, the set of contiguous source character positions selected by the process described in Note f is considered to be a complete individual data item, and is moved to the current destination item according to the rules for the MOVE statement, including any class of usage conversion that might be necessary. You should note that truncation or fill may occur during the execution of the MOVE statement. This data item may contain no character positions at all ·if the pointer-indicated position satisfied condition a of Note el or it may contain as much as the entire source. 5-105 THE PROCEDURE DIVISION UNSTRING (Cont.) h. If a count storage item is specified with the destination item for an iteration of the UNSTRING process, the number of source characters that were examined during the execution of the UNSTRING statement and approved for transfer to the destination item is stored in that count storage item. i. If there is a delimiter storage item specified for particular iteration of the UNSTRING process, then: 1. a If the selection of source character positions described in Note f is terminated because condition a of Note el holds, the str ing of contiguous· source character positions that contain the match for a delimiter string is treated as a complete individual data item and is moved to the delimiter storage item according to the rules for the MOVE statement, including truncation if necessary. If the delimiter string that was matched .is described with the ALL phrase, the set of source character positions containing a match for the simple delimiter string, plus every immediately succeeding set of contiguous source character positions containing a match for the same delimiter string, are used in the data item that is moved to the delimiter stroage item. 2. If the selection of source character positions described in Note f is terminated because of condition b of Note el, spaces are moved to the specified delimiter storage item. j. In an iteration of the UNSTRING process, after the appropriate data has been stored in the destination item, the delimiter storage item, and the count storage item, the pointer is set to a value one more than the ordinal number of the last source character position that participated in the selection process. This includes all character positions that were selected as part of the source to be moved to the destination item and, if a DELIMITED BY phrase is specified, all character positions that were used in the successful match of a delimiter string. k. When the UNSTRING statement has been executed, the real destination counter is updated using the internal destination counter and the internal pointer is stored into the real pointer. 5-106 THE PROCEDURE DIVISION iJNSTRING (Cont.) 9. Overflow a. If the initial value of the pointer is less than one or greater than the size of the source, execution of the UNSTRING statement is aborted before any data is transferred, the real pointer's value is unchanged, and the UNSTRING statement is considered to have caused an overflow. b. If, during the execution of an UNSTRING statement, data has been transferred to all of the destination items in accordance with Note g, but the updated pointer still contains a value less than or equal to the size of the source (that is, not all of the source character positions have been used in the UNSTRING process), the UNSTRING statement is considered to have caused an overflow. c. If the ON OVERFLOW phrase is not specified, after the execution of the UNSTRING statement, regardless of whether or not there was an overflow, control passes to the point in the program immediately following the UNSTRING statement. d. If the ON OVER~LOW phrase is specified, after the transfer of characters has ended and the pointer and destination counter are set to the appropriate values, the flow of control of the program depends on whether or not there was an overflow. 1. If an overflow did not occur, control passes to the point in the program corresponding to the end of the sentence containing the UNSTRING statement (following all the statements in the ON OVERFLOW phrase) . 2. If an overflow did occur, control passes to the point in the program corresponding to the beginning of statement-I. 5-107 THE PROCEDURE DIVISION USE 5.9.42 USE Function The USE statement specifies procedures for error handling that are in addition to the standard procedures provided by the input-output control system. General Format USE AFTER STANDARD tt PROCEDURE ON t) EXCEPTION ERROR ! fil e-name-l INPUT OUTPUT OPEN [fil e-name-2 ] OPEN y:-o- EXTEND USE BEFORE REPORTING identifier. Technical Notes 1. USE statements may appear only in the Declaratives portion of the Procedure Division. The Declaratives portion follows immediately after the PROCEDURE DIVISION header and begins with the word DECLARATIVES. The Declaratives portion ends with the words END DECLARATIVES. Following this must be a section-header as the first entry of the main portion of the Procedure Division. The DECLARATIVES portion itself consists of USE sections, each consisting of a section-header, followed by a USE statement, followed by the associated procedure paragraphs. 5-108 THE PROCEDURE DIVISION USE (Cont.) The general format for below. the DECLARATIVES portion is given PROCEDURE DIVISION. DECLARATIVES. section-name-l SECTION. USE •..... paragraph-name-Ia. (statement) [paragraph-name-Ib. (statement)] [section-name-2 SECTION. USE .•.... ] END DECLARATIVES. section-name-m SECTION. 2. The USE statement may follow on the same line as the section-header and must be terminated by a period followed by a space. The remainder of the section must consist of one or more procedural paragraphs that define the procedures to be used. 3. The USE statement itself is never executed, rather it defines the conditions calling for the execution of the USE procedures. 4. Format 1 causes the designated procedures to be executed after completing the standard input-output error routine. 5. There must not be any reference to any non-DECLARATIVES procedure within a USE procedure. Conversely, there must be no reference to procedure-names that appear within the DECLARATIVES portion in the non-DECLARATIVES portion, except that PERFORM statements may refer to a USE section or to a procedure contained entirely within such a USE section. 6. No input/output can be performed other than ACCEPT DISPLAY statements during execution of a USE procedure. 7. Format 1 causes the associated procedures to be executed after the standard input-output error routine has been executed. If the INPUT option is used, the procedures will be executed for all INPUT files; if the OUTPUT option is used, they will be executed for all OUTPUT files; if the 1-0 or the INPUT-OUTPUT option is used, they will be executed for all INPUT-OUTPUT files; if the filename-l format is used, they will be executed only for that particular file. If more than one USE procedure could apply in a situation, only one will actually be executed. The procedure to be used will be the one which is most restrictive, that is, the one which applies most closely to the situation in question. For example, suppose you specify the file-name-l option and the OPEN option, and you get an error when you attempt to open file-name-l. The procedure you specified for the file-name-l option will be executed, but the procedure for the OPEN option will not, because it is less restrictive. 5-109 and THE PROCEDURE DIVISION USE (Cont.) If the filename-l OPEN format is used, the system performs the associated procedures only if a "FILE BEING MODIFIED" error occurs when an attempt is made to open an output file. After performing the procedure, the system automatically "tries again to open the file, repeating this process until the file is opened. This option allows you to suspend your job until it can access a file that another user" is modifying. 8. Identifier-l in Format 2 represents a report group named in the Report Section of the Data Division. An identifier must not appear in more than one USE statement. The report group must not be TYPE DETAIL. 5-110 THE PROCEDURE DIVISION l\~ITE 5.9.43 WRITE Function The WRITE statement transfers a logical record to an output file. General Format WRITE reco rd-name [FROM i denti fi er-l] [{ [ BEFOREt ADVANCING AFTER J AT Jl] l{ i denti fi er-2 } [LINE integer LINES {mnemOnic-name} PAGE END-OF-PAGE}.. lmperatlve-statement] { EOP WRITE reco rd-name [FROM i dent i fi erJ [I NVALI D KEY i mpe rat i ve-s tatementJ Technical Notes 1. An OPEN OUTPUT, OPEN 1-0, OPEN INPUT-OUTPUT or OPEN EXTEND statement must be executed for the file prior to the execution of the WRITE statement. 2. After the WRITE is executed, the data in record-name-l may no longer be available. 3. Record-name-l must be the name of a logical record in a DATA RECORDS clause of the File Section of the Data Division. 4. Format 1 is valid for any file currently open for output with ACCESS MODE IS SEQUENTIAL. The ADVANCING clause allows control of the vertical positioning of the paper form for print files as follows: If the ADVANCING clause is . not recording mode is ASCII, BEFORE assumed. b. If, identifier-2 or integer-l is specified, it must represent a positive integer or zero. The form is advanced the number of lines equal to the value of identifier-2 or integer-I. 5-111 specified ADVANCING and the 1 LINE is a. THE PROCEDURE DIVISION WRITE (Cont.) c. If mnemonic-name is specified, the form is advanced until the specified channel is encountered on the paper-tape format control loop. Mnemonic-name must be defined by a CHANNEL clause in the SPECIAL-NAMES paragraph of the Environment Division. d. If the BEFORE option is used, before the form positioning. e. If the AFTER option is used, the record is printed after form positioning occurs, and no form positioning takes place after the printing. the record is printed If end-of-reel is encountered while writing on magtape, WRITE statement performs the following operations the a. A file mark is written, and the tape is rewound. b. If the file was assigned to more than one tape unit, units are advanced. the c. If labels are not OMITTED, a label is written on the tape. new 5. If the END-OF-PAGE phrase is specified, the LINAGE clause must be specified in the file description entry for the associated file. The words END-OF-PAGE and EOP are equivalent. 6. The ADVANCING mnemonic-name phrase cannot be specified when writing a record to a file whose file description entry contains the LINAGE clause. 7. The POSITIONING clause allows control of the vertical positioning of the paper form for print files. The record is written after the printer page is advanced according to the following rules: a. If identifier-2 is specified, it must be described as a one character alphanumeric item; that is, with PICTURE X. The valid values that identifier-2 can contain and their interpretations are as follows. blank o + 1-8 Single spacing Double spacing Triple spacing Suppress spacing Skip to channels 1 through 8 respectively on the paper-tape format control loop 5-112 THE PROCEDURE DIVISION WRITE (Coot.) Note that the object-time system interprets the value in identifier-2, substituting the proper positioning characters into the ASCII file. The character stored in the field named identifier-2 is not stored in the output file. b. If integer-l is specified, it must be unsigned, and m.ust be one of the values 0, 1, 2, or 3. The values have the following meanings. a 1 2 3 Skip to channel 1 of next control "eject") Single spacing Double spacing Triple spacing page (carriage 8. Either ADVANCING or POSITIONING can be specified for a file, but not both. Also, if either is specified, the recording mode of the file will be ASCII, regardless of the recording mode specified in the RECORDING MODE clause. 9. When a WRITE statement is executed for a file whose access mode is RANDOM and the RELATIVE KEY contains a value of 0, records will be written sequentially in the file (that is, no records will be left null). If the previous operation performed on the file was by a READ statement, the previous record will be replaced (that is, the record will be updated) • The statement(s) in the INVALID KEY clause is executed when the RECORD KEY contains a value equal to the key of an already existing record in an INDEXED file (refer to the REWRITE statement, Section 5.9.31). 10. When executing a WRITE statement for a SEQUENTIAL file opened for INPUT-OUTPUT, the logical record is placed on the file as the next logical record if the previous input-output operation was a WRITE, or it replaces the previous record if the previous input-output operation was a READ. 11. The INVALID KEY phrase must be specified if an applicable USE procedure is not specified for the associated file. 12. If the FROM option is used, the statement is equivalent to: ~ MOVE identifier-l TO record-name-l WRITE record-name-l (without the FROM option) Note that identifier-l must be a data-name and figurative constant (for example, SPACES), syntactically equivalent to a literal. 5-113 cannot be a because it is THIS PAGE INTENTIONALLY LEFT BLANK. THE PROCEDURE DIVISION VERB FORMATS THE PROCEDURE DIVISION GENERAL FORMAT· FOR PROCEDURE DIVISION PROCEDURE DIVISION ~SING data-name-I ~ata-name-2~ .J UECLARATI VES. { section-name SECTION ~a ragraph-name. C=segment-number~ [sentence] ... ] declarative-sentence ... } END DECLARATIVES~ { section-name SECTION ~egment-numberJ [:aragraPh-name . [sentence] ... ] } 5-114 THE PROCEDURE DIVISION FORMAT FOR VERBS GENEP~L ACCEPT identifier-I j DATE ACCEPT i denti fi er FROM ) DAY ~ TIME ADD {identifier-I literal-l {i~entifier-I} llteral-I l i denti fi er-2] [ 1 i teral-2 [i dentifi er-n [ROUNDE:gf] ADD - ... [fROM mnemonic-name] identifier-2 " • TO identifier-m QOUNDEDJ [ON SIZE ERROR imperati ve-statemen~ {identifier-2} [identifier-3] literal-2 literal-3 [ROUNDE~ ~ dent i fi er-n [}OUNDED~ GIVING i dentifi er-m [ON SI ZE ERROR imperati ve-statementJ ADD {CORRESPONDING} CORR i denti fi er-I TO i denti fi er-2 fROUNDEOJ L.:: [ON SIZE ERROR imperative-statement] ALTER procedure-name-I TO ~ROCEED TOJ procedure-name-2 ~procedure-name-3 TO ~ROCEED TO~ procedure-name-4 :J CALL r, identifier-Il program-name ~SING data-name-I entry-name ~ [ data-name-2 1 ~ON OVERFLOW imperative-statemen~ 5-115 .. J THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS CANCEL {identifier-I} subprogram-I i denti fi er-2] [ subprogram-2 o~~~~ D~ CLOSE file-name-l WITH NO REWIND}} { LOCK DELETE REMOVAL {FOR ~ WITH fi 1 e-·name-2 NO REWI ND }} { LOCK DELETE REMOVAL { FOR [?ITH LOCK] ~il e-name-2 CLOSE fil e-name-1 COMPUTE i dentifi er-1 [ROUNDED J [WITH LOCK J] ~; ~;~;! ji ~r-2 . (IJ.OUNDEDJl ". LJ arlthmetlc-expresslon ~ ~ j IS EQUAL TO ~ ( :QUALS I arithmetic-expression [ON SIZE ERROR imperative-statement] DELETE file-name RECORD i denti fi er- DISPLAY { literal-l [INVALID KEY imperative-statement] r 1.} llliteral-2 ~i dent,i fi er-2 fJ""" I,LUPON mnemonlc.: It:; :--, naml :.JL1ITH NO ADVANCIN~ 5;...116 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS DIVIDE identifier-I} { 1itera1-I [; denti fier-3 01 VI DE INTO identifier-2 [30UNDEDJ] identifier-I} { 1itera1-I ... INTO -- BY identifier-I} { 1itera1-I REMAINDER identifier-4 identifier-I} { 1itera1-1 REMAINDER identifier-4 ENTE R MACRO ) FORTRAN} { COBOL , [ ON SIZE ERROR imperati ve-statementJ {i~entifier-2} 11 teral-2 identifier-2} { 1iteral-2 GIVING identifier-3 'ROUNDED! L1 U GIVING identifier-3 [JROUNDED~ II ~N SIZE ERROR imperati ve-statemen~ Edenti fi er-4 [ROUNDEQ] DIVIDE - J [ON SIZE ERROR imperative-statemen!J tdenti fi er-4 [ROUNDEI[]] identifier-I} { 1itera1-I In ~OUNDED INTO -- {i~entifier-2} 11teral-2 GIVING identifier-3 [JROUNDEDI U IJN SIZE ERROR imperative-statemenQ BY -- identifier-2} { 1iteral-2 Ii: [ON SIZE ERROR imperative-statemenI] ~~ING t ~ identifier-l 1itera1-1 procedure-name-l ENTRY ent ry- name [US I NG i de nt ifi er-l 1 EXIT [lROGRAMJ • 5-117 ~~ ~ ; denti fi er-2 1iteral-2 ~ procedure-name-2 ) [) dent i fi e r-;[J EXIT. =)J GIVING identifier-3 L!0UNDE~ .. J THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS RECORD [KEY - fi1e-name-l J i~entifier-l 1 lltera1-1 I] } { EVERY RECORD FREE identifier-2 ,fi le-name-2 { RECORD [ KEY [ 11i tera 1-2 EVERY RECORD EVERY RECORD [NOT RETAINED statement-l GENERATE [,statement-2] ... ] ~ data-name } { report-name GO TO procedure-name-l [procedure-name-2] procedure-name-n DEPENDING ON identifier GOBACK. } 1£ condition {statement-l [ELSE NEXT SENTENCE INITIATE report-name-l statement-2 }] {NEXT SENTENCE [report-name-2] 5-118 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS INSPECT identifier-l TALLYING INSPECT identifier-l REPLACING CHARACTERS BY {i~entifier-6} fJ{SEFORE} llteral-4 ~AFTER .:::..:.:..:.:..:.:...:~:..:.:.::. - {i~entifier-7}1 INITIAL ~enti fi er-5} -- {i'lteral-4 ~enti fi er-b} ~{BEFORE} { ~~~DING} ~{it llteral-3 I ( BY FIRST J llteral-5 INITIAL U~FTER I1 identifier-7}]1 . . . . .. {"literal-5 INSPECT identifier-l TALLYING i dentifi er-2 { FOR!{{~~~DING} ~ 1~~;:f~ ~r-3}} [{~~;~:E} ~ CHARACTE RS INITIAL --- i dentifi er-4}J} .,. {literal-2 I .., REPLACING CHARACTERS BY .=.;.;,:...;;,;..;.;..;.;;..":,,..=.,;..;,.:; ( -- {i ~enti fi er-6} llteral-4 ~ {~~~DIN(} ~ {i ~enti fi er-5} ~ { llteral-3 { BEFORE} [{AFTER INITIAL {~1~~;!f~~r-7}J identifier-6} BEFORE} {literal-4 [{ AFTER BY MERGE [WITH SEQUENCE CHE CKJ fil e- name-l ON [ON INITIAL {ASCENDING } KEY data-name-l {ASCENDING } KEY data-name-3 DESCENDING DESCENDING ~COLLATING SEQUENCE IS alPhabet-name~ USING file-name-2 file-name-3 [file-name-4] OUTPUT PROCEDURE IS section-name-l THROUGH THRU GIVING file-name-5 5-119 section-name-2 {i~entifier-7}J' llteral-5 f'" I... [ [ . J. data -name-2] data-name-4] 1 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS MOVE i dent i fi er-l} { literal MOVE {CORRESPONDING} - - CORR MUL T1PL Y TO identifier-2 identifier-3] identifier-l TO identifier-2 {~~~~;! i~ ~r-l} !y i dentifi er-2 [ROUNDED] [i dentifi er-3 [ROUNDED]] ~~ULTIPLY [ {i?entifier-l} BY llteral-l -- [ON SIZE ERROR i mperati ve-statement] {i?entif-;oer-2} llteral-2 [identifier-4 [ROUNDED]] •.. GIVING identifier-3 [ROUNDED] [ON SIZE ERROR imperat.ive-statement] PERFORM procedure-name-l [ { THROUGH THRU } procedure-name-2 ] PERFORM procedure-name-l [ { THROUGH THRU } TIMES } procedure-name-2 ] {identifier-l i nteger-l THROUGH PERFORM procedure-name-l [{ THRU } procedure-name-2 ] UNTIL condition-l 5-120 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS PERFORM procedure-name-l [{=UGH } procedure-name-2 ] VARYING BY [AFTER BY [ AFTER BY {~dentifier-2} FROM 1 ndex-name-l -identifier-4} {literal-3 i denti fi er-3} index-name-2 { literal-l UNTIL condition-l FROM f UNTIL condition-2 {~dentifier-8} FROM 1 ndex-name-5 -- i denti fi er-9 index-name-6 literal-5 i denti fi er-lO} {literal-6 co ndit ion - 3] ] t denti fi er-5} index-name-3 t denti fi er-7} literal-4 READ fi 1 e-name dentifi er-6} index-name-4 literal-3 UNTIL [NEXT] RECORD [INTO i denti fi erJ [AT END imperative-statement] READ file-name RECORD [INTO identifier] [INVALID KEY imperative-statement] READ file-name RECORD [INTO identifier] [KEY IS data-name] ~INVALID KEY imperative-statement] RELEASE record-name [FROM i denti fi erJ 5-121 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS SEARCH identifier-l [VARYING WHEN condition-1 [ WHEN conditi on-2 }l dent i fi er- 2 rAT EN 0 i mperati ve-s tatement-1] { 1~ ndex-name-l ~ ~ . imperative-statement-2 } { NEXT SENTENCE imperative-statement-3 }] ... { NEXT SENTENCE SEARCH ALL identifier-1 [AT END imperative-statement-1] Jdata-name-l {i~ EQUAL TO} WHEN ) {i denti fi er-3 } } 1 i tera 1-1 arithmetic-expression-1 { condition-name-1 [AND IS EQUAL TO} {identifier-4 }}] a a-name- 2 { IS = 1iteral-2 {dt 2 arithmetic-expression-2 : .. , con d ll-lon-name- imperati ve-statement-2 } { NEXT SENTENCE SET {identifier-1 index-name-1 SET in dex- name-4 [ i denti fi er-2 ] [index-name-2 ] [index-name-5] } TO .•. i denti fi er-3 } { ~ ndex-name-3 lnteger-1 UP BY } {i denti fi er-4 } { DOWN BY integer-2 5-122 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS SORT file-name-l ON {ASCENDING} DESCENDING KEY data-name-l [data-name-21 ~J ASCENDING } { DESCENDING KEY data-name-3 [ data-name-4] . J. [COLLATING SEQUENCE IS alPhabet-name] NPUT PROCEDURE fI IS section-name-l USING flle-name-2 [{THROUGH} THRU secti on-name-2] } [fil e-name-3] OUTPUT PROCEDURE IS section-name-3 [ {THROUGH} THRU section-name-4] I GIVING file-name-4 START file-name KEY IS EQUAL } IS - - TO IS GREATER THAN IS ) { IS NOT LESS THAN IS NOT " ( data-name [INVALID KEY imperative-statement] RUN } STOP {i"Tteral STRI NG {i ~ent i fi er-l} [i denti fi er-2] llteral-l DELI MI TE D BY literal-2 (i denti fi er-3) {literal-3 } \SIZE DELIMITED BY INTO identifier-7 [WITH POINTER identifier-8] [ON OVERFLOW imperative-statement] 5-123 ~enti , lJ i fi er-6 llteral-6 ( ... { SIZE , THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS SUBTRACT '{i~entifier-It [i~entifier-2J llteral-I ~ llteral-2 [identifier-n [ROUNDED]] SUBTRACT ... [ON SIZE ERROR imperative-statement] {i~entifier-I} [i~entifier-2l llteral-I llteral-2 FRm~ identifier-m [ROUNDED] i dent i fi er-m} { 1 i tera 1-m ~ GIVING identi fier-n [ROUNDED] [i denti fi-er-o [ROUNDED J] ... ~ON SIZE error imperative-statement] SUBTRACT {:ESPONDING} identifier-l FROM identifier-2 [ROUNDEQ] [ON SIZE ERROR imperative-statement] TERMINATE report-name-I TRACE [report-name-2] {~~F} UNSTRING identifier-I [DELIMITED BY [ ALL] {identifier-2} literal-I ~enti OR [ALL] {i fi er-3}] llteral-2 [ - ... J INTO identifier-4 [DELIMITER IN identifier-5][COUNT IN identifier-6] [i denti fi er-7 [DELIMITER IN i dentifi er-a] [COUNT IN i dentifi er-g]] [WITH POINTER identifier-I~[TALLYING IN identifier-II] r=ON OVERFLOW imperative-statement~ 5-124 THE PROCEDURE DIVISION GENERAL FORMAT FOR VERBS USE AFTER STANDARDI{~~~6:TION t ,-- t '{ fi 1e-name-I INPUT PROCEDURE ON. OUTPUT OPEN[fil e-name-2 ]OPEN .•. } 1-0 EXTEND USE BEFORE REPORTING identifier. WRITE record-name [FROM identifier-I] BEFORE [ { AFTER t ADVANCING l{:~~~~!~i er-2 } [ti~~sJIJ f {mnemOnic-name} PAGE [ AT END-OF-PAGE}.. lmperatlve-statement] { EOP WRI TE record-name [FROM i dent i fi erJ [INVALI D KEY imperat i ve-statementJ 5-125 • CHAPTER 6 COMPILER COMMAND STRINGS The general form of the compiler command string is as follows: relfil,lstfil= libfil/l, srcl,src2, •.. where: relfil is the file that is to hold the generated code. If no generated code is desired, the file description for relfil is replaced by a hyphen. Example: lstfil -,lstfil=srcl,src2 ••. is the file that is to hold the generated listing. If no listing is desired, the file description for Istfil is replaced by a hyphen. Example: relfil,-=srcl,src2, •.. libfil is the optional library file verbs in the source files. referenced by COpy srcl,src2 are one or more source files required to form input program. one Each file description has the following form: device:file.ext [project,programmer]/switch/switch where: device is the name of a physical or logical device. The name is composed of 6 or fewer letters and/or digits. file is the name of a file. The name is of 6 or fewer letters and/or digits. ext is the filename extension. It is composed 3 or fewer letters and/or digits. project is a user's project number. programmer is a user's programmer number. switch is any of the switches shown in Table 6-1. 6-1 composed of COMPILER COMMAND STRINGS Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. Certain default assignments are made by the compiler whenever terms are omitted from the command strings or the file descriptions. 1. If the device is omitted in any output file description, DSK is assumed. If the device is omitted in an input file description, either the preceding device or DSK (if no preceding device is specified) is assumed. 2. If the filename for relfil and/or lstfil is omitted, filename of the first source file is used. 3. If the filename extension is omitted from relfil, .REL is assumed; if it is omitted from lstfil, .LST is assumed. If the extension is omitted from the source file descriptor, the compiler looks in the file area for the named file with the extension .COB. If that file is not found, the compiler looks for the named file with the extension .CBL. If that file is not found, the compiler looks for the named file without an extension. If the extension is omit~ed from the library file description, .LIB is assumed •. 4. If the [project,programmer] option is omitted on any file, ~he user's default path is used. On TOPS-20, the connected directory is used. the Examples: MTAl:RELOUT.A/W,LPT:=DSK:SRCIN.C [27,36]/M/S The compiler compiles the program found in the file SRCIN.C in the area reserved for project-programmer 27,36. It treats columns 1-6 of the source as a sequence number (/S). The generated code is written on MTAl, after the tape is rewound (/W). The listing, including maps (1M) is put on the LPT. =LIBl/L,PROG/A The compiler compiles the program found in PROG.CBL (CBL is assumed because the filename extension is omitted from the source file descriptor) on the disk, using LIBl.LIB whenever a COpy verb is seen (/L). The generated code goes into the file DSK:PROG.REL, and the listing onto the file DSK:PROG.LST. The generated code is listed (/A). -=LIBl/L,PROG/A This is identical to the preceding example, with the exception that no generated code is produced because the file descriptor for the file has been replaced by a hyphen. 6-2 COMPILER COMMAND STRINGS Table 6-1 COBOL Switch Summary Switch Action by Compiler A List the machine code generated in the lstfil. B Generate code for all DEBUG lines (those with /D in col. 7) which otherwise would be treated as comments. C Produce a cross-reference user-defined symbols. D:nnnnnn Increment, in octal words, to be object time push down list size. E Check program for errors, but code. H Type description of COBOL-74 command strings and switches. I Suppress output of start address (program is be used only by CALL's). to J Force output of start address in presence of 'subprogram syntax. the L Use the preceding source file as a library file whenever a copy verb is encountered. If the first source file is not a /L file, LIBARY.LIB is used as the library file until the first /L file is encountered. (The default extension for library files is ".LIB".) M Include a map of the user defined items lstfil. in N Do not type compilation terminal. the user's o Optimize the object code. P Production mode. relfil. Omit debugging features from Q Quick mode. DO.not range check turn on /0 and /P. PERFORMs, also R Produce a two-segment object program. The high segment will contain the procedure division; the low segment all else. S The source file is in "conventional" format (with sequence numbers in cols. 1-6 and comments starting in col. 73). U Produce a one-segment object program. 6-3 table of all added to the not generate do errors spite on of the COMPILER COMMAND STRINGS Table 6-1 (Cont.) COBOL Switch Summary Switch Action by Compiler W Rewind the device (magtape only). X Give a usage of DISPLAY-9 to items whose is either omitted or declared as DISPLAY. Y Flag DIGITAL extensions to ANS-74 standard. Z Zero the directory of the device before (DECtape only) . 6-4 before reading or writing usage writing CHAPTER 7 COBOL-74 UTILITY PROGRAMS COBOL-74 provides several utility programs that allow you to perform certain operations within your COBOL program. These utility programs are: • ISAM - Indexed-Sequential File Maintenance Program ISAM provides you with the ability to create and maintain indexed-sequential files (see section 7.1). • LIBARY - Source Library Maintenance Program LIBARY provides you with the facility to create, modify, and delete statements or groups of statements in a library file (See Section 7.2). • COBDDT - Program For Debugging COBOL Programs COBDDT provides you with the ability to: • RERUN 1. Look for areas of error by setting breakpoints 2. Trace the activity of procedures 3. Display and, if necessary, change the contents of data-items 4. Determine time spent in sections of the program by analyzing a histogram (see Section 7.3) - Program to Restart COBOL-74 Programs RERUN provides you with the ability to restart a COBOL-74 program after an abnormal termination has occurted (See Section 7.4). 7-1 COBOL-74 UTILITY PROGRAMS NOTE Many of the examples in this chapter are written for only one operating system that is, they have either the TOPS-IO prompt (.) or the TOPS-20 prompt (@) alone. However, unless you are told otherwise, the examples apply to both TOPS-IO and TOPS-20. Thus, in this chapter you may substitute .R (program name) <RET> for @(program name) <RET> and vice versa. 7.1 ISAM - INDEXED-SEQUENTIAL FILE MAINTENANCE PROGRAM Indexed-sequential files are created, maintained, and compacted for backup storage by means of the ISAM program. ISAM performs the following functions: 1. Builds an indexed-sequential file from a sequential file 2. Maintains an indexed-sequential file by reorganizing it 3. Packs an indexed-sequential file into a sequential backup storage ISAM has the following switches which you may functions: use to these (this switch may only be used Build an indexed file from a sequential one I Ignore errors in packing a file with the P switch) L Read or write standard tape labels (this switch used with the B or P switches) may M Maintain your indexed file by reorganizing it Pack your indexed file for backup storage Figure 7-1 shows the COBOL-74 ISAM File Environment. 7-2 for perform B P file only be COBOL-74 UTILITY PROGRAMS (INPUT SEQUENTIAL DATA FILE) R ISAM G (BUILD) t R ISAM RUN MYPROG (MAINTAIN) 'USER'S APPLICATION PROGRAM' ~_ ~ RISAM / / (PACK) (OUTPUT SEQUENTIAL BACKUP FILE) MR-S-029- 79 Figure 7-1 COBOL-74 ISAM File Environment 7-3 COBOL-74 UTILITY PROGRAMS 7.1.1 Building an Indexed-Sequential File To build an indexed-sequential file you must provide a sequential file in which the record keys are arranged in ascending order. The ISAM program will use this file to create an indexed-sequential data file with a user-specified number of empt~ records and blocks. ISAM then creates the index file according to the description of the data file. To run the ISAM program and select the option indexed-sequential file, type the following: for building the .R ISAM<RET> for users of TOPS-IO or @ISAM~RET> for users of TOPS-20 *devl:indfil.ext[ppnl] ,dev2:datfil.ext=dev3:seqfil.ext[ppn2]/B where: devl, dev2, and dev3 are the devices for the index, data, and input sequential file. Devl and dev2 must be disk. The default for devl, dev2, and dev3 is DSK. indfil.ext is the name and extension of the index file. If the filename is not specified, the name of the input file is assumed. If the extension is omitted, .IDX is assumed. datfil.ext is the name and extension of the data file. If the filename is omitted, the name of the index file is assumed. If the extension is omitted, .IDA is assumed. seqfil.ext is the name and extension of the input sequential file. This filename must be specified, but the extension can be omitted. If it is omitted, .SEQ is assumed. [ppnl], [ppn2] specify directories for the index file and the input file, respectively. If either is omitted, then the directory of the logged-in user is assumed. The data file must reside in the same directory as the index file. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. /B is the switch signifying that ISAM will be used to build an indexed-sequential file. If the switch is omitted from the command string, /B is assumed. The equal sign (=) can be omitted if the specifications for the output files are omitted. After reading the command string, ISAM asks a series of questions, which are described below. Every question must be answered. MODE OF INPUT FILE: Reply with S, A, F, V, or ST according to the mode of the input file. S means SIXBIT, A means ASCII, F means fixed-length EBCDIC, V means variable-length EBCDIC, and ST means STANDARD-ASCII. 7-4 COBOL-74 UTILITY PROGRAMS MODE OF DATA FILE: Specify S, A, F, or V according to the mode in which the ISAM data file is to be recorded. S means SIXBIT, A means ASCII, and both F and V mean EBCDIC, as above. If the mode of the input file differs from that of the data file, characters will be converted in the same manner as they are converted in standard COBOL-74 operations. MAXIMUM RECORD SIZE: Specify the size of the largest record in the input file in bytes. For ASCII records you should not count the carriage return and line feed that are appended to each ASCII record. KEY DESCRIPTOR: Describe the key upon which the file is to be that has the form: a code m specifies the number of the character in the record where key begins. the n specifies the size of the key in characters for types X and N or in digits for types C and P. If nis less than or equal to 10 for type C, one word is used. If n is greater than 10, two words are used. n is ignored for type F because' it is always one word long. [s] indexed using [x]m.n where: s designates· the sign of the key: S - the key is signed U - the key is unsigned x indicates the key type: X - the key is nonnumeric N - the key is numeric display C - the key is COMPUTATIONAL F - the key is COMPUTATIONAL-l P - the key is COMPUTATIONAL-3 The following rules apply to the key descriptor: 1. The key type is optional: if S or U are default is N. Otherwise, the default is X. 2. The key sign is optional; is not X. the default is S if the 3. The sign designators S conjunction with type X. or 4. m and n must be specified. 7-5 U cannot be specified the key type specified in COBOL-74 UTILITY PROGRAMS RECORDS PER INPUT BLOCK: Give the blocking factor of the input file. o should be specified. If the file is unblocked, TOTAL RECORDS PER DATA BLOCK: Give the total number of records to be contained in each block of data file. the EMPTY RECORDS PER DATA BLOCK: Specify the number of records that are to be initially left each block of the data file. empty in in each TOTAL ENTRIES PER INDEX BLOCK: Specify the total number of index entries block of the index file. to be contained EMPTY ENTRIES PER INDEX BLOCK: Specify the number of index entries that are to be initially left empty in each index block. Note that at least two entries must be available in each index block, so that the number of total entries minus the number of empty entries must equal or exceed two. PERCENTAGE OF DATA FILE TO LEAVE EMPTY: Give, as a percentage of the total number of blocks, blocks to be initially left empty in the data file. the number of the number of PERCENTAGE OF INDEX FILE TO LEAVE EMPTY: Give, as a percentage of the total number of blocks, blocks to be initially left empty in the index file. MAXIMUM NUMBER OF RECORDS FILE CAN BECOME: Reply with the maximum number of records that the data file can possess before the file is next maintained. This number sets the upper limit of the size of the data file. It is required because storage allocation tables must be set up in the index when the file is created. There is no harm in making this number excessively large because the index data blocks are allocated in the storage allocation tables, but not actually assigned until needed. Example - Building an indexed-sequential file .R ISAM *TEST.IDX, TEST.IDA=TEST.SEQ /B MODE OF INPUT FILE: SIXBIT MODE OF DATA FILE: SIXBIT MAXIMUM RECORD SIZE: 40 KEY DESCRIPTOR: SN37.4 (The key is signed numeric display; it begins in the thirty-seventh byte; and it is four bytes long.) RECORDS PER INPUT BLOCK: 3 TOTAL RECORDS PER DATA BLOCK: 2 E,MPTY RECORDS PER DATA BLOCK: 1 TOTAL ENTRIES PER INDEX BLOCK: 3 EMPTY ENTRIES PER INDEX BLOCK: 1 PERCENTAGE OF DATA FILE TO LEAVE EMPTY: 60 PERCENTAGE OF INDEX FILE TO LEAVE EMPTY: 10 MAXIMUM NUMBER OF RECORDS FILE CAN BECOME: 12000 7-6 COBOL-74 UTILITY PROGRAMS 7.1:2 Maintaining an Indexed-Sequential File The ISAM program allows you to maintain an existing 'ISAM file after the file has become crowded. More empty space may be added to the file and the number of index levels may be decreased. That is, the files are rearranged and indexes are streamlined. The input is the indexed-sequential file and the output is a new indexed-sequential data and index file. The command string for the ISAM maintain option is as follows: .R ISAM<RET> for users of TOPS-IO or @ISAM<RET> for users of TOPS-20 *devl:indfil.ext[ppnl] ,dev2:datfil.ext=infil.ext[ppn2]/M<RET> where: devl, and dev2, are disk devices on which the files If any of the devices is omitted, DSK is assumed. are stored. indfil.ext is the name and extension of the new index file. the name is omitted, the name of the input file is assumed. the extension is omitted, .IDX is assumed. If If datfil.ext is the name and extension of the new data file. If the name is omitted, the name of the new index file is assumed. If the extension is omitted, .IDA is assumed. infil.ext is the name and extension of the index file of the old indexed-sequential file. The name of the file must be specified, but the extension can be omitted. No extension is assumed if the extension is omitted. [ppnl], [ppn2] specify directories for the new index file and the old index file, respectively. If either is omitted, the directory of the logged-in user is assumed. The new data file must reside in the same directory as the new index file. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. 1M is the switch indicating that the requested. maintain The switch must be specified. If the output file specifications are not string, the equal sign (=) can be omitted. included option in the is being command After the command string has been scanned, ISAM asks a series of questions about values for the new indexed-sequential file. The mode of the file, the record size, and the key cannot be changed. The values from the old file are given in parentheses with the question. If you wish to change a value, enter the new value; if you do not wish to change a value, press the RETURN key. All questions refer to the output file. 7-7 COBOL-74 UTILITY PROGRAMS TOTAL RECORDS PER DATA BLOCK (n): Specify the total number of records to be contained in each the data file. block of EMPTY RECORDS PER DATA BLOCK (n): Give the number of data records that are to be initially left empty in each data block. TOTAL ENTRIES PER INDEX BLOCK (n): Give the total number of index entries to be contained in of the index file. each block initially left EMPTY ENTRIES PER INDEX BLOCK (n): Specify the number of index entries that empty in each index block. are to be PERCENTAGE OF DATA FILE TO LEAVE EMPTY (n): Give, as a percentage of the total number of blocks, blocks to be initially left empty in the data file. the number of the number of PERCENTAGE OF INDEX FILE TO LEAVE EMPTY (n): Give, as a percentage of the total number of blocks, blocks to be initially left empty in the index file. MAXIMUM NUMBER OF RECORD FILES CAN BECOME (n): Specify the maximum number of records that can be contained in the file. This number sets the upper limit on the size of the data file. It is required because storage allocation tables must be set up when the file is created. Example - Maintaining an indexed-sequential file .R ISAM(RET) *test.idx, test.ida=test 1m total records per data block (2): empty records per data block (1): total entries per index block (3): 32 empty entries per index block (1): 10 percentage ,of data file to leave empty (60): 50 percentage of index file to leave empty (10): 40 maximum number of recor~s file can become (12000) 7-8 25000 COBOL-74 UTILITY PROGRAMS 7.1.3 Packing an Inde&ed-Sequential File Packing an indexed-sequential file is the reverse of building one. An indexed-sequential file is copied into a sequential file in the order specified by the index. This option is used primarily to compact an indexed-sequential file for backup storage, although the resulting sequential file can be treated as any other sequential file. The command string for the packing option of ISAM is as follows: .R ISAM<RET> for users of TOPS-IO or @ISAM<RET> for users of TOPS-20 *devl:seqfil.ext[ppnl]=dev2:indfil.ext[ppn2] IP<RET> where: devl and dev2 are the devices on which the sequential file is to be stored and the index file resides, respectively. The input file must be on disk. If neither device is specified, DSK is assumed. seqfil.ext is the name and extension of the output sequential file. If the name is omitted, the name of the input file is assumed. If the extension is omitted, .SEQ is assumed. indfil.ext is the name and extension of the index file of the indexed-sequential file. The name must be specified, but the extension can be omitted. If the extension is omitted, no extension is assumed. [ppnl] [ppn2] are directories for the new sequential file and the old index file, respectively. If either is omitted, the directory of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. IP is the switch signifying that requested. the packing option is being It must be included. If the output file specification is omitted, the equal sign (=) can be omitted. After the command string has been processed, ISAM asks questions. the following MODE OF THE OUTPUT FILE: Specify SIXBIT (or S), ASCII (or A), F, V, or ST according to the mode in which the sequential file is to be recorded. V is variable-length EBCDIC, and F is fixed-length EBCDIC, and ST is STANDARD-ASCII. RECORDS PER OUTPUT BLOCK: Give the blocking factor that you want for the sequential file (i.e., the number of records per logical block). If the file is to be unblocked, the user answers O. 7-9 COBOL-74 UTILITY PROGRAMS Example - Packing an indexed-sequential file .R ISAM *MTA2:TEST.SEQ=TEST.IDX IP MODE OF THE OUTPUT FILE: SIXBIT RECORDS PER OUTPUT BLOCK: 0 7.1.4 Ignoring Errors When packing an indexed-sequential file into a sequential file, you can include the II switch in the command string to force ISAM to ignore certain fatal errors. This switdh causes ISAM to try to recover as much data as possible from a damaged indexed-sequential file. Including the II switch in the command string to ISAM causes the program to make nonfatal those errors that concern duplicate keys or keys out of order. The messages for these errors are preceded by a percent sign (%) rather than a question mark (?) so that ISAM will continue the packing operation. The II switch can be used only with the IP switch. It cannot be used alone. The command string when using the II and IP switches is as follows: .R ISAM<RET> for users of TOPS-IO or @ISAM<RET> for users of TOPS-20 *devl:seqfil.ext[ppnl]=dev2:indfil.ext[ppn2]/P/I<RET> where: devl and dev2 are the devices on which the sequential and index files reside, respectively. The input file must be on disk. If neither device is specified, DSK is assumed. seqfil.ext is the name and extension of the output sequential file. If the name is omitted, the name of the input file is assumed. If the extension is omitted, .SEQ is assumed. indfil.ext is the name and extension of the index file of the indexed-sequential file. The name must be specified, but the extension can be omitted. If the extension is omitted, no extension is assumed. [ppnl], [ppn2] are directories for the new sequential file and the old index file, respectively. If either is omitted, the directory of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programLler number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. 7-10 COBOL-74 UTILITY PROGRAMS .1-"-_ \,,11\::: IF is ~ne sw~~cn signifying that requested. It must be included. _ __ 1.":__ pCl\,;I\. J.uy __.&-': __ Vj:J~J.VH 15 II is the switch signifying that some ignored. fatal errors are It may be included only with the Ip switch. The equal sign (=) can specification is omitted. 7.1.5 be omitted if to output the be file Reading and Writing Magnetic Tape Labels When building or packing an indexed-sequential file, you can include the IL switch to cause ISAM to read or write labels on magnetic tape. The IL switch, when used with the IB switch, causes ISAM to read COBOL-74 standard tape labels on the input magnetic tape. When used with the IP switch, the IL switch causes ISAM to write standard tape labels on the output magnetic tape. The IL switch can only be used on magnetic tape files whose recording mode is not F or V. The command string when using the IL switch with the IB switch follows: is as .R ISAM<RET> for users of TOPS-10 or @ISAM<RET> for users of TOPS-20 *devl:indfil.ext[ppn] ,dev2:datfil.ext=MTAn:seqfil.ext/B/L<RET> where: devl, dev2, and MTAn are the devices for the index, data, input sequential file. Devl and dev2 must be disk devices. default disk for devl and dev2 is DSK. and The indfil.ext is the name and extension of the index file. If the filename is not specified, the name of the input file is assumed. If the extension is omitted, .IDX is assumed. datfil.ext is the name and extension of the data file. If the filename is omitted, the name of the index file is assumed. If the extension is omitted, .IDA is assumed. seqfil.ext is the name and extension of the input sequential file. This filename must be specified, but the extension can be omitted. If it is omitted, .SEQ is assumed. [ppn] specifies the directory for the index file. If it is omitted, the directory of the logged-in user is assumed. The data file must reside in the same directory as the index file. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. IB is the switch signifying that ISAM will be used indexed-sequential file. If command string, 18 is assumed. 7-11 the switch is to build an omitted from the COBOL-74 UTILITY PROGRAMS IL is the switch signifying that ISAM labels. It must be included. will read standard The equal sign (=) can be omitted if the file specifications output files are also omitted. The command string when using the follows: tape for the is as IL switch with the IP switch .R ISAM<RET> for users of TOPS-IO or @ISAM<RET> for users of TOPS-20 *MTAn:seqfil.ext=devl:indfil.ext[ppn]/P/L<RET> where: MTAn: and devl are the devices on which the sequential file is to be stored and the index file resides, respectively. The input file must be on disk. If the name of devl is not specified, DSK is assumed. seqfil.ext is the name and extension of the output sequential file. The name and extension can both be omitted because filenames are not used on magnetic tape. indfil.ext is the name and extension of the index file of the indexed-sequential file. The name must be specified, but the extension can be omitted. If the extension is omitted, no extension is assumed. [ppn] is a directory for the old index file. If it is omitted, the directory of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. IP is the switch signifying that requested. It must be included. the packing is being write standard tape The ISAM program accepts command strings and dialogue indirect command files. responses from IL is the switch signifying that ISAM will labels. It must be included. 7.1.6 option Indirect Commands The command string to direct ISAM to read an indirect command file is: .R ISAM<RET> for users of TOPS-IO or @ISAM<RET> for users of TOPS-20 *@dev:cmdfil.ext[ppn]<RET> 7-12 COBOL-74 UTILITY PROGRAMS where: @ indicates that this is an indirect command file. dev is the device on which the command file is stored. omitted, DSK is assumed. If it is cmdfil.ext is the name and extension of the command file. The name must be specified. If you omit the extension, .CMD is assumed. [ppn] is the directory in which the command file is stored. If it is omitted, the directory of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. After ISAM reads the command string, it reads the command file and performs the processlng specified within it. The command file must contain the complete command string and all dialogue responses for a single ISAM operation exactly as they would be typed if you were giving them directly to the ISAM program. Nothing else can be present in the command file. 7.1.7 Using Indexed-Sequential Files Indexed-sequential files can be read and written, and individual records within them can be rewritten or deleted. You can perform any actions on the records in an indexed-sequential file by specifying the desired record key in the RECORD KEY field. To use an indexed-sequential file, the following statements are employed: 1. 2. 3. 4. 5. 6. 4. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT ISAM-FILE ASSIGN TO DSK ORGANIZATION IS INDEXED ACCESS MODE IS DYNAMIC RECORD KEY IS ISAM-RECORD-KEY. DATA DIVISION. FILE SECTION. FD ISAM-FILE BLOCK CONTAINS 13 RECORDS VALUE OF IDENTIFICATION IS "ISAMFLIDX". 01 ISAM-RECORD. 02 FILLER PIC X(12}. 02 ISAM-RECORD-KEY PIC X(3}. 02 FILLER PIC X(75}. PROCEDURE DIVISION. BEGIN. OPEN INPUT-OUTPUT ISAM-FILE. 7-13 COBOL-74 UTILITY PROGRAMS 7. READ ISAM-FILE, INVALID KEY GO TO ERRPROC. 8. WRITE ISAM-RECORD, INVALID KEY GO TO ERRPROC. 9. DELETE ISAM-RECORD, INVALID KEY GO TO ERRPROC. 10. 11. REWRITE ISAM-RECORD, INVALID KEY GO TO ERRPROC. READ ISAM-FILE NEXT RECORD, INVALID KEY GO TO ENDFILE. The notes in the following list are keyed to the numbers to, of the lines in the preceding program. the left 1. The indexed-sequential file must reside on disk. 2. The ORGANIZATION clause is required. 3. The ACCESS MODE clause is required if you wish to access the file in random fashion, since the ACCESS MODE defaults to sequential. When DYNAMIC is specified, as here, either random or sequential access may take place. 4. The RECORD KEY clause is required in the Environment Division and refers to the data-item designated as the record key which appears in the Data Division within the FD area record description for the indexed-sequential file. 5. An indexed-sequential file must be blocked. 6. The VALUE OF IDENTIFICATION clause is required. It designates the filename and extension of the index file rather than that of the data file. The name of the related data file is stored within the index file. The VALUE OF IDENTIFICATION must be specified because the name of th~ file must be present at initialization time so that the buffer and storage space can be allocated. 7. The READ statement reads the indexed-sequential file to find the record whose key as written on the file matches the record key. If no match is found, the INVALID KEY path is taken. 8. The WRITE statement writes the record that has a key that matches the record key. If the record whose key matches the record key is already in the file, the INVALID KEY path is taken. 9. The DELETE statement causes a search to be made of the file to find the record whose key matches the record key. When the record is found, it is deleted. If the record is not found, the INVALID KEY path is taken. 10~ The REWR~TE statement causes searching of the file to find the record whose key matches the record key. When the record is found, it is replaced with the contents of the record specified in the REWRITE statement. If the record is not found in the file, the INVALID KEY path is taken. 7-14 COBOL-74 UTILITY PROGRAMS 11. 7.2 This snows ~ne method used to read an indexe~-sequential file sequentially. When the READ statement 1S executed, the record accessed is the first record whose record key has a value higher than the last record processed by a READ, WRITE, REWRITE or DELETE statement. If the file has been opened but no READ, WRITE, DELETE or REWRITE statement has been executed, the first record of the file is read. LIBARY - SOURCE LIBRARY MAINTENANCE PROGRAM LIBARY provides a facility for creating or maintaining COBOL library files on disk or DECtape (TOPS-IO only). Library files contain COBOL source-language text organized into statement groups. Specifically, the LIBARY program has the capability of adding source-language text to the library file, replacing and/or deleting lines or whole statement groups, and providing a listing of the file. It allows you to specify those data descriptions or procedures used in many programs and to place them in a common file for use by the COBOL compiler. The statement groups in the library file are included in a COBOL program through the use of the COpy verb. (See Part 2, Section 1.4, for information on the COpy verb.) 7.2.1 Library File Format A library file is a collection of COBOL source-language statement groups, each identified by a unique 1- to 8-character library-name. The library file must be on a directory device. Each statement group is a set of ordinary COBOL language statements conforming to the use of the COpy verb. The statement groups are kept in alphabetic order according to their library names. The maximum number of statement groups that can appear in a library is 3869. The library file is in a LIBARY and the COBOL yourself with the format them as ASCII text; automatically. 7.2.2 binary format that is recognizable only by compiler. You, however, need not concern of the actual entries in the file. You enter LIBARY stores them in the appropriate format Invoking The Library Utility To invoke the library utility program, enter R LIBARY in response to the TOPS-IO prompt (.) or LIBARY in response to the TOPS-20 prompt ( @). Th a t i s , .R LIBARY<RET> for users of TOPS-IO or @LIBARY<RET> for users of TOPS-20 7-15 COBOL-74 UTILITY PROGRAMS When LIBARY is ready to process commands, it issues an asterisk prompting character and waits for you to enter a file specification command line. The file specification command line identifies the library files being either created or used as input. It also identifies the listing file if a listing is required. Enter the file specification command line according to the following format: *output-library,listing=input-library<RET) where: output-library - is the file specification for the being generated. library listing - is the file specification for the file to receive the output listing. input-library - is the file specification for the being used as input. that library file is file Each file specification has the following format: dev:filename.ext[ppn]/sw where: dev: - is the logical device name for the unit on which the desired file is mounted. The default assignment is DSK:. filename - is the name of the file consisting of from one to six SIXBIT characters. Filename must be specified for at least one library file. .ext - is the filename extension consisting of a period followed by zero to three characters. It is used to indicate the type of information in the file. [ppn] is the directory area in which the file is stored. The directory specification, enclosed in brackets, contains the project-programmer number of the file's owner. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. /sw - is one ASCII character preceded specifying a LIBARY switch option. 7.2.4, LIBARY Switches.) by a slash (See Section After you have invoked LIBARY and given it a file specification command line, it automatically creates a scratch file to contain the output file generated by the LIBARY run. When you are through working on your library file and enter the END command (See Section 7.2.6.4, LIBARY Directing Commands), LIBARY renames the scratch file with the proper output name (after any necessary renaming of the input file). 7-16 COBOL-74 UTILITY PROGRAMS If an error occurs causing ~ne execution of LIBARY to be aborted, the input file, if specified, will be unchanged and the scratch file will be deleted. If the error occurred after the input file has been renamed, the original input file has an extension of .BAK. 7.2.3 Command String Defaults The following default values are assumed by LIBARY if any part of file specification is omitted. any 1. If any device is not specified, DSK is assumed. 2. If the file specification for the listing file is omitted, no listing will be produced. 3. If the name of the listing file is omitted, the name input file is assumed. of the 4. If the extension of the listing assumed. .LST is 5. If the file specification for the output file is omitted, is assumed that there is no output file to be produced. it file is omitted, NOTE If you are omitting the output file because you want to run LIBARY to obtain a listing only, the listing file specification, the input file specification, and the /L switch must be specified. 6. If the name of the output file is omitted, the input file is assumed. 7. If the extension of the assumed. 8. If the file specification of the input file is omitted, it is assumed that there is no input file and that a library is being created. Thus, only commands for insertion can be used. 9. The filename for the input file cannot be omitted if the file specification is present. 10. If the extension of assumed. 11. If any project-programmer number is omitted, it is assumed to be that of the logged-in user. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. 12. If the input and output files have the same name and extension, and are both on disk, the extension of the input file is changed to .BAK at the completion of the operation. the output input 7-17 file file is is name omitted, omitted, of the .LIB is .LIB is COBOL-74 UTILITY PROGRAMS 7.2.4 LIBARY Switches The following switches can LIBARY. be included in the command string to /D - List on the user terminal all of the library-names contained on the input library file. /H - List on the user terminal all of the commands available with LIBARY. /L - Create only a listing file of the entire input library. output file specification must be omitted. The /S - Put the input statement group into conventional format. /W - Rewind (for magnetic tape only). /Z - Clear an output directory (for DEC tape only). 7.2.5 Running LIBARY Running LIBARY consists of specifying commands in response to the LIBARY asterisk prompting character (*). Each command causes'LIBARY to move forward in the file. Because LIBARY cannot move backward in the fiie, you should plan your interaction with LIBARY so that you create or modify your files in alphabetical order by statement group. This will keep you from having to restart LIBARY and reprocess your file. LIBARY is organized so that you can optionally create new library files, insert or delete statement groups into an existing file, or make line-by-line changes to an existing file. It has, therefore, two major modes of operation: group mode or edit mode. Group mode provides a means of inserting, replacing, extracting, and deleting entire statement groups; edit mode provides a means of inserting new lines or deleting or modifying existing ones. NOTE Edit mode in" LIBARY acts as a fext editor for the library. However, this editor is not as powerful or as useful as the text editors provided with the operating system (such as TECO and EDIT) • LIBARY edit mode is there for historical reasons and its use is not recommended. 7-18 COBOL-74 UTILITY PROGRAMS 7.2.6 LIBARY Commands The following sections describe the commands available with LIBARY commands are divided into three classes of commands: • Group mode (See Section 7.2.6.1) • Edit mode (See Section 7.2.6.2) • LIBARY~directing (See Section 7.2.6.4) These commands may be abbreviated as abbreviation. long as you supply LIBARY. a unique 7.2.6.1 Group Mode Commands - Group mode commands allow you insert, replace, extract, and delete entire statement gro~ps. group mode commands are: to The NOTE For the remainder of this chapter, the words "line number" refer to the line numbers generated by a system standard editor~ the words "COBOL line number" refer to the conventional line numbers as described in Part 2, Section 1.3, Source Program Format. DELETE, library-name Delete the statement group identified by library-name from the library file. The library-name itself is also deleted. LIBARY moves forward through the input library file. It copies each statement it finds onto the output file until it encounters the library entry specified by library-name. When library-name is reached, LIBARY positions itself at the next sequential library entry and waits for another command. EXTRACT, library-name, file-specification Extract the complete library entry specified by library-name from the input library file and generate a new file named file-name. LIBARY searches the input library file for the library entry specified by library-name. When library-name is found, it creates a file or overwrites an existing file with the attributes specified by file-name and copies the library entry onto it. The input library file remains unchanged. INSERT, library-name, file-specification Insert the statement group contained on the file specified ~y file-name into the output library file. The statement group 1S inserted alphabetically according to the name specified ~by library-name. The file specified by file-name must be an ASCII file. LIBARY assumes that the entire file is to be inserted under library-name. If you want to insert many entries, you must create a separate file for each and execute a separate INSERT command for each. If there are line numbers in the file, they are included when the file is merged. If there are no line numbers, LIBARY generates them starting with 10 and incrementing 7-19 COBOL-74 UTILITY PROGRAMS by 10. If the library entry being inserted contains COBOL line numbers, the /S switch must be specified. (See Section 7.2.4, LIBARY Switches.) REPLACE, library-name, file-specification Replace the library entry identified by library-name with the statement group contained on the file specified by file-name. The file specified by file-name must be an ASCII file. LIBARY assumes that the entire file is to replace the statements currently associated with library-name. If you want to replace many library entries, you must create a separate file for each, and execute a separate REPLACE command for each. If there are line numbers in the file, they are included. If there are no line numbers, LIBARY generates them starting with 10 and incrementing by 10. The /S switch must be specified for files having COBOL line numbers. (See Section 7.2.4, LIBARY Switches.) 7.2.6.2 Edit Mode Commands - Edit mode commands allow you to create a library file or modify an existing one with line-by-line edits from your terminal. To edit your file, you must first specify one of the following commands to enter edit mode; after which, you can enter an appropriate edit command to affect the actual editing you wish to perform: CORRECT, library-name positions LIBARY to the group of statements specified by library-name and enters edit mode. Any of the commands described in Section 7.2.6.3, Edit Commands, can be entered at this time. If the /N switch is specified, LIBARY puts new line numbers on the output (corrected) statements. (See Section 7.2.4, LIBARY Switches.) INSERT, library-name positions LIBARY at the place in the library file that the specified library-name will be inserted. It then enters edit mode and waits for you to enter statements that will compose the module. The I command, described in Section 7.2.6.3, is used for this purpose. REPLACE, library-name positions LIBARY at the statement group specified by library-name and deletes it. It then enters edit mode and waits for you to insert source lines by means of the I comm~nd. (See Section 7.2.6.3, Edit Commands.) 7.2.6.3 Edit Commands - The commands given in this section allow you to insert, delete, and replace individual source lines in a statement group. Source lines should be edited in numeric order within a statement group because LIBARY can only move forward in the file. The following edit commands are provided: Dnnnnnn Delete the line specified by nnnnnn. The line number can be entered without leading zeros. That is, you need not enter six characters unless there are that many characters actually in the line number. 7-20 COBOL-74 UTILITY PROGRAMS Innnnnn COBOL statement Insert the COBOL statement into the statement group according to the line number specified by nnnnnn. The line number can be entered without leading zeros. A space or tab must be included between the line number and the COBOL statement; the space will not be included in the statement, but the tab will. Rnnnnnn COBOL-statement Replace the source line identified by nnnnnn with the specified COBOL-statement. The line number can be entered without leading zeros. A space or tab must be included between the line number and the statement; the space will not be included in the statement, but the tab will. 7.2.6.4 LIBARY-Directing Commands - LIBARY-directing commands allow you to end or restart library processing. The LIBARY-directing commands are: END Copy any remaining statement groups from the input to the output file, close both the input and output files, and rename the input file-with the extension .BAK, if necessary. RESTART Copy any remaining statement groups from the input to the output files, close both the input and output files, rename the input file with the extension .BAK, and reopen the output file as the new input. Any changes made prior to issuing the RESTART command are in the new input file. NOTE LIBARY maintains source modules in ascending order. Line numbers within modules are also in ascending order. If you want to go back in processing to a line previously passed, use the RESTART command. 7.2.6.5 Example of Command Usage - A library on disk contains the routines PAYCOMP, FIND-MP, and MP-DESCR. This example shows you how to do the following: 1. Insert a new routine called JOB-DESC 2. Correct MP-DESCR 3. Delete PAYCOMP These tasks must be undertaken in this order because LIBARY deals with code units in alphabetic order only. The MP-DESCR routine contains the following source statements: 000010 000020 LABEL RECORDS ARE OMITTED DATA RECORD IS MP-RECORD. 7-21 COBOL-74 UTILITY PROGRAMS The dialogue at the terminal might appear as follows: .R LIBARY *LIBARY.NEW=LIBARY.OLD *INSERT JOB-DESC *IlO LABEL RECORDS ARE STANDARD; *I20 VALUE OF ID IS "JOBS DAT"; *I30 DATA RECORD IS JOB-RECORD. *CORRECT MP-DESCR/N *I5 BLOCK CONTAINS 5 RECORDS *DELETE PAYCOMP *END The file LIBARY.NEW now contains the following: 1. FIND-MP 2. JOB-DESe 3. MP-DESCR, altered to appear as follows: 000010 BLOCK CONTAINS 5 RECORDS 000020 LABEL RECORDS ARE OMITTED 000030 DATA RECORD IS MP-RECORD. To insert one or more files in a library, you can issue the commands to LIBARY . following • R LIBARY *ALIB,ALIB= *INSERT AFIL,AFIL *INSERT BFIL,BFIL *END The file ALIB.LIB contains two statement groups (AFIL the file ALIB.LST contains the following information. A F I L 000010 COBOL LIBRARY 7.3 BFIL) 01-DEC-78 09:52 01-DEC-78 09:52 and DISPLAY "A". B F I L 000010 and COBOL LIBRARY DISPLAY "B". COBDDT - PROGRAM FOR DEBUGGING COBOL PROGRAMS COBDDT is an interactive program that is used to debug COBOL at tun-time. With COBDDT, you can: 1. Change the contents of a data-name 2. Set up to 20 breakpoints in a program 3. Continue 4. Display the contents of a data-name fro~ a breakpoint to any other breakpoint 7-22 programs COBOL-74 UTILITY PROGRAMS 5. Trace paragraphs and sections 6. Obtain a histogram of program behavior 7.3.1 Loading and Starting COB DDT COBDDT is run after it is loaded and started with a compiled program. NOTE The program being debugged must not have been compiled with the /P switch. The /P switch suppresses the user symbols that are necessary for COBDDT. The program and COBDDT can be loaded by either the monitor LOAD command or direct commands to LINK. In either case, LINK must load user symbols along with the program and COBDDT. The /LOCALS switch in the LINK command string causes the necessary user symbols to be loaded. After loading, the user issues a monitor command to start the program. The monitor command DEBUG can also be used to load and start COBDDT with a COBOL program. You can specify the name of the source file or the relocatable binary file. If the program cannot be recognized as a COBOL program (i.e., its extension is not .CBL), the /COBOL switch must be included in the DEBUG command string. When COBDDT is loaded with the user program, COBDDT is started, not the program. The three methods of loading and starting are shown below. Although all system prompts shown are for TOPS-IO, TOPS-20 acts exactly the same way. 1. .LOAD % "LOCALS" file spec, SYS:COBDDT<RET> .START<RET> 2. .DEBUG file spec [/COBOL]<RET> 3. .R LINK<RET> */LOCALS file spec, SYS:COBDDT /GO<RET> .START<RET) When the program is started, COBDDT is entered. message: This is shown by the STARTING COBDDT * You can now issue any COBDDT command (described below). If you want to run your program at this time, enter the PROCEED command. This will cause your program to run to completion or until a fatal error is encountered. If an error. is encountered that would normally cause abortion of execution, COBDDT is entered automatically and the message: ?ENTERING COBDDT FROM: <paragraph-name) gives the name of the paragraph in which the error occurred. COB DDT can then be used to check data values at the time of the failure. The program cannot proceed after COBDDT has been entered due to an error. 7-23 COBOL-74 UTILITY PROGRAMS If the COBOL program is in a loop and is not reaching a breakpoint, you can enter COBDDT by typing CTRL/C two times followed by REENTER. For example: ~C~C REENTER This will cause COBDDT to display the following message: DO YOU WANT TO ENTER COBDDT (Y or N) If you enter Y, COBDDT will be entered at the next TRACE entry in the COBOL program. If you enter N, however, your COBOL program will be reentered at the reenter address. 7.3.2 COB DDT Commands The commands to COBDDT are described below. Only the first letter of each command needs to be typed for COBDDT to recognize the command. Data-names and section-names need not be typed in full as long as each name or portion of the name is unique in the program. Paragraph-names may be qualified by section-names, and data-names may be qualified by higher-level data-names or subscript values or both. The subscripts for a qualified data-name must appear immediately after the first data-name. Subscripts must be numeric integers. Section-names and data-names cannot be qualified by program-names because COBDDT uses the names in the program specified in the MODULE command. ACCEPT The ACCEPT command allows you to change the contents of a data item. The new contents of the data item are typed on the next line. The ACCEPT command has the forms: ACCEPT ACCEPT data-name If the data-name is not specified, the last name specified DISPLAY or another ACCEPT command is assumed. in a Example: ACCEPT VAR1<RET> 16.2S<RET> BREAK The BREAK command sets a breakpoint (or pause) at the beginning of the specified paragraph. A breakpoint cannot be set on a section. The form of the BREAK command is: BREAK paragraph-name Not more than 20 Breakpoints cannot program. breakpoints be set in can be set in a program. the high segment of a reentrant Breakpoints can be set in nonresident COBOL segments, whether or not the segment is in memory. If more than one module is in 7-24 COBOL-74 UTILITY PROGRAMS memory, the name of the module in which the break occurred lS typed with the paragraph and section names. You can set breakpoints in LINK overlays, but all breaks in the overlay are cleared when the overlay is overlaid or cancelled. Example: BREAK PARI IN COMPUTING CLEAR The CLEAR paragraph. command removes the breakpoint The CLEAR command has the forms: at a specified CLEAR paragraph-name CLEAR If the paragraph-name is not specified, all breakpoints that have been set in the program are removed. Example: CLEAR PARI IN COMPUTING DISPLAY The DISPLAY command causes the contents of a data item to be displayed on the user's terminal. The forms of the DISPLAY command are: DISPLAY DISPLAY data-name If no data-name is specified, COB DDT uses specified in an ACCEPT or DISPLAY command. the last data-name Example: DISPLAY ALPHA MODULE The MODULE command causes COBDDT to look for data names and procedure names in the specified program. The form of the MODULE command is: MODULE [program-name] If the name is omittea, COBDDT types the name of the current module followed by the names of all modules currently in memory. Normally, within a run unit containing more than one program, COBDDT searches for data names and procedure names in the current program. The MODULE command changes the program in which the search will take place. All subsequent searches for data names and procedure names will be within the specified program until another. MODULE command is issued. 7-25 COBOL-74 UTILITY PROGRAMS If the current module is cancelled or overlaid, the main becomes the current module. program Example: MODULE MYPROG OVERLAY The OVERLAY command either causes a break when an overlay is entered or clears the breakpoint. The forms of the OVERLAY command are: OVERLAY ON OVERLAY OFF OVERLAY ON causes COBDDT to break the first time that a LINK overlay is entered each time it is brought into memory. The break only occurs once for each time the overlay is brought into memory. COBDDT types the following message when the break occurs: BREAK UPON ENTRY TO name where name is the name of the entry point. Following the message, COBDDT types t~e name of the current module and a list of th~ modules currently in memory. OVERLAY OFF causes COBDDT not to break when a LINK overlay is entered and not to type the information described above. OVERLAY OFF is the initial default. PROCEED The PROCEED command causes the program either to be started or to continue execution after a breakpoint caused it to pause. The PROCEED command has the forms: PROCEED PROCEED n After a PROCEED command is executed, the program runs either to completion or until another breakpoint is reached. If an integer is included with the command, the program runs until the n(th) occurrence of the preceding breakpoint has been reached. Thus PROCEED I is equivalent to PROCEED. Example: PROCEED 3 STOP The STOP command is equivalent to the COBOL STOP RUN statement. All files that are open are closed and program execution is terminated. The STOP command has the form: STOP 7-26 COBOL-74 UTILITY 'PROGRAMS TRACE The TRACE command either starts or stops tracing, depending the form of the command. The forms of the TRACE command are: on TRACE ON TRACE OFF TRACE ON causes tracing of all paragraphs and sections as they are executed. Whenever a paragraph or section is entered, its name, enclosed in angle brackets «», is typed on the user's terminal. For each depth of subprogram, COBOOT types an exclamation point (!) before each paragraph or section n~me. For each depth of a PERFORM statement, CO BOOT also types an asterisk (*) before each paragraph or section name. The maximum length of the string printed is 35 characters. Note that the exclamation point and asterisk are printed for each depth of subprogram or PERFORM. Example: TRACE ON !!*!**<PARA> When a LINK overlay is brought into memory, COBOOT types the names of any modules overlaid and the names of the modules in the new overlay. When a LINK overlay is cancelled, COBOOT types the names of the modules in that overlay. TRACE OFF causes COBOOT to stop tracing procedures until either execution is terminated or another TRACE ON command is executed. WHERE The WHERE command causes COBOOT to list the names of all paragraphs at which breakpoints were set. The form of the WHERE command is: WHERE If more than one module is in memory, the module name is included with the paragraph name. 7.3.3 Obtaining Histograms of Program Behavior The histogram facility in COBOOT allows you to obtain a report of the number of times each section and paragraph in your COBOL program was entered as well as the total amount of processor time and elapsed time spent in each section and paragraph. The commands for using this feature are described in the following sections., Both words of the histogram commands can be shortened to their unique abbreviations. None of the commands can be abbreviated to just Hi the first letter of the second word of the command must be present; for example, H I, H B, and H E are legal. 7-27 COBOL-74 UTILITY PROGRAMS 7.3.3.1 Initializing the Histogram Table - The HISTORY INITIALIZE command causes cOBDDT to set up and initialize the histogram table in which are stored the statistics for the histogram. The form of this command is: HISTORY INITIALIZE [filespec] ['title'] The file specification is the device, filename, extension, and project-programmer number of the output histogram report (dev:file.ext[p,pn]). If the entire file specification is omitted, the user's terminal is assumed. If the device is omitted but the filename is included, DSK is assumed. If the extension is omitted, .HIS is assumed. If the project-programmer number is omitted, that of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. The title is the one that will be printed as the second line of the histogram report. It must be enclosed in single quotation marks and can have a maximum length of 70 characters. Once you specify a file specification and/or title, it becomes default for any subsequent reports until explicitly changed. the It is not necessary to use this command, but it is advisable to qo so if only a portion of the program's statistics are to be recorded. The table can also be reinitialized by means of the HISTORY INITIALIZE command to begin a new histogram. 7.3.3.2 Starting the Histogram - The HISTORY BEGIN command causes COB DDT to start gathering statistics for each section and paragraph entered after this command is issued. This command has the form: HISTORY BEGIN [filespec] ['title'] The file specification is the device, filename, extension, and project-programmer number of the output histogram report (dev:file.ext[p,pn]). If the entire file specification is omitted, the user's terminal is assumed. If the device is omitted but the filename is included,DSK is assumed. If the extension is omitted, .HIS is assumed. If the project-programmer number is omitted, that of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. The title is the one that will be printed as the second line of the histogram report. It must be enclosed in single quotation marks and can have a maximum length of 70 characters. Once you specify a file specification and/or title, it becomes default for any subsequent reports until explicitly changed. the The HISTORY BEGIN command implies a HISTORY INITIALIZE command if one has not already been issued and if a histogram has not already been 7-28 COBOL-74 UTILITY PROGRAMS started. If a histogram already exists, HISTORY BEGIN will to that histogram. The statistics collected are: add data The number- of times each paragraph or section is entered The CPU time spent within each paragraph or section The elapsed time spent within each paragraph or section The elapsed time and CPU time for overhead The elapsed time and CPU time that is unaccounted for 7.3.3.3 Stopping the Histogram - The HISTORY END command causes COB DDT to stop gathering statistics for the histogram. This command has the form: HISTORY END If you wish to gather statistics throughout the entire execution of the program, you need not use the HISTORY END command. However, if you wish to stop gathering statistics for the histogram before the program finishes, you must set a breakpoint at the appropriate paragraph and, when the break occurs, use the HISTORY END command. 7.3.3.4 Obtaining Histogram Listing - The HISTORY REPORT command causes COBDDT to list the available statistics in a report. This command has the form: HISTORY REPORT '[file specification] ['title'] The file specification is the device, filename, extension, and project-programmer number of the output histogram report (dev:file.ext[p,pn]). If the entire file specification is omitted, the user's terminal is assumed. If the device is omitted but the name is included, DSK is assumed. If the extension is omitted, .HIS is assumed. If the project-programmer number is omitted, that of the logged-in user is assumed. Users of TOPS-20 who wish to specify a directory other than the default may run the TRANSLATE program to determine the correct project-programmer number. (See the TOPS-20 User's Guide for information on how to do this.) For an alternative which is generally more useful, see Appendix E, Defining Logical Names under TOPS-20. The title is the one that will be printed as the second line of the histogram report. It must be enclosed in single quotation marks and can have a maximum length of 70 characters. Once you specify a file, specification and/or title, it becomes default for any subsequent reports until explicitly changed. the The format for the histogram report is shown below. The heading printed for each module that is in memory at the time the report printed, even if the module was never entered. If the report printed while a module for which statistics were gathered is not memory, the statistics for that module are not printed. is is is in COBDDT HISTOGRAM FOR module-name title PROCEDURE -section-nameparagraph-name OVERHEAD: UNACCOUNTED: ENTRIES integer-2 integer-3 ELAPSED:time-S ELAPSED:time-7 7-29 REPORT: integer-l CPU time-l time-3 CPU:time-6 CPU:time-8 ELAPSED time-2 time-4 COBOL-74 UTILITY PROGRAMS module-name is the name of the PROGRAM 10 clause. integer-l is the report number. It starts at I and is incremented by I for each report produced in a run. title is the title that the user specified of the HISTORY commands. section-name is the name of a section into which control was transferred or passed. Each paragraph in the section to which control was passed is given with the section. integer-2 is the number of times control directly to the section. time-l is the amount section. time spent in the time-2 is the amount of elapsed time section. spent in the paragraph-name is the name of a paragraph to was transferred or passed. which control integer-3 is th~ number of times control was passed this paragraph. time-3 is the amount paragraph. spent in this time-4 is the amount of elapsed time spent paragraph. in this time-5 is the elapsed time spent entering and exiting from subprograms and PERFORM statements. If this time is 0, the line is not printed. time-6 is the CPU time spent entering and exiting from subroutines and PERFORM statements. time-7 is the elapsed time that could not be charged to any section or paragraph. If this time is 0, the line is not printed. time-8 is the CPU time that could not be charged to any section or paragraph. For example, when a subprogram is entered, the time accrued until the first paragraph or section is seen is charged to unaccounted. of of module, CPU CPU time taken from in was the one passed to If control is never passed to a particular section or paragraph, nothing is printed for that section or paragraph. When a PERFORM statement or subprogram is entered, the current paragraph or section is saved on a stack so that COBOOT can continue to charge time to the correct section or paragraph when the return is done. The size of the stack 'is 20 locati'ons. After a depth of twenty calls or PERFORM statements is reached, time is charged to unaccountable. 7-30 COBOL-74 UTILITY PROGRAMS A sample histogram report is shown below. COBDDT HISTOGRAM FOR CASHX PROCEDURE REPORT: 1 ENTRIES CPU ELAPSED 0 721 1 721 1 1 721 721 721 721 1.360 0.008 0.000 0.385 0.016 0.000 0.400 0.167 0.178 0.206 21.707 2.641 0.000 5.616 0.233 0.017 5.575 2.146 2.086 3.393 -GENERATED-SECTION-NAMESTART ST-l START-2 INITIAL-SETUP END-INITIAL-SETUP CONVERT-RECORDS END-CONVERT-RECORDS RATE-IT END-RATE-IT 7.3.3.5 Using the Histogram Feature - To use the histogram feature, issue the following commands upon entering COBDDT for the first time. HISTORY INITIALIZE HISTORY BEGIN At any time when you are stopped at a breakpoint, you can stop gathering statistics for the histogram by issuing the HISTORY END command. If you issue a HISTORY BEGIN command after a HISTORY END command, the histogram will continue from the point where the HISTORY BEGIN command was issued. However, if after a HISTORY END command you issue a HISTORY INITIALIZE and a HISTORY BEGIN command, the previous statistics will be lost and a new histogram begun. To get the previous histogram, issue a HISTORY REPORT command before the HISTORY INITIALIZE command. If a histogram file already exists with the same file specification as the one given, the histogram report is appended to the existing file. If the file specification is different, COBDDT starts a new histogram file. 7.4 RERUN - PROGRAM TO RESTART COBOL-74 PROGRAMS The RERUN program is used to restart a COBOL program that has been terminated abnormally due to a system failure, a device error, or an exceeded disk quota. RERUN uses checkpoint files, which are similar to memory-image dump files. They are created in one of two ways: • By including RERUN statement(s) in the COBOL program itself • By typing CTRL/C twice execution followed by REENTER during program The COBOL system creates a checkpoint file by writing a memory-image dump file of the program onto disk and adding some other information to allow a later restart of the program. At the same time, the COBOL system closes and reopens all disk and magnetic tape output files. The dump is not performed, however, if any files are open for input/output (updating), if an indexed-sequential file is open when the dump is requested, or if a sort is in progress. Each time the checkpoint file is written, the COBOL system types the message DUMP COMPLETED on the user's terminal. 7-31 COBOL-74 UTILITY PROGRAMS If the COBOL program is interrupted during execution, you can restart the program by means of the RERUN program. The RERUN program reads the dump file back into memory, restores the files to their state at the time the checkpoint file was written, and then passes control to the COBOL program so that it can continue processing to completion. RERUN assumes that the operating environment at the time the COBOL program was interrupted is the same as the environment at the time the checkpoint file was written. Thus, the files must be associated with the same types of devices, and devices must have the same logical names. 7.4.1 Operating RERUN To restart a COBOL program from the last checkpoint file written before execution stopped, type R RERUN in response to the operating system prompt (users of TOPS-20 may respond RERUN). For example: .R RERUN<RET> for users of TOPS-IO or @RERUN<RET> for users of TOPS-20 The program responds with the message: TYPE CHECKPOINT FILENAME Type the name of the checkpoint file in which the core-image stored. dump is When a checkpoint dump is being written, the COBOL system uses the filename of the program as the name of the checkpoint file and adds the extension .CKP. If the COBOL program does not have a filename because it was not saved, the COBOL system takes the checkpoint filename from the PROGRAM-ID in the program and adds the extension .CKP. If the program has been divided into a 2-segment file, the high-segment filename must be the same as the low-segment filename. Thus, when you respond with the checkpoint filename you are in effect telling RERUN the program name as well. If a logical device name is encountered in the the following message: program, RERUN types ASSIGN device name TYPE CONTINUE WHEN DONE and exits to monitor command level. The appropriate ASSIGN command should be given to assign the logical device to a specific one. Then a CONTINUE monitor command will reenter RERUN. 7-32 COBOL-74 UTILITY PROGRAMS 7.4.2 Examples of Using RERUN In the following example, the user has a COBOL program that was terminated by a system failure. Checkpoints had been inserted in the program by means of RERUN statements. The program has a filename of ACCNT; thus, the checkpoint filename is ACCNT.CKP. Instead of running the program again from the beginning, the user employs the RERUN program to restart his program from the last checkpoint written before the program stopped. He types: .R RERUN<RET> and RERUN responds: TYPE CHEC~POINT FILENAME The user types: ACCNT.CKP<RET> RERUN loads the checkpoint file into memory, reopens and repositions the magnetic tape and disk files, and passes control to the COBOL program so that it can continue processing to completion. In the example below, a user running a COBOL program is notified that the system is going down. He does not have any RERUN statements in his program, yet he wishes to create a checkpoint file so that the processing done by his COBOL program up to that point is not wasted. He creates the checkpoint file by typing CTRL/C twice and then typing REENTER. The checkpoint file is written by the COBOL system onto disk with a filename of PROGl3 (taken from the PROGRAM-ID) and an extension of .CKP. After the system is restored, the user can restart the program by running the RERUN program. The dialogue is as follows: @RERUN<RET> TYPE CHECKPOINT FILENAME PROGl3.CKP<RET> The program PROGl3 is loaded into memory, its files are reopened, it continues running to completion. 7-33 and CHAPTER 8 FILE FORMATS 8.1 RECORDING MODES The recording mode specifies the byte size of the data and, except for binary mode, also specifies the character set used. The four recording modes and their respective byte sizes are: RECORDING MODE BYTE SIZE ASCII SIXBIT EBCDIC Binary 7 bits 6 bits 8 bits 36 bits (1 word) The following sections describe the recording modes in more detail. 8.1.1 ASCII Recording Mode An ASCII word consists of 5 characters left justified Each character is represented by a 7-bit byte: in the word. ASCII RECORDING MODE BITNU MBER _ _ 0 1 234 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 --. BINAR Y REPRE SENTATION DATA • 0 o 0 00. A o • • 0 0 0 • • 0 0 0 0 • 0 0 • • B 1 0 0 • 2 0 • 0 0 0 0 • • x C BYTES: 5 • = on bit o = off bit X = unused bit MR-S-030-79 Figure 8-1 ASCII Recording Mode NOTE A variant form of ASCII, line-sequence ASCII, sets bit 35 of the line-sequence word to 1. 8-1 FILE FORMATS 8.1.2 SIXBIT Recording Mode SIXSIT is a compressed form of ASCII in which lowercase letters and a few special characters are not used. A SIXBIT word consists of 6 characters per word, with each character represented by a 6-bit byte: SIXBIT RECORDING MODE BITN UMBER _ _ _ o 1 2 3 456 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 BINAR Y REPR ESENTATION DATA . • 0 o o • o • 0 000 • • 0 1 A • 0 0 • 0 0 • 0 • 0 0 0 0 B 0 • • 0 • 0 C 2 • • 0 3 BYTES: 6 • = on bit = off bit o MR·S·031·79 Figure 8-2 SIXBIT Recording Mode 8.1.3 EBCDIC Recording Mode An EBCDIC word consists of 4 characters per word. Each byte is 9 bits long, but the first bit in each byte is unused. Each character is represented by 8 bits: EBCDIC RECORDING MODE BITNU MBER 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Y __ BINAR • 0 o 0 o • X • 0 0 b 0 0 0 0 0 0 0 x x X REPRE SENTATION DATA •• . • • • A • • • • • • • • • 2 B 1 • BYTES: 4 • = on bit o = off bit X = unused bit MR·S-032·79 Figure 8-3 EBCDIC Recording Mode A variant form, used only for magnetic tape, is industry-compatible EBCDIC. In this form of EBCDIC, there are 4 characters per word, left justified within the word. Each character is represented by an 8-bit byte. The last 4 bits in the word are unused: INDUSTRY·COMPATIBLE EBCDIC RECORDING MODE 0 1 234 567 8 9 10 11 12 13 14 HI 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 BITNU MBER BINAR Y REPRE SENTATION - - • DATA .. •• 000 A o • ••• • 0 0 0 • • • • 0 0 B 1 0 • 0 • • • • 0 0 • 0 X X X X 2 BYTES: 4 • = on bit o = off bit MR·S-033·79 Figure 8-4 EBCDIC Recording Mode - Industry-Compatible 8-2 FILE FORMATS 8.1.4 BINARY Recording Mode Unlike the recording modes previously mentioned, binary mode does not specify a character set for the data. In binary mode, the entire 36-bit word is interpreted as a single byte of binary data: BINARY RECORDING MODE BIT N UMBER--- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 BINAR Y REPR ESENTATION DATA --.. 000 o 0 o 00 000 0 0 0 • 0 • 0 0 • • • 0 0 • 0 • • • • 0 0 0 0 0 0 2,739,136 BYTES: 1 • = on bit o = off bit MR·S-034·79 Figure 8-5 Binary Recording Mode 8.2 FILE FORMATS The file format specifies the structure of the record used to store the data. The following sections describe all major file formats. Each section includes a diagram of the file format and a COBOL code segment that will generate the file format. The following conventions are used in the diagrams:. 1. Alphanumeric or numeric character data in a word is shown with each individual character enclosed in a box. The box represents 1 byte. Thus, a word of ASCII data would be shown as follows: 2. Binary data in a word (fixed- and floating-point numbers) shown by a number in the word: is 132156.101 3. EBCDIC packed-decimal values are shown as two decimal digits per EBCDIC byte. The right half of the rightmost byte contains the sign. Neither the digits nor the sign are EBCDIC characters. 4. COBOL signed numeric data, such as produced by PIC S9(n), is shown wi th the over-punched character, .if the sign is negative. For example, -12345 is shown as l234N, with the N representing both the negative sign and the value 5. DIGITAL's COBOL does not use over-punched characters for positive sign representation, so diagrams depicting positive, signed numeric data do not show a sign. 5. Italicized characters in a diagram do not depict data; label or clarify parts of the diagram: RDW301 8-3 ° they FILE FORMATS 6. Heavy vertical lines are used to within a record: delimit individual fields 7. Padding, the use of blanks or nulls to force the next record to begin on some boundary (for example, a word or disk-block boundary), is shown by white space in the word: You cannot consider padding as part of a record field, nor can you use padding as part of a key field. However, the length of any padding must be taken into account when calculating record length and key starting position. 8.2.1 Fixed-Length ASCII A fixed-length ASCII file consists of records containing five characters per 36-bit word, with each group of 5 characters left-justified within the word. Fixed-length ASCII records must end with a carriage-return/line feed. The following diagram illustrates the format of fixed-length ASCII records: WORD RECORD I A B C D E 2 F G G!!) GO A 3 B C D E F 4 G G!!) CD A B 5 C D E F G 6 CID GD A B C D E F G CID 8 2 3 I 4 GD CID ~ CARRIAGE RETURN LINE FEED MR·S·035·79 Figure 8-6 Fixed-Length ASCII 8-4 FILE FORMATS CODE SEGr·1ENT; ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS A~CII. DATA DIVISION. FILE SECTION. FD 01 filename VALUE OF ID 'DATA FIL'. record-i DISPLAY-7. 02 field-l PIC X(6) VALUE "AB12EF". 02 field'-2 PIC A(3) VALUE -GHI". PIC 9(4) VALUE 3249. field-"3 02 PIC S9(6) VALUE -~81253. field-A 02 02 field--5 PIC 99(6) V9999 VALUE +31458.5012. Figure 8-7 illustrates the record produced by the code above: segment shown WORD I A B 1 2 E 2 F G H I 3 3 2 4 9 4 8 4 1 2 5 L 0 5 3 1 4 5 8 6 5 0 1 2 G!) 7 GO MR-5'()36·79 Figure 8-7 8.2.2 COBOL Fixed-Length ASCII Variable-Length ASCII Variable-length ASCII consists of records containing five characters per 36-bit word, with each group of 5 characters left-justified within the word. Variable-length ASCII records must end with some combination of the following control characters: l~ carriage return 2. line feed 3. vertical tab 4. form feed 8-5 FILE FORMATS The following diagram illustrates the format of variable-length records: I A B C D E 2 F GD G!:) A B 3 C D E F G 4 H I J GD C!D 5 A E G!D CD C!D 6 A B C 7 F D E 2 3 4 G!D G!:) (ill) G!:) C!!:) ~ =CARRIAGE RETURN = VERTICAL TAB = FORM FEED =LlNE FEED MR -S-03 7-79 Figure 8-8 Variable-Length ASCII 8-6 ASCII FILE FORMATS CODE SEGMENT~ ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE--CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS ASCII. FILE SECTION. FD 01 filename VALUE OF ID 'DATA FIL'. record-1 DISPLAY-7. 02 field-1 PIC X(7) VALUE 'AB13521 1 • 02 field-2 PIC S9(7) V99 VALUE -3269.02. 02 field-3 PIC A(3) VALUE 'ILM'. 02 field-4 PIC 9(4) VALUE 1359. 01 record-2 DISPLAY-7. 02 field-1 PIC X(7) VALUE 'EFGHI95 1 • 02 field-2 PIC 99(7) V99 VALUE 42553.40. 02 field-3 PIC A(3) VALUE 'LMN'. 02 field-4 PIC 9(7) VALUE 3712536. PROCEDURE DIVISION. WRITE record -1. WRITE recoJ'd-2. o Figure 8-9 illustrates the record produced by the code above: WORD A B t 3 5 2 2 t 0 3 2 3 6 9 0 K I 4 L M t 3 5 5 9 GD GO E F 6 G H I 9 5 4 2 5 5 3 8 4 0 L M N 9 3 7 t 2 5 10 3 6 1 I GD GO MR-5.o38·79 Figure 8-9 COBOL Variable-Length ASCII 8-7 segment shown FILE FORMATS 8.2.3 Fixed-Length SIXBIT In a SIXBIT file, characters are stored six per 36-bit word, and a SIXBIT record must start and end on a word boundary. The left half of the first word in the record contains one of the following: 1. The record sequence number of COBOL magnetic tape records 2. Data specific to COBOL ISAM records 3. Binary zeros The right half of the first word contains the number of characters in the record. To ensure that the record ends on a word boundary, the last word in the record is padded with blanks, if necessary. When determining the size of the record for memory considerations, you must take into account the first word of the record (containing file-access information and a character count) and the possible existence of padding characters (blanks) to enable the record to end on a word boundary. The following diagram illustrates the format of fixed-length SIXBIT records. Note that the character count is the same for each record: WORD CC FAD 2 A B C D 3 G H ...... ...... 4 8 I E ...... I F ...... CC FAD 5 A B C D 6 G H ...... ...... 8 I E ...... I I I 2 F ...... FAD = FILE ACCESS DATA = CHARACTER COUNT ...... = BLANK (USED AS PADDING CHARACTER) CC MR·S-039·79 Figure 8-10 Fixed-Length SIXBIT 8-8 FILE FORMATS CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS SIXBIT. DATA DIVISION. FILE SECTION. FIt 01 filename VALUE OF ID 'DATA FIL'. record-1 IIISPLAY--6. 02 field-l PIC X(4) VALUE 'Al~5B' • 02 field-2 PIC A(S) VALUE • CJ)[FG' • 02 field-3 PIC 9(10) COMP VALUE: <}6~:j4El:39::.~ 1 B. 02 field-4 PIC X(2) VALUE • HI • • 02 field-5 PIC 9(11) COMP VAl.UE: 34~.'j679B2:':H·1. 02 field'-6 PIC 9(4) VALUE 1289. 02 field-7 PIC 9(5) COMp .... 1 VAL.UE 123.45. 02 field-8 PIC 9(11) COMP VAL.UE 1 :~398·7::.'i69f:l3. Figure 8-11 illustrates the record produced by the code segment above: WORD CC FA'D I A 1 3 E F G I c I D I 9654839218 3 4 B 60 H I 5 34567982314 I-6 7 1 2 8 9 I I 123.45 8 9 I-- 12398756983 10 I MR·S.()40·79 Figure 8-11 COBOL Fixed-Length SIXBIT 8-9 shown FILE FORMATS 8.2.4 Variable-Length SIXBIT This format is the same as fixed-length SIXBIT, except that the character count may vary from record to re~ord. The following diagram illustrates the format of variable-length SIXBIT records: CC FAD 2 I 3 B C D E F G H '-' '-' '-' '-' CC FAD 4 5 I 6 8 A 11 A B C D E G H I J K 2 F FAD = FILE ACCESS DATA CC '-' = CHARACTER COUNT .. BLANK (USED AS PADDING CHARACTER) MR-S-041-79 Figure 8-12 Variable-Length SIXBIT 8-10 FILE FORMATS CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-·-CONTROL., • SELECT filename ASSIGN TO DSK RECORDING MODE IS SIXBIT. DATA DIVISION. FILE SECTION. FD 01 filenal'lle VALUE OF 1[1 'DATA FIL' • record-1 DISPLAY--6. 02 field-1 PIC 9(7) COMP--·1 VALUE 123.4567. 02 field-2 F'IC X(3) VALUE -A3C- • 02 field-3 PIC A(3) VALUE -DEF- • 02 field-4 PIC 9(3) VALUE --55. 02 field-5 PIC 9(10) COMP VALUE 1234567809. 02 field-6 F'IC 9(11) COMP VALUE 98765432108. 02 field-7 PIC X(2) VALUE -A2-. 02 field-8 PIC 9(5) COMP VALUE 32571. 01 ,'ecord-2 [.ISPLAY-6. 02 field-1 PIC 9(7) COMP-l VALUE 1395.678. 02 field-2 PIC X(3) VALUE -B5L-. 02 field-3 F'IC A(3) VALUE -LMN- • 02 field--4 PIC 9(3) VALUE 79. 02 field-oS PIC 9(10) COMP VALUE 8176596821. 02 field-6 PIC 9(11) COMP VALUE 18976532150. 02 field-7 PIC X(2) VALUE -M5-. 02 field-8 PIC 9(11) COMP VALUE: 12~~57986183 • PROCEDURE DIVISION. WRITE record-1. WRITE record-2. 8-11 FILE FORMATS Figure 8-13 illustrates the record produced by the code segment on the previous page. shown WORD CC FAD 48 123.4567 2 A 3 C 3 0 5 N 4 D I E I F 1234567809 --, 5 98765432108 '-- 6 A 2 32571 8 CC FAD 54 1395.678 2 B 5 L 3 0 7 9 L - I M I N --~ ~II?!596821 4 5 18976532150 '-- 6 7 8 9 M I 5 L 12357986183 I MR-5-042·79 Figure 8-13 8.2.5 COBOL Variable-Length SIXBIT EBCDIC File Formats On disk and in memory, the characters in an EBCDIC file are represented by 8 bits right-justified in 9-bit bytes. On tape, the characters in an EBCDIC file are represented by 8-bit bytes, and 4 bytes occur per 36-bit word. Within a given file, records may be either fixed or variable length, and may be either blocked or unblocked. Thus, there are four types of EBCDIC files: 1. Fixed-length 2. Variable-length 3. Blocked 4. Blocked variable-length fixed~length 8-12 FILE FORMATS In a file written in fixed-length EBCDIC, records all have the same record length and the records need not begin or end on a word boundary. The following diagram illustrates the format of fixed-length EBCDIC records in an unblocked file: WORD RECORD I A B C D 2 E F A B 3 C D E F A B C D E F 4 I 5 2 I 3 MR·S-043·79 Figure 8-14 Fixed-Length EBCDIC CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS F. DATA DIVISION. FILE SECTION. FII 01 filer'B"If? VALUE OF III 'DATA FIL' • record-'l [IISPLAY-·9. 02 field--1 PIC 9(3) VALUE 123. 02 field-2 PIC X(5) VALUE -AIICDE". 02 field-3 PIC A(2) VALLIE -I...M-. 02 field-4 PIC 9(9) COMp .... 3 VAl.UE 137958795. 02 field-5 PIC S9(6) COMP--3 VAl.UE -,351235. Figure 8-15 illustrates the record produced by the code segment above: I 2 1 2 3 A B C D E I 3 4 5 L M lS 7 :9 , 1 :3 5:+ , 7 19 shown I 3 I 5 5: 1 2:3 5 :MR·S-044·79 Figure 8-15 COBOL Fixed-Length EBCDIC In a file written in variable-length EBCDIC format, the record lengths may vary from record to record. Each record contains a 4-byte Record Descriptor Word (RDW) at the head of the record. The left half-word of the RDW specifies a value equal to the number of bytes in the 8-13 FILE FORMATS record plus 4 (to allow for the length of the RDW itself). The rightmost 2 bytes of the RDW must be zero; if they are nonzero, they indicate spanned records, which are unsupported. The following diagram illustrates the format of variable-length EBCDIC records in an unblocked file: RECORD WORD LROW 0 12 2 A B C D 3 E F G H 4 I ROW 16 5 A B C D 6 E F G H 7 I J K L 8 LROW 12 9 A B C D 10 E F G H 0 0 I I 2 I 3 ROW = RECORD DESCRIPTOR WORD MA-S-045- 79 Figure 8-16 Variable-Length EBCDIC 8-14 FILE FORMATS CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. I::'ILE-CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS V. I'ATA DIVISION. FILE SECTION. FD 01 01 . filename VALUE OF ID 'DATA FIL , record-1 DISPLAY-9. 02 field·--l PIC ~;9 ("7) COMP--·3 VALUE ·--1390569. 02 field-2 PIC 89 (I) COMP---3 VALUE 5763~)93"l. 02 field-3 PIC 9(3) VALUE ~:j96. 02 field--4 PIC A(2) VALUE • AB· • 02 field-oS PIC X(S) VALUE ·A13DE·. record-2 DISPLAY---(l. field-l PIC 89("7) COMP--3 VALUE 5~569"l8"l. 02 field-2 PIC 89(8) COMP--·3 VAL.UE -538(»6156. 02 field-3 PIC 9(3) VALUE 593. 02 field-4 PIC .A( 2) VALUE ·MN·. 02 field-5 PIC X(B) VALUE • I L.H5MLXY • • _ o=~ PROCEDURE DIVISION. WRITE record--j_. WRITE rec(:lrd---2. Figure 8-17 illustrates the record produced by the code segment above: WORD RDW 23 0 I 1 :3 I 2 :5 3 9:8 5 :6 I 9 :I I 7 :6 3 :5 9 :3 7 I1+ 5 9 6 4 A B A 1 5 3 D E RDW 0 5 '3 7 1+ 15 I 26 1 1,2 6 19 7 :8 2,3 3 !8 9:6 1 15 I 6:- 3,4 5 9 3 M 4,5 N I L H 5,6 5 M L X 6 Y I I I I I I I MR·S'()46-79 Figure 8-17 COBOL Variable-Length EBCDIC 8-15 shown FILE FORMATS Fixed-length EBCDIC records may also be blocked. In this file format, fixed-length EBCDIC records are written in groups (or blocks). Each new block begins on a disk-block boundary. For tapes, each block starts a new physical magtape record. CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. F I L.E "CONTROL • SELECT filename ASSIGN TO DSK RECORDING MODE IS F. [lATA DIVISION. FIL.E SECTION. FD 01 02 fj, lenC:Jm€~ VALUE OF II) "DATA FIt..' BLOCK CONTAINS :1. F~EC()F<[lS • ,'eco rd-'l DISPLAY····(» • 02 fiE-'ld"'l PIC 9(3) VI!'.)I... UE "1.94", 02 field-·2 PIC X(5) VALUE "BDEFG" • 02 field'''3 PIC A(2) VALUE "MN". 02 field'-4 PIC 9C:» COMp .... :3 VALUE 13?9l) • 02 field'''S PIC 89(4) COMp·-3 VALUE 1 <?fJ5. record-2 DISPLAY-9. 02 field-l PIC 9(3) VALUE "762". 02 field-2 PIC xes) VALUE "LANBH". 02 field-3 PIC A(2) VALUE "AB". 02 field-4 PIC 9(5) COMP-3 VALUE 76543. 02 field-S PIC 89(4) COMP-:3 VALUE -9764. PROCEDURE DIVISION. WRITE record-·i. WRITE l"eco,'d"'2. Figure 8-18 illustrates the record produced by the code segment above: WORD BLOCK 1 2 I BLOCK 1 9 D E 4 B F G I 3 4 M 61+ N I 1: 3 719 I 918 5:+ I I 11 I I I I I I I ~ II 7 6 2 L 2 A N B H 3 A B 7i6 5;4 4 3 1I+ :9 7:6 ~ I 1 I I I I I 1 I 2 I I I 4 II I I -------~ MR·S-047-79 Figure 8-18 COBOL Blocked Fixed-Length EBCDIC 8-16 shown FILE FORMATS Variable-length EBCDIC records may be blocked as well. In this file format, the record length may vary from record to record. Each record contains a I-word Record Descriptor Word (ROW) at the head of the record. This word contains (in the left half-word) a count of all bytes in the record and in the ROW itself. The right half of the ROW must be zero. The records are read and written in groups called blocks. The actual number of records in a block depends on the blocking factor specified when the file was created. Each block of records contain a I-word Block Descriptor Word (BOW) which contains a count (in the left half-word) of the bytes in the block. That is, the bytes of data and the bytes of the ROW for each record in the block and the 4 bytes of the BOW itself are included in the block count. The following illustrates the format of blocked variable-length EBCDIC records: RECORD WORD BOW 20 0 2 ROW 10 0 3 A B C D 4 E F ROW 6 5 0 0 A B 201 BOW 28 0 202 ROW 6 0 3 203 A B ROW 10 4 0 A B E F I BLOCK 2 L ,..-- 204 205 C D 206 I ROW 8 207 A B 0 C 2 J 5 D BOW = BLOCK DESCRIPTOR WORD ROW = RECORD DESCRIPTOR WORD MR-S-048-79 Figure 8-19 Blocked Variable-Length EBCDIC 8-17 FILE FORMATS CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. 'SELECT filename ASSIGN TO DSK RECORDING MODE IS V. DATA DIVISION. FILE SECTION. FD 01 01 filename VALUE OF ID 'DATA FIL' BLOCK CONTAINS 1 RECORDS. record-l DISPLAY-9. 02 field-l PIC S9(7) COMP-3 VALUE +9356127. 02 field-2 PIC 9(7) COMP~3 VALUE 3987156. 02 field-3 PIC 9(3) VALUE -198-. 02 field-4 PIC A(2) VALUE -MN-. 02 field-5 PIC S9(9) COMP-3 VALUE -569138279. 02 field-6 PIC X(6) VALUE -ABCDEF-. record-2 DISF'LAY-9. 02 field-l PIC S9(7) COMP-3 VALUE -3:;~95865 • 02 field-2 PIC 9(7) COMp··-3 VALLIE 937E)::';18. 02 field-3 PIC 9(3) VALUE -196 - • 02 field-4 PIC A(2) VALUE - Al.. - • 02 field-5 PIC 9(9) COMP-3 VALLIE 569138279. 02 field-6 PIC X(9) VALUE -ABCDEFGHI-. PROCEDURE DIVISION. WRITE record-1. WRITE record-2. 8-18 FILE FORMATS Figure 8-20 illustrates the record produced by the code segment on the previous page. BOW 32 ROW 28 shown 0 0 I 9!3 I 5:6 112 I 7;+ I 8:7 1 1 :5 : 6:+ M I I I 2 3 19 3 1 : N 4 5 6 9 8 I I 5:6 9: , I I 3:8 I I 2j7 9!- A B C 0 E F ~ ..;...- BOW 35 RDW 31 - 0 0 I I !i 9:5 8:6 5 2 9:3 : 7:8 5', : 8:+ 3 1 9 6 A 3!2 2 I ! I 4 L 5 5:6 9p 3:8 2:7 9:+ A B I I C 0 E F G H I I I 6 7 I ~""'l.. __ ~MR-S-049-79 Figure 8-20 8.2.6 COBOL Blocked Variable-Length EBCDIC BINARY File Formats Binary records consist of contiguous 36-bit words. Each record starts and ends on a word boundary. Binary is the only recording mode which does not have a character set associated with it, and standard binary records may only be interpreted as COMPUTAtIONAL and COMPl binary numbers. However, it is possible to associate a character set with binary records by writing ~ixed-mode records. COBOL programs are capable of writing three mixed-mode binary formats. Each format is shown on the following pages. 8-19 FILE FORMATS 8.2.6.1 COBOL ASCII Mixed-Mode Binary - CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT filename ASSIGN TO D8K RECORDING MODE IS BINARY. DATA DIVISION. FILE SECTION. FD 01 I. VALUE OF 'DATA FIL BINARY--REC IHSPLAY---7. 02 field-1 PIC 89(10) CDMF' VALUE 12:"54~)(') 70910. 02 field-2 PIC 89(10) COMP--- :I_ VALUE :I_ 246.597892. 02 field-3 PIC x("7) VALUE • AIICDE 1.2· • 02 field--4 PIC 9( 11> COMP VALUE 123456789~_)4 • 02 field-oS PIC <J (3) VALUE 1532-. 02 field---6 PIC 9(t4) CDMP VALUE 12345678954. 02 field---7 PIC A (~!) VALUE • Lt1· • filename Figure 8-21 illustrates the record produced by the code segment above: shown WORD 1234568910 1246.597892 2 3 A 4 B C E 2 5 12345678954 6 7 5 8 12345678954967 9 10 MR-S.()50-79 Figure 8-21 COBOL Standard Binary and ASCII Mixed-Mode Binary 8-20 FILE FORMATS 8.2.6.2 COBOL SIXBIT Mixed-Mode Binary - CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS BINARY. DATA DIVISION. FILE SECTION. FD 01 filename VALUE OF 'DATA FIL'. BINARY-REC DISPLAY-6. 02 field-l PIC S9(10) COMP VALUE 12345678910. 02 field-2 PIC S9(10) COMFL··1 VALUE 1234.592:1. n). 02 field-3 PIC X(7) VALUE 'ABC[lEI2 1 • 02 field-4 PIC 9(11) COMP VALUE 123456'78954. 02 field-5 PIC 9(3) VALUE 15321. 02 field-6 PIC 9(14) COMP VALUE 1 ;?34:7j678954967. 02 field-7 PIC A(2) VALUE 'LM 1 • Figure 8-22 illustrates the record produced by the code segment above: shown WORD 12345678910 2 1234.592175 3 A 4 2 5 6 L 7 8 BI c 5 1 12345678954 3 - I 12345678954967 L M I 1 l 21 9 10 DIE I l MR-S.Q51-79 Figure 8-22 COBOL Standard Binary and SIXBIT Mixed-Mode Binary 8-21 FILE FORMATS 8.2.6.3 COBOL EBCDIC Mixed-Mode Binary - CODE SEGMENT: ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. I=- I LE -CONTROL. SELECT filename ASSIGN TO DSK RECORDING MODE IS BINARY. DATA DIVISION. FILE SECTION. FD 01 filename VALUE OF 'DATA FIL'. BINARY-REC DISPLAY-9. 02 field-1 PIC 89(10) COMP VALUE 12345678910. 02 field-2 PIC S9(10) COMP-l VALUE 1246.597861. 02 field-3 PIC X(7) VALUE ·ABCDE12·. 02 field-4 PIC 9(11) COMP VALUE 12345678954. 02 field-5 PIC 9(3) VALUE 8532-. 02 field-6 PIC 9(14) COMP VALUE 12345678954967. 02 field-7 PIC A(2) VALUE ·lM-. 02 field-8 PIC 59(5) COMP-3 VALUE -72539. 02 field-9 PIC 9(8) COMP-3 VALUE 36193586. Figure 8-23 illustrates the record produced by the code segment above: shown 12345678910 1246.597861 2 3 A B C 4 E 1 2 5 L 12345678954 6 7 5 3 D l 2 8 "'- 12345678954967 9 10 11 12 I L M 7:2 9 :- :3 6: 1 J 5 :3 I I I 9 :3 I 5:8 6:+ MR-S-052-79 Figure 8-23 COBOL Standard Binary and EBCDIC Mixed-Mode Binary 8-22 FILE FORMATS 8.3 FILE ORGANIZATION AND ACCESS File organization refers to the manner in which the records are arranged in the file. Three types of file organization are available with COBOL-74: sequential, relative, and indexed-sequential. File organization is specified in a COBOL program by means of the ORGANIZATION clause. COBOL-74 provides three methods by which files can be accessed: sequential, random, and dynamic. File access refers to the way in which records from a file are read and/or written. The method of access for a file is specified in a COBOL program by the ACCESS MODE clause. The chart below shows file organizations and the methods by which they can be accessed. File Organization Method of Access ACCESS MODE Sequential Sequential SEQUENTIAL Relative Sequential Random Sequential and Random SEQUENTIAL RANDOM DYNAMIC Indexed Sequential Random Sequential and Random SEQUENTIAL RANDOM DYNAMIC In the following sections, file organizations are described along with the methods by which they can be accessed and the manner in 'which these methods are specified. 8.4 SEQUENTIAL FILES Sequential files are those files that can only be read or written sequentially, that is, starting at the first record in the file and continuing with each subsequent record until the end of the file. Sequential files can reside on any file medium: qards, paper tape, DECtape, magnetic tape, and disk. If the file contains a large amount of data that is read and written frequently, it should be stored on magnetic tape or disk. Since tape storage is normally less expensive than disk storage, magnetic tape is often used for such files. However, if it is necessary to have rapid access to the data, disk storage may be preferable to tape storage. Sequential files on disk or DEC tape should not be blocked unless they are to be open for input/output. When the files are stored on magnetic tape, they should be blocked to reduce wasted space caused by inter-record gaps. A sequential file can be open for input/output (updating), but it must be blocked for this purpose and must reside on disk. If a sequential file is open for input/output, a write to the file causes writing of either the last record read (if the last operation was a READ) or the record after the last record written (if the last operation was a WRITE) • 8.5 RELATIVE FILES Relative files are arranged like sequential files, but differ from sequential files in the method by which they are accessed and by the 8-23 FILE FORMATS devices on which they must be stored. The following requirements must be fulfilled for a file to be relative: 1. It must be on a random-access device. 2. It must be blocked. You can use the ACCESS MODE clause in the SELECT Environment Division to specify the access method. statement of the You must also specify the RELATIVE KEY in the Environment Division. The data-name specified by the relative key must be described in the Working-Storage section as a COMPUTATIONAL item of 10 or fewer characters. Its picture can only contain the characters Sand 9 (or their equivalent, such as S9(4». The RELATIVE KEY specifies to the object-time system the location of a record relative to the beginning of the file. That is, the first record in the file is record 1 and the last record in the file is l+n where n is the number of remaining records in the file. Some records may be zero-length, that is, they d~ not have anything written in them because the file was created randomly. These records have RELATIVE KEYs and can be written but cannot be read until information is placed into them. If an attempt is made to read zero-length records, the INVALID KEY path will be taken. A relative file can be created in one of two ways randomly or sequentially. To create a file randomly (that is, by writing into scattered or random records), you need only open the file, move an integer value into the RELATIVE KEY for each record to be written randomly, and write each record. To create a relative file sequentially, open the file for output and begin writing records. The RELATIVE KEY will default to the next record in the file, and the records will be entered sequentially. No zero-length records will be in the file if it is written sequentially. 8.5.1 Sequential Access Of Relative Files A file with relative organization may still be atcessed sequentially if you specify ACCESS MODE IS SEQUENTIAL i~ the File Control paragraph. Read operations on such a file will retrieve succeeding records, starting with the first non-zero-length record on the file, and continuing with each successive non-zero-length record. Any zero-length records are skipped by the sequential read operation. A file opened for input or I/O may be repositioned using the START statement. An existing record may be updated using the REWRITE statement, assuming the file was opened for I/O and the immediately preceding I/O operation was a READ. A sequential READ or WRITE will update the file's RELATIVE KEY value to indicate the current record position. The AT END or INVALID KEY condition occurs if: 1. A READ is made to a non-existant record End-of-File 2. A WRITE is made to a location record 3. A REWRITE is made to a zero-length record, or not the first I/O operation after a READ 8-24 .containing this a is logical non-zero-length a REWRITE is FILE FORMATS 8.5.2 Random Access Of Relative Files A relative file may be accessed at scattered locations by specifying the clause ACCESS MODE IS RANDOM. In this case the record accessed is the one indicated by the current value of the RELATIVE KEY. The first record on the file is assigned the relative key of 1, with succeeding records numbered 2, 3, 4, •••• Therefore, before you execute a random I/O operation, you must specify the record by moving the value you desire into the RELATIVE KEY for the file. Non-zero-length records may be updated by the use of the REWRITE clause, assuming that the file is open for I/O and that the previous I/O operation was a READ to the file. The INVALID KEY condition occurs if: 8.5.3 1. A READ is made to a zero-length record 2. A WRITE is made to a non-zero-length record 3. A REWRITE is made to a zero-length record, or the last I/O operation before the REWRITE was not a valid READ to the file Dynamic Access Of Relative Files Often you will want to access a file both randomly and sequentially. You may accomplish this by in'dicating that your file's ACCESS MODE IS DYNAMIC. If you specify this mode, you may read your relative file randomly in the normal way, then issue a READ NEXT command and switch to sequential access., This READ statement acts just as it would in sequential access mode, obtaining the next non-zero-length record. As in sequential mode, the RELATIVE KEY will be reset to indicate the relative location of the record just obtained. The first READ NEXT you issue will use the current value of the RELATIVE KEY as its starting point. You may alter this by using the START verb to position the record pointer in the file. You may also update records using the REWRITE verb, with the same considerations as before. Figure 8-24 presents an example program which positions the file pointer to a starting location and updates records sequentially thereafter. ' 8-25 FILE FORMATS ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT RELOUT ASSIGN TO DSK ORGANIZATION IS RELATIVE ACCESS MODE IS DYNAMIC RELATIVE KEY IS RELKEY. DATA DIVISION. FILE SECTION. FD RELOUT BLOCK CONTAINS 8 RECORDS DATA RECORD IS RELREC VALUE OF ID IS "RELFILDAT" 01 RELREC PIC X(80) WORKING-STORAGE SECTION. 77 RELKEY PIC 9(10) VALUE IS 1. PROCEDURE DIVISION. START. OPEN INPUT-OUTPUT RELOUT. UPDATE. MOVE 5 TO RELKEY. START RELOUT, INVALID KEY GO TO STRT-ERR. READ RELOUT NEXT, AT END GO TO FINISH. REWRITE RELREC, INVALID KEY GO TO ERROR. GO TO UPDATE. FINISH. CLOSE RELOUT, STOP RUN. ERROR. DISPLAY "ERROR REPLACING RECORD", DISPLAY RELREC. GO TO FINISH. STRT-ERR. DISPLAY "ERROR IN START - KEY=", RELKEY. GO TO FINISH. Figure 8-24 Statements Used to Sequentially Access a Relative File A relative file can be treated as a sequential file. That is, you can declare its. ACCESS MODE as SEQUENTIAL and read or write the file sequentially. However, the file cannot be read or written randomly when it has been declared as· ACCESS MODE SEQUENTIAL. If you wish to be allowed to access the file both randomly and sequentially you should specify the ACCESS MODE IS DYNAMIC option. 8-26 FILE FORMATS 8.6 INDEXED-SEQUENTIAL FILES Indexed-sequential files (also called ISAM files) are files in which records are accessed through a hierarchy of indexes according to a key within each data record. This file organization is commonly used for applications in which the programmer wishes to identify and access records by the contents of a data field (the key) rather than the relative location of the record within the file. Some examples of applications for which this file organization is commonly used are: o payroll (key is employee number) o inventory control (key is part number) o production control (key is job or batch number) An indexed-sequential file consists of two files: the data file containing the actual data and the index file containing pointers to record keys within the data file. The location of the record key within each record is specified when the file is built. To build an indexed-sequential file, you must provide a sequential file and some necessary information to the ISAM program. (See Section 5.9, ISAM - Indexed-Sequential File Maintenance Program.) ISAM then copies the data from the sequential file and creates a data file and an index file to reference the data file. All reading and writing of the index file is performed by the object-time system; you need not be concerned with this function. When using indexed-sequential files, you need only specify 'which record is to be read, written, rewritten, or deleted. The object-time system performs all searching, insertion, deletion, and updating of both the index and data files. Indexed-sequential files must be accessed from disk. Also, because each indexed-sequential file is actually two files, two software I/O. channels are required - one for the data file and one for the index file. 8.6.1 Data File The data file can be recorded in EBCDIC, SIXBIT or ASCII; in any mode, the file must be blocked. When building an indexed-sequential file (by means of the ISAM utility program), you must provide a sequential file that contains record keys in the same relative location in each record. You are advised to sort the file in advance to insure that the most efficient index is built. Each record must have a unique key and the keys must be arranged in ascending order (numeric, alphabetic, or alphanumeric). You can indicate to the ISAM program that some records in each block are to be left empty and some empty blocks should be added to the file. The empty records and blocks are to allow for insertion or addition of new records in the file. When a program processes the indexed-sequential file, insertions and additions are made by the object-time system. Records are inserted in a block in ascending order. When there are no empty record slots in the block, the bLock is split into two more or less equal blocks, and the record is added to the appropriate block. New blocks created by insertions or additions are placed in the empty blocks that were allocated when the file was built. If empty records and blocks were not provided when the file was built, the object-time system will request additional blocks from the monitor as needed. If the monitor 8-27 FILE FORMATS cannot allocate additional blocks (that is, because the user's quota on the file structure is exceeded or the system's limit was reached), an error message is issued. The format of the data file is similar to that sequential files, with the following exceptions. of relative and 1. The right half of the header word contains the size of the record in bytes. The left half contains a version number. Only the version number of the first record of a block has any meaning; it pertains to all records for that block. All records (ASCII, SIXBIT, and EBCDIC) have a header word. 2. All records are line-blocked; they occupy an integral number of words. ASCII records always end with a single carriage return/line feed pair. 3. For ASCII records, the left half of the header word contains a version number, bits 18 through 34 contain the size of the record in bytes, and bit 35 is always 1. Figure 8-25 shows the structure of an ISAM data file. IN .IDA FILE .IDA BLOCK STRUCTURE I0: A: T: A: : R: E:C:0: R:D:S I DATA RECORD STRUCTURE HEADER WORD DATA WORDS BLOCK NUMBER NO. OF CHARACTERS (SIXBIT OR ASCII) SIXBIT OR ASCII DATA (NOTE ON PADDING CHARACTERS ZEROES FOR ASCII, AND SPACES FOR SIXBIT) MR-S.Q53-79 Figure 8-25 ISAM Data File Structure 8.6.2 Index File The index file is created by the ISAM program from the description of the input data file and parameters specified by the user. It contains up to ten levels of indexes, the lowest of which contains pointers to the record keys in the data file. Each successive level of index points to all of the blocks containing the next lower-level index. The highest level index is contained in one block and points to the blocks containing the next lower-level index. Index levels are provided so that the entire index need not be searched each time that a record key is accessed. When a record key is accessed, the Object-time system reads the highest level index to find which lower-level index contains a pointer to the approximate location of that key. The block of the next lower-level index that contains the 8-28 FILE FORMATS approximate location of the key is then searched. If this is the lowest level index, it points to the first record of the data block in which the record is stored. The data block is then searched for the appropriate record key, and the record is made available. If this is not the lowest level index, the next lower-level is searched until the lowest level is reached. Figure 8-26 illustrates the search. A B C POINTERS TO DATA BLOCKS POINTERS TO NEXT LEVEL POINTERS TO NEXT LEVEL USERS KEYS REQUESTS RECORD WITH t"""--T"""'-""""'" KEY L ---.. 4 r 1 * D 2 D E 3 G F INDEX BLOCK 1 * ~-----II--I 2 J~---..l 5 R DATA BLOCK 1 4 DATA BLOCK 2 J G 5 M H 6 P INDEX BLOCK 4 INDEX BLOCK 2 INDEX BLOCK 6 INDEX LEVEL 2 (HIGHEST) I\,~ 3 R 7 R 8 V 9 Y INDEX BLOCK 5 INDEX LEVEL 1 (INTERMEDIATE) *=LOW VALUES DATA BLOCK 3 INDEX BLOCK 3 INDEX LEVEL 0 (LOWEST) INDEX FILE I J K L DATA BLOCK 4 DATA FILE MR·S'()54·79 Figure 8-·26 Locating a Record in an Indexed-Sequential File 8-29 FILE FORMATS The format of the index file is more complex than that of file. Figure 8-27 shows the structure of the index file. the data IN .IDX FILE I STATS BLOCK I SAT TABLE .IDX BLOCK STRUCTURE HEADER WORD 1 INDEX LEVEL NO. OF CHARS IN BLOCK (AS IF SIXBIT) I VERSION NO. OF THIS BLOCK HEADER WORD 2 I INDEX ENTRIES AS SPECIFIED IN ISAM DIALOG INDEX ENTRY STRUCTURE WORD 1 IPOINTER TO NEXT LOWER LEVEL OF INDEX OR DATA WORD 2 I VERSION NO. OF BLOCK POINTED TO WORDS 3 ·11 VALUE OF KEY COMPUTATIONAL IF NUMERIC OR SIXBIT CHARACTERS MR·S-055·79 Figure 8-27 ISAM Index File Structure Each index block in an indexed-sequential.file is written as were a block of a SIXBIT file. The format of the block is: if it header word 1: is the header word. The right half contains the size of the index block in characters, as if it were SIXBIT (that is, six characters per word). The left half contains a number representing the level of the index (the lowest level is 0). header word 2: contains the version number. This is initially set to 0 by the ISAM program, and is incremented by 1 whenever this block is divided due to the insertion of an entry when a WRITE is executed. Following word 2 are the index entries. Each entry has the format: word 1: contains the pointer to a data block (if this is index level 0) or a pointer to the next lower-level index block (if this is index level 1 or higher). word 2: contains the version number of the index or data block to which the index entry points. 8-30 FILE FORMATS words 3-11: contain the value of a key. If the key is nonnumeric, it extends over as many words as are necessary. If the key is numeric, it is kept in COMPUTATIONAL form (even if the record key for the file is DISPLAY). It is one word if 10 or fewer digits are in the key; it is two words if 11 or more digits are in the key. If the key is COMPUTATIONAL-l (floating point), it is one word. NOTE Take special care to describe your key fields in exactly the same way in both the ISAM program and your COBOL program. For example, if you describe your key field as S9(lO) DISPLAY to ~SAM, you should describe it the same way in your COBOL program. By using the same descriptions you will ensure that the same amount of storage is generated in both the ISAM file and its record area in memory. Within the index file, in addition to the index blocks, are two other blocks: the statistics block and the storage allocation table~The statistics block is a header containing all the necessary information about the index file and the data file. Included in these statistics are: the name and extension of the data file, the number of levels in the index, the blocking factor, and a description of the record key. The storage allocation table shows which data blocks are in use and which are free. There are as many blocks of this table as are necessary to contain this information. In general, an indexed-sequential file should be constructed so that it does not require more than three levels of index because the more levels of index the slower the access of the data will be. Indeed, it is usually a simple matter to restrict a file of moderate size to two levels of index. For example, if the maximum file is to be 200,000 records, the blocking of the data file could be 20 records per block and that of the index file 100 entries per block. Since 100*100*20 = 200,000 the file will never need more than two levels occasionally maintained using the ISAM program. 8-31 of index if it (See Section 7.1) is CHAPTER 9 SIMULTANEOUS UPDATE The COBOL-74 simultaneous update facility allows sequential, relative, or indexed-sequential data files to be updated concurrently by two or more running jobs. That is, it is possible for several truly independent jobs to modify, insert, and delete records in the same data files without loss of information or file integrity. Simultaneous update, under the control of COBOL-74, allows multiple users to share resources at the file level while having exclusive control of a portion of that resource at the record level. You should also refer to Part 2 of this manual, COBOL-74 Language Reference Material, for the simultaneous update features of the OPEN, RETAIN, and FREE statements. To declare in your program that a file is being processed concurrently with other programs, use the appropriate syntax available with the OPEN statements. (See Section 9.1.1, The OPEN Statement.) The OPEN statement identifies the file as being open for simultaneous update and ~xcludes non-simultaneous-update users from accessing it until you are willing to release it. The file is not released until you expressly close it by issuing a CLOSE statement. To gain exclusive control of individual records within the file, use the RETAIN statement. (See Section 9.1.2, The RETAIN Statement.) This statement inhibits any other user from accessing the retained records until you have finished processing them. Records can be released either: • Explicitly, by issuing a FREE statement The FREE Statement). (see • Implicitly, by exhaustion of the verb selection the preceding RETAIN statement. Section 9.1.3, specified on You are advised to make careful use of the RETAIN statement in order to avoid the two most common problems that can occur using simultaneous update. The first, buried update, occurs when two users are updating the same record concurrently and one user's update is overlaid by the other's. (See Figure 9-1, The Problem of Buried Update.) The second is deadly embrace. It occurs when two users make conflicting demands upon the file resources and neither is willing or able to yield to the other. This results in both users being stalled waiting for the other to relinquish control. (See Figure 9-2, The Problem of Deadly Embrace.) Both of these problems can be avoided by carefully declaring the resources'needed with a RETAIN statement prior to performing any I/O operations on a shared file. 9-1 SIMULTANEOUS UPDATE FILE RESOURCE IS AVAILABLE TO ALL USERS INDISCRIMINANTL Y 1. PROGRAM A ACCEPT KEY·A READ FILE·A 2. PROGRAM B ACCEPT KEY·A READ FILE·A 3. PROGRAM A REWRITE RECORD·A 4. PROGRAM B REWRITE RECORD·A NOTE: PROGRAM A'S UPDATE IS NOW LOST. MR·S'()56·79 Figure 9-1 The Problem of Buried Update 9-2 SIMULTANEOUS UPDATE INDIVIDUAL FILE RESOURCES ARE AVAILABLE TO ONLY ONE USER ATN ONE TIME. 1. PROGRAM A ACCEPT KEY-A READ FILE-A WITH LOCK 2. PROGRAM B ACCEPT KEY·8 READ FILE·8 WITH LOCK 3. PROGRAM A ACCEPT KEY·8 READ FILE-8 WITH LOCK (PROGRAM A IS DENIED ACCESS TO KEY·8 OF FILE·8) 4. PROGRAM 8 ACCEPT KEY·A READ FILE-A WITH LOCK (PROGRAM 8 IS DENIED ACCESS TO KEY·A OF FILE-A) NOTE: PROGRAMS A AND 8 ARE NOW STALLED. AS EACH HAS A LOCK ON A RESOURCE THAT THE OTHER WANTS. AND NEITHER CAN GIVE UP THE RESOURCE THAT THEY ALREADY HAVE A LOCK ON. MR·S.oS7·79 Figure 9-2 9.1 The Problem of Deadly Embrace PROGRAMMING CONSIDERATIONS Simultaneous update allows you to project the usage you want at both the file and record level. It also allows you to project the usage you will allow others to have while you have control of the file. A central clearing house in the COBOL-74 object-time system correlates these projections and takes one of three actions with respect to the intent of each user: • Allows the process to proceed • Suspends the process until the required resource is available • Returns with a message to the effect that the proceed at this time process cannot You project file usage by specifying which of the COBOL-74 input/output verbs you will execute during your tenure of the file or record and which you will allow others to execute. Once allowed to proceed, you are bound by the object-time system to act within the scope of your projections and are stopped if you attempt to do otherwise. For example, if you open a file for a read operation and then issue a ~rite you will be stopped from doing so. See Figure 9-3 for an outline of how resources can be projected for simultaneous update. 9-3 SIMULTANEOUS UPDATE PROCEDURE DIVISION. BEGIN-PARAGRAPH. OPEN 1-0 FILE-NAME-l FOR [verb selection] ALLOWING OTHERS [verb selection] (File-wide specification of resources) UNAVAILABLE [Object statements]. LOOP-PARAGRAPH. [Generate key values for records to be retained] RETAIN FILE-NAME-l RECORD KEY ••. FOR [verb selection] UNTIL FREED (Specification of record resources to be retained and manipulated within the context of a user-defined transaction) UNAVAILABLE [Object statement]. 1-0 verb selection as appropriate. Including READ, WRITE, DELETE, REWRITE. FREE [appropriate file records]. GO TO LOOP-PARAGRAPH. END-OF-JOB. CLOSE FILE-NAME-l •.• Figure 9-3 9.1.1 (Release of file-wide resource) Projecting Resources For Simultaneous Update The OPEN Statement The OPEN statement is the vehicle by which you declare a file is being used for simultaneous update. It allows you to specify: • Your projected usage of the operations you wish to perform file in terms • The projected usage you are willing to allow others of the I/O operations they are allowed to perform Figure 9-4 shows the general format of the OPEN statement. 9-4 of the in I/O terms SIMULTANEOUS UPDATE { b~TP~~T ,t fll. e-name-l [ WITH REVERSED r .fll e-name-2 [ WITH REVE:RSED NO REWIND NO REWIND L' { ~N~UT-OUTPUT} file-name-3 :~C~ITE FOR } [ WRITE { DELETE [ AND ALLOWING OTHERS [ £QR [ fil e-name-4 [ REWRITE READ WRITE { DELETE ANYVERB J[ AND [ ALLOWING QTHERS [ EXTEND] fi 1ename-5 [ f i l ename-6 ] [ UNAVAILABLE statement-l l[ READ NONE REWRITE WRITE ( DELETE ANY VERB AND - •.• READ NONE REWRI TE WRITE ( DELETE ANYVERB If READ AN D (NONE REWRITE WRITE DELETE ANYVERB ... J...:.. The OPEN Statement 9-5 READ (NONE ] REWRITE WRITE DELETE ANY VERB REWRITE READ }] WRITE ... { DELETE ANYVERB .,. [,statement-2 ] Figure 9-4 }] WRITE DELETE AiWVfRB ANVVE RB OPEN {:~C~ITE JlJ II ... J SIMULTANEOUS UPDATE The following rules apply to the use of an OPEN being processed under simultaneous update: statement for files 1. To open a file under simultaneous update, the ALLOWING OTHERS clause must be specified. 2. Every user, that is, every program expecting to process the file concurrently, must either open the file under simultaneous update or for input only. Other uses will be denied access. NOTE File access is determined on a first come first served basis. Therefore, if the first user opens a file for simultaneous update all others must likewise open it under simultaneous update. Conversely, if a file is open for normal processing, users attempting to open it under simultaneous update will be denied access. See Figure 9-5, Competing For Program Access to Files. 3. The file must be OPEN in I/O mode. 4. The COBOL-74 I/O verbs you intend to execute must be following the key word FOR. 5. The COBOL-74 I/O verbs you are willing to allow others to execute must be entered following the key words ALLOWING OTHERS. 6. All files to be opened for simultaneous update must be opened in the same OPEN statement. Multiple OPEN statements for simultaneous update are not allowed. Therefore, before another file can be opened for simultaneous update, the previously opened files must be closed. This prevents deadly embrace at the file level. 7. You can use the same OPEN statement to open files simultaneous update as well as for normal processing. 8. A maximum of sixteen (16) files can be OPEN statement. 9. If one or more of the files being opened for simultaneous update is not available in the mode specified, the program requ~sting the OPEN is suspended until the requested file is available. Those files, if any, that were opened during the process remain open. Control is not returned to the program until all of the requested files are open. If the UNAVAILABLE clause is specified, no file is opened, even though available, until all of the requested files are available. In this case, the statements following the UNAVAILABLE clause are executed. 10. The I/O verbs specified in the OPEN statement are the qnly verbs that can be used to process the file. Likewise, the I/O verbs you allow others to use are the only ones available to them. Any attempt to use verbs other than the ones specified will cause the object-time system to abort the program. 9-6 opened by entered a for single SIMULTANEOUS UPDATE Example 9-1 OPEN I/O FILE-A FOR READ AND WRITE, ALLOWING OTHERS READ AND WRITE. Example 9-2 OPEN OUTPUT FILE-A, LIST, INPUT-OUTPUT FILE-B FOR READ AND REWRITE, OTHERS ANY FILE-C FOR READ, OTHERS READ AND REWRITE, FILE-D FOR ANY, OTHERS NONE, INPUT FILE-E WITH NO REWIND, 1-0 FILE-F, FILE-G FOR WRITE. Example 9-3 OPEN 1-0 FILE-A FOR READ AND WRITE, OTHERS ANY, UNAVAltABLE OPEN 1-0 FILE-A FOR READ, OTHERS ANY, UNAVAILABLE STOP RUN. 9-7 SIMULTANEOUS UPDATE WITH AND WITHOUT SIMULTANEOUS UPDATE 1. PROGRAM A OPEN FILE·A FOR SIMULTANEOUS UPDATE 2. PROGRAM B OPEN FILE·A FOR INPUT ONLY 3. PROGRAM C OPEN FILE·A WITHOUT SIMULTANEOUS UPDATE ~ / FILE·A () 1. PROGRAM C ~ OPEN FILE·A WITHOUT .--_ _S_IM_U_L_TA_N_E_O_US_U_P_D_A_TE---, 2. ;;( ----t'. PROGRAM A FI LE.A () OPEN FILE·A UNDER SIMULTANEOUS UPDATE MR·S·058·79 Figure 9-5 9.1.2 Competing For Program Access to Files The RETAIN Statement The RETAIN statement allows you to gain exclusive control of individual records within a file that was previously opened for simultaneous update. Figure 9-6 shows the general format of the RETAIN statement. 9-8 SIMULTANEOUS UPDATE RET AI N fil e- name-l ~ RE COR D [KEY l NEXT RECORD READ REWRITE READ- REW RI TE } DELETE WRITE ANY VERB (identifier-I}] ) lliteral-l f [UNTIL FREED] [KEY { i d'enti fi er-2 } ] literal-2 NEXT RECORD fil e-name-2! RECORD FOR ~~C~ITE ~~~~T~EWRITE } [UNTIL FREED J ... [statement-2 J' ... ] I { WRITE ANY VERB [UNAVAILABLE statement-l Figure 9-6 The RETAIN Statement The following general rules apply to the use of the RETAIN statement. For a description of how the RETAIN statement is used for the individual file types (sequential, relative, indexed-sequential) see Sections 9.1.4, 9.1.5, and 9.1.6 respectively. (See also the COBOL-74 Language Reference Material, Part 2 of this manual.) 1. The file(s) named in a RETAIN statement must have been If not, the previously opened under simultaneous update. object-time system will abort the program. 2. A RETAIN statement must be given before any record on a opened for simultaneous update can be accessed. 3. You can use the same RETAIN statement to reserve records on sequential, relative, or indexed-sequential files. The I/O verbs selected, however, must conform to those allowed for the file. 4. All r~cords to be retained concurrently must be retained with the same RETAIN statement. Once records have been retained, no other records may be retained until the currently retained records are freed. 9-9 file SIMULTANEOUS UPDATE 5 •. The retention of records is purely a logical operation and does not involve any actual I/O. You may, in fact, retain nonexistent records. Obviously, any attempt to read or rewrite any of these records could result in an I/O error that could cause your program to be terminated. (See note 6. ) 6. A RETAIN statement, consistent with note 5, will not cause an AT END condition. This can only be caused by a READ statement. The RETAIN statement in this case merely retains a nonexistent record after the last one in the file. 7. If you retain a record for a READ operation, other users are allowed concurrent access to that record for READ. If you retain a record for any other type of I/O, all other users are denied access until you have freed it. 8. The I/O usage you specify·in a RETAIN statement must agree with the usage you specified in the OPEN statement for the file. For example, if you want to retain a record for a WRITE operation, you must have specified WRITE in the OPEN statement for the file. This holds true as well for the ANY VERB option. The key words ANY VERB must appear in the OPEN statement if you want to use them in a RETAIN statement. 9. The records named in the RETAIN statement are automatically freed upon execution of the I/O verbs specified in the FOR clause. The only exceptioQs are: a. If the ANY VERB option is specified in the FOR clause, FREE statement must be issued to release a record. b. If the UNTIL FREED option is specified, a FREE must be issued to release a record. a statement NOTE The UNTIL FREED option allows you to retain several logically related records for processing without their being automatically freed by the I/O verbs. c. If an I/O verb is specified in a RETAIN statement but that verb is not executed, the record will not be freed until a FREE statement is issued. 10. The KEY phrase allows you to specify a particular record or more than one record in a file. If no key is provided, KEY 0 is assumed. 11. The value of the key may be specified by any identifier that can be subscripted, qualified, or both. Its usage, however, must be COMPUTATIONAL. For example: RETAIN FILE-A RECORD KEY PAY-REC OF RECORD-KEYS FOR READ-REWRITE. 9-10 SIMULTANEOUS UPDATE It may also be a positive numeric literal contalnlng to 10 digits. You can, for example, enter: from 1 RETAIN FILE-A-RECORD KEY 123 FOR READ-REWRITE. 12. The optional word RECORD may be used as a reminder are retaining records, not files. For example: that you RETAIN FILE-A RECORD FOR READ. retains the next record in FILE-A. 9.1.3 The FREE Statement The FREE statement explicitly frees records that have been retained for simultaneous update. Figure 9-7 shows the general format of the FREE statement. identifier-l 1i tera 1-1 RECORD fi1e-name-l { EVERY RECORD FREE [ file-na~-2 RECORD [KEY { J identifier-2 1 1i tera 1-2 EVERY RECORD EVERY -RECORD [NOT RETAINED statement-l Figure 9-7 statement-2] . .• ] .!.. The FREE Statement The following general rules apply to the use of the FREE statement. For a description of how the FREE statement is used- with the individual file types, sequential, relative, and indexed-sequential, see Sections 9.1.4, 9.1.5, and 9.1.6 respectively. (See also the COBOL-74 Language Reference Material, Part 2 of this manual.) 1. The FREE statement is required to explicitly release records that have not been implicitly released by an I/O statement. This could occur when: a. The RETAIN statement contains the UNTIL FREED phrase b. An I/O statement is not issued after the RETAIN statement c. The FOR clause of the RETAIN statement specifies ANY VERB 9-11 SIMULTANEOUS UPDATE 9.1.4 2. The EVERY RECORD phrase allows you to free all of the records retained or just those of a particular file. It saves you from having to issue a separate FREE statement for every record that was retained. 3. When the EVERY RECORD phrase is used, the NOT RETAINED condition will occur only if no records are currently retained or if no records in a specific file are retained. 4. The NOT RETAINED phrase specifies the COBOL statements to be executed in the event that one or more of the record(s) you are attempting to free have not been retained. If this phrase is not specified, the program continues and you are not notified of any possible error. 5. A FREE statement issued to a file that was not opened for simultaneous update will cause the statements following the NOT RETAINED phrase, if present, to be executed. If the NOT RETAINED phrase was not specified in this case, the program continues and you are not notified of a possible error condition. 6. A single FREE statement can be used to free records from all open files, regardless of file type. 7. All records, regardless of how they were automatically freed when the file is closed. retained retained, are Accessing Sequential Files The following sections describe how to use the statements to access records in a sequential file. RETAIN and FREE 9.1.4.1 Basic Reading - The simplest way to read a sequential file opened for simultaneous update is to execute pairs of statements like this: RETAIN FILE-A FOR READ. READ FILE-A AT END GO TO EOJ. The RETAIN statement projects your intent to read the next record of FILE-A. The READ statement delivers the next record to the file's record area in memory, and automatically frees it for use by other users. 9.1.4.2 Basic Writing - Basic writing of a sequential file opened for simultaneous update is analogous to basic reading. For example, you could use code that looks like this: RETAIN FILE-A FOR WRITE. WRITE FILE-A-RECORD. In this case, FILE-A-RECORD is written out to FILE-A and automatically freed for access by other users. 9-12 SIMULTANEOUS UPDATE 9.1.4.3 Basic Updating - ~o update the nex~ record in a file open for simultaneous upate, you can use statements that look like this: RETAIN FILE-A FOR READ-REWRITE. READ FILE-A AT END GO TO EOJ. REWRITE FILE-A-RECORD. FILE-A-RECORD is automatically released upon execution of the REWRITE statement because both verbs named in the RETAIN statement have been executed. If only one or none of the verbs were executed, the record would not have been freed and any attempt to RETAIN any other records would fail. If, however, your application is such that you mayor may not want to update a record once it has been read, code of this nature could be used: RETAIN FILE-A FOR READ-REWRITE. READ FILE-A AT END GO TO EOJ. IF CHANGED REWRITE FILE-A-RECORD ELSE FREE FILE-A. 9.1.4.4 Sophisticated Access to Sequential Files - There are two reasons why the basic reading, writing, and updating of sequential files as outlined in Sections 9.1.4.1, 9.1.4.2, and 9.1.4.3 will not be sufficient for some applications: 1. Performance 2. Logically related records Each time you retain a record and that record happens to be already in your buffer, it is necessary to refill that buffer from mass storage to make sure that you have the very latest copy. Similarly, each time a record that you have written or rewritten is implicitly or explicitly freed, you must be certain that it is the very latest copy, and that no other user has updated that record in the interim. These considerations have little effect on the performance of relative or indexed-sequential files accessed randomly, but the effect on sequentially processed files is profound. Processing a file with a blocking factor of ten as suggested in Sections 9.1.4.1, 9.1.4.2, or 9.1.4.3, would require an order of magnitude more input/output overhead than it would if you were not using simultaneous update mode. This is the performance reason for using more sophisticated coding techniques. Sometimes, several records in a file are logically related and must be updated together. For example, a header record and subsequent trailer records might be logically related in such a way that the trailer records cannot be changed unless the header record remains static. But with the basic techniques outlined in Sections 9.1.4.1, 9.1.4.2, 9-13 SIMULTANEOUS UPDATE and 9.1.4.3, only a single record can be retained at a time. This is the logically-related-records reason for more sophisticated coding techniques. The first step in providing for more sophisticated code is the introduction of a notation for addressing the records of a sequential file. The notation is this: record 0 is defined as the next record to be read or written. Records 1, 2, 3, through n are defined relative to record O. NOTE If you have just written a record, the next record to be written is the one following it. If you have just read a record, however, the next record to be written is the one just read. Therefore, if you have just read a record and then you retain record 0 for WRITE, you have in effect retained the record just read. If, however, you have just read a record and then you retain record 0 for READ-WRITE, you have effectively retained the next record in the file. Sequential file users should cpde for performance by retaining several records at a time. Performance is optimal if the number of records retained is a multiple of the blocking factor and the execution of the RETAIN statement is synchronized with logical block boundaries. A RETAIN statement for 'a file whose blocking factor is 5 might look like this: RETAIN FILE-A KEY 0 FOR READ, FILE-A KEY 1 FOR READ, FILE-A KEY 2 FOR READ, FILE-A KEY 3 FOR READ, FILE-A KEY 4 FOR READ. This would then be followed by READ and/or FREE statements until all Subsequent FREE statements use the same records have been freed. notation for freeing records as was used for retaining them. Thus RETAIN FILE-A KEY 0 FOR READ. FILE-A KEY 1 FOR READ. READ FILE-A AT END GO TO EOJ. FREE FILE-A KEY 1. causes the second record of the pair to be freed, not the next one the file. 9-14 in SIMULTANEOUS UPDATE Providing a notation foe referencing several records of a sequential file is not enouqh for updating several logically related records together. It is also necessary to retain a record, even though you are through with it, until all of the related records have been processed. The UNTIL FREED phrase is provided for this purpose. It allows you to defeat the automatic freeing of records and retain them until you are ready to expressly free them. Also, to facilitate the freeing of multiple records, the EVERY RECORD phrase is provided. It allows you to free every record retained or every record in a particular file. Thus, to update three logically related records in a particular file, you can code: RETAIN FILE-A KEY 0 FOR READ-WRITE UNTIL FREED, FILE-A KEY I FOR READ-WRITE UNTIL FREED FILE-A KEY 2 FOR READ-WRITE. READ FILE-A AT END GO TO EOJ. WRITE FILE-A-RECORD. READ FILE-A AT END GO TO EOJ. WRITE FILE-A-RECORD. READ FILE-A AT END GO TO EOJ. WRITE FILE-A-RECORD. FREE FILE-A EVERY RECORD. You could also use the ANY VERB phrase to accomplish the same results. For example: RETAIN FILE-A KEY 0 FOR ANY VERB results in your having to expressly free finished with it. the record when you have When retaining records, the program will normally be suspended if any of the requested files or records are unavailable. You will not be notified of this suspension unless you have provided the UNAVAILABLE phrase as part of the RETAIN statement. The UNAVAILABLE phrase allows you to specify a procedure to be followed in the event a record or file is unavailable at the time your program attempts to access it. For example: RETAIN FILE-A KEY 0 FOR ANY VERB UNAVAILABLE PERFORM UNAVAIL-RTN. This instructs the object-time system to execute the statement following the word UNAVAILABLE in the event that the file (FILE-A) or the next record in the file is unavailable at the time the RETAIN statement is executed. 9-15 SIMULTANEOUS UPDATE Similarly, if you execute a FREE statement for a record or records that are not currently retained by your program, the object-time system will proce~d to the next instruction in your program as though the condition did not exist. If you wish to be informed of this condition, you must provide the NOT RETAINED phrase in the FREE statement. The NOT RETAINED phrase causes the object-time system to execute the procedures immediately following the words NOT RETAINED. A FREE statement of this kind might look like this: FREE FILE-A KEY 0 NOT RETAINED GO TO ERROR-RTN. 9.1.5 Accessing Relative Files Accessing records in a relative file is similar to the accessing of There are, however, sequential file records. (See Section 9.1.4.) these differences: 1. If a key is not specified, the RELATIVE KEY specified in FD for the file is used. the 2. positive keys, whether specified directly or via RELATIVE KEY, designate fixed (absolute) records of the file (as opposed to designating records relative to the current record) • Thus, record 1 is always the first record of the file, not the next record. A zero key, on the other hand, is interpreted in the same way as for sequential files: that is, record 0 is defined as the next record to be read or written. 3. A RETAIN statement, by virtue of its not performing actual I/O, cannot generate an INVALID KEY condition. any Example 9-4 demonstrates reading a relative file sequentially. Example 9-4 \ A. RETAIN FILE-A FOR READ. READ FILE-A NEXT RECORD; INVALID KEY GO TO ERROR-RTN. GO TO A. Example 9-5 shows how a file can be processed randomly. Note that the UNTIL FREED clause is used to insure that no one can access the record until it is written. 9-16 SIMULTANEOUS UPDATE Example 9-5 A. PERFORM RELATIVE-KEY-GENERATION. RETAIN FILE-A KEY GENERATED-KEY FOR READ-WRITE UNTIL FREED READ FILE-A INVALID KEY GO TO ERR-RTN . . WRITE FILE-A-RECORD. FREE FILE-A RECORD. GO TO A. Example 9-6 shows how to use a field within a record as the RELATIVE KEY for processing a chain of related records in a relative file. Procedure A initializes processing with record number 64. Procedure B insures that record 64 is stable, that is, that it has not been changed by some other user after you read it and that it will not be changed while you are processing it. Example 9-6 A. MOVE 64 TO FILE-A-REL-KEY. RETAIN FILE-A FOR READ. READ FILE-A INVALID KEY GO TO ERR-RTN. B. RETAIN FILE-A FOR READ-REWRITE FILE-A KEY NUMBER OF FILE-A-RECORD FOR READ-REWRITE. READ FILE-A INVALID KEY GO TO ERR-RTN. IF (record not stable) FREE FILE-A EVERY RECORD. GO TO B. C. 9.1.6 (process record 64 and record pointed to ,by NUMBER) Accessing Indexed-Sequential Files Accessing records in an indexed-sequential file is similar to the accessing of sequential file records. (See Section 9.1.4.) There are, however, these differences: 1. You may retain records for REWRITE, DELETE, and READ-REWRITE, in addition to READ, WRITE, and ANY VERB. You may not retain a record for READ-WRITE. 2. If no key is specified, the RECORD KEY defined in the statement for the file is used. 9-17 SELECT SIMULTANEOUS UPDATE 3. If a key is supplied, it must be specified with an identifier that agrees with the file's RECORD KEY in size, class, usage, and number of decimal places. The only exception is a key whose usage is COMP; in this case, a positive numeric literal of ten or fewer digits may be used. 4. Retaining or freeing records does not affect the "remembered" key of the file; that is, the record which would be read by a READ NEXT statement would be the same before and after a RETAIN or a FREE statement. Example 9-7 demonstrates processed sequentially. how an indexed-sequential file can be Example 9-7 A. RETAIN FILE-A KEY FILE-A-KEY FOR READ. READ FILE-A NEXT RECORD; INVALID KEY GO TO ERR-RTN. GO TO A. Example 9-8 shows the random processing of an indexed file. Note how the UNTIL FREED statement is used to insure the stability of the record. Example 9-8 A. ACCEPT DATA~KEY • . RETAIN FILE-A KEY DATA-KEY FOR READ-REWRITE UNTIL FREED. READ FILE-A INVALID KEY GO TO ERR-RTN. DISPLAY FILE-A-RECORD. B. (process and update record if the user wishes) C. FREE FILE-A-RECORD. GO TO A. 9-18 CHAPTER 10 REPORT WRITER The COBOL compiler offers a report writing facility, REPORT WRI~ER. Using this facility can make it easy to format printed reports. The example program on the following pages shows how to use the major features of REPORT WRITER. The full formats and available options for each statement are discussed in detail in the COBOL-74 Language Reference Material, Part 2 of this manual. 10-1 REPORT WRITER PRO G RAM REPORT.CBL 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 0032 0033 0034 0035 0036 0037 0038 0039 0040 0041 0042 REP E X M COBOL-74 l2{60l) BIS 20-0CT-78 11:16 PAGE 1 20-0CT-78 11:16 ID DIVISION. PROGRAM-ID. REPEXM. * ************************************************************** ** ** * * * * * * * This program is an example of the use of REPORT WRITER. The program generates two reports: one is a list of customers by city and state; the other is a list of totals for each state. The two reports are generated at one time and into one file. The line printer spooler can separate them at the time they are to be printed. ** * * * * * * * * * * ************************************************************** ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. * ************************************************************** ** ** * * * * * * ** The following entry in the SPECIAL-NAMES paragraph of the ** CONFIGURATION SECTION defines the codes 'A' and 'B' for * the two reports we are going to generate. The line printer * spooler can separate them when we use the /REPORT switch * Report Codes (Line 37) with the system QUEUE command. both reports, we would use For example, to print * * Q LL:=CUSTMR.LPT/REPORT:A,CUSTMR.LPT/REPORT:B * * ** *************************************************************** 'A' IS BY-CITY-CODE;'B' IS STATE-TOTALS-CODE. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CUSTOMER-FILE; ASSIGN TO DSK; RECORDING MODE IS ASCII. 10-2 REPORT WRITER 0043 PRO G RAM REPORT.CBL 0044 0045 0046 0047 0048 0049 0050 0051 0052 0053 0054 0055 0056 0057 0058 0059 0060 0061 0062 0063 0064 0065 0066 0067 0068 0069 0070 0071 0072 0073 0074 0075 0076 0077 0078 0079 0080 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 2 20-0CT-78 11:16 * ************************************************************** * ** Report file SELECTion and ASSIGNment (Line 55) * ** Like any file, the file for the report must be SELECTed and ** * ASSIGNed. Here we're using a disk file, but any device is * * * legal. ** *************************************************************** SELECT PRINTER-FILEi ASSIGN TO DSKi RECORDING MODE IS ASCII. SELECT SORT-FILEi ASSIGN TO DSK,DSK,DSK,DSK,DSKi RECORDING MODE IS ASCII. DATA DIVISION. FILE SECTION. SD 01 FD 01 SORT-FILE. SORT-RECORD. 02 SORT-NAME 02 SORT-CITY 02 SORT-STATE 02 SORT-STREET 02 SORT-SALES PIC PIC PIC PIC PIC X(24) USAGE DISPLAY-7. X(20) USAGE DISPLAY-7. XX USAGE DISPLAY-7. X(20) USAGE DISPLAY-7. S9(10) USAGE COMPo CUSTOMER-FILE VALUE OF IDENTIFICATION IS 'CUSTMRDAT'. CUSTMR-RECORD. 02 CUSTMR-NAME PIC X(24) USAGE DISPLAY-7. 02 CUSTMR-STREET PIC X(20) USAGE DISPLAY-7. 02 CUSTMR-CITY PIC X(20) USAGE DISPLAY-7. 02 CUSTMR-STATE PIC XX USAGE DISPLAY-7. 02 CUSTMR-SALES PIC S9(10)V99. 02 FILLER PIC X(302). 10-3 REPORT WRITER 0081 PRO G RAM REPORT.CBL 0082 0083 0084 0085 0086 0087 0088 0089 0090 0091 0092 0093 0094 0095 0096 0097 0098 0099 0100 0101 0102 0103 0104 0105 0106 0107 0108 0109 0110 0111 0112 0113 0114 0115 0116 0117 0118 0119 0120 0121 0122 0123 0124 0125 0126 0127 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 3 20-0CT-78 11:16 * ************************************************************** * * * * * The FD for the Report File (Lines 100 - 103) * Here we give the file for the report the name CUSTMR.LPT. * * The REPORTS ARE clause names the RD entries that we'll define in the REPORT SECTION and names the reports to be written in the file. * * * * * * * * * * * * * * * The record named in the 01-leve1 entry must be large enough * to contain the largest line written (including a 1-character* code. In our example, we never refer to PRINTER-RECORD in * the PROCEDURE DIVISION, so we could omit this; the default * size for PRINTER-RECORD is 132 characters. * * * * ************************************************************** FD 01 PRINTER-FILE; REPORTS ARE STATE-TOTALS-ONLY,BY-CITY VALUE OF IDENTIFICATION IS ·CUSTMRLPT'. PRINTER-RECORD PIC X(70) USAGE DISPLAY-7. WORKING-STORAGE SECTION. 01 01 THIS-DATE TD-REDEFINED 02 TD-MONTH 02 TD-HYF-1 02 TD-DAY 02 TD-HYF-2 02 TD-YEAR PICX(8). REDEFINES THIS-DATE. PIC Z9. PIC X. PIC 99. PIC X. PIC 99. 01 UNEDITED-DATE. 02 UE-YEAR 02 UE-MONTH 02 UE-DAY PIC 99. PIC 99. PIC 99. 77 77 77 TEMP PIC S999 USAGE COMPo NR-OF-CITIES PIC S999 USAGE COMPo NR-OF-STATES PIC S999 USAGE COMPo 77 77 77 ONE-COUNT PIC S9 USAGE COMP VALUE 1. CURRENT-STATE PIC XX. CURRENT-CITY PIC X(20) USAGE DISPLAY-7. 10-4 REPORT WRITER 0128 PRO G RAM REPORT.CBL 0129 0130 0131 0132 0133 0134 0135 0136 0137 0138 0139 0140 0141 0142 0143 0144 0145 0146 0147 0148 0149 0150 0151 0152 0153 0154 0155 0156 0157 0158 0159 0160 0161 0162 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 4 20-0CT-78 11:16 * ************************************************************** ** The REPORT SECTION Statement (Line 139) ** ** The REPORT SECTION is in the DATA DIVISION. It must be the ** * * last section of the division. In the REPORT SECTION, we * define the formats for the reports. * ** *************************************************************** REPORT SECTION. * ************************************************************** ** * * * * * * * * ** * * * ** * The RD is the report description for each report. We need * an RD for each report; one is here and the other is below. * * The CODE clause of the RD gives the mnemonic-name of the * code assigned to the report. This is the same code given * by the literal in the SPECIAL-NAMES paragraph of the * ENVIRONMENT DIVISION above. * * The CONTROL clause specifies the break fields in order from * most important to least important. FINAL is a special case * in which a control break will occur at the end of the * The RD for a Report (Lines 160 - 453) * report. * * * ************************************************************** RD STATE-TOTALS-ONLY CODE STATE-TOTALS-CODE CONTROLS ARE FINAL, SORT-STATE. 10-5 REPORT WRITER 0163 PRO G RAM REPORT.CBL 0164 0165 0166 0167 0168 0169 0170 0171 0172 0173 0174 0175 0176 0177 0178 0179 0180 0181 0182 0183 0184 0185 0186 0187 0188 0189 0190 0191 0192 0193 0194 0195 0196 0197 0198 0199 0200 0201 0202 0203 0204 0205 0206 0207 0208 0209 0210 0211 0212 0213 -0214 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 5 20-0CT-78 11:16 * ************************************************************** ** ** * The TYPE Statement (Line 266 and throughout the ROs) The TYPE statement defines the type of each record and where it appears in the report. The record need not be named unless it is referenced in the PROCEDURE DIVISION. ** ** * * * * ** * * * There are seven types of records: ** REPORT HEADING (or RH) is a heading that will appear at the beginning of the report. * * ** * REPORT FOOTING (or RF) is a footing that will appear at * * the end of the report. * * ** PAGE HEADING (or PH) is a page heading that will appear * * at the top of each page of the report. * * * * PAGE FOOTING (or PF) is a page footing that will appear * at the bottom of each page. * * ** ** CONTROL HEADING (or CH) is a heading that will appear * immediately before any detail lines whenever a * control break occurs, and after the page heading of * * * the first page. The name of the control break is * * specified in the CONTROL clause, and tells REPORT * WRITER which field to test for a control break. * * ** CONTROL FOOTING (or CF) is a footing that will appear ** * immediately after the last detail line before a * * control break. * * * DETAIL (or DE) is a detail line that is printed each * * time a GENERATE statement is executed in the * * PROCEDURE DIVISION. * * * * * ************************************************************** * ************************************************************** ** ** * * * * * * * The NEXT GROUP clause given the line-number of the line for * the beginning of the next group written. The argument for * NEXT GROUP can be a number; for example, NEXT GROUP IS 15 * places the next group on line 15 of the page. The argument * can also be relative; for example, NEXT GROUP IS PLUS 2 * places the next line two lines below the current line. * * * The NEXT GROUP Clause (Lines 266 and 424) * * ************************************************************** 10-6 REPORT WRITER 0215 PRO G RAM REP E X M 20-0CT-78 11:16 REPORT.CBL 20-0CT-78 11:16 0216 0217 0218 0219 0220 0221 0222 0223 0224 0225 0226 0227 0228 0229 0230 0231 0232 0233 0234 0235 0236 0237 0238 0239 0240 0241 0242 0243 0244 0245 0246 0247 0248 0249 0250 0251 0252 0253 COBOL-74 12(601) BIS PAGE 6 * ************************************************************** * * * * * * * * * * * (which can be abbreviated to LINE)* The LINE Clause (Line 267 and throughout the ROs) The LINE NUMBER IS clause tells on which line of .the page a report entry should be * written. The LINE clause applies to the item containing it * and continues to apply until the end-of-record or until * another LINE clause is found. * * The LINE clause can take three kinds of arguments: * * * * 1. An integer that specifies the line number. * * For example, LINE NUMBER IS 25 specifies line 25. * * If the number is smaller than the current line, a * * new page is begun. * * * * 2. PLUS with an integer that specifies how many lines * * below the current line to print the current entry. * * For example, LINE PLUS 3 means to skip two lines * * before printing the current entry. * * * * 3. NEXT PAGE, which specifies the next page. If the * * record is a page header, it will be printed on * * line 1; otherwise it will be printed on line 2. * * ** *************************************************************** * * ************************************************************** ** * * * * * The COLUMN Clause (Line 267 and throughout the RDs) * * The COLUMN NUMBER IS clause (we can omit NUMBER IS) tells REPORT WRITER which column is the first for a record or field. If a record or field does not have a COLUMN entry, it will not be printed. * * * * * * * * ************************************************************** 10-7 REPORT WRITER 0254 PRO G RAM REPORT.CBL 0255 0256 0257 0258 0259 0260 0261 0262 0263 0264 0265 0266 0267 0268 0269 0270 0271 0272 0273 0274 0275 0276 0277 0278 0279 0280 0281 0282 0283 0284 0285 0286 0287 0288 0289 0290 0291 0292 0293 0294 0295 0296 0297 0298 0299 0300 0301 0302 0303 0304 0305 REP E X M COBOL-74 12(601) SIS 20-0CT-78 11:16 PAGE 7 20-0CT-78 11:16 * ************************************************************** * The SOURCE Clause (Line 269 and throughout the RDs) * * ** * * * * * The SOURCE IS clause (we can omit IS) specifies the source * for an item. The source item must have been defined in the * FILE or WORKING-STORAGE SECTION. Its value is moved into * the report item before the item is written in-the file. * * * * ************************************************************** 01 TYPE PH NEXT GROUP PLUS 2. 02 LINE 1 COLUMN 22 PIC X(25) USAGE DISPLAY-7 VALUE 'State Totals of Customers'. 02 LINE 2 COLUMN 31 PIC X(8) SOURCE THIS-DATE. 02 LINE 5 COLUMN 1 PIC X(5) USAGE DISPLAY-7 VALUE ·State'. 02 LINE 5 COLUMN 10 PIC X(19) USAGE DISPLAY-7 VALUE 'Number of Customers'. 02 LINE 5 COLUMN 44 PIC X(5) USAGE DISPLAY-7 VALUE 'Sales'. * ************************************************************** ** ** * * * * ** * * * * * * * * * * * * * * * * * * The SUM clause in the second following line specifies that * the data-item will be summed. The data-item summed can be * either a SOURCE item from a TYPE DETAIL line (for example, * SORT-SALES in this program), or a summation counter (for * example, CITY-COUNT). * * When either the SOURCE item or the summation counter is * used, the value of the item is added to a compiler* generated accumulator and this accumulator is moved to the * report item before writing. The summation counter need * not be named unless it is referenced directly in the * PROCEDURE DIVISION or in another REPORT SECTION statement. * * A SUM clause can appear only in a TYPE CONTROL FOOTING * record. The accumulator is zeroed after being moved to the * report item. * ** You can selectively sum portions of a data-item by using the UPON option with the SUM clause. In that case, summing * occurs only when the item is refe~enced by a GENERATE * statement. The individual items to be summed'must be * SOURCE items within a data-name specified as a TYPE DETAIL * The SUM Clause (Line 309 and throughout the RDs) * report group. * * * ************************************************************** 10-8 REPORT WRITER 0306 PRO G RAM REPORT.CBL 0307 0308 0309 0310 0311 0312 0313 0314 0315 0316 0317 0318 0319 0320 0321 0322 0323 0324 0325 0326 0327 0328 0329 0330 0331 0332 0333 0334 0335 0336 0337 0338 0339 0340 0341 0342 0343 0344 0345 0346 0347 0348 0349 0350 0351 0352 0353 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 8 20-0CT-78 11:16 01 TYPE CF SORT-STATE LINE PLUS 1. 02 COLUMN 3 PIC XX SOURCE CURRENT-STATE. 02 COLUMN 15 PIC ZZ,ZZ9 SUM ONE-COUNT. 02 COLUMN 35 PIC ZZ,ZZZ,ZZZ,ZZ9 SUM SORT-SALES. 01 TYPE CF FINAL LINE PLUS 02 COLUMN 1 PIC VALUE 'Total'. 02 COLUMN 15 PIC 02 COLUMN 35 PIC 2. X(5) USAGE DISPLAY-7 ZZ,ZZ9 SUM ONE-COUNT. $$,$$$,$$$,$$9 SUM SORT-SALES. * ************************************************************** * * * * * * Missing COLUMN Clause (Lines 330 - 331) * * * * The following lines illustrate the fact that a report item will not be written in the report (even if directly specified in a GENERATE statement) unless the item has a COLUMN NUMBER clause. * * * * * * * ************************************************************** 01 TYPE DETAIL. 02 02 PIC S9(5) SOURCE ONE-COUNT. PIC S9(lO) SOURCE SORT-SALES. * ************************************************************** * * * * * * * * * * * * The PAGE LIMIT Clause (Line 351) * * * * The PAGE LIMIT clause specifies the number of lines that can be written on one page of the report. If a line is * written that would exceed PAGE LIMIT, page footings are * written, a new page. is begun, and page headings are written.* The PAGE LIMIT clause can contain additional options to control placement of p'age headings and footings, and the placement of first and last TYPE DETAIL lines. * * * * * * ************************************************************** RD BY-CITY CODE BY-CITY-CODE CONTROLS ARE FINAL SORT-STATE,SORT-CITYi PAGE LIMIT IS 58 LINES HEADING 1, FOOTING 58, FIRST DETAIL 6, LAST DETAIL 55. 10-9 REPORT WRITER 0354 PRO G RAM REPORT.CBL 0355 0356 0357 0358 0359 0360 0361 0362 0363 0364 0365 0366 0367 0368 0369 0370 0371 0372 0373 0374 0375 0376 0377 0378 0379 0380 0381 0382 0383 0384 0385 0386 0387 0388 0389 0390 0391 0392 0393 0394 0395 0396 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 9 20-0CT-78 11:16 01 REPORT-HEADER TYPE REPORT HEADING LINE 25. 02 COLUMN 27 PIC X(27) USAGE DISPLAY-7 VALUE 'Customers By City and State'. 02 LINE 29 COLUMN 36 PIC X(8) SOURCE THIS-DATE. 01 REPORT-FOOTER TYPE REPORT FOOTING LINE PLUS 2. 02 COLUMN 30 PIC X(19) USAGE DISPLAY-7 VALUE '** End of Report **'. * ************************************************************** * * * * * * * * * * * * * The compiler generates a data-item called PAGE-COUNTER for * each report descriptor (RD) item. It is set to 1 by the * INITIATE statement, and incremented by l' for each new page. * * If you define more than one report in the same program, you * must qualify a reference to PAGE-COUNTER by using the name * of the repor t. * The PAGE-COUNTER (Line 384) * * * ************************************************************** 01 PAGE-HEADING TYPE PAGE HEADING. 02 LINE 1 COLUMN 1 PIC X(33) USAGE DISPLAY-7 VALUE 'Customers By City and State'. 02 LINE 1 COLUMN 62 PIC X(4) USAGE DISPLAY-7 VALUE 'Page'. 02 LINE 1 COLUMN 66 PIC ZZZ9 SOURCE PAGE-COUNTER OF BY-CITY. 02 LINE 2 COLUMN 1 PIC X(8) SOURCE THIS-DATE. -01 STATE-HEADING TYPE CONTROL HEADING SORT-STATE LINE PLUS 2. 02 COLUMN 1 PIC X(9) USAGE DISPLAY-7 VALUE 'Customer'. 02 COLUMN 30 PIC X(5) USAGE DISPLAY-7 VALUE 'State' . 02 COLUMN 36 PIC X(4) USAGE DISPLAY-7 VALUE 'City'. 02 COLUMN 65 PIC X(5) USAGE DISPLAY-7 VALUE 'Sales'. 10-10 REPORT WRITER 0397 REPORT.CBL 0398 0399 0400 0401 0402 0403 0404 0405 0406 0407 0408 0409 0410 0411 0412 0413 0414 0415 0416 0417 0418 0419 0420 0421 0422 0423 0424 0425 0426 0427 0428 0429 0430 0431 REP ~ A M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 10 20-0CT-78 11:16 PRO G RAM 01 DETAIL-LINE-1 TYPE DETAIL LINE PLUS 2. 02 COLUMN 1 PIC X(24) USAGE DISPLAY-7 SOURCE SORT-NAME. 02 COLUMN 32 PIC X(2) USAGE DISPLAY-7 SOURCE SORT-STATE. 02 COLUMN 36 PIC X(20) USAGE DISPLAY-7 SOURCE SORT-CITY. 02 COLUMN 56 PIC ZZ,ZZZ,ZZZ,ZZ9 SOURCE SORT-SALES. 02 PIC ZZ,ZZ9 SOURCE ONE-COUNT. 01 DETAIL-LINE-2 TYPE DETAIL LINE PLUS 1. 02 COLUMN 1 PIC X(20) USAGE DISPLAY-7 SOURCE SORT-STREET. 01 CITY-FOOTING TYPE CF SORT-CITY LINE PLUS 3. 02 CITY-COUNT COLUMN 4 PIC ZZ,ZZ9 USAGE DISPLAY-7 SUM ONE-COUNT. 02 COLUMN 11 PIC X(17) USAGE DISPLAY-7 VALUE 'customers in city'. 02 COLUMN 36 PIC X(20) USAGE DISPLAY-7 SOURCE SORT-CITY. 02 CITY-SALES COLUMN 56 PIC $$,$$$,$$$,$$9 SUM SORT-SALES. 01 STATE-FOOTING TYPE CF SORT-STATE LINE PLUS 3 NEXT GROUP NEXT PAGE. 02 STATE-COUNT COLUMN 4 PIC ZZ,ZZ9 USAGE DISPLAY-7 SUM CITY-COUNT. 02 COLUMN 11 PIC X(18) USAGE DISPLAY-7 VALUE 'customers in state'. 02 COLUMN 32 PIC X(2) SOURCE SORT-STATE. 02 STATE-SALES COLUMN 56 PIC $$,$$$,$$$,$$9 SUM CITY-SALES. 10-11 REPORT WRITER 0432 PRO G RAM REPORT.CBL REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 11 20-0CT-78 11:16 0433 0434 0435 0436 0437 0438 0439 0440 0441 0442 0443 0444 0445 0446 0447 0448 0449 0450 0451 0452 0453 FINAL-FOOTING TYPE CF FINAL LINE PLUS 1. 02 COLUMN 3 PIC X(5) USAGE DISPLAY-7 VALUE 'Total'. 02 COLUMN 15 PIC X(5) USAGE DISPLAY-7 VALUE 'Total'. 02 COLUMN 25 PIC X(5) USAGE DISPLAY-7 VALUE 'Total'. 02 COLUMN 45 PIC X(5) USAGE DISPLAY-7 VALUE 'Total'. 02 LINE PLUS 1 COLUMN 1 PIC X(9) USAGE DISPLAY-7 VALUE 'Customers'. 02 COLUMN 15 PIC X(6) USAGE DISPLAY-7 VALUE 'States'. 02 COLUMN 25 PIC X(6) USAGE DISPLAY-7 VALUE 'Cities'. 02 COLUMN 45 PIC X(5) USAGE DISPLAY-7 VALUE 'Sales'. 02 LINE PLUS 2 COLUMN 1 PIC ZZ,ZZ9 SUM STATE-COUNT. 02 COLUMN 16 PIC ZZ9 SOURCE NR-OF-STATES. 02 COLUMN 26 PIC ZZ9 SOURCE NR-OF-CITIES. 02 COLUMN 36 PIC $$,$$$,$$$,$$9 SUM STATE-SALES. 01 10-12 REPORT WRITER 0454 PRO G RAM REPORT.CBL 0455 0456 0457 0458 0459 0460 0461 0462 0463 0464 0465 0466 0467 0468 0469 0470 0471 0472 0473 0474 0475 0476 0477 0478 0479 0480 0481 0482 0483 0484 0485 0486 0487 0488 0489 0490 0491 0492 0493 0494 0495 0496 0497 REP E X M 20-0CT-78 11:16 20-0CT-78 11:16 'OTC U.l. .... PAGE 12 PROCEDURE DIVISION. * ************************************************************** * ** The USE BEFORE REPORTING Verb (Line 470) * ** You can include the USE BEFORE REPORTING verb in the * * DECLARATIVES SECTION of the PROCEDURE DIVISION. A report ** * record is specified in the USE statement to indicate when * * the USE procedure is to be performed. It is performed * * immediately before the report record is written. * ** *************************************************************** DECLARATIVES. EOR SECTION. USE BEFORE REPORTING REPORT-FOOTER. EOR-A. DISPLAY 'END OF REPORTS'. END DECLARATIVES. MAIN SECTION. START-PROC1. SORT SORT-FILE ON ASCENDING KEY SORT-STATE,SORT-CITY,SORT-NAME INPUT PROCEDURE IS IN-PROCEDURE OUTPUT PROCEDURE IS OUT-PROCEDURE. STOP RUN. IN-PROCEDURE SECTION. START-PROC2. OPEN INPUT CUSTOMER-FILE. LOOP. READ CUSTOMER-FILE AT END GO TO DONE-INPUT. COMPUTE SORT-SALES ROUNDED = CUSTMR-SALES. MOVE CUSTMR-NAME TO SORT-NAME. MOVE CUSTMR-STATE TO SORT-STATE. MOVE CUSTMR-STREET TO SORT-STREET. MOVE CUSTMR-CITY TO SORT-CITY. RELEASE SORT-RECORD. GO TO LOOP. DONE-INPUT. CLOSE CUSTOMER-FILE. 10-13 REPORT WRITER 0498 PRO G RAM REPORT.CBL 0499 0500 0501 0502 0503 0504 0505 0506 0507 0508 0509 0510 0511 0512 0513 0514 0515 0516 0517 0518 0519 0520 0521 0522 0523 0524 0525 0526 0527 0528 0529 0530 0531 0532 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 13 20-0CT-78 11:16 OUT-PROCEDURE SECTION. * ************************************************************** ** * * * * OPEN the Report File (Line 511) The report file must be OPENed before any records can be written in it. * * * * * * * ************************************************************** START-PROC3. OPEN OUTPUT PRINTER-FILE. ACCEPT UNEDITED-DATE FROM DATE. MOVE UE-DAY TO TO-DAY; MOVE UE-MONTH TO TO-MONTH; MOVE UE-YEAR TO TD-YEAR MOVE ,_, TO TD-HYF-1,TD-HYF-2. * ************************************************************** ** * * * * ** * * * * * The INITIATE statement causes the counters and accumulators * to be initialized. The summation counters are set to 0; * the PAGE-COUNTER is set to 1. * * Each report written must be named in an INITIATE statement. * The output file for the report must be OPENed before any * INITIATE statement is executed. * * * INITIATE the Reports (Lines 531 - 532) * ************************************************************** INITIATE BY-CITY. INITIATE STATE-TOTALS-ONLY. 10-14 REPORT WRITER PRO G RAM REP E X M 20-0CT-78 11:16 REPORT.CBL 20-0CT-78 11:16 U~jj COBOL-74 12(601) BIS PAGE 14 0534 * ************************************************************** 0535. * * 0536 * GENERATE Report Records (Lines 577 - 578) * 0537 * * 0538 * The GENERATE statement causes testing of control fields and * 0539 * writes any required control headings and footings. If the * 0540 * argument to the GENERATE statement is a TYPE DETAIL record, * 0541 * the record is written after any control breaks. If the * 0542 * argument is a report descriptor (RD), the detail lines are * 0543 * set up but not printed, so that a summary report is written.* 0544 * * 0545 * In this program, both types of reports are generated. The * 0546 * GENERATE DETAIL-LINE statement causes a detail report to be * 0547 * written; the GENERATE STATE-TOTALS-ONLY statement causes a * 0548 * summary report to be written. * 0549 * * 0550 * A GENERATE statement performs the following operations: * 0551 * * 0552 * 1. Increments and tests the PAGE-COUNTER and produces * 0553 * any required page footings and headings. * 0554 * , 0555 * 2. Tests for any control breaks and produces any * 0556 * required control footings and headings. * 0557 * * 0558 * 3. Adds all specified identifiers to summation counters. * 0559 * * 0560 * 4. Executes any routines defined by USE statements. * 0561 * * 0562 * 5. If the argument to the GENERATE statement is a TYPE- * 0563 * DETAIL record, writes the detail report group. * 0564 * * 0565 * During the first execution of a GENERATE statement, all * 0566 * required report headings, page headings, control headings, * 0567 * and detail report groups are written. * 0568 * * 0569 * ************************************************************** 0570 LOOP. 0571 RETURN SORT-FILE: AT END GO TO DONE-REPORTS. 0572 IF CURRENT-STATE NOT EQUAL SORT-STATE 0573 ADD 1 TO NR-OF-STATES. 0574 IF CURRENT-CITY NOT EQUAL SORT-CITY 0575 ADD 1 TO NR-OF-CITIES. 0576 GENERATE DETAIL-LINE-l. 0577 GENERATE DETAIL-LINE-2. 0578 GENERATE STATE-TOTALS-ONLY. 0579 MOVE SORT-STATE TO CURRENT-STATE. 0580 MOVE SORT-CITY TO CURRENT-CITY. 0581 GO TO LOOP. 0582 10-15 REPORT WRITER 0583 PRO G RAM REPORT.CBL 0584 0585 0586 0587 0588 0589 0590 0591 0592 0593 0594 0595 0596 0597 0598 0599 0600 0601 0602 0603 0604 0605 0606 0607 0608 0609 0610 REP E X M COBOL-74 12(601) BIS 20-0CT-78 11:16 PAGE 15 20-0CT-78 11:16 * ************************************************************** ** ** * * * * * * TERMINATE the Reports (Line 609) The TERMINATE statement completes the processing for a report. When the TERMINATE statement is executed, breaks occur for all control fields and all control footings are written; all page footings and report footings are also written. If a program writes more than one report in the same file, each report must be named in a TERMINATE statement. * * * * * * * * * * * * * ************************************************************** * ************************************************************** ** ** * * * CLOSE the Report File (Line 610) The CLOSE statement closes the report file. All reports written in the file must be TERMINATEd before the CLOSE statement is executed. * * * * * * * * ************************************************************** DONE-REPORTS. TERMINATE BY-CITY,STATE-TOTALS-ONLY. CLOSE PRINTER-FILE. NO ERRORS DETECTED 10-16 CHAPTER 11 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS You may find it convenient to organize your program into parts to make the programming task easier, to allow the program to run more efficiently, or both. A COBOL programming task can be organized into program segments, into subprograms, or into an overlay structure. 11.1 PROGRAM SEGMENTS You can divide the Procedure Division of a COBOL program into parts called program segments. By doing this, you cause the system to run your program with some segments in memory only when they are needed; when they are not needed, they are on disk storage. Thus, the amount of memory required for execution is reduced. You can define program segments in a main program or in a subprogram, but only one segmented program is allowed in a single load. 11.1.1 Section-Names and Segment Numbers A program segment is made up of one or more sections, begins with a SECTION statement of the form each of which section-name SECTION nne where nn is a two-digit segment number in the range 00 to 99. A section extends from its SECTION statement to the next SECTION statement, or to the end of the program, whichever is first. All sections having the same segment number are in the same segment. A program segment is either resident or nonresident, and writeable or nonwriteable, depending on its segment number, and on the setting of the segment-limit. (The SEGMENT-LIMIT IS nn statement in the Environment Division defines the segment limit, which is the smaller of nn and 49; if nn is omitted or nn is 0, the segment-limit is 49.) A segment with a segment number of 50 or greater is nonresident and nonwriteable; it is brought into memory only when it is needed for execution. Further, such a segment loses any changes made by ALTER statements when it leaves memory. It is in its original state each time it enters memory. A segment with a segment number in the range SEGMENT-LIMIT to 49 is nonresident, but writeable; it retains changes made by ALTER statements. 11-1 PROGRAM SEGMENTS, SUBPROGRAMS, AND ·OVERLAYS A segment with a segment number less than the SEGMENT-LIMIT (or with no segment number) is a resident and writeable segment; it is always in memory during execution. Nonresident segments are suitable for routines that are executed infrequently, run for a long time once begun, and require large amounts of memory. For example, a program that has four maln tasks that are executed sequentially is an ideal application for nonresident segmentation. Placing each task in a nonresident segment allows the program to run with only one of the segments in memory at a time. On the other hand, a frequently used routine should be pla~ed in a resident segment to avoid the overhead of bringing it into memory time after time. 11.1.2 Examples In the following sample program, there are nine program SECTIONs forming six program segments. (Recall that sections having the same segment numbers are in the same segment.) PRO G RAM SEGMNT.CBL 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 S E G MN T 24-0CT-78 09:22 24-0CT-78 09:22 IDENTIFICATION DIVISION. PROGRAM-ID. SEGMNT. ENVIRONMENT DIVISION. CONFIGURATION SECTION. OBJECT-COMPUTER. DECSYSTEM-20 SEGMENT-LIMIT IS 25. DATA DIVISION. PROCEDURE DIVISION. SECTI SECTION 20. CALL A. SECT2 SECTION 65. CALL A. SECT3 SECTION 22. CALL A. SECT4 SECTION 20. CALL A. SECTS SECTION 60. CALL A. SECT6 SECTION 30. CALL A. SECT7 SECTION 35. CALL A. SECT8 SECTION 35. CALL A. SECT9 SECTION 60. CALL A. STOP RUN. NO ERRORS DETECTED 11-2 COBOL-74 12(601) BIS PAGE 1 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS In the example above, the segments are as follows: 11.2 1. Segment 20 contains the sections SECTI and SECT4. The SEGMENT-LIMIT IS 25 statement causes this segment to be resident and writeable. 2. Segment 22 writeable. 3. Segment 30 contains section SECT6. Since its segment number is above the SEGMENT-LIMIT but less than 50, it is nonresident and writeable; changes made to the segment are preserved even if it leaves and returns to memory. 4. Segment 35 contains sections nonresident and writeable. 5. Segment 60 contains sections SECTS and SECT9. Since its segment number is above 50, it is nonresident and nonwriteable; changes made to the'segment are lost when it leaves and returns to memory. 6. Segment 65 contains section SECT2. nonwriteable. contains section SECT3; it SECT7 It and is is resident SECT8. It nonresident and is and SUBPROGRAMS A COBOL subprogram is written and compiled as a separate program, but is meant to be executed together with other programs. When several programs are loaded and executed together, the program in which execution begins is called the main program; the other programs are called subprograms. A large programming task can become more manageable if the program is divided into subprograms. Each subprogram can perform a few relatively simple tasks and each can be written and tested separately by using "dummy" main programs. Using subprograms will also permit you to define an overlay structure at load time. (See Section 11.3 for a discussion of overlays.) A subprogram can open files, perform I/O for them, and close them; but no COBOL subprogram can perform I/O for files in another program. Any COBOL subprogram which will perform I/O must be linked to the main program. That is, there must be a link, consisting of CALL statements, or a series of CALL statements through a series of subprograms, from the main COBOL program to any COBOL subprogram which wishes to do I/O. The CALL statement does not have to be executed to provide a link - in fact, it may be in such a position that it will never be executed. This requirement will of course be met by any group of subprograms all of which are written in COBOL. If, however, you wish to call a non-COBOL subprogram, you must make sure that any COBOL routines which are called by the non-COBOL subprogram have a link to the main COBOL program if the COBOL routines wish to do any I/O. The COBOL compiler recognizes a subprogram by its use of LINKAGE SECTION, ENTRY, GOBACK, or the presence of the USING clause in the Procedure Division header. If a program has none of these, the compiler treats it as a main program. 11-3 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS The compiler generates a start address for a main program, but not for a subprogram. This start address is the address of the beginning of the Procedure Division, that is, the address where the first executable instruction is generated. This start address tells LINK and, in turn, the system where to begin execution of the program. You can force the compiler to generate a start address for a subprogram by using the IJ switch. You can prevent the compiler from generating a start address for a main program by using the II switch. NOTE A subprogram can be treated as a main program (that is, can cont~ln a start address) only if no statements in the Procedure Division refer to data in the Linkage Section. This is because in a main program only Data Division statements can allocate memory locations. There is no space in memory for data in the Linkage Section. 11.2.1 Inter-Program Communication Main programs and subprograms communicate by transfering execution control and by sharing data. The shared data may be in files, but it is often more useful for them to share data that is already in memory. 11.2.1.1 The Calling Program - In the calling program, a CALL statement transfers execution control to a subprogram and optionally makes a list of data-items available to the called subprogram. The CALL statement has the form: CALL {program- or entry-name} [USING identifier-l [,identifier-2] ... ]. The program- or entry-name specifies the point to which execution control is to be passed in a subprogram. If a program-name is given, it is the PROGRAM-ID name in the subprogram, and control 1S transferred to th~ beginning of the subprogram's Procedure Divisi6n. If an entry-name is -given, it is the name given by an ENTRY statement in the subpiogram, and control is transferred to that statement. Each program-name and entry-name must be unique among all those loaded together. The identifiers specified in the CALL statement give a list of data-items in the calling program. The memory locations associated with them ar~ then available for use in the called subprogram. If you omit the USING clause, no memory locations in the calling program are available to the called subprogram. Each identifier must be defined in the File Section, Working-Storage Section, or Linkage Section of the calling program. Eachdata-item must be word-aligned. (Items at the 01 and 77 levels and COMP items are already word-aligned; others may be aligned by using the SYNCHRONIZED LEFT clause.) 11-4 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS 11.2.1.2 The Called Subprogram - A subprogram can begin execution at any of its entry points. The beginning of the Procedure Division is always an entry point. Its entry-name is the name given in the subpr'ogram's PROGRAM-ID statement. You can name data-items to be available to the called program with a USING clause in the PROCEDURE DIVISION statement. This statement has the form: PROCEDURE DIVISION [USING identifier-l [,identifier-2] .•• ]. You can define additional entry which has the form: points using the ENTRY statement, ENTRY entry-name [USING identifier-l [,identifier-2] ••• ]. use by CALL statements in The specified entry-name is defined for calling programs and must be unique among all entry-names and program-names loaded together. The USING clause of the calling program's CALL statement may have defined data-items to be made available to the called subprogram. If so, the USING clause of the entry-point statement (PROCEDURE DIVISION or ENTRY) may give identifiers to be used as local names for the shared memory. The identifiers in the called subprogram's USING clause are assigned data-items in the shared memory from left to right. The lengths of the data-items in the called subprogram need not match those in the calling program; but the total length of the data-items in the called program must not exceed that in the calling program. The identifiers in the USING clause must be defined in the subprogram's Linkage Section and they must be level-Ol or level-77 identifiers. When a subprogram is called, execution proceeds in it as in any program. Control leaves the subprogram at the first executed GOBACK, EXIT PROGRAM, or STOP statement. If the subprogram does any I/O there must be a link to the main program consisting of COBOL subprograms. You may not have a COBOL subprogram doing I/O which is called by a non-COBOL subprogram. Execution of a GOBACK or EXIT PROGRAM statement in a subprogram returns control to the calling program. Execution of the calling program resumes at the statement immediately following the CALL statement that called the subprogram. Any changes to the data-items specified in USING clauses at the entry point are preserved on return to the calling program. The forms of the GOBACK and EXIT PROGRAM statements are: GOBACK. EXIT PROGRAM. Execution of a STOP statement halts execution program. The STOP statement has the form: STOP {RUN or literal}. 11-5 of the entire loaded PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS The STOP RUN statement ends program execution; there is no return to the calling program. The STOP literal statement causes a pause in program execution and the literal is typed on the user terminal. If you then type CONTINUE, execution continues at the statement following the STOP literal. 11.2.2 Loading a Subprogram Structure There are two ways to load a subprogram structure: 1. For simple loads, you can use the COMPILE-class commands. 2. For more complex loads, you must use LINK directly. In either case, the following special considerations for loading subprogram structures apply: every entry point (program-name or entry-name) referenced in a CALL statement anywhere in the loaded program must be satisfied by loading a program containing the program-name or entry-name. If some referenced entry points are missing, a fatal LINK error occurs at load time. 11.2.3 Object Libraries and Searches An object library is a file having one or more object modules; when LINK searches an object library, a module is loaded from the file only if it satisfies an unresolved global reference. (COBOL global references are created by the CALL or ENTER statement in a program; additional global references to routines in the object-time system are created by the COBOL compiler.) NOTE Object libraries are very different from source libraries. The source library is built using the COBOL utility program LIBARY and is accessed by the COpy statement in a COBOL program. The object library is built using the system program MAKLIB and is accessed by LINK command strings or by COMPIL-class system commands. The /SEARCH and /NOSEARCH switches turn on and off LINK's library search mode. When the library search mode is off (the initial default), LINK loads each input file you specify. When the library search mode is on, LINK searches each specified input file as a library. If the /SEARCH switch is appended to a file specification, then switch is automatically turned off after that file is searched. example: MYCOBL/SEARCH, COB4 searches MYCOBL.REL, but loads all of COB4.REL. 11-6 the For PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS If the /SEARCH switch is not appended to a file specification, then the switch remains on until end-of-line or until a /NOSEARCH switch is found, whichever is earlier. For example, COBO,/SEARCH MYLIBl,MYLIB2,/NOSEARCH COBI loads CaBO, searches MYLIBI and MYLIB2, and loads COBI. The system library C74LIB.REL is searched automatically when LINK loads programs compiled with COBOL. This search occurs at the end of loading. You can change this normal search procedure by using LINK switches. The /SYSLIB switch requires LINK to search specified system libraries no matter what kind of modules were loaded. The /NOSYSLIB switch forbids search of specified system libraries. Using these two switches, you can select the time for searching system libraries. The /USERLIB switch specifies that for modules from a specified translator, a given user library must be searched before the corresponding system library. For example, using the switch MYCOBL/USERLIB:COBOL requires LINK to search MYCOBL.REL before searching C74LIB.REL. The /NOUSERLIB switch can suspend the effect of a /USERLIB switch. Using combinations of these search-related switches gives you precise control of library searches. All LINK switches are described in detail in the LINK Reference Manual. 11.2.4 Examples Section 11.3 contains program listings of seven programs. The first of these is called CBLO; it is a main program. The remaining six programs are subprograms. Each has a Linkage Section that defines data items named in USING clauses of PROCEDURE DIVISION or ENTRY statements. The program CBL2 has two entry points defined by ENTRY statements. The following example shows how to load, save, and run these programs. The LOAD system command loads the programs; the SAVE command creates a file (CBLO.EXE) for the loaded program; the RUN CBLO command executes the program. All text between the RUN and EXIT lines were written by the executed program. The example is shown with a TOPS-IO system prompt character (.), but the TOPS-20 system prompt (@) could be there instead. TOPS-20 responds the same way to the LOAD command • . LOAD CBLO,CBLl,CBL2,CBL3,CBL4,CBLS,CBL6 COBOL: CBLO [CBLO.CBL] COBOL: CBLI [CBLl.CBL] COBOL: CBL2 [CBL2.CBL] COBOL: CBL3 [CBL3.CBL] COBOL: CBL4 [CBL4.CBL] COBOL: CBLS [CBLS.CBL] COBOL: CBL6 [CBL6.CBL] Loading LINK: EXIT . SAVE CBLO saved 11-7 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS .RUN CBLO We're at level 0 in program CBLO CBLO calling CBL2A We're at level 1 in program CBL2 at CBL2A calling CBLS CBL2 We're at level 2 in program CBLS CBLS doesn't call anything Returned to CBL2 CBL2 calling CBL6 We're at level 2 in program CBL6 CBL6 calling CBL3 We're at level 3 in program CBL3 CBL3 doesn't call anything Returned to CBL6 Returned to CBL2 Returned to CBLO CBLO calling CBL4 We're at level 1 in program CBL4 CBL4 calling CBLI We're at level 2 in program CBLI CBLI calling CBL2B We're at level 3 in program CBL2 CBL2B doesn't call anything Returned to CBLI Returned to CBL4 Returned to CBLO Execution ends in CBLO EXIT 11.3 at CBL2B OVERLAYS If your loaded program would be too large to execute in one piece, you can define an overlay structure for it. This permits the system to execute the program with only some parts in your virtual address space at one time. (See the chapter on overlays in the LINK Reference Manual.) 11.3.1 When to Use Overlays You do not need an overlay structure unless your program is too large for your virtual address space. If the program can fit in your virtual space, you should not define an overlay structure for it; the monitor's page-swapping facility is faster than overlay execution. 11.3.2 Overlayable COBOL Programs A COBOL subp~ogram following rules: 1. structure is overlayable if it observes the If a subprogram contains I/O verbs other than ACCEPT and DISPLAY 7 it must be placed in the root link. (The other I/O verbs are CLOSE, DELETE, OPEN, READ, REWRITE, START, and WRITE.) Further, the subprogram that does I/O must have a chain of calls from the main program entirely within the root link; the chain of calls cannot contain calls to subprograms in other links. 11-8 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS 2. The subprogram structure must not contain RERUN statements. 3. The subprogram structure must not contain reentrant code (compiled with /R under TOPS-IO or compiled without switches under TOPS-20 - thus users of TOPS-20 must use the /U switch to avoid reentrant code). To insure proper execution of a COBOL overlay, observe rules: the following 1. After bringing the overlay into memory (by a LOAD command), run it using the RUN command (not the START command). 2. Be sure that enough free memory is in the root link program to execute. (See Section 11.3.4.) A subprogram loaded into a nonroot link is not writeable. the link comes into memory, it is in its original state. 11.3.3 for the Each time Defining Overlays A program overlay has a tree structure. The tree is made up of links, each containing one or more program modules. These links are connected by paths. Using LINK switches, you define each link and each path. At the top of the tree is the root link, which must contain the main program. First-level links are below the root link; each first-level link is connected to the root link by one path. Second-level links are below the first-level links, and each is connected by a path to exactly one first-level link. A link at level n is connected by a path to exactly one link at level n-l. Notice that a link can have more than one downward path (to links), but only one upward path (to ancestor links). successor Figure 11-1 shows a diagram of an overlay structure with 5 links. root link is TEST; the first-level links are LEFT and RIGHT; second-level links are LEFTI and LEFT2. TEST Figure 11-1 Example of an Overlay Structure 11-9 The the PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS Defining an overlay structure allows your program to execute in a smaller space. This is because the code in a given link is allowed to make reference to memory only in links along a direct upward or downward path. In the structure in Figure 11-1, the link LEFT can reference memory in itself, in the root link TEST, or in its successor links LEFTI and LEFT2. More generally, a link can reference memory in any link that is vertically connected to it. Referencing memory in any other link is illegal; for example, a from LEFTI to LEFT2 is not a direct upward or downward path. path Because of this restriction on memory references, only one complete vertical path (at most) is required in the virtual address space at anyone time. The remaining links can be stored on disk while they are not needed. LINK has a family of overlay-related switches for defining overlays. These switches are described in detail in the LINK Reference Manual. The following example shows command strings for defining the overlay diagrammed in Figure 11-1. ;Define TEST. LOG ;Important messages ;Define TEST.OVL ;Define TEST.MAP ;Request diagram ;Root link ' ;Left branch ;Left-left branch ;Left-right branch ;Right branch ;Define TEST.EXE ;Execute now TEST/LOG/LOGLEVEL:2 /ERRORLEVEL:5 TEST/OVERLAY TEST/MAP LPT:TEST/PLOT CBLO,CBLI/LINK:TEST /NODE:TEST CBL2,CBL3/LINK:LEFT /NODE:LEFT CBL5/LINK:LEFTI /NODE:LEFT CBL6/LINK:LEFT2 /NODE:TEST CBL4/LINK:RIGHT TEST/SAVE /E/GO The first command string above defines the .LOG file for the overlay. TEST/LOG specifies that the file is named TEST.LOG. The /LOGLEVEL:2 switch directs that only LINK messages at level 2 or greater be written in the .LOG file. In the second command string, the /ERRORLEVEL:5 switch directs that messages below the level of 5 be suppressed for terminal typeout. The third command string, TEST/OVERLAY, tells LINK that an overlay structure is to be defined and that the file for the overlay is to be TEST.OVL. The fourth command string, TEST/MAP, defines overlay symbol maps. the file TEST.MAP The next command string, LPT:TEST/PLOT directs that a diagram overlay links be printed on the line printer. of for the The next command string, CBLO,CBLI/LINK:TEST, loads the files CBLO.REL and CBLl.REL into the root link. The /LINK:TEST switch tells LINK that no more modules are to be in the root link and that the link name is TEST. Each of the next four lines defines one link form: /NODE:linkname filenames/LINK:linkname 11-10 with a string of the PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS where: /NODE:/linkname specifies the previously defined link to which the present link is an immediate successor. filenames/LINK:linkname names the files in the current link and specifies the name of the link. The first of these four lines begins with /NODE:TEST, which tells LINK that the link being defined is to be an immediate successor to TEST, the root link. Then (on the same line) , the string CBL2,CBL3/LINK:LEFT loads the files CBL2.REL and CBL3.REL, ends the link, and names the link LEFT. The next line, /NODE:LEFT CBL5/LINK:LEFTl, defines a link named LEFTI containing the file CBL5.REL, and this link is an immediate successor to the link LEFT. The next line, /NODE:LEFT CBL6/LINK:LEFT2, defines another immediate successor to LEFT, this time containing the file CBL6.REL and called LEFT2. The last link is defined in the next line, /NODE:TEST CBL4/LINK:RIGHT. This string defines the link RIGHT, which is an immediate successor to TEST and contains the file CBL4.REL. The next-to-last line in the example, TEST/SAVE, directs LINK to create the saved file TEST.EXE. The last line, /E/GO, specifies that the loaded program is to be executed and that all commands to LINK are completed. 11.3.4 The /SPACE Switch to LINK For a COBOL overlay structure to execute properly, it must memory in its root link for the following uses: have 1. General-purpose I/O buffers 2. I/O buffers and file tables for sorting 3. Label record area for multireel files 4. File index blocks for split index blocks of ISAM files The /SPACE switch to LINK reserves free memory. free It has the form: /SPACE:n where n is the decimal number of words to be reserved. The /SPACE switch is used in the root link. For example, to allocate 5000 words of free memory in the overlay example above, you would type: CBLO,CBLI/SPACE:5000/LINK:TEST There are two types of space needed in the root link of a overlay: space for buffers and space for dynamic allocation. 11-11 COBOL PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS Use the following guidelines to compute the buffers: 1. free memory needed for Two buffers are needed for each sequential file and one additional buffer is needed for each extra area used in the program. For an unblocked sequential file (on disk or magnetic tape), each buffer is 128 words. For example, the buffer space needed for one sequential file on disk with one alternate area is 3*128 = 384 words. For a blocked sequential file on magnetic tape, the buffer size is the blocksize (record-size*records/block). For example, the buffer space needed for one blocked sequential file with 100 records per block and records of 100 words each is 2*100*100 = 20000 words. 2. One buffer is needed for each random-access file and one for each file that is open for I/O. The buffer size is the number of l28-word blocks needed to hold the logical block, plus seven words. For example, a random-access file with logical blocks of 25 10-word records has a block size of 250 words. The smallest number of 128-word blocks containing 250 words is 2 (= 256 words). Therefore the buffer size is 256 + 7 = 263 words. 3. Indexed-sequential files require one buffer for The buffer size is the sum of the following: each a. Enough l28-word blocks to contain each level of the index file. logical block for b. Enough l28-word blocks to data. logical block of c. A number of l28-word blocks equal to the number used in an index block. These are used for storage allocation tables. d. One 128-word block for the statistics block. e. One 128-word block for the index table. f. A number of words equal to the plus two words. g. A number of words equal to the largest blocking factor of all the indexed-sequential files in the program. For example, if the largest blocking factor is 10, then 10 words are required in the buffer. h. Enough l28-word blocks to contain the largest of the data or index blocks in all indexed-sequential files in the program. 11-12 contain a a largest index file. key-size, PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS For example, to compute the buffer SIze for an indexed sequential file with four levels, with l28-word index blocks and 256-word data blocks, compute as follows: 512 256 128 128 128 256 2 4 Total 1414 Four l28-word index blocks One 256-word data block One l28-word storage allocation table block One l28-word statistics block One l28-word index table block Two l28-word blocks for the largest of all data or index blocks Two words for the largest blocking factor 2-word index key plus two words Buffer size (in words) Use the following guidelines to compute the amount of needed for dynamic allocation during program execution: free memory 1. The size of the label-record area for a multireel file. This size is 16 words for standard labels. For nonstandard labels, the size is the number of characters in the label divided by 5. 2. The size of the index block of an indexed-sequential file the top index block is split. 3. The size of the sort I/O buffers if sorting is used in the program. This size is calculated as the number of devices assigned to the sort file in the SELECT clause times two (for two buffers for each file) plus 26 words for each file table for each device. For example, for a sort file with buffers as follows: four 4 * 128 words *2 + (4 * 26 words) assigned devices, if calculate 1128 words NOTE This calculation reflects only the requirements needed by COBOL. See also the SORT User's Guide for sort requirements. If you do not allocate sufficient free memory with the /SPACE switch, either your program will not begin execution or it will fail during execution. 11.3.5 The CANCEL Statement You can use the CANCEL statement structure to reduce memory size statement has the form: in a COBOL subprogram overlay during program execution. This CANCEL subprogram-l [,subprogram-2] •••• where each named subprogram is in one of the overlay links. 11-13 PROGRAM SEGMENTS, SUBPROGRAMS, AND OVERLAYS The CANCEL statement creates a call to the REMOV. Overlay Handler subroutine. This directs removal from core of the links containing the named subroutines, along with all their successor links. The Overlay Handler attempts to return the recovered memory. A CANCEL statement cannot direct removal of its own link or of any its ancestor links, including the root link. of In the overlay structure diagrammed in Figure 11-1, for example, a subprogram loaded into the link LEFT can CANCEL subprograms in link LEFTl, LEFT2, or both. But it cannot CANCEL subprograms in its own link, LEFT, or in the root link, TEST. 11.3.6 Examples The following pages show terminal listings of the example above. These pages are: associated with 1. COBOL listing files for the (seven pages) used in the 2. Terminal copy of the interactive use of LINK execute the overlay (two pages) to define 3. The file TEST.MAP, generated by LINK, which shows symbol maps for the overlay (eight pages) 11-14 programs files overlay and .TY SEGPRG.TTY PRO G RAM C B L 0 26-0CT-78 10:59 CBLO.CBL 22-NOV-77 19:00 ..... ..... .....I U1 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 COBOL-74 12(600) BIS PAGE 1 10 DIVISION. PROGRAM-ID. CBLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7 VALUE "We're at level" 02 LEVEL PIC 9V VALUE O. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7 VALUE" in program" 02 CALMSG PIC X(9) USAGE IS DISPLAY-7 VALUE" calling ". 02 RETMSG PIC X(12) USAGE IS DISPLAY-7 VALUE "Returned to " 02 B PIC X(8) VALUE" 01 PGMNAM PIC X(6) VALUE "CBLO". 01 ENDMSG PIC X(18) USAGE IS DISPLAY-7 VALUE ;'Execution ends in PROCEDURE DIVISION. DISPLAY LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY PGMNAM,CALMSG,"CBL2A". CALL CBL2A USING INFO. DISPLAY RETMSG,PGMNAM. DISPLAY PGMNAM,CALMSG,"CBL4". CALL CBL4 USING INFO. DISPLAY RETMSG,PGMNAM. DISPLAY PGMNAM,CALMSG,"CBL2B" . CALL CBL2B USING INFO. DISPLAY RETMSG,PGMNAM • DISPLAY ENDMSG,PGMNAM. STOP RUN. NO ERRORS DETECTED to ~ G') ~ 3: til tzj G') 3: tzj 2: 8 til til C D' to ~ G') ~ 3: til >- 2: t7 o < tzj ::c t'1 >- to< til SUB C B L 1 26-0CT-78 10:59 CBL1.CBL 22-NOV-77 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 ID DIVISION. PROGRAM-ID. CBL1. DATA DIVISION. WORKING-STORAGE SECTION. 01 PGMNAM PIC X(6) VALUE "CBL1". LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. PGMMSG PIC X(12) USAGE IS DISPLAY-7. 02 02 CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 RETMSG PIC X(12) USAGE IS DISPLAY-7. 02 B PIC X(8). PROCEDURE DIVISION USING INFO. ADD 1 TO LEVEL. DISPLAY B,B,LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY B,B,"CBL1 doesn't call anything" SUBTRACT 1 FROM LEVEL. GOBACK. NO ERRORS DETECTED .... ....I .... 0'\ COBOL-74 12(600) BIS PAGE 1 19:00 ItI ~ o (j) ~ 3: rn tzl (j) 3: tzl Z rn t-3 rn c tJ:I ItI ~ (j) ~ 3: rn ~ o o < tzl ~ s: "< rn SUB C B L 2 26-0CT-78 10:59 22-NOV-77 CBL2.CBL ..... ..... I ..... ~ 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 0024 0025 0026 0027 0028 0029 0030 0031 COBOL-74 12(600) BIS PAGE 1 19:00 ID DIVISION. PROGRAM-ID. CBL2. DATA DIVISION. WORKING-STORAGE SECTION. 01 PGMNAM PIC X(6) VALUE "CBL2". 01 ENTNAM PIC X(6). 01 ENTMSG PIC X(4) USAGE IS DISPLAY-7 VALUE" at " LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7. CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 02 RETMSG PIC X(12) USAGE IS DISPLAY-7. 02 B PIC X(8). PROCEDURE DIVISION. ENTRY CBL2A USING INFO. ADD 1 TO LEVEL. MOVE "CBL2A" TO ENTNAM. DISPLAY B,LEVMSG,LEVEL,PGMMSG,PGMNAM,ENTMSG,ENTNAM. DISPLAY B,PGMNAM,CALMSG, "CBL5". . CALL CBL5 USING INFO. DISPLAY B,RETMSG,PGMNAM . DISPLAY B,PGMNAM,CALMSG,"CBL6" . CALL CBL6 USING INFO . DISPLAY B,RETMSG,PGMNAM. SUBTRACT 1 FROM LEVEL. GOBACK. ENTRY CBL2B USING INFO. ADD 1 TO LEVEL. MOVE "CBL2B" TO ENTNAM. 0032 DISPLAY B,LEVMSG,LEVEL,PGMMSG,PGMNAM,ENTMSG,ENTNAM. 0033 0034 0035 DISPLAY B,"CBL2B doesn't call anything". SUBTRACT 1 FROM LEVEL. GOBACK. NO ERRORS DETECTED ttl ~ (j) ~ 3: til tzl (j) 3: tzl 2: ~ til til C tJ3 ttl ~ (j) ~ 3: til )II 2: o o < tzl ~ §: t< til SUB C B L 3 26-0CT-78 11:00 16-NOV-77 CBL3.CBL 0001 0002 0003 0004 0005 0006 0007 0008 "0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 COBOL-74 12(600) BIS PAGE 1 19:00 ID DIVISION. PROGRAM-ID. CBL3. DATA DIVISION. WORKING-STORAGE SECTION. PGMNAM PIC X(6) VALUE "CBL3". 01 LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7. 02 CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 RETMSG PIC X(12) USAGE IS DISPLAY-7." 02 B PIC X(8). PROCEDURE DIVISION USING INFO. ADD 1 TO LEVEL. DISPLAY B,B,B,LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY B,B,B,"CBL3 doesn't call anything". SUBTRACT 1 FROM LEVEL. GOBACK. to ~ en ~ 3: til tEl en 3: tEl 2: t-3 til NO ERRORS DETECTED ...... ...... I I-' CO til o tJ:I to ~ en ~ 3: til > 2: o ~ tEl ~ f;: to< til SUB C B L 4 26-0CT-78 11:00 16-NOV-77 CBL4.CBL 0001 0002 0003 0004 0005 0006 0.007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 ..... ..... I ..... \0 COBOL-74 12(600) BIS PAGE 1 19:00 ID DIVISION. PROGRAM-ID. CBL4. DATA DIVISION. WORKING-STORAGE SECTION. 01 PGMNAM PIC X(6) VALUE "CBL4". LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7. 02 CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 RETMSG PIC X(12) USAGE IS DISPLAY-7. 02 B PIC X(8). PROCEDURE DIVISION USING INFO. ADD 1 TO LEVEL. DISPLAY B,LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY B,PGMNAM,CALMSG,"CBL1". CALL CBL1 USING INFO. DISPLAY B,RETMSG,PGMNAM. SUBTRACT 1 FROM LEVEL. GOBACK. NO ERRORS DETECTED "0 ~ G') ~ 3: til tz.:I G') 3: tz.:I Z t-3 til til c:: '"~ "0 G') ~ 3: til )II Z t1 o <: tz.:I ~ §;: to< til SUB C B L 5 26-0CT-78 11:00 CBL5.CBL 16-NOV-77 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 COBOL-74 12(600) BIS PAGE 1 19:00 ID DIVISION. PROGRAM-ID. CBL5. DATA DIVISION. WORKING-STORAGE SECTION. PGMNAM PIC X(6) VALUE "CBL5". 01 LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7. 02 CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 RETMSG PIC X(12) USAGE IS DISPLAY-7. 02 B PIC X(8). PROCEDURE DIVISION USING INFO. ADD 1 TO LEVEL. DISPLAY B,B,LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY B,B,"CBL5 doesn't call anything". SUBTRACT 1 FROM LEVEL. GOBACK. ttl ~ (j) ~ ::: til t!j (j) ::: t:rJ l2: 8 til NO ERRORS DETECTED ..... ..... I tv o til o tl' ttl ~ (j) ~ ::: til )1/ l2: t=' o <: t:rJ l:O ~ to< til SUB C B L 6 26-0CT-78 11:00 16-NOV-77 CBL6.CBL 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 I--' I--' I tv I--' COBOL-74 12(600) BIS PAGE 1 19:00 ID DIVISION. PROGRAM-ID. CBL6. DATA DIVISION. WORKING-STORAGE SECTION. 01 PGMNAM PIC X(6) VALUE "CBL6 LINKAGE SECTION. 01 INFO. 02 LEVMSG PIC X(15) USAGE IS DISPLAY-7. 02 LEVEL PIC 9V. 02 PGMMSG PIC X(12) USAGE IS DISPLAY-7. 02 CALMSG PIC X(9) USAGE IS DISPLAY-7. 02 RETMSG PIC X(12) USAGE IS DISPLAY-7. 02 B PIC X(8). PROCEDURE DIVISION USING INFO. . ADD 1 TO LEVEL. DISPLAY B,B,LEVMSG,LEVEL,PGMMSG,PGMNAM. DISPLAY B,B,PGMNAM,CALMSG,"CBL3". CALL CBL3 USING INFO. DISPLAY B,B,RETMSG,PGMNAM. SUBTRACT 1 FROM LEVEL. GOBACK. NO ERRORS DETECTED 1t • ~ ~ Cl ~ 3: til tzl Cl 3: tI!I ~ toi til til c::: l:J' ~ ~ Cl ~ 3: til )II ~ '=' ~ tzl ~ ~ to< til ~ I-' I N N @R LINK *TEST/LOG/LOGLEVEL:S */ERRORLEVEL:S *TEST/OVERLAY *TEST/MAP *CBLO,CBLI/LINK:TEST [LNKLMN Loading module CBLO] [LNKLMN Loading module CBLI} [LNKLMN Loading module OVRLAY] [LNKLMN Loading module LILOWS] [LNKLMN Loading module CON012] [LNKLMN Loading module TRACED] [LNKLMN Loading module USRDSL] [LNKELN ~nd of link number 0, name TEST} * /NODE~TEST CBL2,CBL3/LINK:LEFT [LNKLMN Loading module CBL2] [LNKLMN Loading module CBL3] [LNKELN End of link number I, name LEFT} * INODE:LEFT CBLS/LINK:LEFTI [LNKLMN Loading module CBLS} [LNKELN End of link number 2, nameLEFTI] * /NODE:LEFT CBL6/LINK:LEFT2 [LNKLMN Loading module CBL6} [LNKELN End of link number 3, name LEFT2] /NODE:TEST CBL4/LINK:RIGHT * [LNKLMN Loading module CBL4} [LNKELN End of link number 4, name RIGHT] *TEST/SAVE */E/GO [LNKXCT CBLO Execution] Define TEST.LOG Important msgs Define TEST.OVL Define TEST.MAP Root link tV ;Left branch ;Left-left branch ;Left-right branch 8 ~ fJl tZJ til 3: tZJ 2: foi fJl ;Right branch fJl C t:D tV ~ til ~ 3: fJl >' 2: C ~ tZJ l:O ~ t< fJl ...... ...... I tv W We're at level 0 in program CBLO calling CBL2A CBLO We're at level I in program CBL2 at CBL2A CBL2 calling CBLS We're at level 2 in program CBLS CBLS doesn't call anything Returned to CBL2 calling CBL6 CBL2 We're at level 2 in program CBL6 CBL6 calling CBL3 We're at level 3 in program CBL3 CBL3 doesn't call anything Returned to CBL6 Returned to CBL2 Returned to CBLO calling CBL4 CBLO We're at level I in program CBL4 calling CBLI CBL4 We're at level 2 in program CBLI CBLI doesn't call anything Returned to CBL4 Returned to CBLO CBLO calling CBL2B We're at level I i~ program CBL2 at CBL2B CBL2B doesn't call anything Returned to CBLO Execution ends in CBLO EXIT @ to !:tI 0 G'l ~ 3: en tr:J G'l 3: tr:J Z Jo3 ..en en c:: tJ:I to 0 !:tI G'l ~ 3: .en :r- z 0 0 < tlIl !:tI §;: t< en LINK symbol map of TEST version 12(600) Produced by LINK version 4(765) on 6-Dec-78 at 13:31:10 page 1 Overlay no. 0 name TEST Low segment starts at 0 ends at 3106 length 3107 = 4P High segment starts at 0 ends at 3462 length 3463 = 4P Control Block address is 3047, length 30 (octal), 24. (decimal) 441 words free in Low segment, 211 words free in high segment 322 Global symbols loaded, therefore min. hash size is 358 Start address is 400010, located in program CBLO "0 ************* ~ 0 Gl JOBDAT-INITIAL-SYMBOLS ~ Zero length module 3: ************* LIBOL-STATIC-AREA Low segment starts at .COMM. 140 (Jl ~ Gl 140 ends at Common 1477 length length 736. 1340 (octal) , .COMM. 736. (decimal) 140 Common length ************* t-J ..... CBLO I f',J .a:. 400022 Entry C 168. 133. tJ::J (decimal) (decimal) "0 ~ Gl Relocatable ~ ************* CBLI m m from DSK:CBLO.REL[4,70} created by COBOL-74 on 6-Dec-78 at 13:29:00 Low segment starts at 1500 ends at 1747 length 250 (octal) , High segment starts at 400010 ends at 400214 length 205 (octal) , CBLO 736. 3: ~ Z t-3 3: m from DSK:CBL1.REL[4,70} created by COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 1750 ends at 2167 length 220 (octal) , High segment starts at 400215 ends at 400440 length 224 (octal), 144. 148. (decimal) (decimal) )II Z ~ CBLI 400217 Entry Relocatable 0 < ~ ************* OVRLAY ~ t"t from SYS:OVRLAY.REL[l,4} created by MACRO on 28-Aug-78 at 14:38:00 Low segment starts at 2170 ends at 2671 length 502 (octal), 322. High segment starts at 400441 ends at 403462 length 3022 (octal), 1554. (decimal) (decimal) BOUT -ERJMP GCVEC GTJFN INlOV. LOGOV. PBOUT REMOV. RPACS RUNTM Global Global Entry Global Global Global Global Global Entry Global 104000000051 320700000000 104000000300 104000000020 402016 402617 104000000074 402045 104000000057 104000000015 Global Global Global Global Entry Entry Global Entry Global Global Absolute Absolute Absolute Absolute Relocatable Relocatable Absolute Relocatable Absolute Absolute CLOSF ERSTR GETOV. HALTF JFNS OPENF PSOUT RMAP RUNOV. SFPTR 104000000022 10400000001I 402026 104000000170 104000000030 104000000021 Hl4000000076 104000000061 402065 104000000027 )II ~ m Absolute Absolute Relocatable Absolute Absolute Absolute Absolute Absolute Relocatable Absolute LINK symbol map of TEST version 12(600) page 2 OVRLAY SIN TIME .FHSLF .OVRLO' .OVRWA 104000000052 104000000014 400000 2176 2175 Global Global Global Global Global Absolute Absolute Absolute Suppressed Relocatable Relocatable SOUT %OVRLA .OVRLA .OVRLU 104000000053 400000037 2171 402346 Global Global Entry Entry Absolute Absolute Suppressed Relocatable' Relocatable ************* LILOWS from SYS:C74LIB.REL[l,4l, created by MACRO on 24-0ct-78 at 8:39:00 ttl ~ Zero length module 0 G'l ************* CON012 from SYS:C74LIB.REL[l,4] created by MACRO on 24-0ct-78 at Low segment starts at 2672 ends at 3036 length CN.12 GJ%OLD GT%ADR JS%GEN JS%PAF PA%PRV .... .... I IV 2672 100000000000 200000 70000000 1 200000000 Entry Global Global Global Global Global Relocatable Absolute Suppressed Absolute Suppressed Absolute Suppressed Absolute Suppressed Absolute Suppressed ~ 8:39:00 145 (octal), COBST. GJ%SHT JS%DIR JS%NAM JS%TYP 3: 10l. (decimal) 2672 1000000 70000000000 7000000000 700000000 Global Global Global Global Global til Relocatable Suppressed Absolute Suppressed Absolute Suppressed Absolute Suppressed Absolute TRACED from SYS:C74LIB.REL[l,4] created by MACRO on 24-0ct-78 at 3037 ends at 3046 length Low segment starts at BTRAC. CBDDT. HSRPT. SBPSG. TRPD. 3042 3044 3042 3042 3043 Entry Entry Entry Entry Entry Relocatable Relocatable Relocatable Relocatable Reiocatable 8:39:00 10 (octal) , C.TRCE CNTRe. PTFLG. SFOV. TRPOP. from SYS:C74LIB.REL[l,4] created by MACRO on 24-0ct-78 at Zero length module ************* {Jl ~ 8. (decimal) 3037 3042 3045 3042 3042 Entry Entry Global Entry Entry Relocatable Relocatable Relocatable Relocatable Relocatable G'l ~ 3: til >' 2: t::I ************* USRDSL 3: tIJ 2: 1-3 til C ttl ttl ************* U1 tIJ G'l 8:39:00 0 < tIJ ~ t'1 >' I< til Name CBLO CBLI Page 1 1 Name CON012 LILOWS page 3 TEST version 12(600) Page Name Page Name Page 2 2 OVRLAY TRACED 1 2 USRDSL 2 Index to LINK symbol map of ~ ~ til ~ :J: til tIJ Cil 3 tIJ Z t-3 til ~ ~ I t-.J 0\ til c::: m ~ ~ til ~ :J: til )II Z 0 0 < tIJ ~ s: t< til LINK symbol map of TEST version 12(600) #1 page 4 Overlay no. 1 name LEFT Low segment starts at 7107 ends at 7642 length 534 = IP High segment starts at 3463 ends at 4466 length 1004 = 2P 7577, length Control Block address is 30 (octal), 24. (decimal) Path is 0 93 words free in Low segment, 211 words free in high segment 23 Global symbols loaded, therefore min. hash size is 26 ************* CBL2 "d from DSK:CBL2.REL[4,70] created by COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 7107 ends at 7356 length 250 (octal), High segment starts at 403463 ends at 404226 length 544 (octal), CBL2 CBL2B 403465 403766 Entry Entry Relocatable Relocatable CBL2A 168. 356. 403503 (decimal) (decimal) Entry ..... ..... I ~ ...,J 404231 ************* 3: G) 3: from DSK:CBL3.REL[4,701 created by COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 7357 ends at 7576 length 220 (octal), High segment starts at 404227 ends at 404466 length 240 (octal), CBL3 ~ Relocatable til tlIJ ************* CBL3 ~ G) Entry Relocatable t!J 2: 144. 160. (decimal) (decimal) ~ til til c:: 07 "d ~ G) ~ 3: til )II 2: o ~ t!J ~ §: t< til LINK symbol map of TEST version 12 (600) *2 page S LEFTI Overlay no. name 2 Low segment starts at 7643 ends at 10110 length IP 246 = 4467 ends at 4712 length IP High segment starts at 224 = 16 (octal), 14. (decimal) Control Block address is 10063, length Path is 0, 1 439 words free in Low segment, 211 words free in high segment 18 Global symbols loaded, therefore min. hash size is 21 ************* CBLS to from DSK:CBLS.REL[4,70] created by COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 7643 ends at 10062 length 220 (octal), High segment starts at 404467 ends at 404712 length 224 (octal), CBLS 404471 Entry Relocatable 144. 148. (decimal) (decimal) ~ Cil e {Jl ************* tZJ Cil 3: tZJ Z Jo3 {Jl ..... ..... I N co {Jl C t:X' to ~ Cil ~ 3: {Jl ~ ~ o <: tZJ l:C §: t< {Jl LINK symbol map of TEST version 12 (600) n page 6 Overlay no. 3 name LEFT2 Low segment starts at 7643 ends at 10112 length 250 = IP High segment starts at 4467 ends at 5204 length 516 = IP Control Block address is 10065, length 16 (octal), 14. (decimal) Path is 0, 1 437 words free in Low segment, 211 words free in high segment 19 Global symbols loaded, therefore min. hash size is 22 ************* CBL6 to from DSK:CBL6.REL{4,70] created by COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 7643 ends at 10064 length 222 (octal), High segment starts at 404713 ends at 405204 length 272 (octal), CBL6 404715 ************* Entry Relocatable 146. 186. (decimal) (decimal) ~ G'l ~ 3: til tzl G'l 3: tzl Z 8 til til ~ ~ I I\) \0 C 03 to ~ G'l ~ 3: til ~ Z tj o <: tzl l:O t"" ~ t< til LINK symbol map of TEST version 12(600) it4 page 7 name RIGHT Overlay no. 4 7107 ends at 7356 length 250 = IP Low segment starts at 5454 length 1772 = 2P High segment starts at 3463 ends at 7331, length 16 (octal), 14. (decimal) Control Block address is Path is 0 273 words free in Low segment, 211 words free in high segment 19 Global symbols loaded, therefore min. hash size is 22 ************* CBL4 "0 from DSK:CBL4.REL[4,70] created by 'COBOL-74 on 6-Dec-78 at 13:30:00 Low segment starts at 7107 ends at 7330 length 222 (octal), High segment starts at 405205 ends at 405454 length 250 (octal), CBL4 405207 ************* Entry Relocatable 146. 168. (decimal) (decimal) ~ G) ~ 3: rn t%J G) 3: t%J z: ~ rn ..... ..... I w o rn c:: 0::1 "0 ~ G) ~ 3: rn > z: t:J o < t%J ::0 ~ I< rn Index to overlay numbers of TEST version 12(600) Overlay Page Overlay Page Overlay Page #0 U #2 #3 3 5 6 #4 7 Page Name Page 7 TEST 3 4 Index to overlay names of TEST version 12(600) Name Page Name 6 RIGHT LEFT LEFTl page 8 Overlay Page Page Name 4 LEFT2 5 "0 ~ G') [End of LINK map of TEST] ~ !!: til t:I:J G') !!: t:I:J Z t-3 til til I-' I-' I w I-' c: IlJ "0 ~ G') ~ !!: til ~ Z o o <: t:I:J ~ t"1 ~ t< til CHAPTER 12 CALLING NON-COBOL SUBPROGRAMS Some programming tasks are more conveniently accomplished in a language other than COBOL. You can write non-COBOL subprograms for these tasks, and then call the subprograms from COBOL programs. To call a non-COBOL subprogram, use the ENTER verb DIVISION. The call has the form: in the PROCEDURE ENTER language entry-name [USING string-l [,string-2] •.• ]. where: language is the name of the subprogram. entry-name is the name of the entry point you want to call. string is one or more procedure-names. compiler that identifiers, generated literals, the or The compilers that can generate COBOL-callable subprograms are COBOL, FORTRAN, and MACRO. The phrase ENTER COBOL is equivalent to CALL and is not discussed further here. The entry point used in the ENTER statement must be an entry-name symbol generated by the compiler for the called program. COBOL generates an entry-name for each ENTRY statement and program-name. FORTRAN generates an entry-name for each SUBROUTINE, FUNCTION, and ENTRY statement. MACRO generates an entry-name for each ENTRY statement. NOTE You can use the "weaker" MACRO statement INTERN instead of ENTRY if you explicitly load the MACRO module. ENTRY is required only if the module must be loaded in a library search. In the USING clause, using an identifier passes the value of the identifier to the called subprogram; uSlng a literal passes the literal to the subprogram; using a procedure-name passes the address of the beginning of the named procedure, which can be used for alternate returns. FORTRAN cannot accept DISPLAY-6 (SIXBIT) , DISPLAY-9 (EBCDIC), or COMP-3 (packed-decimal) data. 12-1 CALLING NON-COBOL SUBPROGRAMS 12.1 CALLING FORTRAN SUBPROGRAMS When the COBOL compiler finds an ENTER FORTRAN statement, it generates a call for the named subprogram. If the ENTER statement contains a USING clause, the values indicated by the given identifiers, literals, and procedure-names are passed to the subprogram. FORTRAN programs called by COBOL programs should not use blank COMMON, even among themselves. Doing so can overwrite storage in the COBOL program. In the following example, the COBOL program CFSQRT calls the FORTRAN subprogram FSQRT to perform a square-root operation. The following list shows how values are passed from the .main program to the subprogram: Use of Value COBOL Identifier FORTRAN Variable Input number INPUT-NUMBER INPUT Answer ANSWER ANSWER Error message location ERROR-MESSAGE ERRMSG Exit message location EXIT-MESSAGE EXMSG The following is the source file for the COBOL program CFSQRT: ID DIVISION. PROGRAM-ID. CFSQRT. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-NUMBER USAGE COMP-l. 01 ANSWER USAGE COMP-l. PROCEDURE DIVISION. LOOP. DISPLAY 'Type a positive integer. '. ACCEPT INPUT-NUMBER. ENTER FORTRAN FSQRT USING INPUT-NUMBER,ANSWER, ERROR-MESSAGE,EXIT-MESSAGE. DISPLAY ANSWER. GO TO LOOP. ERROR-MESSAGE. DISPLAY 'No negative numbers, please. '. GO TO LOOP. EXIT-MESSAGE. DISPLAY 'Thank you. '. STOP RUN. The following is the source file for the FORTRAN program FSQRT: SUBROUTINE FSQRT(INPUT,ANSWER,*,*) REAL INPUT INTEGER ERRMSG,EXMSG ERRMSG=l EXMSG=2 IF(INPUT.LT.O) RETURN ERRMSG IF(INPUT.EQ.O) RETURN EXMSG ANSWER=SQRT(INPUT) RETURN END 12-2 CALLING NON-COBOL SUBPROGRAMS In the following lines, these two source programs are executed. Each positive integer input yields its square root; a negative number yields an error message at an alternate return in the COBOL program; o yields the exit message at another alternate return. Note that the TOPS-IO system prompt could be replaced by the TOPS-20 prompt (@) without altering the example - the programs run exactly the same way under TOPS-20 . . EX CFSQRT.CBL,FSQRT.FOR FORTRAN: FSQRT FSQRT COBOL: CFSQRT [CFSQRT.CBL] Loading LINK: [LNKXCT CFSQRT Eexcution] Type a positive integer. 4 2.0EO Type a positive integer. 3 1.7320508EO Type a positive integer. 2 1.4l42l36EO Type a positive integer. 1 1.OEO Type a positive integer. -1 No negative numbers, please. Type a positive integer. o Thank you. EXIT 12.2 CALLING MACRO SUBPROGRAMS When the COBOL compiler finds an ENTER MACRO statement, the standard calling sequence: it generates MOVEI l6,arglist PUSHJ l7,entry point where arglist is the address of the first word of the and entry point is an entry-name symbol. argument list, If the ENTER statement contains a USING clause, the compiler creates an argument list containing an entry for each identifier or literal in the clause. The word immediately preceding the argument list is of the form: -length"O where length is the number of arguments in the list. If no USING clause appears in the ENTER statement, the length of the list is 0 (but the length word still appears). 12-3 CALLING NON-COBOL SUBPROGRAMS Each entry in the argument list is.a 36-bit storage word of the form: 1=======================================================1 1 0 1 Code I Effective Address (E) 1 1=======================================================1 o 8 9 12 13 35 where code is a 4-bit code (described below), and bits 13-35 the effective address (E) of the first word of the argument. contain If the passed argument is a I-word COMP item, the code is 2 and the location of the argument. E is If the passed argument is a 2-word CaMP item, the code is 11 (octal) and E is the location of the first word of the argument: the second word of the argument is at E+l. If the passed argument is a COMP-l item, the code is 4 and location of the argument. E is the If the passed argument is a DISPLAY-6 or DISPLAY-7 item, the code is 15 (octal) and E is the location of a 2-word descriptor for the argument. The first word of the descriptor is a byte pointer word pointing to the argument. Its byte size is 6 for DISPLAY-6 or 7 for DISPLAY-7. The second word of the descriptor is of the form: bit 0 numeric flag bit 1 signed number flag bit 2 figurative constant flag bit 3 literal flag bits 4-11 reserved bit 12 flag for Ps preceding decimal point in PICTURE bits 13-17 number of decimal places (if bit number of Ps (if bit 12 is 1) bits 18-35 number of bytes in the item 12 is 0), or If the passed argument is a procedure-name (not allowed in a call to a COBOL subprogram), the code is 7 and E is the location of the first word of the procedure. In the following example, the COBOL program CMSQRT calls the MACRO subprogram MSQRT to perform a square-root operation. (The subprogram uses the FORLIB routine SQRT to take the square root.) The argument list follows: generated -4,,0 ARGLST: Z 4,address Z 4,address Z 7,address Z 7,address by the ENTER MACRO statement is :-Arglength"O :<4B12>&<Address of 1st COMP-l item> :<4B12>&<Address of 2nd COMP-l item> :<7B12>&<Address of 1st procedure> :<7B12>&<Address of 2nd procedure> 12-4 as CALLING NON-COBOL SUBPROGRAMS The following is the source .c __ loV1- the COBOL program ID DIVISION. PROGRAM-ID. CMSQRT. DATA DIVISION. WORKING-STORAGE SECTION. 01 INPUT-NUMBER USAGE COMP-l. 01 ANSWER USAGE COMP-l. PROCEDURE DIVISION. LOOP. DISPLAY 'Type a positive integer. '. ACCEPT INPUT-NUMBER. ENTER MACRO MSQRT USING INPUT-NUMBER,ANSWER, ERROR-MESSAGE,EXIT-MESSAGE. DISPLAY ANSWER. GO TO LOOP. ERROR-MESSAGE. DISPLAY 'No negative numbers, please. '. GO TO LOOP. EXIT-MESSAGE. DISPLAY 'Thank you. '. STOP RUN. The following is the source file for the MACRO program MSQRT. Notice that the entry-name MSQRT must be declared ENTRY and that the FORLIB routine SQRT, which is to be called, must be declared EXTERNAL. Notice also that at NEG and ZERO, the return address in the stack is replaced by a procedure-nam~ (address) to set up the alternate returns. At POS, the pointer to the argument list must be saved before calling SQRT. MSQRT: POS: TITLE MSQRT ENTRY MSQRT EXTERN SQRT SKIPN 1,@O(16) JRST ZERO JUMPL 1,NEG MOVEM 1,ARG MOVEM l6,SAVPTR MOVEI 16,1+[-1,,0 Z 4,ARG] PUSHJ 17,SQRT MOVE 16,SAVPTR MOVEM 0,@l(16) POPJ 17, ZERO: MOVEI 1,@3(16) MOVEM 1,0(17) POPJ 17, NEG: MOVEI 1,@2(16) MOVEM 1,0(17) POPJ 17, ARG: BLOCK 1 SAVPTR: BLOCK 1 END ;Skip if not zero ;To zero routine ;To negative routine ;Fall into positive routine ;Save arg in reg 1 ;Save return address ;Set up arg for SQRT ;FORLIB square root routine ;Restore return address ;Set up return arg ;Return ;Set up alternate return for zero arg ;Return ;Set up alternate return ; for negative arg ;Return In the following lines, these two source programs are executed. Since neither program is a FORTRAN program, FORLIB must be explicitly searched. 12-5 CALLING NON-COBOL SUBPROGRAMS Each positive integer input yields its square root; a negative number yields an error message at an alternate return in the COBOL program; o yields the exit message at another alternate return. Note that the execution of these programs will yield the same output if run under TOPS-IO. @EXE CMSQRT.CBL,MSQRT.MAC,SYS:FORLIB.REL/SEARCH COBOL: CMSQRT [CMSQRT.CBL] MACRO: MSQRT LINK: Loading [LNKXCT CMSQRT Excution] Type a positive integer. 4 2.0EO Type a positive integer. 3 1.7320508EO Type a positive integer. 2 1.4l42l36EO Type a positive integer. 1 1.OEO Type a positive integer. -1 No negative numbers, please. Type a positive integer. o Thank you. EXIT @ 12-6 CHAPTER 13 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS Normally, the code generated by the COBOL-74 compiler is adequately efficient. However, since there are certain COBOL-74 constructions for which efficient code is not generated, it is possible to write programs that perform poorly. If your programmed application performs inefficiently, you are left with the following alternatives: 1. Assume that a higher-performance compiler will solve the problem 2. Purchase new or faster hardware 3. Redesign the entire program 4. Rewrite only the bad portions of the program version of the COBOL-74 Assuming that you are unwilling to wait for an improved compiler or purchase new or faster hardware, let us consider the remaining alternatives. Although redesigning the entire program or application is possible, it is expensive and is generally not done. Like any system rewrite, however, it does offer the opportunity to add new features and eliminate old, out-of-date ones. It is a good alternative, in the long run. The much cheaper solution is to determine why a program is performing poorly and rewrite only the inefficient portions. This normally does not require a large effort since most COBOL programs spend 90% of the time executing only 10% of their code. The biggest task involves determining why a program is inefficient. Most programs lend themselves to some improvement. There have been many instances where a program used less than half the CPU time after improvement than it did before. Most often, the gain is in the range of 30%. Most significant is the fact that the reprogramming generally involved only 20 lines or less. Because some optimization techniques may be contrary to programming standards, it is necessary' to use discretion when choosing which programs to improve and how much to improve them. It is, therefore, not recommended that all programs be optimized. For example, little is gained if a weekly application has its CPU time cut from 10 to 5 minutes. A program that runs for 2 hours a day, on the other hand, probably should be investigated. Program optimization is usually done on an as-needed basis: the greater the resource consumption by a program, the greater the priority for optimization. Therefore, your installation's programming standards should guide programmers towards efficient, partially optimized programs. 13-1 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS Each computer system is different. Therefore, it is likely that installation programming standards will reflect, to some extent, practices which promote efficient use of the presently installed system. On some systems, for example, the size of a program, the .number of files open, and the type of devices used will affect a program's performance. On other systems, emphasis is placed on data types, coding practices, and data patterns. It is normal for a programming standard to reflect those practices that normally produce efficient results without impairing reliability or maintainability. The standard, therefore, could stipulate that all counters, indexes, and subscripts be described as COMPUTATIONAL. It could also, as is the case with most TOPS-IO and TOPS-20 installations, standardize around DISPLAY-6 files because of file space economics. Another standard practice is to request that an analysis of the data be made and that the program be written to efficiently process it. For example, the following program statements make some decisions based on the value of a particular item: IF ABLE > BAKER GO TO CHARLIE. IF ABLE < BAKER GO TO DOG. IF ABLE BAKER GO TO ECHO. If the value of ABLE is normally equal to BAKER, the program should be reordered with the following statement first: IF ABLE BAKER GO TO ECHO. Programming techniques of this type will promote virtually every system and should be encouraged. efficiency on Any programmer who can write COBOL programs can optimize them. Most of the programming tools currently available require minimal knowledge of anything other than COBOL. The optimization tools and techniques described in this chapter plus the techniques described in your installation standard provide most of the information needed to improve most COBOL programs. It is easy to apply already known optimizations to a program. It becomes more difficult to make programs more efficient, however, when the known optimization techniques are not applicable. The person who can be most successful will be one who understands a little about the code generated by the compiler and can read assembler code. By using the /A switch option to obtain a listing of the assembly language code generated for the program, he/she can determine, from the code generated, which alternatives produce the best results. There are many ways to make a program more efficient. The best results come from good program design. Minimizing disk access, segmenting programs into small well-defined pieces, and keeping irrelevant information out of records are some ways to gain more efficiency. Discussion of these techniques, because they are applications-specific, are beyond the scope of this chapter. They are mentioned here in order that you will take them into consideration when designing your individual applications. The remainder of this chapter deals with program improvements. It is a collection of techniques that have been used to good advantage by various installations. 13-2 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.1 HOW TO PROCEED WITH PROGRAM OPTIMIZATION The actual coding required to optimize a program is usually minimal and not time-consuming. The largest component of time is spent learning the nature of the problem, that is, determining where and how much time is being spent by the program. Therefore, once a program has been selected for investigation, it is advisable to form a plan or procedure to be followed. This plan should consist of a series of small steps each designed to improve a small portion of the program. As one portion of the program is improved, begin on the next, and so on until the entire program has been improved to your satisfaction. NOTE Do not attempt program optimization until the program has been debugged and runs correctly! 13.1.1 Where to Begin Begin by gathering together the following material and information: 1. An understanding of the goal (lower elapsed or CPU time) 2. Copies of the source program and supporting software 3. Enough data to make this program run long enough to measure, and short enough to endure: 10 to 15 minutes is usually sufficient. 4. Files for output verification 5. Access to the measurement tools (see Section 13.1.2) 6. A notebook to record all observations, results (see Section 13.1.5). 13.1.2 measurements, and What Tools are Available There are some tools that are part of the system software; you may have others at your installation; and some are available through DECUS and other agencies. This chapter discusses those that are part of the system software and are commonly used and understood. These tools are: For users of TOPS-IO and TOPS-20 7.3 and 13.2 • COB DDT - • SET WATCH - For users of TOPS-IO only see Operating System Commands Manual 13-3 see Sections the TOPS-IO IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.1.3 What Method or Procedure to Use Once you have gathered all of the information and materials required, and are familiar with the various tools at your disposal, it is time to decide upon a course of action. The following procedure is provided as a guide. You can expand or shorten it as benefits your application or installation. 1. Generate a version of the program and its data that will use 10 to 15 minutes elapsed time. Remove anything from the program (terminal interaction, logical names, etc.) that make it difficult to run. 2. Schedule your machine time to coincide with periods when the system is lightly loaded. This will enable you to make better use of the elapsed time statistics. 3. Run the unaltered (original) following statistics: program and determine the a. Amount of CPU time used b. Elapsed time c. Amount of idle time on the system d. Amount of disk I/O, swapping, etc. e. its Use SET WATCH to observe the program during execution. SET WATCH will aid you in determining CPU time, peripheral usage, etc. Some of these statistics are not too meaningful on a system with even a moderate work load. Only the person conducting the test can determine to what extent the system work load may bias the measurement. However, even if the system is loaded, CPU time is normally a good indication of how the program performs. If the program runs with idle time, determine the reason for it (disk wait, tape wait, etc.). Often, additional buffering can lower the elapsed time. (See Section 13.1.4, Evaluating Performance.) 4. Run a COBDDT histogram to determine its runtime statistics. The histogram will aid you in spotting potential problem areas in the program. 5. If other tools are available, use them. 6. Save the output from this first run for verification. 7. Analyze the results and make any improve the program. believe will 8. Recompile, link, and execute the program using the tools techniques mentioned above. and 9. Compare the statistics from previous or original run. the 10. write down all observations, Section 13.1.5, Documentation.) 13-4 changes this you run with those facts, and hunches. of (See IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 11. Repeat steps 7 through 10 until you are results. satisfied with the The last step, repeat until satisfied, is very important. It is very easy to get carried away with program optimization. Start with a premise, for example, "I will be satisfied with a 30% improvement". When you reach this level of performance, stop. 13.1.4 Evaluating Performance Generally the best criteria for evaluating performance is the one that led you to be suspicious of the program in the first place. Most generally, CPU time is used. It is easy to measure and easy to reproduce. You simply observe the CPU time in the original program, make changes as appropriate, rerun the program and observe it again. If the CPU time decreases, the changes were effective. NOTE Because CPU time can vary with the load on the system, only changes in excess of 5% can be considered relevant. Another, more effective, way to determine performance is to measure the amount of work done per second of CPU time. By counting the number of records processed per second or minute, you have a good way to document a program's performance. Thus, if a program can normally process 100 records per CPU minute, and the volume increases by 1000 records per run, the effect is easily predictable. 13.1.5 Documentation It is a good practice to document everything you have done during program optimization. You will want to improve other programs, and the notes you take for the first attempt will aid you in saving time and effort on each succeeding attempt. The documentation kept should be simple and should include the following information: 1. The name of the program, the time and date of the name of the programmer the run, 2. The amount of data used by the test 1000 records for a 10-minute run for example, 3. The time (CPU and elapsed) used by the original program 4. The level of performance desired 5. The optimization techniques utilized 6. The results obtained, both positive and negative 7. COB DDT histogram 8. Any observations about system performance 13-5 program, and IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 9. Any other statistics collected, feelings, hunches, and perceptions other The documentation need not and should not be elegant. It should, however, be permanent. You might even tape portions of the console log into your notebook as a quick way of recording timings. 13.2 LISTING THE TOOLS This section discusses the tools most commonly used by COBOL programmers for program optimization: COBDDT and SET WATCH. You are advised to read Section 7.3, COBDDT, before reading this section. The write-up on SET WATCH in the TOPS-IO Operating System Commands manual is also recommended for users of TOPS-IO.. This section will not attempt to redo anything that has already been done. It attempts only to present information relevant to program optimization. 13.2.1 COBDDT This section discusses COBDDT as used for evaluating program performance. Therefore, only the histogram feature is described. The COB DDT histogram provides you with the following information for each procedure that was executed in your program (see Figure 13-1, Sample COBDDT Histogram): • Procedure name • The number of times the procedure was entered • The CPU time the procedure used • The elapsed time the procedure used (ENTRIES) (CPU) (ELAPSED) COBDDT HISTOGRAM FOR XDDT04 XDDT4B.HIS PROCEDURE REPORT: 1 ENTRIES CPU ELAPSED 1 5 1 1 2 3 3 7 7 7 10 10 0.336 0.251 0.028 0.005 0.045 0.123 0.013 0.032 0.030 0.030 0.115 0.050 1.649 1.239 0.333 0.005 0.065 0.398 0.029 0.065 0.152 0.047 0.380 0.108 1ST P12 PP3 PP4 PP5 2ND 2PO 2Pl 2P3 2PlO 3RD 3PO XDDT4B.HIS OVERHEAD: ELAPSED: Figure 13-1 0.002 CPU: Sample COB DDT Histogram 13-6 0.002 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.2.1.1 The ENTRIES Column - The infoLmation listed in the ENTRIES column of the histogram helps you to set your priorities for program improvement. Very high counts relative to others establishes the paragraph as one which needs further investigation. For example: 1. Why is it entered so often? 2. Is anything done there that could be elsewhere? 3. Can it be rewritten to do less? Coding Conventions.) done more effectively (See Section 13.5, Efficient Often, the numbers will guide you into understanding how to order your decision lists. For example: Suppose P-l was entered 1000 times, P-2 was entered 500 times, and these paragraphs are chosen via a decision list that looks like this: S-l. IF A " S-2. IF A "00" GO TO P-l. " GO TO P-2. It is apparent, then, that the order of S-l reversed because A is usually 00. and S-2 should be Also, based on the number of records processed, unexpected certain paragraphs should be accounted for. counts in Do not be afraid to add new paragraph names to the program. Not only does this technique allow you to break large paragraphs up into smaller ones, it also enables you to better understand exactly where the program spends its time. 13.2.1.2 The CPU Column - The histogram's CPU column lists the amount of CPU time each paragraph used up. Generally, if you can cut the CPU time, the elapsed time will also drop and the application will perform more efficiently. By analyzing this column, you can easily identify the big spenders - those procedures that eat up most of the CPU time. One approach is to rank the paragraphs in terms of CPU time and to look for paragraphs that spend more time per entry than others. Then, proceeding in rank order, determine what each paragraph is doing, if it has to do it, and if a better coding technique is in order. Usually only a few paragraphs need be examined. NOTES 1. CPU time for a paragraph also includes time spent in paragraphs performed or routines called. Therefore, the sum of the CPU time is greater than the total time actually spent within this paragraph. (See Section 13.2.1.4.) 2. CPU time also includes time spent in the object-time system and the monitor. 13-7 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS If after examining the list of the most time-consuming paragraphs, you determine that all can be explained, it is unlikely that changing any particular thing will improve performance. Either the program cannot be improved any further, or other techniques are needed. 13.2.1.3 ELAPSED Column - In a lightly loaded system, the elapsed time can be a guide to the effective blocking of records. Some experiences with programs that seemed I/O-bound indicated that they were spending a great deal of time in the paragraphs that dealt with relative or ISAM reads and updates. Inspection of the blocking revealed that while the files were blocked to conserve disk space, large amounts of data was being transferred (1 block) when the desired object was to update 1 record. Therefore, if a disproportionate amount of time is spent in some paragraphs, there could be a problem in processing. These paragraphs should definitely be investigated. 13.2.1.4 OVERHEAD - This entry in the histogram, (see Figure 13-1) represents the time spent for PERFORM or CALL overhead. Look at this entry to evaluate the cost of PERFORM loop control mechanisms. If this figure is high, then some very short paragraph is being performed a large number of times. If this is the case, a more efficient method of loop control is probably in order. 13.3 USING THE CORRECT DATA TYPE Understanding the various data types available is extremely important because there are so many of them. COBOL-74 offers you three different DISPLAY types and several COMPUTATIONALS. Each data type will offer some advantages and some disadvantages. It is necessary to understand these in order to maximize the efficiency of a particular application. 13.3.1 DISPLAY Data Types There are 3 display data types used within COBOL. EBCDIC ASCII SIXBIT EBCDIC and character defined by defined by 13.3.2 ASCII are character codes which occupy 8 and 7 bits per respectively. The representations for each character are industry standards. SIXBIT is a 6-bit BCD code which is DIGITAL. EBCDIC The 8-bit EBCDIC code allows 256 different characters. It is compatible with IBM and thus is a natural where data interchange with 360s and 370s is necessary. EBCDIC files may contain a mixture of EBCDIC and COMPUTATIONAL-3 data. EBCDIC is packed into the computer's memory, 4 characters per word. 13-8 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS EBCDIC processing is going to be somewhat slower tnan either A~Cil or SIXBIT because of amount of space that each character takes up. As an example, a 120-character record would occupy: 1. 30 words in EBCDIC 2. 24 words in ASCII 3. 20 words in SIXBIT Since movement of data is roughly linear with volume (it takes twice as long to move twice as much), it can be seen that SIXBIT and ASCII are 33% and 20% more efficient than EBCDIC respectively. The amount of file storage is also proportional to the byte size. For example, five ASCII records or 6 SIXBIT records can be stored in the same space taken by only 4 EBCDIC records. Thus the usage of EBCDIC should be restricted to those cases where: 1. The ASCII and SIXBIT character set is too small (128 and characters respectively compared with 256 for EBCDIC). 2. The transmittal of data to and from EBCDIC systems is a major part of the application. 3. The application depends on the collating after alphabetics). 4. The existance of many redefined records with mixtures EBCDIC and COMP-3 make reprogramming unthinkable. sequence 64 (numerics of In summary, it suffices to say that EBCDIC is a useful data type available to the COBOL user. For whatever its benefit, you must realize that it is slower and that a 33% increase on throughput could be realized by going to SIXBIT. 13.3.3 ASCII Seven-bit ASCII is the coding sequence utilized by the unit record peripherals and terminals. Any other data type (EBCDIC or SIXBIT) will have to be converted to ASCII if it is to be sent to one of these devices. In memory, the usage of ASCII will make the movement of data proceed faster than EBCDIC but slower than SIXBIT because of the number of characters per word. On the disk, all ASCII records are variable length as defined by industry standards, the end of an ASCII record is defined by the existance of a "vertical form" (normally a line feed) character (or several such characters). Thus when reading ASCII files, it is necessary to read them a character at a time in order to find the end-of-record character. This implies that ASCII records can be variable length and efficiently stored on the disk. It also implies that moving such records to or from memory is more costly than the other data types which can be moved via the block transfer instruction. ASCII is the standard data type for "text files". Files created by editors which contain arbitrary length records can be stored economically and processed easily using the ASCII data type. Cards from a reader can be "trailing blank suppressed" so that they can be stored economically and are easily manipulated using ASCII. However, 13-9 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS unless the full character set capabilities of ASCII (128 with lowercase plus line control) are necessary or the data is coming from or going to an ASCII peripheral, conversion to SIXBIT files is probably preferable. 13.3.4 SIXBIT By far the most efficient DISPLAY code is SIXBIT. Six characters can be packed per word. Each record on disk or tape is preceded by a word with a character count allowing for block transfers of data. And the transmission time for moving the data around memory is less than any other data type. The only problem with SIXBIT is the number of characters possible within the 6-bit code. Basically, 64 characters allows for uppercase, numerics, and punctuation. It does not allow for lowercase, device control characters, or special graphics. Most installations put the bulk of their files into SIXBIT due to the storage economy and the processing efficiency. It is highly recommended wherever possible. 13.3.5 COMPUTATIONAL There are several flavors of computational data types available to the COBOL programmer including: 1. COMPUTATIONAL-3, the four bit complement of EBCDIC 2. COMPUTATIONAL, internal binary (35 bits plus sign) 3. Double-word COMPUTATIONAL, automatically invoked when the number of digits desired is greater than 10 (70 bits plus sign) 4. COMPUTATIONAL-I, floating point (the hardware supports double precision floating point, but COBOL does not) Aside from the usage of COMP-3 as an adjunct to EBCDIC, the most useful data type is COMPUTATIONAL. This is normally used for indexes, counters, and subscripts. If other data types are used for these purposes, there will be continual conversion taking place since all arithmetic is done in binary. You can read arbitrary files by defining them as BINARY mode and use the data as desired. 13.4 then DATA EFFICIENCIES Programming standards should insist on using the corect data types for certain operations. Using COMPUTATIONAL for counters will work better on almost any machine. 13-10 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.4.1 Counter, Indexes, Subscripts In DIGITAL COBOL indexes and subscripts are not different (this is not the case with some systems). They are, in fact, the same as COMPUTATIONAL. A data item that will be used as a counter or subscript should be declared: 77 THE-NAME PICTURE S9(10) COMPUTATIONAL. COMPUTATIONAL items are always word-aligned no matter at what level they are defined and thus are equally efficient. However, there are some things which must be observed. 1. If the number of digits is greater than 10, it will become double-word computational, and all arithmetic will be done with calls to the object-time system. However, it is still faster and more efficient than DISPLAY. 2. It is important that the variable be signed. If it is not, much less efficient code is generated in order to insure that it is never negative. 13.4.2 File Storage SIXBIT files are the best for file storage and data manipulation efficiencies. Not only do they require less space than ASCII or EBCDIC, but they are efficient to move about. Each SIXBIT record is preceded by a "length descriptor" which provides the information necessary to do block transfers of data in memory rather than character by character. Also, since SIXBIT records are always word aligned, they can be transferred with block transfer instructions. ASCII is good for text which is of variable length (for example those created by EDIT) and for line control. It suffers from the necessity to process each character to determine the end of the record. EBCDIC is necessary if more than 128 characters is needed and if data transfer to systems using EBCDIC is necessary. It is also necessary to read files character by character since EBCDIC records (fixed length) need not necessarily be word aligned. It may be somewhat more efficiently processed than ASCII however since a specified number of characters is always transferred rather than an arbitrary number. 13.4.3 Blocking Data Processing data from disk is more efficient if it is not blocked. This allows the system to pack information as tightly as possible on the disk with no slack bytes between blocks. Blocks always start on one of the disk's 128-word sector boundaries. Thus blocking inefficiently could waste considerable space. If you block disk records, remember to count the length descriptor words on SIXBIT' and variable length EBCDIC records. Records for these two data types are also word aligned. 13-11 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.5 EFFICIENT CODING CONVENTIONS This section contains a listing of some practical coding practices which have proven efficient. Any of these can be demonstrated beneficial by writng short programs which execute these sequences a large number of times. It is also possible to look at the MACRO expansion of the program to see why things are different. 13.5.1 Alignment When the addresses of the data items are known at compile time the compiler may generate efficient in-line code. This code may include the usage of the block transfer instruction where the two data items are aligned and of the same type. When they are not aligned, or when conversion is necessary, an object-time system routine may be called. The simplest way to insure that data will be aligned is to define it at either the "77" level or at the "01" level. It is possible by counting characters or by using the COBOL data map to also determine alignment. Alignment simply means that the first byte of each item begins in the same position in the beginning word, that the items are the same length, and that they are of the same type. 13.5.2 Usage of Subscripts Avoid the usage of subscripts whenever possible. Subscripts are recomputed every time they are used, they are never remembered. If you use a subscripted item more than once, it is more efficient to move it into a simple variable and then use that. For example: 01 THE-TABLE OCCURS 200 TIMES 02 THE-COUNT PIC S9(10) COMP. 02 THE-DATA PIC XXXXXXXX. 77 THE-TABLE-COUNT PIC S9(10) COMP. The sequence MOVE THE-COUNT(IDX) TO THE-TABLE COUNT. IF THE-TABLE-COUNT 3 GO TO P-l. IF THE-TABLE-COUNT = 4 GO TO P-2. is more efficient if it is likely that the count is not following: IF THE-COUNT(IDX) 3 GO TO P-l. IF THE-COUNT(IDX) = 4 GO TO P-l. 13-12 3, than the IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS It is usually advantageous to move the whole entry from a LdOie into some Ol-level structure which contains similar items rather than to process the data from the table via subscripts. For example: 01 THE-TABLE OCCURS 20 TIMES. 02 THE-CNT PIC S9(10) COMPo 02 THE-DATA PIC XXXXXXX. 01 THE-TABLE-ENTRY. 02 THE-TABLE-CNT PIC S9(10) COMPo 02 THE-TABLE-DATA XXXXXXX. MOVE THE-TABLE(IDX) TO THE-TABLE-ENTRY. IF THE-TABLE-CNT = 5 DISPLAY THE-TABLE-DATA. In this example, only one subscript had to be calculated, and one unsubscripted move performed. Savings in often-referenced paragraphs (in a loop) can be quite large. Simply remember that there is additional overhead here and it pays to eliminate it. 13.5.3 Incrementing Counters COBOL-74 provides three ways of incrementing counters. the same function in different ways. For example: Each performs 77 COUNTER PIC S9(10) COMPo This counter can be modified in the following ways: SET COUNTER UP BY 1. ADD 1 TO COUNTER. COMPUTE COUNTER = COUNTER +1. The first two examples are equivalent, the third is much therefore, not recommended. slower and, Keep in mind that computational counters should always be signed even when they logically will never become negative. If they are not signed, additional instructions will be generated to make sure they do not become neiative. 13.5.4 The PERFORM Statement The PERFORM statement provides an essential element of structured programming. It provides implicit loop control and it makes listings easy to follow. However, it suffers from the fact that it requires some information to be posted upon entry to a routine and cleared upon exit from that routine. COBOL-74 is fussy about the nesting of PERFORMs so that there is a concept of level. Each time a PERFORM statement is encountered, the level counter is incremented by 1. Each time a performed routine exits, it is decremented by 1. The level counter must have the same value at exit time as it has at entry or else there is an error in the program. Here are a few known ways to improve the efficiency of programs use PERFORMs. 13-13 which IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS Example 13-1 SET lOX TO 0 PARI. PERFORM PARI 100 TIMES. SET lOX UP BY 1. IF TABLE(IOX) ABLE MOVE 6 TO FOO. is more efficient than: PERFORM PAR2 VARYING lOX FROM 2 BY 1 UNTIL lOX> 100. When a loop or PERFORM is done repeatedly, the loop should do everything possible on each iteration. This minimizes the expense of the loop control mechanism. Thus: PERFORM F-l 1000 TIMES. PERFORM F-2 1000 TIMES. should be rewritten so that both functions of F-l and F-2 can be accomplished by a single PERFORM. This is most meaningful when the word being accomplished by each paragraph is small. 13.5.5 Use of the INSPECT Statement Use of the INSPECT statement is preferable to doing the same process in other ways. You should understand all the options (including REPLACING) so that the power of the statement can be applied. For information on the INSPECT statement see Part 2, COBOL Language Reference Material. 13.5.6 Data Movement This is just an observation on data movement. On a character-oriented machine, there is generally a machine instruction with a name something like MVC (for move characters). On such a system, there is a fixed cost for picking up the instruction, plus a variable cost which is a function of the number of characters. TOPS-IO and TOPS-20 act similarly, but the fixed cost is higher. Especially if data conversion is implied (ASCII to SIXBIT), then it is more efficient to change all fields in a record with one move statement than to move the data field by field. If the compiler recognizes that data conversion is not necessary, and that the records are aligned, then efficient in-line code can be generated. Because the fixed cost to move any number of characters is higher on TOPS-IO and TOPS-20 than on some systems, programmers should try to avoid loops where small numbers of characters are continually being transferred. If it is impossible to avoid such situations, then make sure that the data is aligned. 13-14 IMPROVING PERFORMANCE OF COBOL-74 PROGRAMS 13.5.7 Ordering Statements All programs should be written so that they avoid executing large numbers of useless instructions. Thus classic decision lists like: IF AB = " " GO TO FOO. IF CD "1" GO TO FOO-l IF EF "2" GO TO FOO-2. IF GH = "3" GO TO FOO-3 should be ordered by expected frequency. The following type of coding should be avoided if it is in a highly used spot: IF AB IF AB IF AB " " MOVE Z TO DOD. "1" MOVE Z TO FFF. "2" MOVE Z TO GGG. In this type of code all statements get executed though only one actually does anything useful. 13.5.8 each time, even Asking the Correct Question Some small efficiencies can be gained by asking the correct questions. Thus the following example is inefficient. LOOP. SET X TO 1. MOVE B(X) TO C(X). SET X UP BY 1. IF X > 1000 GO TO ZIP. GO TO LOOP. While this is not bad coding, the program will only go to ZIP one time in a 1000. Some better code is developed if the statement were rewritten: IF X < 1001 GO TO LOOP ELSE GO TO ZIP. The first option is the one that happens the most often. 13-15 APPENDIX A DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 The terms COBOL-68 and COBOL-74, which are used in the following text, refer to DIGITAL's implementation of ANS-68 and ANS-74 COBOL, respectively. Any references to ANS COBOL will be made clear by the use of the initials "ANS". COBOL-74 differs from COBOL-68 in the following ways: 1. A stroke (slash, "/", virgule) in the continuation area (seventh character position) of a line causes page ejection of the compilation listing. (The line is treated as a comment.) <lNUC (1) New feature to COBOL-74> 2. Two contiguous quotation marks may be used to represent a single quotation mark character in a nonnumeric literal. <lNUC (1) New feature.> 3. REMARKS paragraph is deleted. replaced by the comment line.> 4. Continuation of Identification Division comment-entries must not have a hyphen in the continuation indicator area. <lNUC (2» 5. PROGRAM COLLATING SEQUENCE clause specifies that the collating sequence associated with alphabet-name is used in nonnumeric comparisons. <lNUC (1) New feature.> 6. SPECIAL-NAM~S 7. Alphabet-name clause relates a user-defined name to a specified collating sequence or character code set (ANSI, native, or implementor-specified). <lNUC (1) New feature.> 8. Alphabet-name clause: the literal phrase specifies user-defined collating sequence. <2NUC (1) New feature.> 9. All items which are immediately subordinate to a must have the same level-number. <lNUC (2» 10. Object of a REDEFINES clause can be subordinate to an item described with an OCCURS clause, but must not be referred to in the REDEFINES clause with a subscript or an index. <lNUC (1) New feature.> 11. An asterisk used as a zero suppression symbol in a PICTURE clause and the BLANK WHEN ZERO clause may not appear in the same entry. <lNUC (2» <lNUC (2) Function was paragraph: ilL", II / " , and "=" may not be specified 1n the CURRENCY SIGN clause. <2NUC (2) This restriction did not exist in X3.23-l968.> A-l group a item DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 12. Alphabetic PICTURE character-string may contain the character B. <lNUC (1) New feature.> 13. Stroke (/) permitted as an editing character. feature.> <lNUC (1) 14. SIGN clause' allows the specification of <lNUC (1) New feature.> sign 15. In the Procedure Division a section may contain zero or paragraphs and a paragraph may contain zero or sentences. <lNUC (1) New feature.> 16. In relation and sign conditions, arithmetic expressions must contain at least one reference to a variable. <lNUC (2» 17. Comparison of nonnumeric operands: If one of the operands is described as numeric, it is treated as though it were moved to an alphanumeric item of the same size and the contents of this alphanumeric item were then compared to the nonnumeric operand. <lNUC (3» 18. Abbreviated combined relation condition: When any portion is enclosed in parentheses, all subjects and operators required for the expansion of that portion must be included within the same set of parentheses. <2NUC (2) No such restriction appeared in X3.23-1968.> 19. Abbreviated combined relation condition: If NOT is immediately followed by a relational operator, it is interpreted as part of the relational operator. <2NUC (2) In X3.23-1968, NOT was a logical operator in such cases.> 20. Class condition: The numeric test cannot be used with a group item composed of elementary items described as signed. <lNUC (3» 21. In an arithmetic operation, the composite of operands must not contain more than 18 decimal digits. However, if your COBOL-74 compiler makes use of the Business Instruction Set, the maximum is 36 digits. <lNUC (2) X3.23-1968 specified limits only for ADD and SUBTRACT.> 22. ACCEPT identifier FROM DATE/DAY/TIME allows the programmer to access the date, day, and time. <2NUC (1) New feature.> 23. COMPUTE statement: feature.> 24. DISPLAY statement: If the operand is a numeric must be an unsigned integer. <lNUC (2» 25. DIVIDE statement: the INTO identifier series and the identifier series. <lNUC (2» 26. DIVIDE statement: the remainder item can be <2NUC (1) New feature.> 27. GO TO statement: the word TO is not X3.23-1968 requires the word TO.> 28. EXAMINE statement and the special register TALLY were deleted. <lNUC (2) Function was replaced by the INSPEC~ statement.> the identifier A-2 the series. New position. <2NUC more more (1) literal, New it GIVING numeric-edited. required. <lNUC (1) DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 29. INSPECT statement provides ability to count or replace occurrences of single characters or groups of characters. <lNUC (1) New feature.> 30. MOVE statement: A scaled integer item (i.e., the rightmost character of the PICTURE character-string is a P) may be moved to an alphanumeric or alphanumeric-edited item. <lNUC (I) New feature.> 31. MULTIPLY statement: the BY identifier series and the identifier series. <2NUC (1) New feature.> 32. PERFORM statement: There is no logical - difference to the user between fixed and fixed overlayable segments. <lNUC (1) X3.23-l968 did not permit fixed overlayable segments to be treated the same as a fixed segment.> 33. PERFORM statement: Control is passed only once for each execution of a Format 2 PERFORM statement (i.e., an independent segment referred to by such a PERFORM is made available in its initial state only once for each execution of that PERFORM statement). <lNUC,lSEG (3» 34. STOP statement: If the operand is numeric literal, be an unsigned integer. <lNUC (2» 35. A data description entry with an OCCURS DEPENDING clause may be followed within that record only by entries subordinate to it. That is, only the last part of the record may have a variable number of occurrences. <2TBL (2) This rule did not appear in X3.23-l968.> 36. When a group item, having subordinate to it an entry that specifies Format 2 of the OCCURS clause, is referenced, only that part of the table area that is defined by the value of the operand of the DEPENDING phrase will be used in the operation. That is, the actual size of a variable length item is used, not the maximum size. <2TBL (2» 37. The subject of the condition in the WHEN phrase of the' SEARCH ALL statement must be a data item named in the KEY phrase of the table; the object of this condition may not be a data item named in the KEY phrase. <2TBL (2) X3.23-l968 specified that either the subject or object could be a data item named in the KEY phrase.> 38. SORT statement: COLLATING SEQUENCE phrase provides the ability to override the program collating sequence. <2SRT (1) New feature.> 39. No more than one file-name from a multiple appear in a SORT statement. <2SRT (2» file 40. Segment-numbers permitted in DECLARATIVES. <lSEG (1» 41. ACCESS MODE IS DYNAMIC clause: provides ability to access a file sequentially or randomly in the same program. <2REL,2INX (l) New feature.> 42. ACTUAL KEY clause deleted. 43. RELATIVE KEY clause added for relative (1).New featue.> A-3 GIVING it reel must can «2» organization. <IREL DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 44. FILE-LIMITS clause deleted. «2» 45. PROCESSING MODE clause deleted. «2» 46. ORGANIZATION IS RELATIVE clause. <lREL (2) New feature.> 47. ORGANIZATION IS SEQUENTIAL clause. 48. ORGANIZATION IS INDEXED clause. 49. MULTIPLE REEL/UNIT clause deleted. «2» 50. RESERVE •.• ALTERNATE AREAS deleted. «2» 51. RESERVE integer AREAS to allow the user to specify the exact number of areas to be used. <lSEQ,lREL,lINX (1) New feature.> 52. The data-name option of the LABEL RECORDS clause was deleted. <lSEQ,lREL,lINX (2) X3.23-l968 provided for user-defined label records.> 53. LINAGE clause permits programmer definition of size. <2SEQ (1) New feature.> 54. CLOSE •.. FOR REMOVAL statement. 55. DELETE statement. 56. OPEN REVERSED positions the file at its end. <2SEQ (2» 57. OPEN EXTEND statement adds <2SEQ (1) New feature.> existing 58. The OPEN REVERSED statement applies to all devices that claim support for this function. <2SEQ (1) X3.23-l968 restricted the application of this phrase.> 59. READ statement: AT END phrase required only if no applicable USE AFTER ERROR/EXCEPTION procedure specified. <lSEQ,lREL,lINX (1) New feature."> 60. READ statement: INVALID KEY phrase required only if no applicable USE AFTER ERROR/EXCEPTION procedure specified. <lREL,lINX (1) New feature.> 61. READ ••• NEXT statement: used to retrieve the next logical <2REL, record from a file when the adcess mode is dynamic. 2INX (1) New feature.> 62. REWRITE statement. 63. SEEK statement was deleted. 64. START statement provides for logical positioning within a relative or indexed file for sequential retrieval of records. <2REL, 2INX (1) New feature.> 65. USE statement: the label processing options were deleted. <lSEQ,lREL,lINX (2) X3.23-l968 provided for the processing of user-defined labels.> <lSEQ (2) New feature.> <lINX (2) New feature.> logical page <2SEQ (1) New feature.> <lREL (1) New feature.> records to an file. <lSEQ,lREL (1) New feature.> A-4 «2» DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 e:.e:. vv. USE .•• ERROR/EXCEPTION feature.> 67. Recursive invocation <lSEQ,lREL,lINX (2» 68. WRITE statement: INVALID KEY phrase required only if no applicable USE AFTER ERROR/EXCEPTION procedure specified. <lREL,lINX (1» 69. WRITE statement: BEFORE/AFTER PAGE phrase to skip to top of a page. <lSEQ (1» provides 70. WRITE statement: feature.> <2SEQ 71. CALL identifier statement. statement; of USE END-OF-PAGE A-5 <lSEQ;lREL:IINX procedures phrase. (1 ) New prohibited. <lIPC (1) New feature.> ability (1) New DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 Note A. (RELATIVE files) The RANDOM file access method of COBOL-68 has been replaced by the RELATIVE file organization in COBOL-74. This means a number of syntactic changes, but in addition it means some important semantic changes as well. In the Environment Division, the syntactic changes include the substitution of an ORGANIZATION IS RELATIVE clause for the old ACCESS IS RANDOM clause, and the substitution of the ACCESS IS SEQUENTIAL / RANDOM / DYNAMIC for the old PROCESSING IS SEQUENTIAL clause. The FILE LIMITS clause goes away. The ACTUAL KEY clause is replaced by the RELATIVE KEY clause, although the meaning of the key value is identical to that in COBOL-68. The Data Division is unchanged. The Procedure Division verbs are changed considerably. Of EN , CLOSE and the USE ON ERROR procedures are unchanged. The WRITE statement is unchanged in syntax, but its meaning is restricted to writing a record into an "empty" position in the file. If the record position in the file into which the record is being written is already "occupied", the WRITE must not alter the existing contents of the record position, but must instead take the INVALID KEY path (or execute a USE procedure). In order to change the contents of an "occupied" record position one either has to REWRITE it or DELETE and WRITE it. Attempting to DELETE or REWRITE a record position which is already "empty" causes the INVALID KEY path to be taken. In other words, each record position of the relative file must have an "occupied" state, which can be recognized by the object time I/O routines. There is also a START verb which can be used to position at or beyond a given record position. Then sequential READs or WRITEs may be done. The sequential READ is done with a READ NEXT statement, whereas the random READ is just a READ statement. The sequential READ uses the AT END phrase (which is optional) and the random READ uses the INVALoD KEY phrase (also optional). Thus, there are not only many syntactic changes in existing verbs, but new verbs, and a markedly different approach to the file's contents. Note B. (INDEXED files) The INDEXED I/O module of COBOL-74 is fairly similar to that of COBOL-68. There are syntactic differences in the Environment Division and in the Procedure Division. COBOL-68 had a SYMBOLIC KEY clause to designate the key used in READ, WRITE, REWRITE and DELETE statements. COBOL-74 does not have a SYMBOLIC KEY clause. The random READ statement has a "KEY IS identifier" phrase which supplies a key value. The WRITE statement uses key values from the record being written, and the DELETE and REWRITE statements must follow a successfully executed READ and use the "remembered" key from that operation. COBOL-74 includes a START statement in the Procedure Division which positions the record pointer in the file specified. Also, the READ NEXT statement is used to do sequential reading through the existing records of the file. Note C. (Segmentation and PERFORM rules) In COBOL-74, sections in the Procedure Division can have segment numbers (called "priority numbers" in COBOL-68) that range from 00 to 99. Segments with numbers 50 and above are called A-6 DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 "independent" segments. Also, the programmer can specify a SEGMENT LIMIT IS clause with a value between 00 and 49. divides the segments with numbers below 50 into two groups. all segments fall into one of three groups: This Thus 1. Below the segment limit, called "fixed permanent", always resident~ that is, 2. From the segment limit to 49, called "fixed overlayable", that is, each segment number defines an overlay and the code in such a segment is brought into memory only as needed. Any GO TOs which have been ALTERED will retain their most recently set values when they are brought into memory. 3. From 50 up, called "independent", that is, each segment number defines an overlay and the code is brought into memory only as needed. Any GO TOs which have been altered will be reset each time the segment is brought into memory. The restrictions on the ALTER and PERFORM verbs have not really changed from ANS-68 COBOL to ANS-74 COBOL but they have become more explicit. COBOL-74 implements the restrictions on the ALTER statement correctly (by either standard) but implements the restrictions on PERFORM in a manner different from either standard. COBOL-74 uses the segment-limit value as the dividing line for the PERFORM restrictions, whereas the standards use the segment number 50 as the dividing line. When you do not specify a segment limit value the compiler supplies 50 as the default, making the restrictions the same for COBOL-74 and the standards. However, when you do supply the segment limit value, COBOL-74 applies the rules in such a way as to make all overlayable segments behave the same. (In the Journal of Development, the ALTER statement has been abolished and segment numbers are restricted to 00 to 49, hence all these rules go away, but the JOD change occurred after the ANS-74 COBOL standard was frozen for publication.) Note D. (CALL and CANCEL rules) There are many differences between COBOL-74's implementation CALL and CANCEL and the ANS-74 COBOL standard. of 1. The syntax is different for both statements in that COBOL-74 interprets a user-word as a program-name with or without quotes around it, whereas ANS-74 COBOL interprets a user-word as a data-name in which is stored the program-name. 2. In ANS-74 COBOL there is an ON OVERFLOW clause for handling instances in which there is insufficient memory space available to load the c'alled subprogram. This does not exist in COBOL-74. 3. COBOL-74 allows alternate entry points to subprograms, not allowed in ANS-74 COBOL, and COBOL-74 uses the ENTER user to call (MACRO/FORTRAN) statement to allow the subprograms written in those languages. 4. The semantics are very different. COBOL-74 uses LINK to construct a tree-structured overlay scheme from user-supplied commands to LINK. When a subprogram is CALLed, the branch of the tree up to that subprogram is loaded along with the sub.program. Likewise, when a subprogram is CANCELled, the entire tree beyond that subprogram is cancelled. ANS-74 A-7 DIFFERENCES BETWEEN COBOL-68 AND COBOL-74 COBOL recognizes no such tree structure, and allows loading and cancelling to occur strictly on a subprogram basis. In addition, LINK allows more than one subprogram to be linked into a single overlay, with the effect that a cancel of one of the subprograms in the overlay results in a cancel of all subprograms in that overlay. Note E. (COpy statement) The double equal sign (==) is a syntactic element new to ANS-74 COBOL (but not new to users of COBOL-68 version 12) used to set off pseudo-text. This notation is used to delimit pieces of text which you wish to replace or insert with the COpy verb. It is not necessary to use the double equal sign if your text-string is a literal or a data-name, but if you wish to replace complex pieces of text the double equal sign will serve as a clear delimiter, and you may include the notation any time you wish without risk of confusing the compiler. A-8 APPENDIX B COBOL RESERVED WORDS In the listing below, words not preceded by symbols are reserved in both ANSI-74 Standard COBOL and in DECsystem-lO and DECSYSTEM-20 COBOL. Words preceded by '*' are reserved in ANSI-74 Standard COBOL but not reserved in DECsystem-lO and DECSYSTEM-20 COBOL. Words preceded by '**' are reserved in DECsystem-lO and DECSYSTEM-20 COBOL but not reserved in ANSI-74 Standard COBOL. Reserved words may not be used as user-created names. A ACCEPT ACCESS ACTUAL ADD *ADDRESS ADVANCING AFTER ALL **ALLOWING ALPHABETIC ALSO ALTER ALTERNATE AND ARE AREA AREAS **ASCII ASSIGN ASCENDING AT **ANY AUTHOR B BEFORE BEGINNING BLANK BLOCK BY BYTE **BINARY BOTTOM C **CALL **CANCEL CD CF CH **CHANNEL CHARACTER CHARACTERS **CLASS *CLOCK-UNITS CLOSE COBOL CODE CODE-SET COLLATING COBOL RESERVED WORDS COLUMN COMMA COMP **COMP-l **COMMUNICATION **COMP-3 **COMPILE COMPUTATIONAL **COMPUTATIONAL-3 COMPUTE CONFIGURATION **CONSOLE CONTAINS CONTROL COpy CORR **COUNT **CURRENCY **DATABASE-KEY **DATE DATE-WRITTEN **DBKEY DE *DEBUG-CONTENTS *DEBUG-ITEM *DEBUG-LINE *DEBUG-NAME *DEBUG-SUB-l *DEBUG-SUB-2 *DEBUG-SUB-3 DEBUGGING DECIMAL-POINT DECLARATIVES **DECSYSTEM-IO **DECSYSTEM-20 **DECSYSTEMIO CONTROLS CORRESPONDING **COMPUTATIONAL-l CURRENT D DATA **DATE-COMPILED **DELETE DELIMITED **DENSITY DEPENDING **DEFERRED DELIMITER **DEPTH DESCENDING DESTINATION DISABLE DISPLAY **DISPLAY-6 **DISPLAY-7 **DISPLAY-9 DIVIDE DIVISION **DUPLICATE DOWN DETAIL **DUP DUPLICATES DYNAMIC **EBCDIC EGI ELSE EMI **EMPTY ENABLE E END END-OF-PAGE ENDING ENTER **ENTRY ENVIRONMENT EOP **EPI EQUAL **EQUALS ERROR ESI **EVEN EVERY EXCEPTION B-2 COBOL RESERVED WORDS **EXCL **EXCLUSIVE EXIT EXTEND F FD FILE FILE-CONTROL FILE-STATUS FILLER FINAL FIRST FOOTING **FIND FOR **FORTRAN-IV **FORTRAN **FREED FROM GENERATE **GET GIVING GO **GOBACK GREATER **FREE G GROUP H HEADING HIGH-VALUE HIGH-VALUES I I-O I-O CONTROL IDENTIFICATION IF IN INDEX INDEXED INDICATE INITIAL INITIATE INPUT **ID INPUT-OUTPUT **INSERT INSPECT INSTALLATION INTO INVALID **INVOKE IS J **JOURNAL JUSTIFIED JUST K KEY KEYS L LABEL LAST LEADING LEFT LENGTH LESS B-3 COBOL RESERVED WORDS LIMIT LIMITS LINAGE LINAGE-COUNTER LINE LINE-COUNTER LINES LOW-VALUE **LINKAGE LOCK LOW-VALUES M **MACRO **MEMBER **MEMBERS MEMORY MERGE MESSAGE MODE **MODIFY MODULES MOVE MULTIPLE MULTIPLY NEGATIVE NEXT NO **NOMINAL **NONE NOT NUMBER N NATIVE NUMERIC 0 OBJECT-COMPUTER OCCURS OF OFF ON **ONLY **OPT **ODD OMITTED OPEN OPTIONAL ORGANIZATION **OTHERS OVERFLOW **OWNER OR OUTPUT P PAGE **PDP-IO PAGE-COUNTER **PARITY PERFORM PF PH PIC PICTURE PLUS **POINTER POSITION POSITIVE PRINTING **PRIVACY PROCEDURE **POSITIONING **PRIOR PROCEED PROCEDURES **PROGRAM PROGRAM-ID **PROTECTED B-4 PROCESSING **PROT COBOL RESERVED WORDS Q QUEUE QUOTE QUOTES RANDOM RD READ *READ-REWRITE *READ-WRITE RECEIVE RECORD **RECORDING RECORDS R REDEFINES REEL REFERENCES RELATIVE RELEASE REMAINDER REMARKS REMOVAL **REMOVE RENAMES REPLACING REPORT REPORTING REPORTS RERUN RESERVE RESET **RETAIN **RETAINED **RETR **RETRIEVAL RETURN REVERSED REWIND REWRITE RF RH RIGHT ROUNDED RUN **SCHEMA SD **RUN-UNIT S SAME SEARCH SECTION SECURITY SEGMENT SEGMENT-LIMIT SELECT **SELECTIVE SEND SENTENCE SEPARATE **SEQUENCE SEQUENTIAL SET **SETS SIGN **SIXBIT SIZE SORT SORT-MERGE SOURCE SOURCE-COMPUTER SPACE SPACES SPECIAL-NAMES STANDARD STANDARD-l START STATUS STOP **STORE STRING SUB-QUEUE-l **SUB-QUEUE-2 **SUB-QUEUE-3 B-5 **STANDARD-ASCII **SUB-SCHEMA COBOL RESERVED WORDS SUBTRACT SUM **SUPPRESS SYMBOLIC SYNC TABLE TALLY TALLYING TAPE TERMINAL TERMINATE TEXT THAN THROUGH THRU TIME TIMES TO TOP **TRACE **SWITCH SYNCHRONIZED T TRAILING **TRANSACTION TYPE U * *UNAVAI LABLE UNIT UNSTRING UNTIL UP **UPDATE **UPDATES UPON USAGE **USAGE-MODE USE **USER-NUMBER USING V VALUE **VERB VALUES VARYING **VIA W WHEN WITH WORDS WORKING-STORAGE WRITE ZEROES ZEROS **WITHIN Z ZERO B-6 APPENDIX C ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-l shows the ASCII and SIXBIT collating sequence and the conversions from ASCII to EBCDIC, SIXBIT to ASCII, and SIXBIT to EBCDIC. If the ASCII character does not convert to the same character in EBCDIC, the EBCDIC character is shown in parentheses next to the EBCDIC code. Note that the first and last 32 characters do not exist in SIXBIT. Also, the characters in the first column (NUL, SOH, STX, and so forth,) are control characters, which are nonprinting. Table C-l ASCII and SIXBIT Collating Sequence and Conversion to EBCDIC Character ASCII 7-bit EBCDIC 9-bit NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DCl DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US 000 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017 020 021 022 023 024 025 026 027 030 031 032 033 034 035 036 037 000 001* 002* 003* 067 055* 056* 057* 026 005 045 013* 014* 025* (NL) 006*(LC) 066*(UC) 044* (BYP) 024 * (RES) 064* (PN) 065* (RS) 004*(PF) 075* 027*(IL) 046*(EOB) 052* (CM) 031* 032*(CC) 047* (PRE) 023* (TM) 041* (SOS) 040*(DS) 042*(FS) Character SIXBIT ASCII 7-bit EBCDIC 9-bit Space 00 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 30 31 32 33 34 35 36 37 040 041 042 043 044 045 046 047 050 051 052 053 054 055 056 057 060 061 062 063 064 065 066 067 070 071 072 073 074 075 076 077 100 132 177 173 133 154 1·20 175 115 135 134 116 153 140 113 141 360 361 362 363 364 365 366 367 370 371 172 136 114 176 156 157 ! il # $ % & , ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 .: I < = > ? C-l ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-1 (Cont.) ASCII and SIXBIT Collating Sequence and Conversion to EBCDIC Character SIXBIT @ 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 60 61 62 63 64 65 66 67 70 71 72 73 74 75 76 77 A B C D E F G H I J K L M N 0 p Q R S T U V W X y Z [ \ ] ASCII 7-bit EBCDIC 9-bit 100 101 102 103 104 105 106 107 110 174 301 302 303 304 305 306 307 310 311 321 322 323 324 325 326 327 330 331 342 343 344 345 346 347 350 351 255 1 340 275 137 155 III 112 113 114 115 116 117 120 121 122 123 124 125 126 127 130 131 132 133 134 135 136 137 Character , a b c d e f g h i j k 1 m n 0 P q r s t u v w x Y z 1 { ,... Delete ASCII 7-bit EBCDIC 9-bit 140 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164 165 166 167 170 171 172 173 174 175 176 177 171 201 202 203 204 205 206 207 210 211 221 222 223 224 225 226 227 230 231 242 243 244 245 246 247 250 251 300 1 117 320 241 007 These EBCDIC codes either have no equivalent in the ASCII or SIXBIT character sets, or are referred to by different names. They are converted to the indicated ASCII characters to preserve their uniqueness if the ASCII character is converted back to EBCDIC. C-2 ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-2 shows the conversion of ASCII eoae to SIXBIT code. The table does not show ASCII codes 000 through 037 because they all convert to SIXBIT 74 (\), except 11 (TAB) which converts to SIXBIT 00 (space) • Table C-2 ASCII to SIXBIT Conversion ASCII 7-bit SIXBIT 040 041 042 043 044 045 046 047 00 01 02 03 04 05 06 07 / 050 051 052 053 054 055 056 057 10 11 12 13 14 15 16 17 0 1 2 3 4 5 6 7 060 061 062 063 064 065 066 067 20 21 22 23 24 25 26 27 8 070 071 072 073 074 075 076 077 30 31 32 33 34 35 36 37 Character Space ! " # $ % & , ( ) * + , - . 9 : ., < = > ? ASCII 7-bit SIXBIT G 100 101 102 103 104 105 106 107 40 41 42 43 44 45 46 47 H 110 I III J 112 113 114 115 116 117 50 51 52 53 54 55 56 57 120 121 122 123 124 125 126 127 60 61 62 63 64 65 66 67 130 131 132 133 134 135 136 137 70 71 72 73 74 75 76 77 Character @ A B C D E F K L M N 0 p Q R S T U V W X y Z [ \ ] t +- C-3 ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-2 (Cont.) ASCII to SIXBIT Conversion ASCII code 140 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164 165 166 167 170 171 172 173 174 175 176 177 ASCII character SIXBIT code ... 74 41 42 43 44 45 46 47 a b c d e f 9 h i 50 51 52 53 54 55 56 57 j k 1 In n 0 60 61 62 63 64 65 66 67 P q r s t u v w 70 71 72 73 74 75 74 74 x Y z { I } "" delete C-4 SIXBIT character \ A B C D E F G H I J K L M N 0 P Q R S T U V W X y Z [ \ ] \ \ ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-3 shows the EBCDIC collating sequence and the conversion from EBCDIC to ASCII. When conversion is from EBCDIC to SIXBIT, it is as if the code was converted to ASCII and then from ASCII to SIXBIT. Table C-3 EBCDIC Collating Sequence and Conversion to ASCII EBCDIC code EBCDIC character ASCII code ASCII character 000 001 002 003 004 005 006 007 NUL SOH STX ETX PF HT LC Delete 000 001 002 003 024 011 016 177 NUL SOH STX ETX DC4 HT SO Delete 050 051 052 053 054 055 056 057 010 011 012 013 014 015 016 017 SMM VT FF CR SO SI 134 134 134 013 014 134 134 134 \ \ \ 060 061 -62 063 064 065 066 067 020 021 022 023 024 025 026 027 DLE DCl DC2 TM RES NL BS IL 134 134 134 034 021 015 010 026 030 031 032 033 034 035 036 037 CAN EM CC CUI IFS IGS IRS IUS 134 031 032 134 134 134 134 134 040 041 042 043 044 045 046 047 DS SOS FS 036 035 037 134 020 012 027 033 BYP LF ETB ESC EBCDIC code VT FF \ \ \ 070 071 072 073 074 075 076 077 \ \ \' FS DCI CR BS SYN 100 101 102 103 104 105 106 107 \ EM SUB \ \ \ \ \ RS GS US EBCDIC character \ \ ENQ ACK BEL PN RS UC EOT 134 134 134 134 022 023 017 004 \ \ \ \ \ \ CU3 DC4 NAK SUB 134 134 134 134 134 025 134 134 SM cuz Space III \ DLE LF ETB ESC C-5 ASCII character 134 134 030 134 134 005 006 007 110 112 113 114 115 116 117 ASCII code ¢ . < { + I 040 134 134 134 134 134 134 134 134 134 134 056 074 050 053 174 CAN \ \ ENQ ACK BEL DC2 DC3 SI EOT \ \ \ NAK \ \ Space \ \ \ \ \ \ \ \ \ \ < { + I ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-3 (Cont.) EBCDIC Collating Sequence and Conversion to ASCII EBCDIC code 120 121 122 123 124 125 126 127 130 131 132 133 134 135 136 137 140 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164 165 166 167 EBCDIC character & ! $ * t - / , % > ? ASCII ASCII code character 046 134 134 134 134 134 134 134 \ \ \ \ \ \ \ 134 134 041 044 052 051 073 137 EBCDIC code 170 171 172 173 174 175 176 177 & \ \ 200 201 202 203 204 205 206 207 ! $ * t \ 055 057 134 134 134 134 134 134 - 134 134 134 054 045 137 076 077 \ \ \ ? 220 221 222 223 224 225 226 227 134 134 134 134 134 134 134 134 \ \ \ \ \ \ \ \ 230 231 232 233 234 235 236 237 210 211 212 213 214 215 216 217 / \ \ \ \ \ \ , % > C-6 EBCDIC character : # @ , = " a b c d e f 9 h i j k 1 m n 0 P q r ASCII code ASCII character 134 140 072 043 100 47 075 042 \ 134 141 142 143 144 145 146 147 \ a 150 151 134 134 134 134 134 134 h i 134 152 153 154 155 156 157 160 161 162 134 134 134 134 134 134 : # @ , = II b c d e f 9 \ \ \ \ \ \ \ j k 1 m n 0 P q r \ \ \ \ \ \ ASCII, SIXBIT, AND EBCDIC COLLATING SEQUENCES AND CONVERSIONS Table C-3 (Cont.) EBCDIC Collating Sequence and Conversion to ASCII EBCDIC code 240 241 242 243 244 245 246 247 250 251 252 253 254 255 256 257 EBCDIC character s t u v w x y z [ ASCII code 134 176 163 164 165 166 167 170 171 172 134 134 134 133 134 134 260 261 262 263 264 265 266 267 175 134 134 134 134 134 134 134 270 271 272 273 274 275 276 277 134 134 134 134 134 135 134 134 300 301 302 303 304 305 306 307 360 361 362 363 364 365 366 367 ] ASCII character EBCDIC code EBCDIC character ASCII code \ 310 311 312 313 314 315 316 317 H 110 110 134 134 134 134 134 134 ........... s t u v w x z \ \ \ [ \ \ { 340 341 342 343 344 345 346 347 \ \ \ \ \ ] \ \ { G 0 1 2 3 4 5 6 7 060 061 062 063 064 065 066 067 F 330 331 332 333 334 335 336 337 \ \ \ \ \ \ 173 101 102 103 104 105 106 107 A B C D E 320 321 322 323 324 325 326 327 Y I J K L M N 0 p Q R S T U V W X y G 350 351 352 353 354 355 356 357 1 1 2 3 4 5 6 7 370 371 372 373 374 375 376 377 8 A B C D E F C-7 Z 9 175 112 113 114 115 116 117 120 121 122 134 134 134 134 134 134 134 134 123 124 125 126 127 130 131 132 134 134 134 134 134 134 070 071 134 134 134 134 134 134 ASCII character H I \ \ \ \ \ \ } J K L M N 0 P Q R \ \ \ \ \ \ \ \ S T U V W X y Z \ \ \ \ \ \ 8 9 \ \ \ \ \ \ APPENDIX D ALTERNATE NUMERIC TEST LIBOL as normally assembled will include the ANSI standard NUME~IC test. However, a switch has been provided to allow the installation manager to replace this with the ALTERNATE NUMERIC test at installation time. The ALTERNATE conditions: NUMERIC test result is TRUE under the following 1. For alphanumeric and unsigned numeric items, each character must be a digit (0 through 9). Leading and trailing spaces and leading and trailing tabs are ignored. No signs are permitted. 2. For signed numeric items, the sign may have only one of the three following representations: a leading graphic sign ("+" or "-"), a trailing graphic sign, or a trailing embedded sign. Leading and trailing spaces and leading and trailing tabs are ignored. All other characters must be digits. D-l APPENDIX E DEFINING LOGICAL NAMES UNDER TOPS-20 Most of the file specifications for the COBOL compiler and the utilities associated with COBOL-74 use project-programmer numbers to identify areas on the disk. Users of TOPS-20 do not normally deal with project-programmer numbers; named directories are used instead. However, the compiler and the utilities often will not accept named directories in the command strings. There are two ways for TOPS-20 users to specify a directory to be searched. One is to use the TRANSL command to translate a named directory to a project-programmer number. This way is perfectly functional, but usually inconvenient. The other way is to define a logical name and use it in the command string in place of the device name and the project-programmer number. The TRANSL and DEFINE commands are described in the DECSYSTEM-20 User's Guide. Refer to that manual for more information on these two commands. A short description of the DEFINE command has been included here for convenience. The DEFINE command has the following format: @DEFINE (LOGICAL NAME) logname: (AS) filespecs where: logname: is the logical name being defined. It consists of up to 6 alphanumeric characters (A-Z and 0-9 only) followed by a colon. filespecs is a list of file specifications (separated by commas) that define the logical name. A file specification may contain any combination of a structure name, device name, directory, file name, file type, generation number, and wildcards. If you wish to remove a logical name, you should leave the filespecs entry blank. The following characteristics of the DEFINE command should be noted. 1. The DEFINE command is used at TOPS-20 monitor level (or in a batch or command file). The command does not alter any program and leaves you at monitor level. 2. Some programs may expect certain logical names to be defined certain ways. You should exercise caution in deciding on a character string to use as a logical name. See the INFORMATION command in the DECSYSTEM-20 User's Guide for a description of how to determine what logical names are already defined. DEFINING LOGICAL NAMES UNDER TOPS-20 Example: DEFINE PR: <PAYROLL> will allow you to type the compiler: following command to the COBOL-74 PR:FEDTAX=TESTFT.CBL This command string will take a file in your connected directory named TESTFT.CBL and compile it, writing the .REL file in the directory <PAYROLL>. As written, the command string would also write the .LST file to your connected directory. If you wish to have it in the <PAYROLL> directory you must use the following command: PR:FEDTAX,PR:FEDTAX=TESTFT.CBL E-2 GLOSSARY The terms in this glossary are defined in accordance with COBOL' as used in this document. Therefore, these terms may not have the same meanings in other languages. These definitions are also intended to serve either as reference material or as introductory material to be reviewed before reading the detailed language specifications that follow. For this reason, these definitions are, in most instances, brief and do not include detailed syntactical rules. Abbreviated Combined Relation Condition The combined condition that results from the explicit omission of a common subject, or a common subject and common relational operator in a consecutive sequence of relation conditions. Access Mode The manner in which records are to file. be operated upon within Actual Decimal point The physical representation (decimal point characters period or comma (,» of the decimal point position in a data item. a (.) Alphabet-Name A user-defined word in the SPECIAL-NAMES paragraph of the Environment Division that assigns a name to a specific character set and/or collating sequence. Alphabetic Character A character that belongs to the following set of letters: A, B, C, D, E, F, G, H, I, J, K, L, M, N, 0, P, Q, R, S, T, U, V, W, X, Y, Z, and space. Alphanumeric Character Any character in the computer's character set. Alternate Record Key A key, other than the prime record key, whose contents identify a record within an indexed file. Glossary-l Arithmetic Expression An arithmetic expression can be an identifier or a numeric elementary item, a numeric literal, such identifiers and literals separated by arithmetic operators, two arithmetic expressions separated by an arithmetic operator, or an arithmetic expression enclosed in parentheses. Arithmetic Operator A single character, or a fixed belongs to the following set: 2-character Character Meaning + addition subtraction multiplication division exponentiation * ** / combination that Ascending Key A key upon the values of which data is ordered starting with the lowest value of key up to the highest value of key in accordance with the rules for comparing data items. Assumed Decimal Point A decimal point position that does not involve the existence of an actual character in a data item. The assumed decimal point has logical meaning but no physical representation. At End Condition A condition caused: 1. during the execution of a READ statement for accessed file. a sequentially 2. during the execution of a RETURN statement, when no next logical record exists for the associated sort or merge file. 3. during the execution of a SEARCH statement, when the search operation terminates without satisfying the condition specified in any of the associated WHEN phrases. Block A physical unit of data that is normally composed of one or more logical records. For mass storage files, a block may contain a portion of a logical record. The size of a block has no direct relationship to the size of the file within which the block is contained, or to the size of the logical record(s) that are either continued within the block or that overlap the block. The term is synonymous with physical record. Body Group Generic name for a report group of TYPE DETAIL, CONTROL or CONTROL FOOTING. HEADING, Called Program A program that is the object of a CALL statement combined object time with the calling program to produce a run unit. Glossary-2 at Calling Program A program that executes a CALL to another program. Cd-Name A user-defined word that names an MCS interface area described in a communication description entry within the Communication Section of the Data Division. Character The basic indivisible unit of the language. Character position A character position is the amount of physical storage required to store a single standard data format character described as usage is DISPLAY. Further characteristics of the physical storage are defined by the implementor. Character-String A sequence of contiguous characters that form a COBOL word, literal, a PICTURE character-string, or a comment-entry. a Class Condition The proposition, for which a truth value can be determined, that the content of an item is wholly alphabetic or is wholly numeric. Clause A clause is an ordered set of consecutive COBOL character-strings whose purpose is to specify an attribute of an entry. COBOL Character Set The complete COBOL character set consists of listed below: the 51 Character Meaning 0,1, ••. ,9 digit letter space (blank) plus sign minus sign (hyphen) asterisk stroke (virgule, slash) equal sign currency sign comma (decimal point) semicolon period (decimal point) quotation mark left parenthesis right parenthesis greater than symbol less than symbol A,B, .•. ,Z + * / $ " ( ) > < Glossary-3 characters COBOL Word (See Word.) Collating Sequence The sequence in which the characters that computer are ordered for purposes of comparing. are acceptable in a sorting, merging, and Column A character position within a print line. numbered from 1, by 1, starting at the position of the print line and extending position of the print line. The columns are leftmost character to the rightmost Combined Condition A condition that is the result of connecting two conditions with the 'AND' or the 'OR' logical operator. or more Comment-Entry An entry in the Identification Division that may be combination of characters from the computer character set. any Comment Line A source program line represented by an asterisk in the indicator area of the line and any characters from the computer's character set in area A and area B of that line. The comment line serves only as documentatl0n in a program. A special form of comment line represented by a stroke (/) in the indicator area of the line, and any characters from the computer's character set in area A and area B of that line, causes page ejection prior to printing the comment. Communication Description Entry An entry in the Communication Section of the Data Division that is composed of the level indicator CD, followed by a cd-name, and then followed by a set of clauses as .required. It describes the interface between the Message Control System (MCS) and the COBOL program. Communication Device A mechanism (hardware or hardware/software) capable of sending data to a queue and/or recelvlng data from a queue. This mechanism may be a computer or a peripheral device. One or more programs containing communication description entries and residing within the same computer define one or more of these mechanisms. Communication Section The section of the Data Division that describes the interface areas between the MCS and the program. This section is composed of one or more CD description entries. Compile Time The time at which a COBOL source program is translated by a COBOL compiler to a COBOL object program. GlosSary-4 Compiler Directing Statement A statement beginning with a compiler-directing verb that causes the compiler to take a specific action during compilation. Complex Condition A condition in which one or more logical operators act upon one or more conditions. (See Negated Simple Condition, Combined Condition, Negated Combined Condition.) Computer-Name A system-name that identifies the computer upon which the program is to be compiled or run. Condition A status of a program at execution time for which a truth value can be determined. Where the term 'condition' (condition-I, condition-2, .•. ) appears in these language specifications in or in. reference to 'condition' (condition-I, condition-2, ..• ) of a general format, it is a conditional expression consisting of either a simple condition optionally parenthesized, or a combined condition consisting of the syntactically correct combination of simple conditions, logical operators, and parentheses, for which a truth value can be determined. Condition-Name A user-defined word assigned to a specific value, set of values, or range of values, within the complete set of values that a conditional variable may possess; or the user-defined word assigned to a status of an implementor-defined switch or device. Condition-Name Condition The proposition, for which a truth value can be determined, that the value of a conditional variable is a member of the set of values attributed to a condition-name associated with the conditional variable. Conditional Expression A simple condition or a complex condition specified in an IF, PERFORM, or SEARCH statement. (See Simple Condition and Complex Condition.) Conditional Statement A conditional statement specifies that the truth value of a condition is to be determined, and that the subsequent action of the object program is dependent on this truth value. Conditional Variable A data item of which one or assigned to it. more values has a condition-name Configuration Section A section of the Environment Division that describes specifications of source and object computers. Glossary-5 overall Connective A reserved word that is used to: 1. Associate a data-name, paragraph-name, text-name with its qualifier. 2. Link two or more operands written in a series. 3. Form conditions Operator.) (logical condition-name, connectives). or Logical (See Contiguous Items Items that are described by consecutive entries in the Data Division, and that bear a definite hierarchical relationship to each other. Control Break A change in the value of a data item that is referenced in the CONTROL clause. More generally, a change in the value of a data item that is used to control the hierarchical structure of a report. Control Break Level The relative position within a control most major control break occurred. hierarchy Control Data Item A data item, in whose contents a change break. may produce Control Data-Name A data-name that appears in a CONTROL control data item. clause and at which the a control refers to Control Footing A report group that is presented at the end of the control of which it is a member. a group Control Group A set of body groups that is presented for a given value of a control data item or of FINAL. Each control group may begin with a CONTROL HEADING, end with a CONTROL FOOTING, and contain DETAIL report groups. Control Heading A report group that is presented at the beginning of the group of which it is a member. Control Hierarchy A designated sequence positional order of clause. control of report subdivisions defined by the FINAL and the data-names within a CONTROL Glossary-6 Counter A data item used for storing numbers or number representations in a manner that permits these numbers to be increased or decreased by the value of another number, or to be changed or reset to zero or to an arbitrary positive or negative value. Currency Sign The character '$' of the COBOL character set. Currency Symbol The character defined by the CURRENCY SIGN clause in the If no CURRENCY SIGN clause is present SPECIAL-NAMES paragraph. in a COBOL source program, the currency symbol is identical to the currency sign. Current Record The record that is available in the record area the file. Current Record Pointer A conceptual entity that is used in the record. associated selection of the with next Data Clause A clause that appears in a data description entry in the Data Division and that provides information describing a particular attribute of a data item. Data Description Entry An entry in the Data Division that is composed of a level-number followed by a data-name, if required, and then followed by a set of data clauses, as required. Data Item A character or a set of either case, literals) program. contiguous characters (excluding, in defined as a unit of data by the COBOL Data-Name A user-defined word that names a data item described in a data description entry in the Data Division. When used in the general formats, 'data-name' represents a word that cannot be subscripted, indexed, or qualified unless specifically permitted by the rules for that format. Debugging Line A debugging line is any line with 'D' in the the line. Debugging Section A debugging section DEBUGGING statement. is a section Glossary-7 that indicator contains a area of USE FOR Declaratives A set of one or more special-purpose sections, written at the beginning of the Procedure Division, the first of which is preceded by the key word DECLARATIVES, and the last of which is followed by the key words END DECLARATIVES. A declarative is composed of a section header, followed by a USE compiler-directing sentence, followed by a set of zero, one, or more associated paragraphs. Declarative-Sentence A compiler-directing sentence consisting of statement terminated by the separator period. single a USE Delimiter A character or a sequence of contiguous characters that identify the end of a string of characters and separate that string of characters from the following string of characters. A delimiter is not part of the string of characters that it delimits. Descending Key A key upon the values of which data is ordered starting with the highest value of key down to the lowest value of key, in accordance with the rules for comparing data items. Destination The symbolic identification of the from a queue. receiver of a transmission Digit position A digit position is the amount of physical storage required to store a single digit. This amount may vary depending on the usage of the data item describing the digit position. Further characteristics of the physical storage are defined by the implementor. Division A set of zero, one, or more section~ of paragraphs, called the division body, that are formed and combined in accordance with a specific set of rules. There are four divisions in a COBOL Identification, Environment, Data, and Procedure. program: Division Header A combination of words followed by a period and a space that indicates that beginning of a division. The division headers are: IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION [USING data-name-l [data-name-2] ••• ] • Dynamic Access An access mode in which specific logical records can be obtained from or placed into a mass storage file in a nonsequential manner (see Random Access), and obtained from a file in a sequential manner (see Sequential Access), during the scope of the same OPEN statement. Glossary-8 Editing Character A single character or a fixed 2-character to the following set: combination Character Meaning B space zero plus minus credit debit zero suppress check protect currency sign comma (decimal point) period (decimal point) stroke (virgule, slash) o + CR DB Z * $ / Elementary Item A data item that is described subdivided. as not being End of Procedure Division The physical position in a COBOL source program further procedures appear. beloriging further after logically which no Entry Any descriptive set of consecutive clauses terminated by a period and written in the Identification Division, Environment Division, or Data Division of a COBOL source program. Environment Clause A clause that appears as part of an Environment Division entry. Execution Time (See Object Time.) Extend Mode The state of a file after execution of an OPEN statement with the EXTEND phrase specified for that file, and before the execution of a CLOSE statement for that file. Figurative Constant A compiler-generated value referenced through the use of reserved words. File A collection of records. Glossary-9 certain File Clause A clause that appears as Division entries: part of any of the following Data File description (FD) Sort-merge file description (SD) Communication description (CD) FILE-CONTROL The name of an Environment Division paragraph in which files for a given source program are declared. the data File Description Entry An entry in the File Section of the Data Division that is composed of the level indicator FD, followed by a file-name, and then followed by a set of file clauses as required. File-Name A user-defined word that names a file described in a file description entry or a sort-merge file description entry within the File Section of the Data Division. File Organization The permanent logical file structure established at the time that a file is created. File Section The section of the Data Division that contains file description entries and sort-merge file description entries together with their associated record descriptions. Format A specific arrangement of a set of data. Group Item A named contiguous set of elementary or group items. High Order End The leftmost character of a string of characters. I-O-CONTROL The name of an Environment Division paragraph in which object program requirements for specific input-output techniques, rerun points, sharing of same areas by several data files, and multiple file storage on a single input-output device are specified. 1-0 Mode The state of a file after execution of an OPEN statement, with the input-output phrase specified, for that file and before the execution of a CLOSE statement for that file. Glossary-IO Identifier A data-name followed as required by the syntactically correct combination of qualifiers, subscripts, and indexes necessary to make unique reference to a data item. Imperative Statement A statement that begins with an imperative verb and specifies an unconditional action to be taken. An imperative statement may consist of a sequence of imperative statements. Implementor-Name A system-name that refers to a particular that implementor's computing system. feature available on Index A computer storage position or register, the contents of which represent the identification of a particular element in a table. Index Data Item A data item in which the value associated with an index-name be stored in a form specified by the implementor. Index-Name A user-defined word specific table. that names an index associated can with a Indexed Data-Name An identifier that is composed of a data-name followed by one more index-names enclosed in parentheses. or Indexed File A file with indexed organization. Indexed Organization The permanent logical file structure in which each record is identified by the value of one or more keys within that record. Input File A file that is opened in the input mode. Input Mode The state of a file after execution of an OPEN statement with the INPUT phrase specified for that file, and before the execution of a CLOSE statement for that file. Input-Output File A file that is opened in the input-output mode. Input-Output Section The section of the Environment Division that names the files and the external media required by an object program, and that provides information required for transmission and handling of data during execution of the object program. Glossary-II Input Procedure A set of statements that is released to the sort file. executed each time a record is Integer A nonnegative numeric literal or a numeric data item that does not include any character positions to the right of the assumed decimal point. Where the term 'integer' appears in general formats, integer must not be a numeric data item, and must not be signed or zero, unless explicitly allowed by the rules of that format. Invalid Key Condition A condition at object time caused when a specific value of the key associated with an indexed or relative file is determined to be invalid. Key A data item that identifies the location of a record, or a set of data items that serve to identify the ordering of data. Key of Reference The key, either prime or alternate, currently access records within an indexed file. being Key Word A reserved word whose presence is required when the which the word appears is used in a source program. used to format in Language-Name A system-name that specifies a particular programming language. Level Indicator Two alphabetic characters that identify a specific type or a position in hierarchy. of file Level-Number A user-defined word that indicates the position of a data item in the hierarchical structure of a logical record or that indicates special properties of a data description entry. A level-number is expressed as a 1- or 2-digit number. Level-numbers in the range 1 through 49 indicate the position of a data item in the hierarchical structure of a logical record. Level-numbers in the range 1 through 9 may be written either as a single digit or as a zero followed by a significant digit. Level-numbers 66, 77, and 88 identify special properties of a data description entry. Library-Name A user-defined word that names a COBOL library that is to be used by the compiler for a given source program compilation. Glossary-12 Library Text A sequence of character-strings library. and/or separators in a COBOL Line (See Report Line.) Line Number An integer that denotes the vertical position of a report line on a page. Linkage Section The section in the Data Division of the called program that describes data items available from the calling program. These data items may be referred to by both the calling and called program. Literal A character-string whose value is implied by the ordered characters constituting the string. set of Logical Operator One of the reserved words AND, OR, or NOT. In the formation of a condition, both or either of AND and OR can be used as logical connectives. NOT can be used for logical negation. Logical Record The most inclusive data item. The level-number for a 01. (See Report Writer Logical Record.) record is Mass Storage A storage medium on which data may be oganized and maintained both a sequential and nonsequential manner. in Mass Storage Control System (MSCS) An input-output control system that processing of mass storage files. the Low Order End The rightmost character of a string of characters. Mass Storage File A collection of records medium. that is directs assigned to or controls a mass storage MCS (See Message Control System.) Merge File A collection of records to be merged by a MERGE statement. The merge file is created and can be used only by the merge function. Glossary-13 Message Data associated with an end of message indicator group indicator. (See Message Indicators.) or end of Message Control System (MCS) A communication control system that supports messages. processing of exist the the Message Count The count of the number of complete messages that designated queue of messages. an in Message Indicators EGI (end of group indicator), EMI (end of message indicator), and ESI (end of segment indicator) are conceptual indications that notify the MCS that a specific condition exists (end of group, end of message, end of segment). Within the equivalent equivalent terminated terminated hierarchy of EGI, EMI, and ESI, an EGI is conceptually to an ESI, an EMI, and an EGI. An EMI is conceptually to an ESI and an EMI. Thus, a segment may be by an ESI, an EMI, or an EGI. A message may be by an EMI or an EGI. Message Segment Data that forms a logical subdivision of a message normally associated with an end of segment indicator. (See ~essage Indicators.) Mnemonic-Name A user-defined word that is associated Division with a specified implementor-name. in the Environment MSCS (See Mass Storage Control System.) Native Character Set The implementor-defined character set associated computer specified in the OBJECT-COMPUTER paragraph. with the Native Collating Sequence The implementor-defined collating sequence associated computer specified in the OBJECT-COMPUTER paragraph. with the by a Negated Combined Condition The 'NOT' logical operator immediately parenthesized combined condition. Negated Simple Condition The 'NOT' logical operator condition. immediately Glossary-14 followed followed by a simple Next Executable Sentence The next sentence to which control will be transferred execution of the current statement is complete. after Next Executable Statement The next statement to which control will be transferred execution of the current statement is complete. after Next Record The record that logically follows the current record of a file. Noncontiguous Items Elementary data items in the Working-Storage and Linkage Sections that bear no hierarchical relationship to other data items. Nonnumeric Item A data item whose description permits its contents to be composed of any combination of characters taken from the computer's character set. Certain categories of nonnumeric items may be formed from more restricted character sets. Nonnumeric Literal A character-string bounded by quotation marks. The string of characters may include any character in the computer's character set. To represent a single quotation mark character within a nonnumeric literal, two contiguous quotation marks must be used. Numeric Character A character that belongs to the following set of digits: 2, 3, 4, 5, 6, 7, 8, 9. 0, l, Numeric Item A data item whqse description restricts its contents to a value represented by characters chosen from the digits '0' through '9'; if signed, the item may also contain a '+', '-' or other representation of an operational sign. Numeric Literal A literal composed of one or more numeric characters that also may contain eith.er a decimal point, or an algebraic sign, or both. The decimal point must not be the rightmost character. The algebraic sign, if present, must the leftmost character. OBJECT-COMPUTER The name of an Environment Division paragraph in which the computer environment, within which the object program is executed, is described. Object of Entry A set of operands and reserved words within a Data Division entry that immediately follows the subject of the entry. Glossary-IS Object Program A set or group of executable- machine language instructions and other material designed to interact with data to provide problem solutions. In this context, an object program 1S generally the machine language result of the operation of a COBOL compiler on a source program. Where there is no danger of ambiguity, the word 'program' alone may be used in place of the phrase 'object program. ' Object Time The time at which an object program is executed. Open Mode The state of a file after execution of an OPEN statement for that file, and before the execution of a CLOSE statement for that file. The particular open mode is specified in the OPEN statement as either INPUT, OUTPUT, 1-0, or EXTEND. Operand Whereas the general definition of operand is 'that component that is operated upon,' for the purposes of this publication any lowercase word (or words) that appears 1n a statement or entry format may be considered to be an operand and, as such, is an implied reference to the data indicated by the operand. Operational Sign An algebraic sign associated with a numeric data item or a numeric literal, which indicates whether its value is positive or negative. Optional Word A reserved word that is included in a specific format only to improve the readability of the language and whose presence is optional to the user when the format in which the word appears is used in a source program. Output File A file that is opened in either the output mode. mode or the extend Output Mode The state of a file after execution of an OPEN statement, with the OUTPUT or EXTEND phrase specified for that file, and before the execution of a CLOSE statement for that file. Output Procedure A set of statements to which control is given during execution of a SORT statement after the sort function is completed, or during execution of a MERGE statement after the merge function has selected the next record in merged order. Glossary-16 Page A vertical division of a report representing a physical separation of report data, the separation being based on internal reporting requirements and/or external characteristics of the reporting medium. Page Body That part of the logical page and/or spaced. in which lines can be Page Footing A report group that is presented at the end of a report determined by the Report Writer Control System. written page as Page Heading A report group that is presented at the beginning of a page and determined by the Report writer Control System. report Paragraph In the Procedure Division, a paragraph-name followed by a and a space, and by zero, one, or more sentences. Identification and Environment Divisions, a paragraph followed by zero, one, or more entries. period In the header Paragraph Header A reserved word followed by a period and a space that indicates the beginning of a paragraph in the Identification and Environment Divisions. The permissible paragraph headers are: In the Identification Divisio~: PROGRAM-ID. AUTHOR.INSTALLATION. DATE-WRITTEN. DATE-COMPILED. SECURITY. In the Environment Division: SOURCE-COMPUTER. OBJECT-COMPUTER. SPECIAL-NAMES. FILE-CONTROL. I-O-CONTROL. Paragraph-Name A user-defined word that identifies and begins a paragraph in the Procedure Division. Phrase A phrase is an ordered set of one or more character-strings that form a portion of statement or of a COBOL clause. Glossary-17 consecutive COBOL a COBOL procedural Physical Record (See Block.) Prime Record Key A key whose contents uniquely identify a record within an indexed file. Printable Group A report group that contains at least one print line. Printable Item A data item, the extent and contents of which are specified by an elementary report entry. This elementary report entry contains a COLUMN NUMBER clause, a PICTURE clause, and a SOURCE, SUM, or VALUE clause. Procedure A paragraph or group of logically successive paragraphs, or a section or group of logically successive sections, within the Procedure Division. Procedure-Name A user-defined word that is used to name a paragraph or section in the Procedure Division. It consists of a paragraph-name (which may be qualified) or a section-name. Program-Name A user-defined word that identifies a COBOL source program. Pseudo-Text A sequence of character-strings and/or separators bounded by, but not including, pseudo-text delimiters. Pseudo-Text Delimiter Two contiguous equal pseudo-text. sign (=) characters Punctuation Character A character that belongs to the following set: Character Meaning " comma semicolon period quotation mark left parenthesis right parenthesis space equal sign ( ) Glossary-18 used to delimit Qualified Data-Name An identifier that is composed of a data-name followed by one or more sets of either of the connectives OF and IN followed by a data-name qualifier. Qualifier 1. A data-name that is used in a reference together with another data-name at a lower level in the same hierarchy. 2. A section-name that is used in a reference paragraph-name specified in that section. together with a 3. A library-name that is used in a reference text-name associated with that library. together with a Queue A logical collection processing. of messages awaiting transmission or Queue Name A symbolic name that indicates to the MCS the logical path by which a message or a portion of a completed message may be accessible in a queue. Random Access An access mode in which the program-specified value of a key data item identifies the logical record that is obtained from, deleted from, or placed into a relative or indexed file. Record (See Logical Record.) Record Area A storage area allocated for processing the record described in a record description entry in the File Section. Record Description (See Record Description Entry.) Record Description Entry The total set of data particular record. description entries associated with Record Key A key, either the prime record key or an alternate record whose contents identify a record within an indexed file. Record-Name A user-defined word that names a record description entry in the Data Division. Glossary-19 described in a a key, record Reference Format A format that provides a standard source programs. method for describing COBOL Relation (See Relational Operator.) Relation Character ·A character that belongs to the following set: Character Meaning > < greater than less than equal to Relation Condition The proposition for which a truth value can be determined that the value of an arithmetic expression or data item has a specific relationship to the value of another arithmetic expression or data item. (See Relational Operator.) Relational Operator A reserved word, a relation character, a group of consecutive reserved words, or a gr?up of consecutive reserved words and relation characters used In the construction of a relation condition. The pe~missible operators and their meanings are: Relational Operator Meaning IS [NOT] GREATER THAN Greater than or not greater than IS [NOT] > IS [NOT] LESS THAN Less than or not less than IS [NOT] < IS [NOT] EQUAL TO Equal to or not equal to IS [NOT] Relative File A file with relative organization. Relative Key A key whose contents identify a file. logical record in a relative Relative Organization The permanent logical file structure in which each record is uniquely identified by an integer value grater than zero, which specifies the record's logical ordinal position in the file. Report Clause A clause in the Report Section of the Data Division that appears in a report description entry or a report group description entry. Glossary-20 Report Description Entry An entry in the Report Section of the Data Division that is composed of the level indicator RD followed by a report name, followed by a set of report clauses, as required. Report File An output file whose file description entry contains a REPORT clause. The contents of a report file consist of records that are written under control of the Report Writer Control System. Report Footing A report group that is presented only at the end of a report. Report Group In the Report Section of the Data Division, entry and its subordinate entries. an 01 level-number Report Group Description Entry An entry in the Report Section of the Data Division that is composed of the level-number 01, the optional data-name, a TYPE clause, and an optional set of report clauses. Report Heading A report group that is presented report. only at the beginning of a Report Line A division of a page representing one row of horizontal character positions. Each character position of a report line is aligned vertically beneath the corresponding character position of the report line above it. Report lines are numbered from 1, by 1, starting at the top of the page. Report-Name A user-defined word that names a report described in a report description entry within the Report Section of the Data Division. Report Section The section of the Data Division that contains one or more report description entries and their associated report. group description entries. Report Writer Control System (RWCS) An object-time control system provided by constructs reports. the implementor that Report Writer Logical Record A record that consists of the Report Writer print line and associated control information necessary for its selection and vertical positioning. Glossary-21 Reserved Word A COBOL word specified in the list of words that may be used in COBOL source programs, but that must not appear in the programs as user-defined words or system-names. Routine-Name A user-defined word that identifies language other than COBOL. a procedure written in a Run unit A set of one or more object programs that function at object time as a unit to provide problem solutions. RWCS (See Report writer Control System.) Section A set of zero, one, or more paragraphs or entries, called a section body, the first of which is preceded by a section header. Each section consists of the section header and the related section body. Section Header A combination of words followed by a period and a space that indicates the beginning 6f a section in the Environment, Data, and Procedure Division. In the Environment and Data Divisions, a section header is composed of reserved words followed by a period and a space. The permissible section headers are: In the Environment Division: CONFIGURATION SECTION. INPUT-OUTPUT SECTION. In the Data Division: FILE SECTION. WORKING-STORAGE SECTION. LINKAGE SECTION. COMMUNICATION SECTION. REPORT SECTION. In the Procedure Division, a section header is composed of a section-name followed by the reserved word SECTION, followed by a segment-number (optional), followed by a period and a space. Section-Name A user-defined Division. word that names a section in the Procedure Segment-Number A user-defined word that classifies sections in the Procedure Division for purposes of segmentation. Segment-numbers may contain only tqe characters '0', '1', ••. , '9'. A segment-number may be expressed either as a 1- or 2-digit number. Glossary-22 Sentence A sequence of one or more statements, the terminated by a period followed by a space. last of which is Separator A punctuation character used to delimit character-strings. Sequential Access An access mode in which logical records are obtained from or placed into a file in a consecutive predecessor-to-successor logical record sequence determined by the order of records in the file. Sequential File A file with sequential organization. Sequential Organization The permanent logical file structure in which a record is identified by a predecessor-successor relationship established when the record is placed into the file. Sign Condition The proposition, for which a truth value can be determined, that the algebraic value of a data item or an arithmetic expression is either less than, greater than, or equal to zero. Simple Condition Any single condition chosen from the set: relation condition class condition condtion-name condition switch-status condition sign condition (simple-condition) Sort File A collection of records to be sorted by a SORT statement. The sort file is created and can be used by the sort function only. Sort-Merge File Description Entry An entry in the File Section of the Data Division that is composed of the level indicator SD, followed by a file-name, and then followed by a set of file clauses, as required. Source The symbolic identification of the originator of to a queue. a transmission SOURCE-COMPUTER The name of an Environment Division paragraph in which the computer environment, within which the source program is compiled, is described. Glossary-23 Source Item An identifier designated by a SOURCE value of a printable item. clause that provides the Source Program Although it is recognized that a source program may be represented by other forms and symbols, in this document it always refers to a syntactically correct set of COBOL statements beginning with an Identification Division and ending with the end of the Procedure Division. In contexts where there is no danger of ambiguity, the word 'program' alone may be used in place of the phrase 'source program.' Special Character A character that belongs to the following set: Character Meaning + plus sign minus sign asterisk stroke (virgule, slash) equal sign currency sign comma (decimal point) semicolon period (decimal point) quotation mark left parenthesis right parenthesis greater than symbol less than symbol * / $ " ( ) > < Special-Character Word A reserved word that is an character. arithmetic operator or a relation SPECIAL-NAMES The name of an Environment Divi~ion paragraph in which implementor-names are related to user-specified mnemonic-names. Special Registers Compiler-generated storage areas whose primary use is to store information produced in conjunction with the user of specific COBOL features. Standard Data Format The concept used in describing the characteristics of data in a COBOL Data Division under which the characteristics or properties of the data are expressed in a form oriented to the appearance of the data on a printed page of infinite length and breadth, rather than a form oriented to the manner in which the data is stored internally in the computer, or on a particular external medium. Statement A syntacti'cally valid combination of words and symbols written in the Procedure Division and beginning with a verb. Glossary-24 Sub-Queue A logical hierarchical division of a queue. Subject of Entry An operand or reserved word that appears immediately following the level indicator or the level-number in a Data Division entry. Subprogram (See Called program.) Subscript An integer whose value table. identifies a particular element in a Subscripted Data-Name An identifier that is composed of a data-name followed by one more subscripts enclosed in parentheses. or Sum Counter A signed numeric data item established by a SUM clause in the Report Section of the Data Division. The sum counter is used by the Report writer Control System to contain the result of designated summing operations that take place during production of a report. Switch-Status Condition The proposition, for which a truth value can be determined, that an implementor-defined switch, capable of being set to an 'on' or 'off' status, has been set to a specific status. System-Name A COBOL word that is environment. used to communicate with the operating Table A set of logically consecutive items of data that are defined the Data Division by means of the OCCURS clause. Table Element A data item that belongs to the set of repeated items a table. in comprising Terminal The originator of a transmission to a queue r or the receiver of a transmission from a queue. Text-Name A user-defined word that identifies library text. Text-Word Any character-string or separator, library or in pseudo-text. Glossary-25 except space, in a COBOL Truth Value The representation of the result of the evaluation of a condition in terms of one of two values true false Unary Operator A plus (+) or a minus (-) sign that precedes a variable or a left parenthesis in an arithmetic expression, and that has the effect of multiplying the expression by +1 or -1, respectively. Unit A module of mass storage the dimensions of which are determined by each implementor. User-Defined Word A COBOL word that must be supplied by the format of a clause or statement. user to satisfy the variable A data item whose value may be changed by execution of the object program. A variable used in an arithmetic expression must be a numeric elementary item. Verb A word that expresses an action to be taken by a or object program. COBOL compiler Word A character-string of not more than 30 characters that user-defined word, a system-name, or a reserved word. forms a Working-Storage Section The section of the Data Division that describes working storage data items, which is composed either of noncontiguous items or of working storage records or of both. 77-Level-Description-Entry A data description entry that describes a noncontiguous data item with the level-number 77. Glossary-26 INDEX Abbreviated combined relation condition, 5-16 Absolute line number, 4-81 ACCEPT, 5-20 Access, Competing for file, 9-8 Dynamic, 8-23 File, 8-23 Random, 8-23 Sequential, 8-23 ACCESS MODE, 3-19 Action code, 3-27, 3-32, 3-33 Actual decimal point, 4-45 ADD, 5-21, 5-22 ADVANCING, 3-6 Alignment, 13-12 ALL literal, 1-7 Alphabet-name, 1-9 Alphabet-name IS, 3-5, 3-7 Alphabetic item, 4-42, 4-48 ALPHABETIC test, 5-10 Alphanumeric item, 4-42, 4-48 Alphanumeric literals, 1-11 Alphanumeric-edited item, 4-42, 4-48 ALTER, 5-23 AND, 5-11, 5-15 Approximate key, 5-87 Area A, 1-13, 1-15, 1-16 Area B, 1-13, 1-15, 1-16, 1-17 Area C, 1-16 Area L, 1-15, 1-16 Area Z, 1-16 Arithmetic characters, Special, 1-5 Arithmetic computations, Usage in, 5-18 Arithmetic expressions, 5-6 Evaluation of, 5-6 Formation of, 5-6 Arithmetic operators, 5-6 Arithmetic signs, Symbols for, 4-40 Arithmetic verbs, 5-17 Array, 4-9 ASCII, Fixed-length, 8-4, 8-5 Line-sequence, 8-1 Variable-length, 8-5, 8-6, 8-7 ASCII characters, Valid, 1-4 ASCII mixed-mode BINARY, 8-20 ASCII recording mode, 3-22, 8-1, 13-8, 13-9, 13-10 Assigments, Logical hardware, 3-10 ASSIGN, 3-13, 3-14 Assumed decimal point, 4-43, 4-44 BINARY, 8-19 ASCII mixed-mode, 8-20 EBCDIC mixed-mode, 8-22 SIXBIT mixed-mode, 8-21 BINARY recording mode, 3-22, 8-3 BIS instructions, 1-1 BIS-code, 3-4 BIS-compi1er, 1-1 BLANK WHEN ZERO, 4-31, 4-51 Block, 1-3 Logical, 4-16 BLOCK CONTAINS, 4-16 Block type, ISAM, 3-28 Blocked EBCDIC, Fixed-length, 8-16 Variable-length, 8-17, 8-18, 8-19 Blocked zero, 4-16 Blocking data, 13-11 Bottom margin of report, 4-79, 4-80 Braces, 1-2 Brackets, 1-2 Breakpoints, 7-22, 7-24, 7-26, 7-31 Removing, 7-25 Buffer areas, Input/output, 3-16 Building ISAM files, 7-4, 7-5, 7-6 Bur ied, update, 9-1, 9-2 Business instruction set, 3-4 BYTE MODE, 3-24 CALL, 5-24, 5-25, 5-37, 11-4, 11-5 Called subprograms, 11-5 Calling program, 11-4 CANCEL, 5-26, 11-13, 11-14 Card sequence numbers, 1-15 Card-type format, 1-14 Category of elementary item, 4-43 Causing a report to be printed, 4-8 Index-l INDEX (Cont.) Cd-name, 1-9 CHANNEL, 3-6, 5-112 Character chart, Picture string, 4-53 Character code set, 3-7, 4-17 Character set, COBOL-74, 1-4 Characters, Floating replacement, 4-52 Over-punched, 8-3 Punctuation, 1-4 Special arithmetic, 1-5 Special conditional, 1-5 Special editing, 1-5 Valid ASCII, 1-4 Checkpoint files, 7-31, 7-32, 7-33 CHECKPOINT OUTPUT, 3-18 Class condition, 5-7, 5-9 Class condition format, 5-9 CLOSE, 5-27 CLOSE options and file types, 5-30 COBDDT, 5-98, 7-1, 7-22, 13-5, 13-6, 13-7, 13-8 Entering, 7-24 Linking programs with, 7-23 Loading, 7-23 Starting, 7-23 Commands, 7-24, 7-25, 7-26, 7-27 COBOL language, Elements of, 1-3 COBOL library facility, 1-19 COBOL line number, 7-19 COBOL programs, Debugging, 7-1, 7-22 Restarting, 7-1, 7-31, 7-32 COBOL symbols, 1-1 COBOL terms, 1-1, 1-3 COBOL-74 character set, 1-4 COBOL-74 compiler switch summary, 6-3, 6-4 COBOL-74 utility programs, 7-1 CODASYL, 1-1 CODE, 4-72 Code set, Character, 3-7, 4-17 CODE-SET, 4-17, 4-58 Collating sequence, 3-7 COLLATING SEQUENCE, 3-7 Collating seq~ence, Sort key, 5-86 COLUMN NUMBER, 4-77 Combined condition, 5-15 Negated, 5-15 Combined condition format, 5-15 Combined relation condition, Abbreviated, 5-16 Combining files, 5-54 Comma, 1-12, 3-6 Command string, Compiler, 6-1, 6-2 Command string defaults, LIBARY, 7-17 Commands, COBDDT, 7-24, 7-25, 7-26, 7-27 LIBARY, 7-19 LIBARY edit, 7-20 LIBARY edit mode, 7-20 LIBARY group mode, 7-19 LIBARY-directing, 7-21 Comment lines, 1-14 Comment paragraph, 2-2 Communication, Inter-program, 11-4 COMMUNICATION SECTION, 4-1, 4-4, 4-5 COMP, 4-63 COMP-l, 4-63, 8-19 COMP-3, 4-64, 5-18 Comparison of nonnumeric items, 5-8, 5-9 Comparison of numeric items, 5-8 Competing for file access, 9-8 Compiler command string, 6-1, 6-2 Compiler-directing sentence, 5-4 Compiler-directing statement, 5-2 Compiling for production, 5-98 COMPUTATIONAL, 4-63, 5-18, 8-19 COMPUTATIONAL data types, 13-10, 13-11 COMPUTATIONAL-I, 4-63, 5-18 COMPUTATIONAL-3, 4-64 Computations, Usage in arithmetic, 5-18 COMPUTE, 5-31 Computer-name, 3-3, 3-4 Concatenating items, 5-90 Condition, 5-15 Abbreviated combined relation, 5-16 Class, 5-7, 5-9 Index-2 INDEX (Cont.) Condition (Cont.) Combined, 5-15 Condition-name, 5-7, 5-10 Negated combined, 5-15 Object of, 5-8 Relation, 5-7 Sign, 5-7, 5-11 Subject of, 5-8 Condition format, Class, 5-9 Combined, 5-15 Condition-name, 5-10 Relation, 5-8 Sign, 5-11 Condition-name, 1-9, 4-33 Condition-name condition, 5-7, 5-10 Condition-name condition format, 5-10 Condition-name (level-88), 4-32 Conditional characters, Special, 1-5 Conditional expressions, 5-7 Evaluation of, 5-11, 5-12, 5-13 Formation of, 5-11 Conditional sentence, 5-4 Conditional statement, 5-2 Conditional variable, 4-32 Conditional expressions, 5-47 CONFIGURATION SECTION, 3-2 Connectives, 1-6, 4-9 CONSOLE, 3-6, 5-20, 5-33 Continuation area, 1-13, 1-14, 1-16, 1-17 CONTROL, 3-5, 4-73, 4-88 Control break, 4-7, 4-73, 4-78, 4-84, 5-43, 5-97 Control break, FINAL, 4-7 CONTROL FOOTING, 4-7, 4-87, 4-88 CONTROL HEADING, 4-7, 4-87 Control tape, Line printer, 3-6 Conversion, Data, 13-14 COPY, 1-19, 1-20, 1-21, 1-22 CORRESPONDING option, 5-18 Counter, SUM, 4-84, 4-86 Counters, 13-11, 13-13 Counters, Summation, 5-43 Creating library files, 7-18, 7-20 CURRENCY SIGN, 3-8, 4-47 Damaged ISAM files, Recovering, 7-10 Data, Rules for positioning, 4-35 Data Base Management System, 4-1, 4-67 Data characters, Symbols for, 4-40 Data conversion, 13-14 Data Description entry, 4-2, 4-29, 4-56 Signed numeric, 4-59 DATA DIVISION, 1-3, 4-1, 4-13 Data efficiencies, 13-10 Data file, ISAM, 8-27, 8-28 Data movement, 13-14 DATA RECORD, 4-18 Data record, Usage of, 4-62 Data types, COMPUTATIONAL, 13-10, 13-11 DISPLAY, 13-8 Understanding, 13-8 Data-name, 1-9, 4-34 DATABASE-KEY, 4-67 DATE, 1-8, 1-9 DATE-COMPILED, 2-2 DATE-WRITTEN, VALUE OF, 4-26 DAY, 1-8 DBKEY, 4-67 DBMS, 4-4 Deadly embrace, 5-74, 9-1, 9-3 Debug lines, 1-14, 1-16, 1-17, 3-3 Debugging COBOL programs, 5-98, 7-1, 7-22 DEBUGGING MODE, 3-3 DECIMAL PQINT, 3-8 Decimal point, 3-6 Actual, 4-45 Assumed, 4-43, 4-44 Decimal points, Symbols for, 4-40 DECLARATIVES, 5-4 DECLARATIVES format, 5-109 DECLARATIVES section, 5-1, 5-108, 5-109 Index-3 INDEX (Cont.) DECtape and disk, Standard labels for, 4-20 Default condition notation, 1-2 DEFERRED OUTPUT, 3-17, 3-18 Defining overlays, 11-9, 11-10, 11-11 DELETE, 5-32 Deleting library source lines, 7-20 Deleting library statement groups, 7-18, 7-19 Delimiter, Pseudo-text, 1-12 DETAIL, 4-7, 4-87 Device, 6-1 Device-names, Logical, 3-14, 3-15 Physical, 3-14 Direct indexing, 4-11 Qualified, 4-11 Direct subscripting, 4-11 Qualified, 4-11 Disk, Standard labels for DECtape and, 4-20 DISPLAY, 3-5, 4-65, 5-33 DISPLAY data types, 13-8 DISPLAY-6, 4-65, 5-18 DISPLAY-7, 4-65, 5-18 DISPLAY-9, 4-66, 5-18 DIVIDE, 5-34, 5-35 Documenting optimization techniques, 13-5, 13-6 Dollar sign, 4-47 Double-precision fixed-point usage, 5-18, 5-19 Dynamic access, 8-23 EBCDIC, Blocked fixed-length, 8-16 Blocked variable-length, 8-17, 8-18, 8-19 Fixed-length, 8-13 Industry-compatible, 8-2 Variable-length, 8-13, 8-14, 8-15 EBCDIC formats, Types of, 8-12 EBCDIC mixed-mode BINARY, 8-22 EBCDIC packed-decimal, 8-3 EBCDIC recording mode, 8-2, 13-8, 13-9 EDIT, 1-15 ' Editing, Fixed insertion, 4-49 Floating insertion, 4-46, 4-47, 4-49, 4-50 Insertion, 4-48 Replacement, 4-48, 4-49 Simple insertion, 4-49 Special insertion, 4-49 Suppression, 4-48 Zero suppression, 4-49, 4-51 Editing allowed, Type of, 4-48 Editing characters, Special, 1-5 Editing sign control, Symbols for, 4-41, 4-45, 4-50 Efficiencies, Data, 13-10 Efficient coding conventions, 13-12 Elementary item, 4-3 Category of, 4-43 Elements of COBOL language, 1-3 Ellipsis, 1-2 End-of-reel, 5-112 Ending labels for magnetic tape, 4-20 ENTER, 5-36, 12-1 Entering COBDDT, 7-24 ENTRY, 4-5, 5-37 Entry point, 11-4, 11-5 ENVIRONMENT DIVISION, 1-3, 3-1 Error, I/O, 3-26, 3-27 Error codes, Monitor, 3-31, 3-32 Error handling, 5-108 Error number, 3-27, 3-28, 3-29, 3-33 Error status bits, I/O, 3-29 Evaluating performance, 13-5 Evaluation, Overriding normal order of, 5-13 Evaluation of arithmetic expressions, 5-6 Evaluation of conditional expressions, 5-11, 5-12, 5-13 Execution, Sequence of, 5-5 EXIT, 5-38 EXIT PROGRAM, 5-39 Index-4 INDEX (Cont.) Expressions, Arithmetic, 5-6 Conditional, 5-7 Conditional, 5-47 Evaluation of arithmetic, 5-6 Evaluation of conditional, 5-11, 5-12, 5-13 Formation of arithmetic, 5-6 Formation of conditional, 5-11 External media for object program, 3-9 Extracting library statement groups, 7-19 F recording mode, 3-22 FD filename, 4-19 Figurative constants, 1-6 File access, 8-23 Competing for, 9-8 File description (FD), 4-14 File description, 4-2 File formats, 8-3 File medium, 3-10 File organization, 8-23 FILE SECTION, 4-1, 4-2 FILE STATUS, 3-26 File status, 3-27 File status bits, Monitor, 3-30 FILE STATUS items, 3-27, 3-32 File storage, 13-11 File type, 3-28 FILE-CONTROL, 3-9, 3-10 File-name, 1-10 File-table pointer, 3-27 Files required by object program, 3-9 FILLER, 4-34 FINAL control break, 4-7 Fixed insertion editing, 4-49 Fixed-length ASCII, 8-4, 8-5' Fixed-length EBCDIC, 8-13 Blocked, 8-16 Fixed-length SIXBIT, 8-8, 8-9 Fixed-point usage, Double-precision, 5-18, 5-19 Single-precision, 5-18, 5-19 Floating insertion editing, 4-46, 4-47, 4-49, 4-50 Floating replacement characters, 4-52 Floating-point usage, 5-18, 5-19 Format control loop, Paper-tape, 5-112 Formation of arithmetic expressions, 5-6 Formation of conditional expressions, 5-11 FORTRAN, 12-1 FORTRAN subprograms, 5-36, 12-2, 12-3 FREE, 5-40, 5-41, 5-42, 9-11, 9-12 GENERATE, 4-8, 5-43, 5-44 GO TO, 5-23,' 5-45 GOBACK, 5-46 GROUP INDICATE, 4-78 Group items, 4-3 Hardware assigments, Logical, 3-10 Header labels, 4-2 HIGH-VALUE, 1-7, 3-5, 3-7 HIGH-VALUES, 1-7 Histogram, 7-23, 7-30, 13-5, 13-6, 13-7, 13-8 Listing, 7-29 Obtaining, 7-27 Sample, 7-31 Starting, 7-28 Stopping, 7-29 Using, 7-31 Histogram table, Initializing, 7-28 Horizontal tab, 1-12 I-a-CONTROL, 3-9, 3-34 I/O error, 3-26, 3-27 I/O error status bits, 3-29 Identification area, 1-15 IDENTIFICATION DIVISION, 1-3, 2-1 Identifier, 5-19 IF, 5-47 Ignoring ISAM errors, 7-10 Imperative sentence, 5-4 Imperative statement, 5-2 Improving performance, 13-1, 13-2, 13-3, 13-4, 13-5 IN, 4-9 Index-5 INDEX (Cont.) INDEX, 4-66, 5-18 Index file, ISAM, 8-28, 8-29, 8-30, 8-31 Index file structur~, ISAM, 8-30, 8-31 Index-name, 1-10 Indexed-sequential organization, 8-23 Indexes, 4-38, 13-11 Indexing, 4-9, 4-10 Direct, 4-11 Qualified direct, 4-11 Relative, 4-11 Indirect commands to ISAM, 7-12, 7-13 Industry-compatible EBCDIC, 8-2 Initializing histogram table, 7-28 INITIATE, 4-8, 5-49 INPUT-OUTPUT SECTION, 3-9 Input/output buffer areas, 3-16 Inserting library source lines, 7-20 Inserting library statement groups, 7-18, 7-19 Insertion characters, Symbols for" 4-40 Insertion editing, 4-48 Fixed, 4-49 Floating, 4-46, 4-47, 4-49, 4-50 Simple, 4-49 Special, 4-49 INSPECT, 5-50, 5-51, 5-52, 13-14 Integer, 1-10 Inter-program communication, 11-4 Invoking LIBARY, 7-15 ISAM, 7-1, 7-2 Indirect commands to, 7-12, 7-13 ISAM block type, 3-28 ISAM data file, 8-27, 8-28 ISAM errors, Ignoring, 7-10 ISAM file environment, 7-3 ISAM files, 8-27 Building, 7-4, 7-5, 7-6 Maintaining, 7-7, 7-8 Packing, 7-9, 7-10 Recovering damaged, 7-10 Simultaneous use of, 9-17, 9-18 Using, 7-13, 7-14 ISAM index file, 8-28, 8-29, 8-30, 8-31 ISAM index file structure, 8-30, 8-31 ISAM switches, 7-2 Item, 1-3 JUSTIFIED, 4-35, 4-36 Key words, 1-6 LABEL RECORD, 4-20 Label records, 5-62 Standard, 4-25 Labels, Header, 4-2 Magnetic tape, 7-12 Reading magnetic tape, 7-11 Trailer, 4-2 Writing magnetic tape, 7-11 Labels for DECtape and disk, Standard, 4-20 Labels for magnetic tape, Ending, 4-20 Standard, 4-20, 4-21 Level numbers, 4-3 Level-66, 4-3, 4-4 Level-66 items, qualified, 4-9 (level-66) , RENAMES, 4-56, 4-57 Level-77, 4-3, 4-5 Level-77 items, Unique names for, 4-9 Level-88, 4-3, 4-4 Level-88 item, 4-68 (level-88) , Condition-name, 4-32 Level-number, 1-10, 4-2, 4-37 LIBARY, 7-1, 7-15, 7-16, 7-17 Invoking, 7-15 Running, 7-18 Using, 7-22 LIBARY command string defaults, 7-17 LIBARY commands, 7-19 LIBARY edit commands, 7-20 LIBARY edit mode commands, 7-20 Index-6 INDEX LIBARY group mode commands, 7-19 LIBARY modes of operation, 7-18, 7-19 LIBARY switches, 7-18 LIBARY-directing commands, 7-21 Library, Object, 11-6 Searching an object, 11-6, 11-7 Source, 11-6 Library facility, COBOL, 1-19 Library file format, 7-15 Library files, 6-1, 7-15 Library files, Creating, 7-18, 7-20 Modifying, 7-20 Library maintenance program, 7-1, 7-15 Library source lines, Deleting, 7-20 Inserting, 7-20 Replacing, 7-20 Library statement groups, Deleting, 7-18, 7-19 Extracting, 7-19 Inserting, 7-18, 7-19 Replacing, 7-19 Library-name, 1-10 Limit on record size, 4-22 LINAGE, 4-79, 4-80 LINAGE-COUNTER, 1-8, 1-9, 4-80 LINE NUMBER, 4-81 Line number, 7-19 Absolute, 4-81 COBOL, 7-19 Relative, 4-81 Line numbers, 1-14, 1-15, 1-16 Source, 1-4 Line printer control tape, 3-6 LINE-COUNTER, 4-71, 5-43, 5-49 Line-sequence ASCII, 8-1 LINK program, 4-5 LINKAGE SECTION, 4-1, 4-5, 4-6 Linking programs with COBDDT, 7-23 Listing file from compiler, 6-1 Listing histogram, 7-29 Literals, 1-10 Alphanumeric, 1-11 Numeric, 1-10 If"',.... .... ~ \ \ '-vu \.. • ) Loading COBDDT, 7-23 Loading subprograms, 11-6 Logical block, 4-16 Logical device-names, 3-14, 3-15 Logical hardware assigments, 3-10 Logical operators, 5-11, 5-15 Logical page, Size of, 4-79 Logical positioning in files, 5-87 Logically related records, 9-13 LOW-VALUE, 1-7, 3-5, 3-7 LOW-VALUES, 1-7 MACRO, 12-1 MACRO subprograms, 5-36, 12-3, 12-4, 12-5, 12-6 Magnetic tape, 3-24, 8-2 Ending labels for, 4-20 Standard labels for, 4-20, 4-21 Magnetic tape labels, 7-12 Reading, 7-11 Writing, 7-11 Maintaining ISAM files, 7-7, 7-8 Maintenance program, Source library, 7-1, 7-15 Margin A, 1-13, 1-14, 1-15, 1-16 Margin B, 1-13, 1-14, 1-15, 1-16 Margin L, 1-13, 1-14, 1-15, 1-16 Margin of report, Bottom, 4-79, 4-80 Top, 4-79 Margin R, 1-13, 1-14, 1-15, 1-16 Maximum number of statement groups, 7-15 MCS, 4-1, 4-5 Media for object program, External, 3-9 Memory for overlays, Reserving, 11-11, 11-12, 11-13 MEMORY SIZE, 3-4 MERGE, 3-5, 3-7, 5-54, 5-55, 5-78 Message Control System, 4-1, 4-4 Index-7 INDEX (Cont.) Methods of program optimization, 13-4, 13-5 Mixed-mode BINARY, ASCII, 8-20 EBCDIC, 8-22 SIXBIT, 8-21 Mixed-mode records, 8-19 Mnemonic-name, 1-10 Modifying library files, 7-20 Monitor call, 3-28 Monitor error codes, 3-31, 3-32 Monitor file status bits, 3-30 MOVE, 5-56, 5-57 Multi-dimensional tables, 4-10 Multi-reel file, 5-28 MULTIPLE FILE, 3-35 MULTIPLY, 5-58 Negated combined condition, 5-15 NEXT GROUP, 4-83 NEXT PAGE, 4-82 Non-COBOL subprograms, 12-1 Non-reel file, 5-27 Nonnumeric items, Comparison of, 5-8, 5-9 Nonresident segments, 5-6, 11-1, 11-2 Nonwriteable segments, 11-1, 11-2 Normal order of evaluation, Overriding, 5-13 NOT, 5-11, 5-16 Numeric data description entry, Signed, 4-59 Numeric item, 4-48 Numeric items, 4-42 Comparison of, 5-8 Numeric literals, 1-10 NUMERIC test, 5-10 Numeric-edited item, 4-42, 4-48 Object library, 11-6 Searching an, 11-6, 11-7 Object of condition, 5-8 Object program, External media for, 3-9 Files required by, 3-9 OBJECT-COMPUTER, 3-2, 3-4 Obtaining histogram, 7-27 OCCURS, 4-38, 4-39 OF, 4-9 OPEN, 5-59, 5-60, 5-61, 5-62, 9-4, 9-5, 9-6, 9-7 Operational sign, 4-43 Operations, Order of, 5-7 Optimization, Methods of program, 13-4, 13-5 Program, 13-1, 13-2 Tools for program, 13-3, 13-6 Optimization techniques, Documenting, 13-5, 13-6 Optional files, 5-60 Optional words, 1-6 Options and file types, CLOSE, 5-30 OR, 5-11 Order of evaluation, Overriding normal, 5-13 Order of operations, 5-7 Ordering statements, 13-15 ORGANIZATION, 3-17, 3-18 Organization, File, 8-23 Indexed-sequential, 8-23 Relative, 8-23 Sequential, 8-23 Over-punched characters, 8-3 Overlay structure, 11-8, 11-9 Overlays, 5-25, 5-26, 11-1, 11-8, 11-13, 11-14 Defining, 11-9, 11-10, 11-11 Reserving memory for, 11-11, 11-12, 11-13 Overriding normal order of evaluation, 5-13 Packed-decimal, EBCDIC, 8-3 Packing ISAM files, 7-9, 7-10 Padding, 8-4 Page, Size of logical, 4-79 Page breaks, 4-78 PAGE FOOTING, 4-7, 4-87, 4-88 PAGE HEADING, 4-7, 4-87 Index-8 INDEX (Cont.) PAGE-COUNTER, 4-71, 5-43, 5-49 Paper-tape format control loop, 5-112 Paragraph-name, 1-10, 5-4 Paragraphs, 5-4 Parentheses, 1-12, 5-6, 5-7, 5-12, 5-13, 5-15 PERFORM, 5-64, 5-65, 5-66, 5-67 PERFORM cycle logic, 5-66, 5-67 PERFORM statement efficiency, 13-13 Performance, Evaluating, 13-5 Improving, 13-1, 13-2, 13-3, 13-4, 13-5 Physical device-names, 3-14 PICTURE, 4-40 Picture string, 4-41 Picture string character chart, 4-53 Positioning data, Rules for, 4-35 Positioning in files, Logical, 5-87 Printer control tape, Line, 3-6 Priority numbers, Section-name, 5-5 PROCEDURE DIVISION, 1-3, 5-1 Verb formats, 5-19 Production, Compiling for, 5-98 PROGRAM COLLATING SEQUENCE, 3-5, 3-7 Program format, Source, 1-13 Program optimization, 13-1, 13-2 Methods of, 13-4, 13-5 Tools for, 13-3, 13-6 Program segments, 11-1, 11-2, 11-3 Program structure, 1-3 PROGRAM-ID, 2-1 Program-name, 1-10 Project-programmer number conversion, 4-27 Projecting resource usage, 9-3, 9-4 Pseudo-text delimiter, 1-12 PULSAR, 4-21 Punctuation characters, 1-4 QUALIFICATION, 4-9 Qualified, Level-66 items" 4-9 Qualified direct indexing, 4-11 Qualified direct subscripting, 4-11 Quotation mark, 1-11, 1-12 QUOTE, 1-7 QUOTES, 1-7 (RD) , Report description, 4-70 Random access, 8-23 READ, 5-68, 5-69, 5-70 Reading magnetic tape labels, 7-11 Record, 1-3 RECORD CONTAINS, 4-22 Record description, 4-2 RECORD KEY, 3-20, 4-5 Record size, Limit on, 4-22 Record-name, 1-10 RECORDING DENSITY, 3-22, 3-24 RECORDING MODE, 3-22, 3-23, 3-24, 4-15 Recor~ing mode, 4-62, 8-1, ASCII, 3-22, 8-1, 13-8, IJ-9, 13-10 BINARY, 3-22, 8-3 EBCDIC, 8-2, 13-8, 13-9 F, 3-22 SIXBIT, 3-22, 8-2, 13-8, 13-10 STANDARD-ASCII, 3-23 V, 3-23 Recording modes, table of, 3-25 RECORDING PARITY, 3-22, 3-24 Recovering damaged ISAM files, 7-10 REDEFINES, 4-54 Relation condition, 5-7 Abbreviated combined, 5-16 Relation condition format, 5-8 Relational operators, 5-8 Relative files, 8-23, 8-24, 8-25, 8-26 ,Simultaneous use of, 9-16, 9-17 Relative indexing, 4-11 RELATIVE KEY, 3-21, 4-5 Index-9 INDEX (Cont.) Relative line number, 4-81 Relative organization, 8-23 Relative subscripting, 4-11 RELEASE, 5-71 Releasing records, 9-1 Removing breakpoints, 7-25 RENAMES (level-66), 4-56, 4-57 Replacement characters, Floating, 4-52 Replacement editing, 4-48, 4-49 Replacing library source lines, 7-20 Replacing library statement groups, 7-19 REPORT, 3-23, 4-23 Report, 4-1, 4-2, 5-97 Bottom margin of, 4-79, 4-80 Top margin of, 4-79 Report description (RD), 4-70 Report file, 4-8 REPORT FOOTING, 4-7, 4-87, 4-88 Report group, 4-7, 5-110' Report group description, 4-74 REPORT HEADING,. 4-7, 4-87 Report lines, 4-7 REPORT SECTION, 4-1, 4-6, 4-8 Format of, 4-7 Report to be printed, Causing a, 4-8 REPORT WRITER, 5-43,10-1 Report-name, 1-10 RERUN, 7-1, 7-31 Operating, 7-32 Using, 7-32, 7-33 RERUN DUMP, 3-34 RESERVE, 3-16 Reserved words, 1-5 Reserving memory for overlays, 11-11, 11-12, 11-13 RESET, 4-84 Resident segments, 5-6, 11-1, 11-2 Resource usage, Projecting, 9-3, 9-4 Restarting COBOL programs, 7-1, 7-31, 7-32 RETAIN, 5-72, 5-73, 5-74, 5-75, 5-76, 5-77, 9-8, 9-9, 9-10, 9-11 Retaining records, 9-1 RETURN, 5-78 REWRITE, 5-79 ROUNDED option, 5-17 Routine-name, 1-10 Rules for positioning data, 4-35 Running LIBARY, 7-18 SAME AREA, 3-35 SAME RECORD AREA, 3-35 Sample histogram, 7-31 SCHEMA SECTION, 4-1, 4-4 SD filename, 4-24 SEARCH, 5-80, 5-81, 5-82 Searching an object library, 11-6, 11-7 Section-name, 1-10, 5-4, 11-1 Section-name priority numbers, 5-5 Sections, 5-1, 5-4 Security restrictions, 2-1 Segment numbers, 3-5, 11-1, 11-3 SEGMENT-LIMIT, 3-5 Segment-name, 1-10 Segmentation, 5-5 Segments, 5-26 Nonresident, 5-6, 11-1, 11-2 Nonwriteab1e, 11-1, 11-2 Program, 11-1, 11-2, 11-3 Resident, 5-6, 11-1, 11-2 Types of, 5-5 Writeab1e, 11-1, 11-2 SELECT, 3-13, 3-14 Semicolon, 1-12 Sentences, 5-4 Separators, 1-11 Sequence numbers, Card, 1-15 Sequence of execution, 5-5 Sequential access, 8-23 Sequential files, 8-23 Simultaneous use of, 9-12, 9-13, 9-14, 9-15, 9-16 Sequential organization, 8-23 SET, 5-83 SET WATCH command, 13-6 SIGN, 4-58 Sign, Operational, 4-43 Sign condition, 5-7, 5-11 Sign condition format, 5-11 Sign control', Symbols for editing, 4-41, 4-45, 4-50 Index-10 INDEX (Cont.) SIGN IS SEPARATE, 4-41, 4-43 Signed numeric data description entry, 4-59 Signs, Symbols for arithmetic, 4-40 Simple insertion editing, 4-49 Simultaneous update, 5-60, 5-61, 5-62, 5-72, 5-73, 5-74, 9-1 Simultaneous update programming, 9-3 Simultaneous use of ISAM files, 9-17, 9-18 of relative files, 9-16, 9-17 of sequential files, 9-12, 9-13, 9-14, 9-15, 9-16 Single reel file, 5-28 Single-precision fixed-point usage, 5-18, 5-19 SIXBIT, Fixed-length, 8-8, 8-9 Variable-length, 8-10, 8-11, 8-12 SIXBIT mixed-mode BINARY, 8-21 SIXBIT recording mode, 3-22, 8-2, 13-8, 13-10 SIZE ERROR option, 5-17 Size of logical page, 4-79 SORT, 3-4, 3-5, 3-7, 5-71, 5-78, 5-84, 5-85, 5-86 Sort key collating sequence, 5-86 SOS, 1-15 SOURCE, 4-85 Source file, 6-1, 6-2 Source library, 11-6 Source library maintenance program, 7-1, 7-15 Source line numbers, 1-4 Source lines, Deleting library, 7-20 Inserting library, 7-20 Replacing library, 7-20 Source program format, 1-13 SOURCE-COMPUTER, 3-2, 3-3 Space, 1-11 SPACE, 1-7 SPACES, 1-7 Special arithmetic characters, 1-5 Special conditional characters, 1-5 Special editing characters, 1-5 Special insertion editing, 4-49 Special registers, 1-8 SPECIAL-NAMES, 3-2, 3-6 Standard label records, 4-25 Standard labels for DEC tape and disk, 4-20 Standard labels for magnetic tape, 4-20, 4-21 STANDARD-ASCII recording mode, 3-23 START, 5-87, 5-88 Starting COBDDT, 7-23 Starting histogram, 7-28 Statement, Compiler-directing, 5-2 Conditional, 5-2 Imperative, 5-2 Statement categories, Verb and, 5-3 Statement groups, Deleting library, 7-18, 7-19 Extracting library, 7-19 Inserting library, 7-18, 7-19 Maximum number of, 7-15 Replacing library, 7-19 Statements, 5-2 Status items, FILE, 3-32 STOP, 5-89 Stopping histogram, 7-29 STRING, 5-90, 5-91, 5-92, 5-93, 5-94 String pointer, 5-92 Structure of program, 1-3 Subject of condition, 5-8 Subprograms, 4-1, 4-5, 5-1, 5-25, 5-26, 5-39, 5-46, 11-1, 11-3, 11-4, 11-6, 11-8 Subprograms, Called, 11-5 FORTRAN, 5-36 Loading, 11-6 MACRO, 5-36 Non-COBOL, 12-1 Subscripting, 4-9, 4-10 Subscripting, Direct, 4-11 Qualified direct, 4-11 Relative, 4-11 Index-II INDEX (Cont.) Subscripts, 4-38, 13-11, 13-12, 13-13 SUBTRACT, 5-95, 5-96 SUM, 4-86 SUM counter, 4-84, 4-86 Summation counters, 5-43 Suppression editing, 4-48 Zero, 4-51 Switch summary, COBOL-74 compiler, 6-3, 6-4 Switches, ISAM, 7-2 LIBARY, 7-18 Symbols, COBOL, 1-1 Symbols for arithmetic signs, 4-40 Data characters, 4-40 Decimal points, 4-40 Editing sign control, 4-41, 4-45, 4-50 Insertion characters, 4-40 Zero suppression, 4-40 SYNCHRONIZED, 4-60, 4-61 TPS, 4-1, 4-5 TRACE, 5-98, 5-99 Trace paragraphs, 7-23, 7-27 Trailer labels, 4-2 Transactional Processing System, 4-1, 4-4 TYPE, 4-87 Type of editing allowed, 4-48 Types of EBCDIC formats, 8-12 Types of segments, 5-5 Types of user-defined words, 1-9 UNAVAILABLE, 5-61 Unblocked, 4-16 Underline, 1-2 Understanding data types, 13-8 UNSTRING, 5-100, 5-101, 5-102, 5-103, 5-104, 5-105, 5-106, 5-107 USAGE, 4-62 Usage, Double-pr~cision Tab, Horizontal, 1-12 Tables, 4-9, 4-10, 4-38, 5-80, 5-81 Mu1ti.-dimensiona1, 4-10 Tape, Ending labels for magnetic, 4-20 Line printer control, 3-6 Magnetic, 3-24, 8-2 Standard labels for magnetic, 4-20, 4-21 Tape labels, Magnetic, 7-12 Reading magnetic, 7-11 Writing magnetic, 7-11 TECO, 1-16 Terminal-type format, 1-15 Line-numbered, 1-15, 1-16 Unnumbered, 1-16 TERMINATE, 4-8, 5-97 Terms, COBOL, 1-1, 1-3 Text files, 13-9 Text-name, 1-10 TIME, 1-8, 1-9 Tools for program optimization, 13-3, 13-6 Top margin of report, 4-79 fixed-point, 5-18, 5-19 Floating-point, 5-18, 5-19 Single-precision fixed-point, 5-18, 5-19 In arithmetic computations, 5-18 Of data record, 4-62 USE, 5-108, 5-109, 5-110 USE BEFORE REPORTING, 4-8 Use of ISAM files, Simultaneous, 9-17, 9-18 Use of relative files, Simultaneous, 9-16, 9-17 Use of sequential files, Simultaneous, 9-12, 9-13, 9-14, 9-15, 9-16 USE procedure, 3-26, 3-32, 3-33 User-defined words, 1-4, 1-9 Types of, 1-9 USER-NUMBER, VALUE OF, 4-26 USING, 4-5, 5-1, 5-24 Using histogram, 7-31 Using ISAM files, 7-13, 7-14 Using LIBARY, 7-22 Using RERUN, 7-32, 7-33 Index-12 INDEX (Cont.) utility programs, COBOL-74, 7-1 V recording mode, 3-23 Valid ASCII characters, 1-4 VALUE, 4-68 VALUE OF DATE-WRITTEN, 4-5, 4-25, 4-26 VALUE OF ID, 3-27, 4-5 VALUE OF IDENTIFICATION, 4-25, 4-28 VALUE OF USER-NUMBER, 4-5, 4-25, 4-26 Variable-length ASCII, 8-5, 8-6, 8-7 Variable-length EBCDIC, 8-13, 8-14, 8-15 Variable-length EBCDIC, Blocked, 8-17, 8-18, 8-19 Variable-length SIXBIT, 8-10, 8-11, 8-12 Verb and statement categories, 5-3 Verb formats, Procedure Division, 5-19 Verbs, Arithmetic, 5-17 Warning message, 3-26 Words, 1-5 Key, 1-6 Optional, 1-6 Reserved, 1-5 Types of user-defined, 1-9 User-defined, 1-4, 1-9 WORKING-STORAGE SECTION, 4-1, 4-5 WRITE, 5-111, 5-112, 5-113 Writeab1e segments, 11-1, 11-2 Writing magnetic tape labels, 7-11 ZERO, 1-7 Zero suppression, 4-44 Symbols for, 4-40 Zero suppression editing, 4-49, 4-51 ZEROES, 1-7 ZEROS, 1-7 Index-13 COBOL-74 Language Manual AA-5059A-TK READER'S COMMENTS NOTE: This form is for document comments only. DIGITAL will use comments submitted on this form at the company's discretion. If you require a written reply and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Did you find this manual understandable, usable, and well-organized? Please make suggestions for improvement. .=· ~ Did you find errors in this manual? page number. If so, specify the error and the Please indicate the type of reader that you most nearly represent. [] Assembly language programmer [] Higher-level language programmer [] Occasional programmer (experienced) [] User with little programming experience [] Student programmer [] Other (please specify) ______________________________________ Name Date _________________________ Organization ________________________________ Telephone ___________________ Street ____________________________________________________________________ City.____________________________ State _____________ Zip Code _____________ or Country .------------------------------------------------------------Fold lIere------------------------------------------------------------ .-------------------------. .-------------------- Do Not Tear· Fold'lIere and Staple ----------------. .----.....----------------------- FIRST CLASS PERMIT NO. 152 MARLBOROUGH. MA 01752 BUSINESS REPLY MAIL NO POSTAGE STAMP NECESSARY IF MAILED IN THE UNITED STATES Postage will be paid by: mamaoma Software Documentation 200 Forest Street MRI-2/E37 Marlborough, Massachusetts 01752
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies