First and foremost to comment in cobol use the *>
characters. In a cobol program there are several possible divisions. A division is just a way to break up the program into areas responsible for different things. So IDENTIFICATION DIVISION
is responsible for identifying the program (docs). We are only going to use the PROGRAM-ID
keyword, giving our program a name, to keep it simple. The DATA DIVISION
is a place where we can declare variables we want to use in our program, we will use the WORKING-STORAGE
keyword (docs). The PROCEDURE DIVISION
is like the main function of our program. It actually runs our code and can access anything defined in the data division (docs). The STOP RUN
sentence (sentence=one or more ‘statements’ that ends with a ‘.’) exits the program (like sys.exit() in python). You will also notice 6 spaces on the left of all my programs. This is not a mistake; the compiler expects this and on a mainframe these 6 spaces would be used for line numbers. Also: EVERYTHING IN COBOL IS CAPITALIZED SO ITS OFTEN EASIER TO TYPE WITH CAPSLOCK ON. You may notice the dot/period at the end of some lines. This is how you end a sentence (a series of one or more statements) in cobol. Below I may refer to anything that ends with a period as a statement. Ok so now that we have gotten through the basics of the program structure let’s write some programs.
Leave a Reply