The Wayback Machine - https://web.archive.org/web/20240715225203/https://www.geeksforgeeks.org/programming-construction-in-cobol/
Open In App

Programming Construction in COBOL

Last Updated : 05 Dec, 2022
Improve
Suggest changes
Post a comment
Like Article
Like
Save
Share
Report

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:

  1. The first line is the COBOL label identifier. It defines the name of the program.
  2. The second line is the program category. It defines the category of programs, such as “Management” or “System”.
  3. The third line is the programmer label identifier. It identifies the name of the author of the program.
  4. Fourth through seventh lines is the initial values for seven character positions (often called “AAAAA”) within the computer listing.
  5. 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. 
  6. 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).
  7. 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:

  1. First line—the data type declaration for each variable. It defines the kind of data the variable will store.
  2. Second through fifth lines—the initial values for six position spaces (“AAAAA”) within the computer listing.
  3. 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:

  1. 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.
  2. 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”.
  3. 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” 
  4. 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”
  5. 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 typically includes the identification division, envir
2 min read
COBOL - Installing COBOL
There are three things that interested software developers always need when learning a new programming language: a desire to learn, a few good books on said programming language as well as a decent IDE to master the basics. If you’re a Computer Science student who has had to program in both Java and Python, you’ll know that obtaining good resources
5 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 data types, Alphabetic data types, and Alpha-Numeric
2 min read
COMP-2 in COBOL
In COMP Usage data will get stored in the complete binary form. Based on the usage the data will get stored either in HALF-WORD or FULL-WORD. HALF-WORD which is nothing but 2-bytes data and FULL-WORD is nothing but 4 bytes of data. When comes COMP-2, is similar to COMP-1. In COMP-1 data will get stored in one word in the floating point form whereas
2 min read
Program Structure of COBOL
COBOL is a programming language that was developed to solve business problems. COBOL stands for Common Business Oriented Language. Being a High-Level Structured Language, COBOL is very similar to English-like language, which is used to develop major business applications. Due to its easier maintenance, ability to work with any database (DB2, VSAM),
2 min read
Database Interface in COBOL
Programs in COBOL communicate with the DB2 Database. Data Base2 is DB2, and it was created by IBM. The database is a relational one. The relational information is kept in the TABLE format, which consists of multiples of rows and attributes (Columns). DB2 is generally used for storing sizable amounts of Mainframe application data. It is comparable t
4 min read
Difference Between Search and Search All in COBOL
There are two ways in which we can perform the searching operations in COBOL, first using the traditional method i.e. by applying the loop with the help of PERFORM statement, or by using the predefined verbs: SEARCH and SEARCH ALL. SEARCH and SEARCH ALL verbs can be used only in the INDEXED FILES because they use the indexed variable associated wit
3 min read
Difference Between Sequential, Indexed, and Relative Files in COBOL
Files are the collection of records related to a particular entity. Through file handling, we can store these records in an organized order. These records are stored either on magnetic tape or on a hard disk. The files are further classified into 3 types: Sequential file organization.Relative file organization.Indexed file organization.Advantages o
5 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 false. There are various types of Conditional state
7 min read
Coding Sheet in COBOL
Every language needs an environment or platform to write codes. For example, in Java, we use notepad to write codes then compile them to run. Similarly, COBOL requires a coding sheet to write codes. COBOL is a business-oriented high-level language. It was developed for business, finance, and administrative systems for companies and governments. COB
7 min read
Article Tags :
three90RightbarBannerImg