Friday, 12 December 2008

COBOL Words:-

A sequence of continuous characters from the character set can form a word. The words can be classified into two types.

i) Reserved words

ii) User-defined words.

(i) Reserved words:-

Reserved words are words that are defined syntactically and semantically by the COBOL language.

Ex:-

ACCEPT, ADD, ALL, CALL, DATA, DELETE

(ii) User defined words:-

User defined words are words supplied by the programmers (language user) in order to satisfy the format of statement in the language.

Rules:-

A word must conform to the following rules:

i) The total number of characters must not be greater than 30.

ii) One of the characters must be a letter. Some compilers put the additional restrictions that the first character must be a letter.

iii) A word cannot begin or end with a hyphen..

iv) A word must not contain a blank and any special character except a hyphen.

Ex:-

Valid Invalid

GROSS-PAY -GROSS

B OVERTIME HOURS

Z31-4 1-2-3

Structure of COBOL Program:-

A COBOL program must have four divisions. They are,

IDENTIFICATION DIVISION

ENVIRONMENT DIVISION

DATA DIVISION

PROCEDURE DIVISION

Out of these divisions, the PROCEDURE DIVISION is one where the algorithm is described in terms of some elements of the COBOL language called statements.

v Every statement begins with a verb which indicates the kind of operation that is to be performed during the execution of the statement.

v Usually a statement is terminated by a period (.)

v Two or more statements can also be separated by spaces or comma followed by a space. A group of such statements with the last one having a terminating period is called a sentence.

v In COBOL, names for data fields are called data names.

v All the data names which are used in the PROCEDURE DIVISION statements must be defined in the DATA DIVISION.

v The definition of data name should include the size of the data item, its type, etc.

v Data names that hold the results of intermediate computations should appear in the WORKING-STORAGE SECTION of the DATA DIVISION.

v The ENVIRONMENT DIVISION consists of two sections – the CONFIGURATION SECTION and INPUT-OUTPUT SECTION.

v The IDENTIFICATION DIVISION consists of a number of paragraphs showing the name of the program, name of its author, date on which the program is compiled and similar information.

v An entry or a statement of a COBOL program can be written in one or more coding lines.

Data names and Identifiers

A data name gives reference to the storage space in the memory where the actual value is stored. This value takes part in the operation when that particular data name is used in the PROOCEDURE DIVISION.

Data names are one form of identifiers. A data name must be a user-defined word and cannot be a reserved word.

Literals

Literals are constants. It refers constant values used in programs. These literals can be numeric, non-numeric or figurative constant.

(i) Numeric Literals:-

Numeric literals can be formed with the help of digits only. It is used in arithmetic operations and calculations.

Rules:-

i) It should be made up of only digits (0 – 9), positive or negative sign (+ or -) and a decimal point (.).

ii) The positive or negative sign should be before the number and there should be no blank spaces between the sign and the numbers.

iii) The use of decimal point should be followed by another at least one digit.

iv) The biggest number that can be represented in COBOL can have a maximum of 18 digits.

Ex:-

Valid Invalid

+20.1 20+

-31.0 “150”

(ii) Non-numeric literals:-

String of characters grouped together is known as non-numeric literals. It is used to output messages or headings. Even if the non-numeric literal is made up of only digits, these digits cannot be considered for arithmetic calculations.

Rules:-

i) The non-numeric literals should be enclosed with in quotation marks (“ “).

ii) The length o0f non-numeric literals should not exceed 120 characters.

(iii)Figurative constants:-

It represents values that may be frequently used by most programs.

List of figurative constants:

i) ZERO, ZEROS AND ZEROES can be used to represent a 0.

ii) SPACE OR SPACES can be used to represent blanks.

iii) QUOTE OR QUOTES can be used to represent “ “.

iv) HIGH-VALUES, LOW-VALUES and all literals are the other figurative constants used in COBOL.

No comments:

Post a Comment