From the course: COBOL Essential Training

Introduction to verbs - COBOL Tutorial

From the course: COBOL Essential Training

Introduction to verbs

- You might have noticed that COBOL is kind of a wordy language. As a matter of fact, COBOL uses the English grammar word verb, to describe the commands available for performing tasks in COBOL. We've already seen several of these verbs such as open, close, read, and even compute. For this video, I have a new program that I want to use as our guide. It's called SalesDataValidation.CBL and it's available in the Exercise Files folder under Chapter Three. Because COBOL normally processes extremely large amounts of data records, it's often necessary to run any input files through a validation program first, to make sure all the records are valid. In this program, I'm reading the sales.datfile, which is similar to the one we used in chapter two. But in chapter three, I have a copy of that file, where I've made some changes to the incoming data to make sure some of the records are invalid. This program then checks each input record field for validity, and then writes the good records to a new file for subsequent processing. This was a common practice in COBOL programming. The program also creates an error report identifying any bad records from the file that need to be fixed and processed during the next run of the program. Before looking at the verbs in this program, let's take a quick look at the error report, so you can see what I mean. In the error report, you can see the first record has an invalid character in the ID, it should be all numeric, but it has the letter A. So on the right hand side, if I scroll over a little bit, you can see it says, employee ID was not numeric. The next record had an invalid sales amount, and finally, the last record had an invalid gender identifier. All right, let's go back over to our COBOL program. To talk about the verbs in the program, I'm going to scroll down to the procedure division, but you might want to go back and look at the working storage to see where I've added some of the error messages. In the procedure division starting on line 122, we see the familiar verb, open. We were opening our input file, sales file, and we're opening our output files, new sales file, and error report. On line 124, I've added an initialized verb to set the working storage date to zeros. The initialized verb is used to initialize a group or elementary data item. When this is used, numeric data items are always set to zeros, and alphanumeric or alphabetic data items are set to spaces. Below that we have the Accept verb, which allows the program to get data from the operating system or directly from the user. An example of obtaining data from the operating system is the next line, except WS-date from date. Note when you're retrieving the system date this way, it will return the value as YY, MM, DD format. Next, we have the Mover. The Move, verb, is used to move data from one data field to another. It can be used with both group and elementary items. When it's used for group items, we use the move corresponding, I think it's important to mention that data will be truncated if the receiving variable of a move is too small. If the destination is too large, it will fill it with zeros or spaces. Keep this in mind when working with COBOL, data overflow is not often captured as an error. So always make sure you allocate correct space for your variables. The last verb that I want to point out in this program is in the Read-Sales-Record-Paragraph, let me scroll down a little bit. In the Read-Sales-Record-Paragraph, we have the read verb, read sales file at end set end of sales to true. We also have an end read, which indicates that this is the end of the statement. Some of the verbs in COBOL have corresponding end verbs, the read is one of those verbs. Another one is the if statement. You'll see if and end if, I'll point them out as we go through the course.

Contents