sams_teach_yourself_cobol_in_24_hours_-_hour_1_getting_started

Sams Teach Yourself COBOL in 24 Hours - Hour 1 Getting Started

Return to Teach Yourself COBOL in 24 Hours, COBOL bibliography, COBOL, COBOL DevOps, Awesome COBOL, Awesome IBM Mainframe, IBM Mainframe development, IBM Mainframe bibliography, Fortran

“ (TYCb24H 1998)

Part I

COBOL Program Basics

Hour

1 Getting Started

2 Writing Your First Program in COBOL

3 Different Data Types

4 Basic User Interface

5 Procedure Division

6 Manipulating Data

7 Manipulating String Data

8 Conditional Statements

9 The Evaluate Statement

10 Processing Loops

11 Advanced Perform Statements

12 Tables

Hour 1

Getting Started

Welcome to Sams Teach Yourself COBOL in 24 Hours. In the first hour, you learn about the following:

• The history and purpose of COBOL

• The special requirements of business data processing

• The mother of modern information technology and COBOL in particular

Installing and using your compiler

COBOL Purpose and History Image

COBOL stands for Common Business Oriented Language. It is one of the oldest high-level computer programming languages. The purpose of a programming language is to communicate instructions to the computer. Each type of central processing unit, or CPU, understands a particular set of instructions. Because these instructions appear cryptic and confusing to humans, the early pioneers of the computer industry developed programming languages. These languages, which add a layer of comprehension for the programmer and analyst, are translated into the native instructions of the computer's processor, otherwise known as machine language. The process of translating the original program, or source code, into machine language is called compilation. The compiler program translates (or compiles) the source code, that is, code with instructions that humans can understand, into machine language.

Image

A high-level language is one that must be converted or translated into machine language. The closer a language is to machine language, the lower its level. Languages in which each statement in the source language corresponds to only one or two machine language instructions are very low-level languages. When source statements are converted, or compiled, into many machine language statements, as is the case with COBOL, the programming language is considered a high-level language.

COBOL is essentially a recipe for making a program. You list the ingredients, determine the amounts and proportions for the mixture, and describe the order and method of their assembly. You could mix the batter for a cake, including all the proper ingredients in all the proper proportions, but until it is baked, it can't be served. The compiler program is what takes your program recipe and prepares it for the computer's consumption.

Business Data Processing

Business data processing began long before computers entered the picture. In the interest of efficiency, businesses found ways to handle the large volume of information necessary to successfully manage their operation. Computers were initially considered the tools of scientists and engineers. However, business rapidly recognized the value of computers in automating tedious and repetitive tasks that were necessary for the success of commerce.

The computing needs of business are unique and are different from those in the scientific or engineering fields. Programming languages geared toward solving complex engineering or mathematical formulas were ill suited to business processing. Early scientific computations centered on solving complex mathematical formulas. The computer could make these calculations with much more speed and accuracy. In contrast, business typically does not need to solve complex mathematical formulas. Business processing centers more on large amounts of transactional data and is geared more toward financial accuracy.

Businesses typically collected transactional data and applied those transactions manually to books or ledgers. Entire divisions of large companies were dedicated to bookkeeping. Reports were carefully prepared for management to analyze. Creating and analyzing these reports was a time-consuming process, and in many cases businesses were harmed because they were unable to react to events in a timely manner.

The advent of the computer changed all that. Business readily accepted the computer into its daily operation. Business now demands fast and reliable results. These results help businesses stay competitive and viable.

COBOL: The Language of Business

COBOL is ideally suited to business processing. Business processing involves data collection, validation, updating, and reporting. The types of data processed are frequently numbers and amounts. No other computer language is as well equipped to excel at this type of processing.

COBOL was designed to be an easy-to-understand and self-documenting language. It intentionally mirrors common English. As a COBOL programmer, I can testify to the fact that nearly anyone can look at a section of a COBOL program and see exactly what is happening. I have had people look over my shoulder as I examine a program and understand exactly what is occurring and why.

