Teach Yourself COBOL in 21 Days

Peter Kitson

ISBN : 0672317885

Order a printed copy of this book from Amazon.

Cover Design - Teach Yourself COBOL in 21 Days

For your free electronic copy of this book please verify the numbers below. 

(We need to do this to make sure you're a person and not a malicious script)



Sample Chapter From Teach Yourself COBOL in 21 Days
     Copyright © Mo Budlong


COBOL is a language that was developed specifically for business programming. It actually can be used for a wide range of programs and programming problems, but it is most popular for handling traditional business activities. COBOL excels in accounting systems and related activities such as inventory control, retail sales tracking, contact management, commissions, payroll--the list is almost endless.

It is the most widespread commercial programming language in use today. It is English-like and easy to read. This makes it very popular with nonprogrammers. Financial officers frequently can read a section of a COBOL program and understand what it is doing with figures, without having to rely on programmers to interpret the program for them.

There is no doubt that COBOL is the most successful programming language ever. With an estimated 80 million lines of COBOL code in use just in the United States, it remains a key language of choice for business applications.

Four years ago, the popular computer media were chanting a funeral dirge for COBOL. Today, the tune has changed remarkably. Nearly every major software and information systems magazine has carried recent articles about the year 2000 problem and the need for COBOL programmers to handle the problem.

Major software companies are backing this resurgence with research and development dollars. A wide range of new COBOL-based products has been announced by Micro Focus Inc., Acucobol Inc., Computer Associates International Inc., Fujitsu Inc., and many more.

Programming work is available in COBOL for entry-level, intermediate, and advanced programmers. This cannot be said of other languages, which usually require high intermediate-to-expert experience before you can market that skill.

An additional factor has spurred the demand for COBOL programmers--the approach of the year 2000. Over the years, thousands of programs have been written using only a 4 digit date. When the computer has to calculate into and beyond the year 2000, all kinds of problems arise. Millions of lines of code have to be corrected before the year 2000, and there are just not enough COBOL programmers available. The situation is not limited to COBOL programs, but because COBOL has been the language of preference for business applications for so long, there are vastly more COBOL programs in existence. The magnitude of the year 2000 crisis has caused experienced software experts to predict dire consequences. It is estimated that the cost of fixing the problem will run into the billions of dollars. The demand for COBOL programmers increases almost weekly, as more and more companies realize the scope of the year 2000 problem and begin to allocate resources for its solution.

Although planning, supervision, and management of a year 2000 project requires highly skilled, experienced technicians, there is lots of work that entry-level programmers can do. In fact, a ComputerWorld article on the need for training COBOL programmers quotes Sheldon Glasser, a veteran consultant, as recommending that entry-level personnel be used for maintenance work to free up more highly skilled programmers for the more difficult year 2000 work. Teach Yourself COBOL in 21 Days has been revised to include more information on dates and the year 2000 problem.

Other magazines such as Information Technology Training Association and Unisphere have stressed the importance of getting novices trained and productive fast. With fewer than 1,000 days until the year 2000, there\'s no time to waste on academic or theoretical exercises. I wanted to create a way for students to be able to quickly and easily learn the language, and the feedback in calls and letters as well as media response has been encouraging in this regard. This book is being used in college and other courses across the country as well as in businesses and as a home study course.

Although the enormous demand for programmers to fix year 2000 problems probably will not continue far into the new millennium, undoubtedly the demand for COBOL programmers will continue. Many companies are putting off other maintenance and development that is not crucial in favor of completing their year 2000 projects. Given the amount of money that is being invested in updating and correcting existing COBOL code and the date problems in it, no one will want to throw away that investment in the near future--which means COBOL is here to stay for another round.

Additionally, recent developments in COBOL include a graphical user interface that works for COBOL programs running on PCs and UNIX-based systems. This has created a trend in downsizing--taking existing COBOL programs from mainframes and minicomputers and moving them to PCs as COBOL applications.

COBOL is also a good general-purpose language and can be used for creating simple or very complex programs. It has been standardized since 1968, and learning it on any computer enables you to use it on other computers.

COBOL has invaded UNIX, an area that was dominated by the C language. A friend of mine recently called who was desperately looking for COBOL programmers. He is a systems administrator for a large network of UNIX computers at a major oil company. He has been a C purist for years, but the company has decided to buy a business package in COBOL, and he needed help immediately. COBOL obviously has a long and healthy life ahead of it.

About This Book

Teach Yourself COBOL in 21 Days went through many versions before it was right for the job. Several adventurous volunteers agreed to learn COBOL from scratch by doing each lesson as I completed it, and I installed revisions based on their feedback. For the second edition, each day\'s text incorporated suggestions from the first edition users and then underwent multiple revisions to ensure that it could be easily understood and that the correct gradient approach was used. Concepts are introduced slowly and repeated many times. The first edition included four Bonus Day lessons. This new edition has been extended to include two additional Bonus Day lessons, with emphasis on the year 2000 problem.

In many cases, it is difficult to illustrate a programming point by using a full program. The point being highlighted gets lost against the background of all the other things going on in the program.

The answer to this is to write short programs just to show how something works. The problem with this approach is that some examples are silly or trivial programs. One of my more determined volunteers frequently showed up at my desk looking perplexed and asking, \"I understand what the program is doing, but why would anyone ever want a program like this?\"

The answer always is, \"No one would; the example is only to illustrate how that part of the language works.\" I have revised each chapter and added specific comments indicating which examples aren\'t \"real\" programs. If I\'ve missed any of these, and you see a program that seems to do something silly, irrelevant, or useless, be tolerant. Review the program as an example of how the language works and not as a program that you might use for some purpose.

Lots of code is used. COBOL experience comes from writing, reading, and understanding lots of code. Sometimes one point is illustrated by repeating a whole program with only that one point changed.

Programming Style

It is impossible to write a book about a programming language without spilling over into programming style. I have tried to balance teaching you good programming habits and teaching you the language.

It also is one of the realities of COBOL that a great deal of COBOL programming consists of maintaining existing programs written by other people. Some of these existing programs are just plain awful. You have to know a little about the \"dark side\" of programming to be able to deal with these. Techniques are described that you should never use, but you do need to know what is going on in a program when you see it.

Which is the best programming style is debated almost as hotly as which is the best programming language. You probably will run into some criticism of the programming styles used in this book. Don\'t get tangled up by it; you always can improve your style.

How to Use This Book

This book starts at the beginning, taking people who know nothing about COBOL and stepping them through 21 lessons and on to programming proficiency.

Within this book, you\'ll find hands-on tutorials, timely tips, and easy-to-understand technical information to help you get your footing with COBOL. You begin by writing simple programs, and progress to complex, useful programs that you can apply to your day-to-day situations. This book also addresses the year 2000 problem and offers useful solutions to apply.

Who Should Read This Book

Whether you are a complete novice to programming or a programmer ready to take the plunge into COBOL, this book is for you. The book walks you day by day through the process of learning COBOL. In addition, if you\'re feeling really ambitious, you can plunge into the six Bonus Day chapters at the end of the book, which give you even more information about programming with COBOL. You can go chapter by chapter through the lessons, or just choose those lessons that most interest you. Either way, this book is the perfect companion for anyone ready to learn programming in COBOL.


This book uses several different typefaces to help you differentiate between COBOL code and regular text. COBOL code appears in the book in a special typeface. Placeholders within the code--words to represent the type of infomation you need to enter in the code--appear in a special italic typeface.

New Term: In addition, when new terms are introduced in the text, a New Term icon appears to the left of the text to indicate that term is being defined.

TYPE: The type icon denotes a new program for you to enter into your editor.

OUTPUT: The output icon highlights the results of compiling and executing the program.

ANALYSIS: Analysis of the programs reveals insights and information about several key lines of the listing.

Throughout this book, the emphasis has been on providing useful information in a way that is fast, easy, and fun.

Who Should Use This Book?

Teach Yourself COBOL in 21 Days, Second Edition is aimed at beginners. It also is suitable for anyone who needs a refresher in COBOL, and for entry-level programmers who want to take their next step in COBOL. This book also can be used by experienced programmers who do not know COBOL.

What I Expect from You

You are expected to have some familiarity with the computer that you will use with this book. I would not expect people who have no experience with computers to be interested in learning COBOL as their first step with computers.

This is not an academic book. I expect that a person wanting to learn COBOL programming will actually do the exercises, write the code, compile it, and run it. You will not learn to program by just reading about it. You have to learn to use the tools by practicing their use. Therefore, you must either own a COBOL compiler or have access to one in order to get the most out of your study.

You should have good English and computer dictionaries available in order to look up words you do not fully understand. It is impossible to understand what you are studying if you do not know the meaning of the words used.

Two things are important if you are new or relatively new to programming. Don\'t skip anything. The course is organized to be a gradual accumulation of skills. Skipping a section will cause problems in later sections. Also, be sure to do all the exercises. Frequently, the explanations and examples in a chapter are based on an assumption that you completed the exercises at the end of a preceding chapter.

The other important point is to use good study habits. Study with a schedule and with a definite intention to get through some portion of the course. You must also read and understand questions and exercises before you begin doing them.

Working with Your Computer

You must know how to do four things in order to work with this book. These are covered in the first chapters of the book, and you must master these skills. You will be using them again and again as you progress through the book. If you skimp on any of them, you will hit a wall somewhere in this course. You must learn how to do the following:

  • Edit a text file. An editor is somewhat similar to a word processor but does not have all the formatting features. The editor is used to write the programs in the book.

  • Compile. A compiler converts the file that you have just edited into something that will run on your computer as a program.

  • Link. This might not be necessary on your system, but you must find out whether it is needed, and you must learn how to do it. Linking takes the executable program created by the compiler and links it with any programs that your computer needs in order to be able to operate.

  • Run. You must know how to execute a program when it is ready to run.

These four steps are covered in some detail in the manual for your compiler, and in Appendix C, \"Editing, Compiling, and Linking.\" If you aren\'t familiar with these by the time you finish Day 1, \"Your First COBOL Program,\" you will be in trouble for the rest of the course.

Target Compiler and Computers

Teach Yourself COBOL in 21 Days, Second Edition was written in such a way that it can be used with most computers and most versions of COBOL. There is a great deal of difference in the way different computers behave and the way versions of COBOL interact with the user.

The programs are written to work with Micro Focus COBOL, Micro Focus Personal COBOL, LPI COBOL, ACUCOBOL on UNIX or MS-DOS computers, and VAX COBOL on VAX VMS computers. The programs also should work with IBM COBOL for the AIX computer, RM COBOL, Realia COBOL, and Microsoft COBOL. There probably are many others.

All the volunteers worked with Micro Focus Personal COBOL, and the book tends to favor that compiler because it is a full compiler at a reasonable price. This makes it a good tool for self-teaching.

You must have a COBOL compiler in your computer system in order to be able to master the basic COBOL programming skills. If you do not have a compiler, an order form for one is included at the back of the book.

Supporting Material

Teach Yourself COBOL in 21 Days, Second Edition includes several appendixes designed to supplement points touched on in the text:

  • Appendix A, \"Answers,\" contains the answers to all the quiz questions and exercises posed at the end of each chapter.

  • Appendix B, \"ASCII,\" contains the ASCII character chart.

  • Appendix C, \"Editing, Compiling, and Linking,\" describes how to edit, compile, link, and run using various computers and versions of COBOL.

  • Appendix D, \"Handling Compiler Errors,\" covers some of the trickier compiler errors produced by COBOL compilers and how to track them down.

  • Appendix E, \"Summary of COBOL Syntax,\" is a brief listing of the syntax of the COBOL language used in this book.

  • Appendix F, \"Transaction Processing,\" describes methods of updating groups of files simultaneously to prevent data corruption.

  • Appendix G, \"Glossary,\" includes definitions of unusual terms used in the book.

The Companion Disk

A low-cost companion disk is available from the author, Mo Budlong, for $15.00 through King Computer Services, Inc., PO Box 728, Tujunga, CA 91043-0728. (See the King Computer Services order form at the back of the book.) This disk offer is made by the author and not by Sams Publishing. The disk will save you a lot of typing. It contains all the programs in the book, including sample programs for the exercises. If you choose to order the disk, it will be sent to you quickly so that you can begin work as soon as possible.

Teach Yourself COBOL in 21 Days, Second Edition will enable you to take the bold step into the world of COBOL programming. It is an exciting world. Happy programming!