COBOL Tutorial
COBOL stands for Common Business Oriented Language and is a high-level programming language originally developed in the late 1950s. COBOL was intended to be as legible as possible and, as a result, includes structures -- such as section, paragraph and sentence -- traditionally associated with English prose. COBOL programs are typically more verbose, or wordy, than those written in more contemporary programming languages, such as C or C++.
-
Syntax
-
The syntax, or grammar, of COBOL is defined by a notation known as the COBOL Metalanguage. COBOL reserved words -- words that have a fixed meaning and cannot be redefined by programmers -- are written in uppercase and underlined if mandatory. Material enclosed in braces ({ }) indicates that a programmer must choose one of the options within the braces, while material enclosed in square brackets ([ ]) is entirely optional. A sequence of three dots (…), otherwise known as an ellipsis, indicates that the syntax before the ellipsis can be repeated at the discretion of the programmer.
Program Structure
-
COBOL programs consist of a hierarchy of divisions, sections, paragraphs, sentences and statements. A division is a block of code that contains one or more sections, which begin with the reserved word “SECTION” followed by a period and, in turn, contain one or more paragraphs. A paragraph is a block of code containing one or more sentences, each of which consists of one or more statements terminated with a period.
-
Variables
-
COBOL variables are defined in a division known as the data division and each variable declaration consists of a level number, a data name or identifier and, in the case of so-called elementary variables, a picture clause, which describes the structure of the variable. Elementary variables -- which might be described as ordinary variables in other programming languages -- aren’t further subdivided and require a picture clause to reserve the storage required for the variable. Group variables, on the other hand, consist of a collection of elementary variables, or items, treated as a single group. They don’t reserve storage space, so can’t have a picture clause.
Error Messages
-
Common COBOL error messages include pre-compiler, compiler and runtime error messages. Pre-compiler error messages are caused by problems that prevent a job from being submitted to the program that translates high-level COBOL statements into machine code, known as the compiler. Compiler errors are caused by problems with the COBOL code itself, while runtime errors are caused by programs doing something illegal during execution.
-
References
- Photo Credit Stockbyte/Stockbyte/Getty Images