Next chapterContents


Teach Yourself COBOL in 21 days, Second Edition

By Mo Budlong

Dedication

I want to dedicate this book to the army of programmers and computer professionals who are already sweating or will shortly be sweating with the rest of us over the year 2000 problem.

Acknowledgments

In this second edition of Teach Yourself COBOL in 21 Days, I have had a chance to correct errors from the first edition, expand on areas that needed elaboration, and write about many of the new and exciting things that are happening in the COBOL world. But most important to me, I have been able to act on the feedback that I have had from readers of the first edition. All of it was good, and all of it was helpful. There are way too many of you to thank. There were lots of little suggestions and a couple of major ones, and they all have been incorporated. I want to thank you all.

This is my third project for Sams and Macmillan, and I want to thank Chris Denny for noticing that the first edition was climbing the sales charts and for realizing that it was time for a new edition.

I want to thank Heather Mlodinow, an accomplished COBOL programmer who reviewed the technical end of the first edition, and Lee Ann Phillips who reviewed the second edition. Lee Ann was a tough editor, but she was usually right, and I am particularly indebted to her for additional material on dates and calendars. Greg Adams, president of International Digital Scientific, Inc., also reviewed the dates chapters and provided helpful suggestions. All the Sams and Macmillan editors and crew have been terrific. Ryan Rader, Rich Alvey, Drew Cupp, Heather Butler, Mary Ann Abramson, Fran Hatton, and Gayle Johnson all gave excellent advice and encouragement.

Mostly, I want to thank my wife Helen, who was not only my first line editor, but the first guinea pig to take the course. In fact, all three of the trial students--Helen, Victoria St. James, and Colleen Lerian--were patient and capable and made it very easy to adjust the book to get it right for a newcomer to COBOL. The book is much better because of their efforts.

In order to do this job properly, I needed to get my hands on a great deal of software and hardware, and I want to thank Micro Focus Inc. for providing Micro Focus Personal COBOL and Micro Focus Professional COBOL, as well as a lot of encouragement.

Acucobol Inc. graciously made its ACUCOBOL-85 package available.

A huge team is involved in taking a manuscript from the author's pen (or word processor) to final print. A lot of help, advice, and changes are contributed by this team. But ultimately the book is the author's work, and therefore I want to stress that I have made every effort to provide useful and accurate information, but any errors you find are mine alone.

About the Author

Mo Budlong has been a programmer and hardware engineer for 25 years. He has written several computer books, including COBOL Dates and the Year 2000, Moving from COBOL to C, COBOL Cookbooks Volumes 1, 2, and 3, and the C100 Manual. He currently writes regular columns for UNIX magazines in the U.S. and England, including the monthly "UNIX 101" column for SunWorld Online, a Web-based magazine. As a software consultant, he programs in multiple languages, including C/C++, Visual Basic, SQL, and numerous Assembly languages, and he has several software packages currently on the market.

Tell Us What You Think!

As a reader, you are the most important critic and commentator of our books. We value your opinion and want to know what we're doing right, what we could do better, what areas you'd like to see us publish in, and any other words of wisdom you're willing to pass our way. You can help us make strong books that meet your needs and give you the computer guidance you require.

Do you have access to the World Wide Web? Then check out our site at http://www.mcp.com.


NOTE: If you have a technical question about this book, call the technical support line at 317-581-3833 or send e-mail to support@mcp.com.

As the team leader of the group that created this book, I welcome your comments. You can fax, e-mail, or write me directly to let me know what you did or didn't like about this book--as well as what we can do to make our books stronger. Here's the information:

Fax: 317-581-4669

E-mail: programming_mgr@sams.mcp.com

Mail: Christopher Denny
Comments Department
Sams Publishing
201 W. 103rd Street
Indianapolis, IN 46290

Introduction

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.

Conventions

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:

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:

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!


Next chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.