Although COBOL is the language of business, its use has grown over time to include many other areas. Any organization that follows common business practices can take advantage of the strengths of the COBOL language. Governments are a prime example. They operate very much like businesses, and their needs are often satisfied by the use of COBOL as the primary computer programming language.

Contrary to popular media description, COBOL is far from a dead language. If COBOL is dead, someone forgot to tell the computer programs that hold businesses together! COBOL is the dominant computer language for business processing applications. Even in areas in which COBOL was once considered inappropriate, it has made tremendous inroads. Client/server development is relying more and more upon COBOL.

Client/server processing has become the watchword of the day. In a nutshell, it involves a central server, usually holding a repository of information that is accessed by clients that attach to this server. Large mainframes and COBOL programs have historically carried out these processes. Many businesses have tried to replace these systems with client/server processes, only to find the reliability and performance to be lacking. Consequently, large mainframes frequently become the server in client/server processing, with the root business logic written in COBOL remaining intact. COBOL is used today for both the client side and the server side of client/server processes.

At the root of COBOL is a very simple set of instructions. Like any good game, the rules are simple, but using those rules in combination can make for a very fun and challenging adventure.

This book uses real-world business examples to illustrate and teach programming techniques. The sample business I have chosen is a small consignment or antique store. No matter what the source of your interest in learning COBOL, these examples will help you to understand the language and make learning fun.

The Origin of COBOL The first specification for COBOL was developed in 1959 by the Conference on Data Systems Language, or CODASYL. Its goal was to define a common business computer programming language, and COBOL was the result. The design of the language was heavily influenced by the only business programming language in use at the time, FLOW-MATIC. FLOW-MATIC was the brainchild of a very interesting and colorful individual, whose influence on data processing and the use of computers in modern life is often and frequently understated. That person is Admiral Grace Murray Hopper.

Grace Hopper Admiral Grace Murray Hopper (1906–1992) is generally considered to be the mother of business computing and COBOL. Her early insights and ideas have echoed down through the years and still affect the entire information technology industry. Admiral Hopper was a strong advocate for the use of computers in business. She was the first to advocate sharing common libraries of programming code. Throughout her life, she stressed efficiency in programming, desiring that programmers not waste even a microsecond of time. She actively participated in demonstrations of COBOL, showing how the language lent itself to machine independence. COBOL was the first cross-platform, compatible language and remains one of the few programming languages that can easily be rehosted to other platforms.

Image

Rehosting is changing a program to run on a different platform. For example, you might take a COBOL program written for a mainframe computer and recompile it, making any necessary changes, and then run it on a personal computer. This type of change is an example of rehosting.

Grace began her work in computers as a research fellow at Harvard University from 1946 to 1949 in the computing laboratory. While there she developed the first compiler, a program that converted mnemonics into machine language, called A-0. Grace was convinced that computers could be a great boon to business and, to that end, started working with the UNIVAC series of computers at a company that later became Sperry. She firmly believed that computers should be programmed in English, but was admonished that computers did not understand English. She made sure that they could.

Her first English-like computer language was FLOW-MATIC, which understood 20 English words. The language was geared toward activities such as payroll processing and automated billing. It took several years for her approach to be accepted, and in 1952, she published her first compiler paper.

Grace participated in the early CODASYL meetings that defined the standard for COBOL. She stayed on the committee as one of its two technical advisors. She remained a strong COBOL advocate. After entering the U.S. Navy, she was instrumental in the Department of Defense move to make COBOL its first required programming language. Her work with the Navy on standardization remains one of her most important legacies. She developed tests to validate the different COBOL compilers. Her work led directly to the formation of different international and national standards for programming languages.

Along with her work on computer programming languages and data processing in general, Admiral Hopper is credited with coining the term computer bug. When a computer problem was traced to a moth stuck in one of the electronic relays, Hopper taped the offender in her logbook next to the entrybug.”

