Gnucobol Programmer's Guide
Total Page:16
File Type:pdf, Size:1020Kb
GnuCOBOL Programmer's Guide For Version 2.2 Final [7Sept2017] Gary L. Cutler ([email protected]). For updates Vincent B. Coen ([email protected]). This manual documents GnuCOBOL 2.2 Final, 7Sept2017 build. Document Copyright 2009-2014 Gary L. Cutler, FSF (Free Software Foundation). Updates: Copyright 2014-2017 Vincent B. Coen, Gary L. Cutler & FSF. The authors and copyright holders of the Cobol programming language itself used herein: FLOW-MATIC (trademark for Sperry Rand Corporation) Programming for the Univac(R) I & II. Data Automation Systems copyrighted 1958, 1959, by Sperry Rand Corporation; IBM commercial translator form F28-8013, copyrighted 1959 by IBM; FACT DSI27A5260-2760, copyrighted 1960 by Minneapolis-Honeywell, have specifically authorised the use of this material in whole or in part of theCOBOL specifications. Such authorisation extends to the reproduction & use ofCOBOL specifications in programming manuals or similar publications. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License [FDL], Version 1.3 or any later version published by the Free Software Foundation; with Invariant Section "Intro- duction", no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". GnuCOBOL 2.2 Final [7Sept2017] Programmer's Guide i Table of Contents Amendment Changes for Programmers Guide::::::::::::::::::: 1 1. Introduction ::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 1.1. Additional Reference Sources ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 1.2. Introducing COBOL:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 3 1.2.1. Why YOU Should Learn COBOL :::::::::::::::::::::::::::::::::::::::::::::: 4 1.2.2. Programmer Productivity:::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 1.3. So What is GnuCOBOL? ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 1.3.1. Language Reserved Words ::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 1.3.2. User-Defined Words ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 8 1.3.3. Case Insensitivity :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 8 1.3.4. Readability of Programs ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 8 1.3.5. Divisions Organize Programs ::::::::::::::::::::::::::::::::::::::::::::::::: 11 1.3.6. Copybooks ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 1.3.7. Structured Data :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 11 1.3.8. Files ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 12 1.3.9. Table Handling ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 15 1.3.10. Sorting and Merging Data ::::::::::::::::::::::::::::::::::::::::::::::::::: 16 1.3.11. String Manipulation Features :::::::::::::::::::::::::::::::::::::::::::::::: 16 1.3.12. Screen Formatting Features:::::::::::::::::::::::::::::::::::::::::::::::::: 19 1.3.12.1. A Sample Screen ::::::::::::::::::::::::::::::::::::::::::::::::::::::: 19 1.3.12.2. Color Palette and Video Attributes ::::::::::::::::::::::::::::::::::::: 20 1.3.13. Report Writer Features :::::::::::::::::::::::::::::::::::::::::::::::::::::: 22 1.3.14. Data Initialization ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 23 1.3.15. Syntax Diagram Conventions :::::::::::::::::::::::::::::::::::::::::::::::: 23 1.3.16. Format of Program Source Lines ::::::::::::::::::::::::::::::::::::::::::::: 25 1.3.17. Program Structure :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 28 1.3.18. Comments :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 30 1.3.19. Literals ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 1.3.19.1. Numeric Literals:::::::::::::::::::::::::::::::::::::::::::::::::::::::: 31 1.3.19.2. Alphanumeric Literals :::::::::::::::::::::::::::::::::::::::::::::::::: 31 1.3.19.3. Figurative Constants ::::::::::::::::::::::::::::::::::::::::::::::::::: 33 1.3.20. Punctuation ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 34 1.3.21. LENGTH OF ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 34 1.3.22. Interfacing to Other Environments ::::::::::::::::::::::::::::::::::::::::::: 35 2. CDF - Compiler Directing Facility ::::::::::::::::::::::::::: 37 2.1. >>CALL-CONVENTION :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 38 2.2. COPY :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 39 2.3. REPLACE :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 41 2.4. >>DEFINE :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 44 2.5. >>IF :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 45 2.6. >>SET :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 47 2.7. >>SOURCE ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 48 2.8. >>TURN :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 49 2.9. >>D ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 50 1 November 2017 Contents ii GnuCOBOL 2.2 Final [7Sept2017] Programmer's Guide 2.10. >>DISPLAY ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 51 2.11. >>PAGE ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 52 2.12. >>LISTING :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 53 2.13. >>LEAP-SECONDS:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 54 2.14. * Directives :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 55 3. IDENTIFICATION DIVISION::::::::::::::::::::::::::::::: 57 4. ENVIRONMENT DIVISION :::::::::::::::::::::::::::::::: 59 4.1. CONFIGURATION SECTION :::::::::::::::::::::::::::::::::::::::::::::::::::: 60 4.1.1. SOURCE-COMPUTER :::::::::::::::::::::::::::::::::::::::::::::::::::::: 61 4.1.2. OBJECT-COMPUTER::::::::::::::::::::::::::::::::::::::::::::::::::::::: 62 4.1.3. SPECIAL-NAMES ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 64 4.1.3.1. Alphabet-Name-Clause :::::::::::::::::::::::::::::::::::::::::::::::::: 68 4.1.3.2. Class-Definition-Clause :::::::::::::::::::::::::::::::::::::::::::::::::: 70 4.1.3.3. Switch-Definition-Clause ::::::::::::::::::::::::::::::::::::::::::::::::: 71 4.1.3.4. Symbolic-Characters-Clause:::::::::::::::::::::::::::::::::::::::::::::: 72 4.1.4. REPOSITORY ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 73 4.2. INPUT-OUTPUT SECTION :::::::::::::::::::::::::::::::::::::::::::::::::::::: 74 4.2.1. SELECT ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 75 4.2.1.1. ORGANIZATION SEQUENTIAL ::::::::::::::::::::::::::::::::::::::: 80 4.2.1.2. ORGANIZATION LINE SEQUENTIAL ::::::::::::::::::::::::::::::::: 82 4.2.1.3. ORGANIZATION RELATIVE::::::::::::::::::::::::::::::::::::::::::: 84 4.2.1.4. ORGANIZATION INDEXED :::::::::::::::::::::::::::::::::::::::::::: 86 4.2.2. SAME RECORD AREA:::::::::::::::::::::::::::::::::::::::::::::::::::::: 88 4.2.3. MULTIPLE FILE :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 89 5. DATA DIVISION:::::::::::::::::::::::::::::::::::::::::::::: 91 5.1. Data Definition Principles ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 92 5.2. FILE SECTION::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 94 5.2.1. File/Sort-Description ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 95 5.2.2. FILE-SECTION-Data-Item ::::::::::::::::::::::::::::::::::::::::::::::::::: 98 5.3. WORKING-STORAGE SECTION ::::::::::::::::::::::::::::::::::::::::::::::: 100 5.4. LOCAL-STORAGE SECTION ::::::::::::::::::::::::::::::::::::::::::::::::::: 102 5.5. LINKAGE SECTION :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 104 5.6. REPORT SECTION ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 106 5.6.1. Report Group Definitions:::::::::::::::::::::::::::::::::::::::::::::::::::: 110 5.6.2. REPORT SECTION Data Items::::::::::::::::::::::::::::::::::::::::::::: 112 5.7. SCREEN SECTION ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 114 5.8. Special Data Items ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 116 5.8.1. 01-Level Constants :::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 116 5.8.2. 66-Level Data Items ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 119 5.8.3. 77-Level Data Items ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 120 5.8.4. 78-Level Data Items ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 121 5.8.5. 88-Level Data Items ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 122 5.9. Data Description Clauses ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 123 5.9.1. ANY LENGTH ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 123 5.9.2. AUTO :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 124 5.9.3. AUTO-SKIP :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 125 5.9.4. AUTOTERMINATE :::::::::::::::::::::::::::::::::::::::::::::::::::::::: 126 5.9.5. BACKGROUND-COLOR ::::::::::::::::::::::::::::::::::::::::::::::::::: 127 5.9.6. BASED ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 128 Contents 1 November 2017 GnuCOBOL 2.2 Final [7Sept2017] Programmer's Guide iii 5.9.7. BEEP :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::