Open In App

Programming Construction in COBOL

Improve
Improve
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.

Last Updated : 05 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads