Wednesday, December 15, 2010

Introduction to COBOL

COBOL stands for COmmon Business Oriented Language. It is a complete  Programming Language and is  widely used for developing business applications. COBOL is a third-generation high-level language, procedure-oriented and machine-independent.
COBOL was initially developed with an objective to provide for the handling of mass storage of data.

 Evolution of COBOL
 Cobol was developed by a group called Conference on Data Systems Language (CODASYL)  in 1959.The first COBOL compiler was released by December 1959.
First ANSI approved version              - 1968
Modified ANSI approved version       - 1974 (OS/VS COBOL)
Modified ANSI approved version       - 1985 (VS COBOL 2 )

FEATURES OF THE SYSTEM / 370 COBOL - AN OVERVIEW
* Consists of 3 record formats :
Fixed length
Variable length
Undefined length
* Appends 4 bytes to the front of the record to specify the record length and 4
additional  bytes to specify the block size.
* There are 2 file access methods - Sequential & Random access
* It is possible to delete a disk or drum file, allowing the space to be reallocated
and reused
* Records may be spanned - Spanned records allow the record length to exceed
the block length so that the logical record is contained in two or more physical
records
* Limits the block size to a minimum of 18 bytes and  a maximum of 32, 676
bytes
The COBOL language closely resembles the English Language. A COBOL program is written using an English-like syntax that looks and reads like ordinary Business English. However,  COBOL is a structured programming language and thus requires that a program be written in a specific format. Thus, a COBOL program is a lengthy one consisting of COBOL words, clauses, sentences and paragraphs.

1.1  COBOL Source Statements

CODING FORMS AND CONVENTIONS

COBOL programmers use a standard coding form for writing programs. The form has 80 columns across the page and 25 lines for instructions.

RULES FOR CODING A COBOL PROGRAM

Columns 01 to 06 Line Numbers: Reserved for line numbers automatically assigned by the Compiler. These numbers are not used in the actual manipulations within the program.
Column 07Indicator Area:- Used for documentation purpose.
'*' - To comment a line
'/'  - To Page Break
'D'- To Debug the program in debugging mode
'-' -  To specify that the commands continue onto the
        next line.
Columns 08 to 72 Columns 08 to 11Are reserved for programming statements.
Area A: The following must begin in area A:
  • Division and section headers
  • Paragraph names
  • Declaratives and End Declaratives
  • End Program header
  • Level indicator (FD or SD)or level-number (01 or 77)
Columns 12 to 72Area B: The following must begin in area B:
  • Entries, sentences, statements, clauses
Column 73 onwardsIs ignored by the Compiler


1.2   Source Statement Continuation
  • Any COBOL sentences, clauses, phrases etc. may be continued in area B of the next source line.
  • If there is no hyphen (-) in the indicator area, the last character of the line is assumed to be followed by a space.
  • When there is a hyphen (-) in the indicator area, the first non-blank of the continuation line immediately follows the last non-blank of the continued line (without an intervening space).
  • Special rules for non-numeric literal:
When there?s no closing quotation on the continued line, all blanks up through column 72 are part of the literal.
The continuation line have a hyphen in column 7 and the first non-blank character (area B) must be a quotation mark.
Examples
1 col.7                                                                                                                   72
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
77    ANY-DATA-ITEM    USAGE           DISPLAY
                       PIC    X(20).

77  CONTINUATION-EX1   PIC   X(26)            VALUE             ?ABCDE?
-               ?FGHIJKLMNOPQRSTUVWXYZ?

77  CONTINUATION-EX2     PIC     X(40)     VALUE                  ?01  02
-            ?03  04  05  06  07  08  09  10  ?.

1.3        Character
Alphabetic Characters : A - Z, ? - ? i.e. hyphen preceded or followed by either a  letter or  a digit.
Numeric Characters : 0 - 9
Punctuation Characters : , . ; ? (  )
Special Characters         : + - / * = > < . $
The hyphen may NOT appear as the first or last character.
Lowercase is equivalent to uppercase (except in non-numeric literals).
Non-numeric literals and comments may contain any of the characters from the character set of the computer.
NOTE: The program-name in PROGRAM-ID paragraph must begin with an alphabetic and hyphen(s) will be changed to zero(s).
1.4 Words Used in COBOL
COBOL is based on syntax rules and words derived from the English Language. Any violation of the rules would result in compilation errors. The 2 kinds of words used in COBOL are :
*  RESERVED WORDS
*  USER-DEFINED WORDS
1.5 Reserved words : A reserved word is a character-string with a predefined meaning in a COBOL source program. There are several types of reserved words in COBOL.
1.6 User-Defined Words: Unlike the reserved word the user-defined word is constructed and used by the application programmer. The following are the rules to be followed while framing user-defined words.
  • Length may be up to 30 characters
  • Only alphabets, digits and hyphen (-) are allowed
  • Embedded blanks are not allowed
  • At lease one character must be alphabetic
  • Cannot be a Cobol reserved word
  • May not begin or end with a hyphen

1.7 Constants and variables
Literals are Constants whose value does not change throughout the program. There are 2 types of literals :  Numeric and Non-numeric.
A Numeric  literal can  be  composed of  a  maximum of 18 digits. It may have   a plus or  a  minus  sign  to the left  of  the  number  and  a   decimal point may  be  within  the  literal  or  to  the  left  of  the literal.  It  should  not be  enclosed  within  single quotes.  E.g. 03, 15.00,145, -12, +20
A Non-numeric literal cannot be used in Arithmetical Operations. It may consist of upto 120 characters including spaces.  It must be enclosed in single or double quotes. It can be used only for display purposes. E.g. ?hello?, ?257?, ?JOHN?.
Variables are those areas where we assign some numbers or store a string of letters, or some numbers as result of numeric operations. A Data-Name is the same as a programmer-defined name and the same rules apply to it.  Variable names are often called data-names or data-items.
* A data-name can be up to 30 characters long and can include alphabetic, numeric    characters and hyphens
* At least one character must be alphabetic
* Blanks may not be included

FIGURATIVE CONSTANTS
COBOL reserved words , where the word actually represents  a value is called a Figurative Constant. They may be used in the singular or the plural forms.
E.g. ZERO/ ZEROS/ZEROES, SPACE/SPACES/? ?, HIGH-VALUE/HIGH-
VALUES, LOW-VALUE/LOW-VALUES, ALL, QUOTE, QUOTES
ZERO/ZEROS/ZEROES : results in the field being filled with all zeros.  May be used interchangeably in the PROCEDURE DIVISION. ZEROS can be moved to both numeric and alphanumeric fields.
? ?, SPACE/SPACES results in blanks being placed in every position of the field. Should be moved only to alphabetic or alphanumeric fields.
QUOTE/QUOTES :  This figurative constant is used to print a quotation mark as it cannot be a part of a non-numeric literal.
HIGH-VALUES : Represents one or more occurences of the character that has the highest ordinal position in the collating sequence used.HIGH_VALUE is used as a non-numeric literal. HIGH-VALUES is a figurative constant that may be used only with fields that are defined as alphanumeric.
LOW-VALUES : Represents the lowest character in the computer?s collating sequence. This means when a comparison is performed, one unique character would always be less than any other.
ALL : The format is : ALL ?character?
The ALL option represents one or more occurrences of the single character that is enclosed in quotation marks. Any character, except the quotation mark, may be used with this option.

1.8 Structure Of Cobol Programs





No comments:

Post a Comment