From the course: COBOL Essential Training

Learn COBOL syntax - COBOL Tutorial

From the course: COBOL Essential Training

Start my 1-month free trial

Learn COBOL syntax

- [Instructor] If you're new to COBOL, the syntax might seem quite different from other programming languages, such as Java, C plus plus, or even Python. Right away you might notice that the end of the statements in COBOL end with a period instead of a semicolon. In COBOL, it's really important to start certain keywords and statements in specific column numbers. Column numbers are important in COBOL and reflect the historic use of punch cards. Let's take a look at what has to be in each of the columns. Starting with columns one to six, they're optional but they contain either sequence numbers or line numbers. I've included them here for this example, but in future programs, I probably won't include the line numbers. Next is columns eight to 11. They're considered the A margin. This is where you'll write your division headers, your section headers, your paragraph names and your file descriptions. In this program, we have the identification division starting in column eight. The identification division must contain the program ID, but it can include some optional fields such as the author. It is the first and only mandatory division of every COBOL program. The program ID specifies the program name and can consist of one to 30 characters. Lines four to six contain comments. We know that there are comments because column seven has an asterisk. This indicates that it's a comment. You might also see a hyphen in column seven, which means it's the continuation of a non-numeric literal. We'll see that later on in the course. So let's quickly review the remaining statements in this small program for hello world. Line seven is the environment division, which must start in column eight. Line nine is the data division, the same thing. It must start in the A margin. The procedure division on line 11. Then we have the first paragraph name on line 12, the paragraph named 0100 dash start dash here. We have display world on line 13, notice that starts in the B margin, which again is columns 12 to 72. And finally, the last two statements stop, run, and end program also start in the A margin. The end program is optional. If it's omitted, the program ends when there are no more lines of code. As we worked through the course, I will continue to introduce additionals and tactical elements.

Contents