Bom, veio por meio desse tutorial tentar explicar um pouco sobre a programação em COBOL.
Esse tutorial é bem simples, partindo do principio que você saiba Inglês, o que é muito importante.
mas se você não sabe, não se preocupe, apenas poste suas dúvidas que eu tento esclarece-las a medida do possível !
Vamos lá !
Introduction to COBOL Programming
Q. What does COBOL stand for? What are the application areas where COBOL Programs written?
COBOL stands for Common Business Oriented Language. COBOL Programs are used for processing business data. COBOL is an English-like language. Writing a COBOL program is just like writing a passage in English.
Q. You said COBOL Programming language bears resemblance with English. How’s that?
Just as text in English is organised into sections and para’s, COBOL Programs can also be broken down into divisions, divisions further into sections, and sections into paragraphs. Each paragraph contain sentences, or COBOL Statements. Like the English language, sentences(statements) in COBOL should end with a period(full-stop).
When you start new paragraphs in COBOL, you need to indent them, just as in English you follow indentation rules. COBOL then is whole-lot English like. Even instructions in COBOL, are words borrowed from English, ADD, SUBTRACT, MULTIPLY, DIVIDE etc.
Q. What’s the basic skeleton of a COBOL Program
The basic skeleton of a COBOL Program is as follows :
Esqueleto de um programa COBOL.
A COBOL Program can be divided or broken down into 4 parts – IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION and PROCEDURE DIVISION. The PROCEDURE DIVISION contains the instructions to be executed(performed), one after the other, step-by-step till you reach the end of the Program and stop running it(STOP RUN).
However , to better organize a COBOL Program, under a division, you may have several sections as well, and sections in turn can have several paragraphs. Divisions, sections and paragraphs help make the COBOL Program more structured, and the flow of the COBOL Program is easy to grasp.
Q. What are the Alignment(Indentation rules) in COBOL?
The lines in a COBOL Program are indented or aligned, as its done in English. When you write COBOL Program on the Mainframe terminal, you have 80 columns on a line to code on. The area spanning from columns 8-11 is called Area A. The area spanning from columns 12-72 is called Area B.
In COBOL, division names, sections and paragraphs begin in Area A. See below, how I’ve coded IDENTIFICATION DIVISION, ENVIRONMENT DIVISION,.. etc. starting on Column 8 -
Divisões do COBOL dentro do programa.
You code COBOL Instructions, COBOL Statements in Area B(that’s anywhere between Column 12 – 72). So, all your COBOL Instructions in the PROCEDURE DIVISION like ADD, SUBTRACT, MOVE should begin on or after Column 12. Look below, how I’ve coded COBOL Instructions in Area B.
Exemplo Identification Division
Q. What is the IDENTIFICATION DIVISION used for?
The IDENTIFICATION DIVISION is used to identify the COBOL Program to the system. It has the following paragraphs :
PROGRAM-ID.
AUTHOR.
INSTALLATION.
DATE-WRITTEN.
DATE-COMPILED.
SECURITY.
The PROGRAM-ID gives the identity or name of the COBOL Program. The INSTALLATION would be the name of the company.DATE-WRITTEN gives the date when the COBOL Program is written. DATE-COMPILED gives the date when the COBOL Program was compiled. SECURITY gives the level of security. Remember, that only the PROGRAM-ID paragraph is mandatory, all the other entries are optional.
Exemplo Program ID
To properly highlight the COBOL program, you can type HI COBOL in ISPF.
Q. What does the PROCEDURE DIVISION look like? What’s the format/syntax. Can you elaborate..
The PROCEDURE DIVISION indicates the entry-point or starting point of the COBOL Program. This is where the computer system begins to run(execute the COBOL instructions). Hence, all your instructions/programming logic must be written inside
this PROCEDURE DIVISION. I will now show you a simple Hello World Program in COBOL to illustrate the
process of writing a COBOL Program, compiling it, linking it and running the program.
In the COBOL Program, we want display output, or print some text. When we want to display output, or print text, we use the DISPLAY instruction/verb. The syntax of DISPLAY is as follows : DISPLAY text
The text must be enclosed in single quotes. For example, to print Hello World, we must write the instruction :
DISPLAY ‘HELLO WORLD’.
The PROCEDURE DIVISION of a COBOL Program can have many instructions. We can also divide these instructions into small groups/paragraphs. Thus, the PROCEDURE DIVISION has the following format -
PROCEDURE DIVISION.
Instruction-1
Instruction-2
Instruction-3
Instruction-4
...
Instruction-N
STOP RUN.
Every COBOL Program has a statement/instruction STOP RUN. The STOP RUN instruction tells the mainframe system, that this is the end of the COBOL Program. So, STOP RUN is the point in the COBOL Program, where program execution stops/halts – the control exits out of the COBOL Program. Given below is a simple Program that prints HELLO WORLD to the Output.
Mensagem de Saída.
Q. How do you compile a COBOL Program? What is meant by Linking a COBOL Program? Finally, how do you run the Program on a Mainframe System?
Compiling a COBOL Program :
COBOL is a high-level language. The Mainframe Computer System only understands binary Machine Language 0 and 1. Thus, your COBOL Program has to be translated from COBOL Language to Binary Machine Language.
So, you give the Program in COBOL Language as Input to the Translator(Compiler), and you get the Output Program in Binary Machine Language. The original COBOL Program is called Source Module and it is present as a dataset(file) inside a PDS which we refer to as Source Library. The output of COBOL Compiler – your program in Binary Machine Language is called OBJECT Module.
Linking a COBOL Program
Linking is the process of tying up/bundling up OBJECT MODULES together. You see, you Program may sometimes use(call) your friend’s Program for some task(like finding Square Root). Thus, your Program and your friend’s Program need to be Linked(Connected). Combining Object Modules together, so that they can find each other is called Linking, and this is performed by the Linker. The Linker takes OBJECT MODULE(s) as Input, puts them together and wraps them up as a single package, and gives this gift-package as the Output. This single package is called LOAD MODULE, and it is stored as a member of a PDS – we call LOAD LIBRARY.
Running a COBOL Program
To run a COBOL Program, you need to write a JOB Stream/JCL, which executes your COBOL Program(by specifying your LOAD MODULE in the EXEC PGM Job step), and providing the necessary DD Cards for Input Files, Output Files, Error Files etc.
Given below is a simple schematic, which explains the above process of Comilation, Link-edit, and running diagrammatically.
Estrutura de compilação de um programa COBOL

CRÉDITOS : Leonardo Martins
Obrigado !
