MASTERING COBOL PROGRAMMING

Similar documents
Mastering. Spreadsheets Q

0 Mastering Microsoft Office

Mastering. Pascal and Delphi Programming

MACMILAN MASTER SBUEI

In Business Now Series Graphs and Charts Renee Huggett Markets Renee Huggett

Mastering. C Programming 0

Program and Electronic Projects for the SSC, Electron and Spectrum Computers

Fundamentals of Operating Systems. Fifth Edition

.,JID Macmillan Modern Office f..dst'pj lnto . 4 D I. :.sp.. w ay :e ~l. ..II Joanna Gosling l... l. MACMILLAN

Computer Literacy - A Beginners' Guide

Fundamentals of Operating Systems

Assembly Language Assembled for the Sinclair ZX81

X/Open CAE Specification

Macmillan Computer Science Series

Interfacing with C++

Using the Template to Format the Thesis/Dissertation

Creating a procedural computer program using COBOL Level 2 Notes for City & Guilds 7540 Unit 005

Word Processing with Amstrad

Stock Message Boards

The Commodore 64 in Action

GnuCOBOL Quick Reference

Software Development for SAP R/3

New Syllabus Mathematics for 0-Level 1

Research on Industrial Security Theory

Advanced Graphics with the Commodore 128

HiTi Picvite Minilab 2 user manual

Graphics Programming in c++

Published by the Caribbean Examinations Council.

INFORMATION SECURITY FOR MANAGERS

DIFFERENTIAL EQUATION ANALYSIS IN BIOMEDICAL SCIENCE AND ENGINEERING

Section 1. The essence of COBOL programming. Mike Murach & Associates

Microprocessor Theory

Workbook for C++ THIRD EDITION. Yedidyah Langsam, Ph.D. Brooklyn College of the City University of New York. Custom Publishing

Digital Electronics A Practical Approach with VHDL William Kleitz Ninth Edition

Copyright 2005 Department of Computer & Information Science

Only the original curriculum in Danish language has legal validity in matters of discrepancy

Please note: Only the original curriculum in Danish language has legal validity in matters of discrepancy. CURRICULUM

General Qualifications 2017/2018

A Structured Programming Approach to Data

Mobile Phone Security and Forensics

An Introduction to Programming with IDL

COURSE SYLLABUS. Credit Hours: Contact Hours Lab Hours 4 4 As needed by student

General Qualifications

MACHINE INDEPENDENCE IN COMPILING*

Pearson New International Edition. The 8051 Microcontroller and Embedded Systems Mazidi Mazidi McKinlay Second Edition

Understanding and Writing Compilers

HIGH SCHOOL SUPPLY LIST

Computer Architecture

This content has been downloaded from IOPscience. Please scroll down to see the full text.

The Unofficial Guide to Creating Reports In Crystal using your Pastel Data

Scenario Manager User Guide. Release September 2013

Changes to assessment in Higher courses from session onwards

Installation BEFORE INSTALLING! Minimum System Requirements

SimuSys. Super fast design & prototyping for the iseries 400 a White Paper

Workplace Communications The Basics George J. Searles Fifth Edition

EMBEDDED SYSTEMS: Jonathan W. Valvano INTRODUCTION TO THE MSP432 MICROCONTROLLER. Volume 1 First Edition June 2015

COSO Enterprise Risk Management

Word Processing Knowledge and Skills: Word Processing Knowledge and Skills:

Jackson State University School of Lifelong Learning Bachelor of Science in Professional Interdisciplinary Studies Transcript Evaluation Sheet

Learning Community Course. Units/Semester Hours (SH) Required Prerequisite Required Corequisite. Enrollment Limitation (SH) 3 u

Office Administration

1. Introduction to Programming

Accuplacer Arithmetic Review

Introduction to Computer Programming Using FORTRAN 77

MICROSOFT WORD. Table of Contents. What is MSWord? Features LINC FIVE

FUNDAMENTALS OF DIGITAL CIRCUITS

George Grätzer. Practical L A TEX

The Architectural Logic of Database Systems

Real-Time Graphics Rendering Engine

About the Authors. Preface

COMPONENT-ORIENTED PROGRAMMING

ELECTIVE CREDIT HOURS 37 37

