Programming Construction in COBOL
Last Updated :
05 Dec, 2022
COBOL is a compiled, imperative, procedural programming language designed for business use. It can handle very large numbers and strings. COBOL is still in use today because it's robust, with an established code base supporting sprawling enterprise-wide programs. Learning to program in COBOL will set you up well for career prospects in fields like banking, insurance, investment management, and much more.
Role of Programmer:
The COBOL program structure is very straightforward. It consists of the following components:
- The identification section, which contains program sub-names and data names
- The procedure division, which contains instructions for using data in a program, including screen display instructions
- The working storage section, which contains instructions for updating variables in the computer's memory
- The executable section (run), which contains instructions that are performed at run time (as opposed to compile time)
The first three components are physical divisions of the source code of COBOL programs, while the last is a logical division. All four components can be placed in any order within the source code, except for the identification section, which must appear first. While the use of procedures, variables and working storage is fairly standard in many programming languages, COBOL's "procedural" approach to syntax is not. The following sections describe each of these components.
Section:
The identification section is preceded by the "main program" label or a line with no program labels at all. Every program in COBOL must start with this label (or lack thereof). Much like the beginning of English sentences (and almost every other text format), every program begins with an identification statement—these are the parts that identify what kind of program you're writing and set up some basic information about the program. There are three main parts to the identification section: the program-id statement, which sets up information about the name of the program; the author statement, which sets up information about you (the programmer); and the date statement, which sets up information about when you wrote it. The text immediately following the identification section is called a "comment"; any COBOL statements following this are ignored by the computer and serve only as explanatory notation for humans.
The program-id statement includes seven parts:
- The first line is the COBOL label identifier. It defines the name of the program.
- The second line is the program category. It defines the category of programs, such as "Management" or "System".
- The third line is the programmer label identifier. It identifies the name of the author of the program.
- Fourth through seventh lines is the initial values for seven character positions (often called "AAAAA") within the computer listing.
- The eighth line is the "organization unit" statement, which identifies an entity that created or controls changes to a program, such as a department or a group within your company.
- The ninth line is a statement used to identify any external files necessary for running or creating your COBOL program (such as data from another computer).
- The tenth line is a statement used to indicate the use of a COBOL standard.
After the program-id statement is a list of data-name declarations, which define variables used to store information from the user. There are two kinds of data in COBOL: "field" and "group." Group data is information that appears on a screen as one unit—for example, a number with 3 decimal places and 5 digits to the right of the decimal point. Individual characters within that unit are referred to as "fields".
Working Storage Section:
The working storage section contains instructions for updating variables in computer memory (such as adding two numbers together). Colloquially, variables are referred to as "data" and the instructions that change variables are considered to be "code". COBOL provides several variable types: numeric, string, character and date. Numeric variables can store either whole numbers or floating point numbers (base 10 or base 14), while characters (including alphanumeric characters) can store only single values of a given character type. The type of data stored in each variable is specified on the first statement of its right-hand side:
- First line—the data type declaration for each variable. It defines the kind of data the variable will store.
- Second through fifth lines—the initial values for six position spaces ("AAAAA") within the computer listing.
- Sixth line—the "page layout" statement, which describes how data look and how they're arranged to be read.
Types of Programming Construction in COBOL:
- Sequence: A sequence is a series, an order in which the programmer can insert or delete records in a record set. In COBOL, an example of a sequence construction is using the INPUT statement to populate a file.
- Task: This is an abbreviation for A task that looks like: "SUBMIT QTY QM" The meaning of these words are as follows: SUBMIT = relay, TASK = procedure that is responsible for accomplishing some action as quickly as possible. In this case, it would be uploading product data to the system. The object name would probably be "PRODUCT".
- Selective: "Selective construction" is a single statement, containing a single record, with an INCLUDE statement. A SELECT statement looks like:
"SELECT <object_name> FROM <table_name> INCLUDE <pattern>" An example of selective construction is: "SELECT * FROM ORDERING VALUE WHERE VENDOR LIKE ‘%SOFTWARE%’ "An example of selecting records from a table would be: "SELECT * FROM PRODUCTS INCLUDE ORDERING VALUE" - Iterative: The loop is used to execute the same sequence of statements repetitively. An example of an iterative construction is: "PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10 END-PERFORM"
- Data description: A description in COBOL is a data item that gives information about other data items. It has the form "DATA <data_items> <data_name>". It may be mandatory or optional. Data names are used for further reference i.e. adding/removing etc.
Similar Reads
Sequence Programming Construction in COBOL
COBOL (Common Business-Oriented Language) supports sequence programming construction through the use of sections, paragraphs, and sentences. A section is a group of paragraphs, a paragraph is a group of one or more sentences, and a sentence is a single statement. The structure of a COBOL program typ
2 min read
Functions in Programming
Functions in programming are modular units of code designed to perform specific tasks. They encapsulate a set of instructions, allowing for code reuse and organization. In this article, we will discuss about basics of function, its importance different types of functions, etc.Functions in Programmin
14 min read
Entry Controlled Loops in Programming
Entry controlled loops in programming languages allow repetitive execution of a block of code based on a condition that is checked before entering the loop. In this article, we will learn about entry controlled loops, their types, syntax, and usage across various popular programming languages. What
6 min read
Variable Declaration in Programming
Declaration of Variables is a fundamental concept in programming, where programmers define variables to store data within a program. In this article, we will provide a detailed overview about the declaration of variable, its importance how they are implemented in different programming languages. Tab
3 min read
Working Storage Section in COBOL
Cobol is a high-level language, which has its own compiler. The COBOL compiler translates the COBOL program into an object program, which is finally executed. To execute the COBOL program without any error, these divisions must be written in the order in which they are specified below: 1. Identific
3 min read
Display Computation in COBOL
DISPLAY is the most common form of internal data representation. DISPLAY stores in decimal form. Each character of the data will represent one byte of storage. If there is no usage clause for data items, then by default it will come under DISPLAY. DISPLAY can be used for all types namely Numeric da
2 min read
Conditional Statements in COBOL
While writing a program a programmer needs to check for various conditions, if the condition is true then a particular block of statement/s are executed, or else another block of statement/s is execute. To check these conditions we use Conditional Statements. These statements return either true or f
7 min read
String Handling in COBOL
The string is the data type, used to represent the sequence of characters, which ends with /0. String provides much functionality which makes our programming easy when it comes to groups of chars, words, sentences, or lines. String Handling:  String handling is the process or method to handle the s
7 min read
File Declaration in COBOL
COBOL (Common Business-Oriented Language) is a high-level programming language that was developed in the 1950s for business applications. In COBOL, a file is a collection of records that are stored on external storage devices such as tapes or disks. A file can be input, output, or both input and out
9 min read
Control flow statements in Programming
Control flow refers to the order in which statements within a program execute. While programs typically follow a sequential flow from top to bottom, there are scenarios where we need more flexibility. This article provides a clear understanding about everything you need to know about Control Flow St
15+ min read