A famous quote that is widely used in computer circles is attributed to her: “It's always easier to ask forgiveness than it is to get permission.”

The COBOL Standard In 1968 the American National Standards Institute (ANSI), in an attempt to eliminate the growing incompatibility between different COBOL compilers, developed a common standard for the language. This version was called ANS COBOL. Programs written to this standard will continue to compile 30 years later. Although the language today has many more features and enhancements, many programs written in the 1960s are still in use. In the last year, I have maintained programs that were originally written in 1972.

The COBOL standard was revised in 1974, adding many new features. This version received wide acceptance and was the basis for IBM's VS COBOL. In 1985 the language was again revised, further enhancing and enriching COBOL. Several very powerful features were added to aid in the development of structured programs.

Image

This book generally follows the structured programming approach. Structured programs have small, organized sections of processing. Each area performs only a single function. Structured programming avoids the GO TO statement, which branches, or jumps, to another place in the program without returning; structured programs proceed in an organized and orderly fashion and do not jump from place to place with little rhyme or reason. Structured programming uses a top-down design approach. Each major function is made up of smaller functions, each of which is also made up of smaller functions, and so on until the problem is broken down to individual programming statements. Structured programs are easy to maintain and debug.

Image

In 1989 a special modification to the 1985 standard was issued. This modification introduced an item called intrinsic functions. Intrinsic functions formalized some of the features most desired by COBOL programmers, including many that relate to the next century. Prior to the 1989 extensions, COBOL did not have a formally defined method for determining the current four-digit year. The Current Date intrinsic function solved that problem in 1989, a full 11 years before problems processing two-digit years would occur, in the year 2000.

The 1985 standard, with the 1989 extensions, is the current standard for COBOL. The ANSI committee is currently considering the next standard, which will include object orientation. Several compiler vendors are beginning to support features that are in the next standard.

This book conforms to the current COBOL standard with one exception. In an effort to standardize the user interface portion of COBOL, because none was defined in the ANSI standard, a committee named X/OPEN defined a language extension called the Screen Section. A form of the Screen Section is included in the pending COBOL standard. Most compiler vendors already support the Screen Section, and the examples and exercises in this book should work with those compilers.

Installing the Compiler The accompanying CD-ROM contains a Windows-based COBOL compiler. Fujitsu COBOL has been kind enough to provide its free COBOL starter kit for your use with this book. This compiler has everything you need to learn COBOL and to compile and run the exercises and examples. Although the examples work with other COBOL compilers, many elements related to writing programs are closely linked to the development tools used. It is beyond the scope of this book to cover all of the many available COBOL compilers. All examples and exercises are geared toward the Fujitsu COBOL development environment.

Required Hardware and Software The following hardware and software are required to run the Fujitsu COBOL compiler:

• 486 or better processor

• VGA graphics display monitor

• 25MHz CPU or better (recommended)

• Mouse or other pointing device

• 5MB RAM

• 48MB of available hard disk space for basic configuration; more to install the on-disk documentation and utilities

• CD-ROM drive

Using the Examples in This Book All the examples, exercises, and quiz answers are included on the CD-ROM and can be used with the Fujitsu development environment, also on the CD-ROM. If you are using a different compiler, you will have to familiarize yourself with the requirements for that development environment and compiler.

How to Install the Fujitsu Compiler Take the time now to install and test the Fujitsu COBOL 3.0 Starter Set compiler. You will use the development environment and compiler very shortly. These steps guide you through the installation process.

1. Insert the CD-ROM into your CD-ROM drive.

2. Click the Start button.

3. Choose Run.

4. Choose Browse.

5. Select the down arrow next to Look In.

6. Choose your CD-ROM drive.

7. Double-click the COBOL32 folder.

8. Choose SETUP.EXE and click the Open button.

9. Click OK.

10. When the required serial number entry appears, type in 99-03811-10092, making sure to include the dashes. The first portion of the number is provided for you, and it must remain on the screen. Do not overtype this number; only complete it with the number above. The full number entered should be 103-2001-1699-03811-10092.