Jinkun Liu Xinhua Wang. Advanced Sliding Mode Control for Mechanical Systems. Design, Analysis and MATLAB Simulation

Low Level X Window Programming

Inside Relational Databases with Examples in Access

A Structured Programming Approach to Data

Overview of a computer

Higher Still. Notes. Higher. Information Systems. Release date 27/05/2003 File reference HSN33400.

Gengsheng Lawrence Zeng. Medical Image Reconstruction. A Conceptual Tutorial

Change Management Implementation Guide Release 9.2

Spokane Community College Divisional FTES Summary

COP 1170 Introduction to Computer Programming using Visual Basic

COP 1220 Introduction to Programming in C++ Course Justification

Ryan Stephens. Ron Plew Arie D. Jones. Sams Teach Yourself FIFTH EDITION. 800 East 96th Street, Indianapolis, Indiana, 46240

CYMA IV. Accounting for Windows. CYMA IV Getting Started Guide. Training Guide Series

Batch Versions Guide Release 9.2

SECOND YEAR III Paper I Applied Mathematics Paper II Microprocessors & Assembly Language Programming

Setup Guide. Operating Instructions. 1 Before Setting Up 2 Installation 3 Start-up/Shutdown

Chapter 1: Building Blocks of Programming

FR-V/FR FAMILY SOFTUNE C/C++ CHECKER MANUAL for V5

Understanding Math 2008 and Understanding Numeration 2008 Installation Manual for Macintosh

INFS 214: Introduction to Computing

MATLAB Programming for Numerical Analysis. César Pérez López

gg--c}/-/j) r x Revision: New: COBOL I TWO Date: Author: Date SAULT COLLEGE OF APPLIED ARTS & TECHNOLOGY SAULT STE. MARIE, ONTARIO

DESIRE2LEARN SHARED CONTENT REPOSITORY COURSE DESIGNERS INSTRUCTIONS. Current as of 8 August 2013

1. BACHELOR OF SCIENCE IN COMPUTER SCIENCE EDUCATION

COBOL 64 Software Syste~ ~bacus Software. By K. A. Alexander. A Data Becker Product Published by

Microsoft. SharePoint Your Organization s Name Here

PROGRAM EXECUTION DYNAMICS. Samuel Dellette Patton. A thesis submitted in partial fulfillment of the requirements for the degree.

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Transcription:

MASTERING COBOL PROGRAMMING

MACMILLAN MASTER SERIES Banking Basic English Law Basic Management Biology British Politics Business Communication Business Microcomputing Chemistry COBOL Programming Commerce Computer Programming Computers Data Processing Economics Electrical Engineering Electronics English Grammar English Language English Literature Financial Accounting French French 2 German Hairdressing Italian Keyboarding Marketing Mathematics Modern British History Modern World History Nutrition Office Practice Pascal Programming Physics Practical Writing Principles of Accounts Social Welfare Sociology Spanish Spanish 2 Statistics Statistics with your Microcomputer Study Skills Typewriting Skills Word Processing

MASTERING COBOL PROGRAMMING R. HUTTY M MACMILLAN EDUCATION

R. Hutty 1983 All rights reserved. No reproduction, copy or transmission of this publication may be made without written permission. No paragraph of this publication may be reproduced, copied or transmitted save with written permission or in accordance with the provisions of the Copyright Act 1956 (as amended), or under the terms of any licence permitting limited copying issued by the Copyright Licensing Agency, 7 Ridgmount Street, London WCIE 7AE. Any person who does any unauthorised act in relation to this publication may be liable to criminal prosecution and civil claims for damages. First published 1983 Reprinted 1986, 1987 Published by MACMILLAN EDUCATION L TO Houndmills, Basingstoke, Hampshire RG21 2XS and London Companies and representatives throughout the world ISBN 978-0-333-34385-2 ISBN 978-1-349-17254-2 ( ebook) DOI 10.1007/978-1-349-17254-2 ISBN 978-0-333-35457-5 (paperback export edition)

