Speaker Notes to Accompany Hello World Presentation

Slide 1:

This slide presentation covers the first week program that does a display and accept of HELLO WORLD. We are using a different starting approach this semester. We will start the traditional course in a few weeks!

Slide 2:

This slide shows COBOL ready to have you enter your program.

The program that I am entering will display three messages on the screen including the message HELLO WORLD. After the three messages have been displayed, it will wait for user input. When the user presses ENTER, the program will stop.

See the sample program and written notes for additional information!

Slide 3:


First I entered IDENTIFICATION DIVISION followed by a period (starting at column 8/margin A). This is where the cursor will be position. This is the first of the 4 COBOL divisions. I then pressed ENTER.

I then entered PROGRAM-ID followed by a period. PROGRAM-ID is a reserved which calls for the name of the program to be entered next. I decided to call my program HELLO. I must use letters and numbers (at least one letter) and no more than 8 characters when I make up a name. Notice that after the name there is another period.

As the last entry in the IDENTIFICATION DIVISION, I entered the reserved word AUTHOR followed by a period. Then I entered my name followed by a period since I am the author of this program.

Note that the ENVIRONMENT DIVISION is not needed for this program. I put it in as a reminder that there are 4 divisions, but I put an * in column 7 to have COBOL treat the line like a comment. Note that I could have just left the line without putting in the * and it would have done no harm.

Slide 4:

The DATA DIVISION can have a WORKING-STORAGE SECTION which is used to describe the data that we wish to hold in memory. Because in complicated programs we store a lot in memory, good programming calls for grouping the like areas together. I am only storing one thing, but I will establish a group to hold it. The group is called ANSWER-AREA and the individual area where I will store the user response is called GET-ANS. Note that the group is at an 01 level and that the 01 starts in column 8 or margin A. The actual item has an 05 in front of it to indicate it is a sub item and the 05 starts in column 12 or margin B.

To establish the size and type of GET-ANS, I need to give it a picture. Picture can either be written as PICTURE or PIC. A picture of X indicates that alphanumeric data will be stored here. Alphanumeric data is any kind of data: letters, numbers, spaces, special characters etc. The fact that the picture is simply one X says that only one character can be stored in GET-ANS.

Slide 5:

The PROCEDURE DIVISION is where the actual processing is done. To help organize and control processing, the PROCEDURE DIVISION is broken down into paragraphs. In this example, there is only one paragraph and it is named MAINLINE. Note that paragraph names start in column 8/margin A. They can be made up of letters, numbers and hyphens. There can be no embedded spaces. The maximum length is 32 characters.

Inside the paragraph, I am using three commands: DISPLAY, ACCEPT and STOP RUN. The DISPLAY command displays information on the screen. The information here is a message or literal and it must be enclosed in quotes.

Three DISPLAY commands are used to display three different messages.

The ACCEPT command pauses the program and waits for a user response. When the user responds - in this case by pressing the ENTER key, processing continues. The key stroke that the user entered is stored in the field that is named in the ACCEPT command, that is GET-ANS.

When processing continues the STOP RUN statement is executed and the program stops.

Note that when the program is run, it moves through the commands in sequence, one command at a time.

This is the plan, however all we have done at this point is write the program. We have other steps before we can test the program and see if it worked as planned.

Slide 6:

When it is time to run the program go to Compile/Run and select Compile Program.

Note that the menu may be slightly different on the version in the labs.

Slide 7:

The program had no language errors that the compiler could not understand so the compile was successful. In addition, the lines are now numbered. Note that I must have left a blank line at the end when I wrote the program because there is a blank line 16. This was not necessary but it is also not a problem!

Slide 8:

Our program compiled successfully, but let me address problems that might occur. Let's say that in the second display command I wrote DSPLAY instead of DISPLAY. The following error would occur.

Notice that the message is reasonable vague and hard to understand.

I selected YES at this point to continue checking. This means it will stop at each error. You could also select ZOOM to have it go through the whole program and highlight all of the errors.

Slide 9:

I moved the complete with errors message aside and you can see that although the message is vague is does show the line that has the problem.

After I click OK, the line will get highlighted in the program. See the next slide!

Slide 10:

The line with the problem is now highlighted. I can see what the problem is and fix it. Now I need to do a File/Save so that the correction is saved. Then I need to do the compile again.

Slide 11:

Note that the extra period caused two error messages to come up.

For clarification: the 01 ANSWER-AREA does not have a picture because it is being subdivided. You only use pictures on the lowest level (also known as the detail level).

Slide 12:

As you can see the first type of error got flagged twice so there were actually three errors that showed for this mistake.

Slide 13:

The line with the error is highlighted. The programmer examines it carefully using the messages to help locate the error.

Slide 14:

I fixed the error and now I need to recompile. First the file must be saved. If you forget to save the file, this message comes up. If you respond yes, the file will be saved and the compile will be done.

This time when I compiled, there were no errors so now I can execute or run the program to test it and see if it works.

First, I need to do a File/Close.

Slide 15:

After you close the program that you compiled, you now to open it for execution. You do this through File and Open for execution.

Slide 16:

When you do File/Open for execution, the programs that have been compiled are shown. These programs have a .int extension. Remember that the programs we wrote had a .cbl extension. Programs with a .cbl extension are source programs (programs that we wrote) while programs with an .int extension are object programs (programs that have been compiled and turned into machine language).

Slide 17:

Notice that when the program is ready to run, the PROCEDURE DIVISION is what you see. Scroll up to see the whole program.

Note again that the menus are slightly different in the labs.

Slide 18:

When the program runs, the DISPLAY puts the three lines on the screen and then the cursor stops on the next line waiting for user input. This is the ACCEPT statement waiting for a response from the user.

Slide 19:

After the user has given information to the accept, it is stored in GET-ANS. Then control moves to the next command which is STOP RUN. The screen appears with a return code of +00000 which indicates that the program ran without problems and is now complete.

Even if something executes perfectly, you need to examine the output and make sure it is what you wanted. If one of the DISPLAY messages does not say what you wanted, you need to go back to the .cbl version of the program and make changes.

Note that the .cbl version is called the source program and the .int version is called the object program.

Slide 20:

Close the executable and go to File/Open for edit. The .cbl versions of the program will come up and you can select the one you want to modify. Remember when you make changes to the program you must recompile to get a new .int version and then execute that version.

Slide 21:

I have now loaded the source program (the program that I wrote). I can make changes to the program, save those changes, compile to get a new object program with those changes and test the object program to see if it does what I want.

Compiles catch language errors that keep the compiler from generating the object program in machine language.

Executing or running the object program gives output. The programmer looks at the program and looks at the output and decides whether the program created the desired output. The programmer looks for logic errors that the programmer made when the program was written or things that the programmer left out or extra things that the programmer put in.