Hi. This is Kevin White. Welcome to the Basic Procedures, Part 1. During this lesson, you're going to be able to identify statements, sentences, paragraphs, and sections, understand how scope terminators are used, know how to code the initialization statement and its purpose, and how to utilize what we call IO statements, opening, closing, reading, and writing. The procedure division consists of comments, statements, sentences, scope terminators, paragraphs, and sections. This example shows how the first line is actually a comment. Do you see that asterisk over on the left-hand side? Well, if this is in position number 7, then it's going to treat that entire line as a comment. That line doesn't do anything other than telling us when it was put together in February. Now statements are next. They combine words and symbols that cause action to occur. There's a MOVE statement that you can see. You can also see an IF statement as well as a PERFORM the February Process. Sentences contain one or more statements that are terminated by a period. In this example, you can see the period character after the words total counter. Now sometimes seeing this period is very difficult and you're not sure if it's there or not there. That's why there's another way that you can use for terminating sentences. This brings us to scope terminators. The use of independency on the period to end an action is unique to COBOL, as other languages have things like, do ends and semi-colons. The scope of a verb remains in effect until a period is reached or the else is encountered. This is called implicit termination of the verb in COBOL. Explicit termination of the verb occurs when we use a scope terminator instead of typing a period. The scope terminator consists of the word end, E-N-D, meaning this is the end, followed by a dash and the action verb that is actually being terminated. Here is a partial list of the 18 scope terminators that are available to us in COBOL. As you can see, they all begin with E-N-D and then a dash and then what they're trying to terminate. What is a paragraph? A paragraph is one or more logically related sentences physically grouped together in independent, self-contained routine. Paragraphs are coded in what we call the A margin, beginning with the name, made up of letters and numbers and must be unique from all other names in the program. Each paragraph ends with a period before the next paragraph begins. What is a section? Like paragraphs, a section is one or more logically related sentences physically grouped together. It begins with a header in the A margin, followed by section and a period. Each section ends with a period before the next section begins. Let's take a look at the structure of a COBOL program. Get the big picture here. Reading top to bottom, the COBOL program is made up of four divisions. You might remember these as identification division, environment division, data division, and procedure division. Now the procedure division may have sections, though most do not. You can expect the procedure division to contain things like paragraphs that contains sentences, that contain statements that use both reserved words and user-defined words. Words, as you know, contain characters. Initialize is one of the commands that we use. It places a value in working storage data fields, which is an alternative to using the value clause that we saw in the previous segment. Initialize cannot be used for files in the linkage section. Examples at the bottom of our screen show initialize work area. This work area has two items in it. One is a picture x and one has a picture 9 next to it. The one with the nines is going to have zeros there and the ones that are x's are going to have spaces. The second thing we see on this screen is we see initialize Counter 2 replacing numeric by one. The number one is going to be placed there, not a zero or a space. Now, input and output commands are going to show up on your screen momentarily. They govern the flow of data from and to external devices and provide for the storage, retrieval, and updating of files. Let's look at the four of these. We've got the open that prepares one or more files for processing. The close, which ends the processing of one or more files. We've got the read that retrieves a record from the file and a write that sends a record to the file. Let's look at these one at a time. The open command identifies files to be either input or output. This first example has two files, master file and monthly file, identified as input files, and place a period at the end. The second example on this screen has one file called out-file, being an output file with an explicit termination of this command due to a scope terminator. Notice in one example, the period is being used. In the other example, the scope terminator is being used. Both of these work just fine. Most people think having the scope terminator is easier to see and work with. Now what's the opposite of open? Well, I think it's close. Close terminates anymore processing of one or more files. Every file that is opened should be closed before the program finishes running. Otherwise, you could have some difficult problems. At the top of the screen, you see two files, master file and monthly file. They're being closed using the implicit termination, which is putting a period at the end. In the second example, there's four files that are being closed with an explicit termination of the scope terminator and close, which again, we recommend to use. The read command, retrieves one record at a time from an external file and stores it in a data record underneath the file description or FD entry. This diagram shows the records that are being retrieved. They can be stored in more than one place, two places. This happens when the close into is used so that it can be stored in both of these places. The read statement has options that can detect whether there are no more records. That's called at- end and detect that when more records remain, that's called not-at-end. In this example that we're looking at, when the read encounters the end of a file. In other words, the end, the number one is stored in switch end. The next example we have, if the read has not read the final record, the number one is going to be added to the employee count. The write is the opposite of the read. It sends a record from the output record area in the FD to the external file. Look at this example and you may notice that the syntax for write is different than read. Good for you. Write requires using the record name. In this example, the record name is employee record rather than the file name. A couple of more things. In this example, we have a write command that transfers data in working storage to the data record below the FD first, but also writes it to the external file as well. We've covered a lot of stuff here. Getting us started, let's just review what we've done. During this section we've learned how to do things like identify statements, sentences, paragraphs, and sections. We took a good look at how to use scope terminators because they're a good choice as an alternative from using the period. We've also taken a look at coding the initialize statement and the purpose of using it. Last but not least, we took a look at the inputs and outputs that we have, the statements called open, close, read, and write. Take care now.