Next, you are prompted to select the different options for the install. I suggest using the default options. However, if you are interested in installing other features and tools, feel free to do so. The instructions associated with these are presented during the install. These additional options require significantly more disk space.

11. Follow the onscreen instructions, choosing the default values for all selections.

12. After the setup process is complete, restart your computer.

The following instructions install the 16-bit Windows 3.1 version of the Fujitsu compiler, also included on the accompanying CD-ROM.

1. Insert the CD-ROM into your CD-ROM drive.

2. From Program Manager, click File, and then click Run.

3. At the command line, type d:\COBOL16\SETUP.EXE.

Replace the d: with the drive letter of your CD-ROM drive.

4. Click OK to begin the installation process.

5. Click Next to acknowledge the copyright.

6. Click Yes to accept the license agreement.

7. Complete the serial number displayed so that the entire number reads as follows: 103-2001-1699-03811-10092

8. Click Next.

9. Accept the default selections as provided by the install program and click Next. The next portion of the installation process selects the location for the install and copies the programs to your computer.

10. Accept the default installation location and click Next.

11. The default action on the next screen is to copy all the books to your hard drive. If you do not want to do so, and you want to save disk space, click the View Books from CD check box. You may then deselect the COBOL 85 Books and the PowerCOBOL Books check boxes. Do not deselect the PowerCOBOL 16-bit check box. Click Next.

12. Accept the default program folder by clicking Next.

13. Click Next once more to accept the install options. The program files will now be installed on your computer.

14. After the files are installed, you will be prompted to register the software. You may complete the registration or cancel that process.

A long delay occurs between completing the registration and the installation of the Common Ground viewer. Your computer has not locked up, and the program will eventually proceed with the installation. This delay is upward of 2 minutes and is related to the launching of the secondary installation of the Common Ground viewer.

In addition to the Common Ground viewer, you may elect to view the documents in Adobe™ Acrobat format. These viewers are included on the CD in the SOFT-COPY folder.

15. Continue with the installation of the Common Ground viewer, following the prompts.

16. After the Common Ground installation is complete, click the Return to Windows button; the installation of the rest of the system will complete.

17. Click OK to acknowledge the changes made to your AUTOEXEC.BAT file, adding the compiler to your path.

18. Click Finish to complete the installation.

Validating the Install To make sure the compiler will run on your computer, you need to try to compile a program. The Fujitsu compiler comes with many examples and samples. Perform the following steps to compile and run one of the sample programs. Hour 2, “ Writing Your First Program in COBOL,” discusses the purpose for each of these steps. Performing them here ensures that the compiler software has installed properly.

1. Click the Start button.

2. Highlight Programs.

3. Highlight Fujitsu COBOL 3.0.

4. Click Programming Staff.

5. Click the Tools menu option.

6. Click WINCOBCompile.

7. Click the Browse button.

8. The current folder will be the PCOBOL32 folder. Double-click the SAMPLES folder.

9. Double-click the SAMPLE1 folder.

At this point, some necessary compiler options must be set. The purpose for these options is covered in detail in the appropriate hours. To ensure that you can compile the sample programs and exercises, simply follow these instructions:

1. Single-click the SAMPLE1.COB item and then click Open.

2. Click the Options button.

3. Click the Add button.

4. Scroll down the window until you see Main. Single-click Main and then click the Add button.

5. The Compiler Option window appears. Click the Compile Program as Main Program radio button and then click the OK button.

6. Close the Compiler Options window by clicking the X in the upper-right corner.

7. Click the OK button.

8. Click the Compile button. A countdown clock appears during the compilation process.

9. When the compile is complete, an Editor window displays the results of the compiler diagnostics. The message should be the following:

    [[STATISTIC]]S: [[HIGH]]EST SEVERITY [[CODE]]=I, [[PROGRAM]] [[UNIT]]=1.