v CONTENTS Preface Acknowledgements fllustrations viii X xi 1 Introduction 1.1 COBOL computer systems 1.2 COBOL programs 2 1.3 Program development 5 1.4 The IDENTIFICATION DIVISION 8 1.5 Practical 9 2 Data and procedure 2.1 The DATA DIVISION 12 division fundamentals 2.2 Data-item descriptions 13 2.3 The PROCEDURE DIVISION 15 2.4 Uterals and figurative constants 17 2.5 The DISPLAY statements 18 2.6 COBOL syntax format 19 2.7 ADD statement variations 19 2.8 The GIVING option 22 2.9 The MOVE statement 23 2.10 Practical 25 3 Fractions, signed numbers 3.1 Fractional numbers 27 and the subtract statement 3.2 The V picture 27 3.3 The picture 28 3.4 Signed numbers 30 3.5 The S picture 30 3.6 The + and - pictures 31 3.7 The SUBTRACT statement 32 3.8 The ROUNDED option 34 3.9 The SIZE ERROR option 35 3.10 Practical 37 4 The multiply, divide and 4.1 The MULTIPLY statement 38 compute statements 4.2 The DIVIDE statement 39 4.3 The arithmetic statements together 41

CONTENTS 4.4 The COMPUTE statement 42 4.5 Zero suppression 44 4.6 Insertion pictures 46 4.7 Floating pictures 46 4.8 Practical 47 5 The IF and GO TO 5.1 The IF statement 48 statements 5.2 Conditions 50 5.3 Nested IF statements 52 5.4 The NEXT SENTENCE option 54 5.5 Data validation 55 5.6 The GO TO statement 58 5.7 Practical 59 6 PERFORMing paragraphs 6.1 Modular programming 61 6.2 Looping 63 6.3 PERFORM... UNTIL 64 6.4 PERFORM... VARYING 66 6.5 PERFORM THRU and EXIT 71 6.6 Common paragraphs 73 6.7 The PERFORM procedure structure 74 6.8 Practical 75 7 Lists 7.1 List definition 78 7.2 List input and output 80 7.3 List calculations 81 7.4 Sorting 84 7.5 Practical 89 8 Tables 8.1 Table definition 90 8.2 Table searching 92 8.3 Sorting tables 95 8.4 Look-up tables 97 8.5 A table example 99 8.6 Practical 99 9 Files 9.1 File deunition 103 9.2 Record definition 105 9.3 The OPEN and CLOSE statements 106 9.4 The WRITE statement 107

vii 9.5 The READ statement 109 9.6 Printing a file 112 9. 7 Practical 115 10 FDe processing 11 Further COBOL 10.1 File search 10.2 Record update 10.3 Record insertion 10.4 Practical 116 118 119 122 123 Appendix A COBOL language formats Appendix B ANS COBOL reserved words Appendix C ASCII character set Index 125 144 146 147

viii PREFACE COBOL, the COmmon Business Orientated Language, is one of many computer programming languages. It differs from other languages by being the most widely used language, reflecting the fact that a majority of computing is of a commercial nature and COBOL was particularly designed for use in commercial/business applications. Compared with most other programming languages COBOL has many facilities, some of which are quite sophisticated. It would be impossible for a single book to cover all the details of all the facilities of COBOL and do them justice. The facilities covered by this book approximate to the Level 1 s of the Nucleus, Table Handling and Sequential 1-0 of the COBOL 1974 standard. These facilities are sufficient to write COBOL programs for almost all applications. This book is not only concerned with the rules of COBOL. There is an art to programming: it is not enough to know the rules of a language, it is equally important to develop intelligible programs which have style and use the best techniques. A professional approach to programming is encouraged at all times throughout the book. As with a foreign language there is only one sure way to learn a programming language, and that is by plenty of practical experience. Several directed practical experiences are given at the end of each chapter. This book is not presented in the normal manner of one or two COBOL features per chapter. Instead most features are spread over a few chapters, and each chapter covers parts of a few features. This approach enables more relevant programs to be written and tested earlier in the book, and, by making the text more interesting, helps the reader's concentration. Additionally, because a feature is spread over two or more chapters, a reader has time to assimilate gradually the concepts contained within a feature. The order in which the COBOL features are presented in this book have been chosen so that COBOL programs can be written right from the start, from the first chapter onwards. At the end of each chapter some practical work is suggested. In most cases this work consists of two parts: trainers, which help the reader to become familiar with the topics included in the chapter, and programs to write and test. It is assumed that practical work for one chapter has been done before moving on to the next. Although COBOL was originally designed as a language for a batch computer system (punched-card input and line-printer output) the language is being used more and more through a workstation (keyboard input and