10. Close the Editor window by clicking on the top X in the upper-right corner.

11. Close the WINCOB window by clicking the X in the upper-right corner.

Compiling the program is the first step applied against a source program to get it ready to run. The second step is to link the program. Linking is covered in more detail in Hour 2.

1. Click Tools again and select WINLINKLink.

2. Click the Browse button.

3. A Browse Files window shows a single .OBJ file. Select that file and click Open.

4. Click the Add button.

5. Click the Link button.

6. When the link is finished, close the Link window by clicking the X in the upper-right corner.

7. Close the WINLINK window by clicking the X in the upper-right corner of the window.

After successfully compiling and linking the program, it is time to run the program. The Fujitsu Programming Staff development environment provides a shortcut for running the programs you have recently compiled and linked.

1. Select the Tools option again.

2. Select the WINEXECExecute option.

3. Click the Browse button.

4. Choose SAMPLE1 and click Open.

5. Click the Execute button.

6. When the Runtime Environment Setup window appears, click OK.

7. This sample program accepts a single lowercase letter and displays a word that starts with that letter. For this test, type the letter a and press Enter.

8. The word apple appears and a message box tells you that the Console window is closed. Click OK. Your screen should now appear as illustrated in Figure 1.1.

9. Close the WINEXEC window by clicking the X in the upper-right corner.

10. Close the Programming Staff window by clicking the X in the upper-right corner.

If all the steps completed successfully, you have installed the compiler and it can be used

Figure 1.1 Results of running the Sample1 program.

Image

If you are using Windows 3.1 and have installed the 16-bit version of the Fujitsu COBOL compiler, follow these instructions to compile and link the sample program:

1. Open the Fujitsu COBOL Family V2 program group by double-clicking the icon.

2. Start Programming Staff 16 by double-clicking the icon.

3. Click the Utilities menu option.

4. Click WINCOB.

5. Select Browse and double-click the SAMPLES folder.

6. Double-click the SAMPLE1 folder.

7. Click SAMPLE1.COB and then click OK to accept your selection.

At this point, some necessary compiler options must be set. The purpose for these options is covered in the correct context in later hours. To ensure that you can compile the sample programs and exercises, simply follow these instructions:

1. Click the Options menu item.

2. Click the Add button.

3. Scroll down to the word Main. Select it and then click the Add button.

4. Toggle on the Compile Program as Main Program option by clicking the radio button.

5. Click OK.

6. Click Exit.

7. Click OK in the Compiler Options window.

8. Click the Compile button to compile the program. A countdown clock appears during the compilation process.

9. When the compile is complete, an Editor window appears with the results of the compiler diagnostics. The message should be the following:

STATISTICS: HIGHEST SEVERITY CODE=I, PROGRAM UNIT=1.

10. Close this window by double-clicking the upper-left corner of the window.

11. Close the WINCOB window by selecting the Exit menu option.

Compiling the program is the first step applied against a source program to get it ready to run. The second step is to link the program. Linking is covered in more detail in Hour 2.

12. Click the Utilities menu option.

13. Choose WINLINK.

14. Click the Browse button.

15. Select the Sample1.obj file and click OK.

16. Click the Add button.

17. Click the Build button to link the program.

18. After the program is linked, a message box displays the following message: Linking files has ended. Click OK.

19. Close the WINLINK window by selecting the Exit menu option.

After successfully compiling and linking the program, it is time to run the program. The Fujitsu Programming Staff development environment provides a shortcut for running the programs you have recently compiled and linked.

1. Click the Utilities menu option again.

2. Click WINEXEC.

3. Click the Browse button, select Sample1.EXE, and then click OK.

4. Click the Execute button to run the program.

5. When the Runtime Environment Setup:SAMPLE1 window appears, click Run.

6. Type the letter a and press Enter.

7. Your screen should display the word apple, and a message box states The console window is closed. The screen should look a lot like Figure 1.1. (Because you are using Windows 3.1, the look of the window border and the message box icon will be slightly different from the figure's.)

8. Click OK to close the window. You may exit the WINEXEC utility by selecting the Exit menu option.

for all the exercises and examples in this book.

Summary In this hour, you learned the following:

COBOL is one of the earliest programming languages.

COBOL is an English-like programming language, designed to satisfy the computing needs of business.

• The early design of COBOL, and business programming in general, was greatly influenced by Admiral Grace Hopper.

Grace Hopper discovered the earliest computer bug, an actual insect in a computer.

Q&A Q Why is COBOL such an accepted language?

A COBOL is an English-based language that is self-documenting and easy to understand. COBOL is the first language mandated for use by the U.S. Department of Defense. A version of COBOL exists for virtually every computing platform, and programs written for one computer are easy to convert to run on other computers.

Q Is COBOL easy to learn?

A Yes. COBOL is a fairly simple language. The commands and features that make up the language are in English and are easy to use and comprehend.

Q What is structured programming, and why is it important?

A Structured programming is a reverse building-block approach. The first element is a wall, which is made up of rows. Each row is made up of individual bricks, and each brick is made up of mud being poured into a mold and hardened by heat. In structured programming, the programmer breaks a large problembuilding a wall, for example—into the next smallest task, which in this analogy is laying the bricks. This task is further broken down into making the bricks. In structured programming, each task performs one and only one function. The program follows one orderly path; it doesn't jump around from within one task, out to an unrelated task, and back. In contrast, a nonstructured program might jump to one place; then, depending on a condition, do something else; and then go in a different direction. This type of program is extremely hard to follow and debug. It's like following a piece of spaghetti through a dish, trying not to disturb the other strands of pasta. That's why nonstructured programs are sometimes referred to as “spaghetti code.”

Workshop To help reinforce your understanding of the material presented in this hour, refer to the sectionQuiz and Exercise Questions and Answers” that can be found on the CD. This section contains quiz questions and exercises for you to complete, as well as the corresponding answers.

[[Fair Use]] [[Source]]s

COBOL: COBOL Fundamentals, COBOL Inventor - COBOL Language Designer: 1959 by Howard Bromberg, Norman Discount, Vernon Reeves, Jean E. Sammet, William Selden, Gertrude Tierney, with indirect influence from Grace Hopper, CODASYL, ANSI COBOL, ISO/IEC COBOL; Modern COBOL - Legacy COBOL, IBM COBOL, COBOL keywords, COBOL data structures - COBOL algorithms, COBOL syntax, Visual COBOL, COBOL on Windows, COBOL on Linux, COBOL on UNIX, COBOL on macOS, Mainframe COBOL, IBM i COBOL, IBM Mainframe DevOps, COBOL Standards, COBOL Paradigms (Imperative COBOL, Procedural COBOL, Object-Oriented COBOL - COBOL OOP, Functional COBOL), COBOL syntax, COBOL installation, COBOL containerization, COBOL configuration, COBOL compilers, COBOL IDEs, COBOL development tools, COBOL DevOps - COBOL SRE, COBOL data science - COBOL DataOps, COBOL machine learning, COBOL deep learning, COBOL concurrency, COBOL history, COBOL bibliography, COBOL glossary, COBOL topics, COBOL courses, COBOL Standard Library, COBOL libraries, COBOL frameworks, COBOL research, Grace Hopper, COBOL GitHub, Written in COBOL, COBOL popularity, COBOL Awesome list, COBOL Versions. (navbar_cobol)


Cloud Monk is Retired (for now). Buddha with you. © 2005 - 2024 Losang Jinpa or Fair Use. Disclaimers

SYI LU SENG E MU CHYWE YE. NAN. WEI LA YE. WEI LA YE. SA WA HE.


sams_teach_yourself_cobol_in_24_hours_-_hour_1_getting_started.txt · Last modified: 2022/05/17 07:15 by 127.0.0.1