ix display output) such as a terminal connected to a computer or a standalone microprocessor. This book takes account of COBOL's use in this new environment by assuming that input is from a keyboard, and output is to a display. This book is suitable for COBOL courses in educational establishments (schools, colleges, polytechnics and universities) and for individuals who wish to learn the language by self-instruction. R.HUTTY

X ACKNOWLEDGEMENTS I wish to thank Leicester Polytechnic for the use of their computing equipment in producing the programs which are listed in this book, Sheila Carrington for typing the draft manuscript, and my family for their support while I was writing the book. R.H. Any organization interested in reproducing the COBOL report and specifications in whole or in part, using ideas taken from this report as the basis for an instruction manual or for any other purpose is free to do so. However, all such organizations are requested to reproduce this section as part of the introduction to the document. Those using a short passage, as in a book review, are requested to mention 'COBOL' in acknowledgment of the source, but need not quote this entire section. 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 COBOL 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. Procedures have been established for the maintenance of COBOL. Inquiries concerning the procedures for proposing changes should be directed to the Executive Committee of the Conference on Data Systems Languages. The authors and copyright holders of the copyrighted material used herein 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. F28-8013, copyrighted 1959 by IBM; 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 specification in programming manuals or similar publications. (from the ANSI COBOL STANDARD, X3.23-1974)

xi ILLUSTRATIONS 1.1 A basic COBOL computer system 2 1.2 A simple COBOL program 3 1.3 The four divisions of a COBOL program 4 1.4 Structure diagrams for the AGE CHECK program 6 1.5 The compilation and execution stages 7 1.6 The shortest COBOL program 10 2.1 A program to add 10 to a number 16 2.2 A program to add two numbers 20 2.3 A program to add four numbers 21 2.4 A program to add three numbers, using GIVING 22 2.5 A program to add two numbers, using MOVE 24 2.6 A practical program to add numbers 25 3.1 The COST program 29 3.2 The BALANCE program 32 3.3 The DISCOUNT program 34 3.4 The SUBTRACT PRACTICAL program 37 4.1 The INVESTMENT program 41 4.2 The COMPOUND INTEREST program 45 5.1 The structure diagram of the PAY program 49 5.2 The PAY program 49 5.3 The WORD ORDER program 52 5.4 Structure diagram of the ELECTRICITY BILL program 53 5.5 The ELECTRICITY BILL program 54 5.6 The COLOUR program 57 6.1 The PAY (MODULAR VERSION) program 62 6.2 The CHARACTER DISPLAY program 64 6.3 The MORTGAGE program 65 6.4 The SHOPPING BILL program 66 6.5 The NUMBERS DISPLAY program 67 6.6 The TABLES program 68 6.7 The MORTGAGE END program 70 6.8 The CHECK AGE program 72 6.9 The VALl DATE DAYS program 74 6.10 The structure diagram of the TABLES program 75 7.1 A list of five students' MARKS 79 7.2 The data structure diagram of MARK-LIST 79 7.3 The MARKS INPUT/OUTPUT program 81 7.4 The MARKS AVERAGE program 82

ILLUSTRATIONS 7.5 The MARKS STATISTICS program 85 7.6 The SORT NAMES program 88 8.1 A table of students' names and marks 91 8.2 The data structure diagram of STUDENT-TABLE 91 8.3 The FIND STUDENT'S MARK program 93 8.4 The SORT CLIENTS program 96 8.5 The DAYS IN MONTH program 98 8.6 The WAGES program 100 9.1 A logical file structure 102 9.2 File processing in a COBOL system 103 9.3 The data structure of PERSON record 105 9.4 The WRITE TO FILE program 108 9.5 The READ FROM FILE program 110 9.6 The READ A RECORD program 111 9.7 The PRINT A FILE program 113 10.1 The STOCK REORDER program 117 10.2 The STOCK PRICE CHANGE program 119 10.3 The STOCK ITEM INSERT program 120