2 More things on Advanced COBOL Programming

30 High Paying Jobs
30 High Paying Jobs

A great opportunity for mainframe programmers to implement these advanced concepts into their development projects. As you gain experience you need to show some performance improvement in your day to day coding. These, you can tell, that you did in your projects, in your appraisal meetings.

EVALUATE

In advanced COBOL programming, the EVALUATE verb makes COBOL programs flexible because it enables you to transfer program control on the basis of data-items or literals in addition to integers. Literals are alphanumeric or numeric constants and do not limit the use of CASE construct to integers. The EVALUATE END-EVALUATE construct indicates the use of the EVALUATE verb.

Syntax for evaluate:

EVALUATE {Condition1}[ALSO {Condition2}]…
{WHEN {[ALSO]
{ANY/Condition/TRUE/FALSE/[NOT]{DiffCondition
[{THRU/THROUGH DiffCondition}]}…}
} Statements1
}…
[WHEN OTHER Statements1]
END-EVALUATE.
In this listing, the conditional expressions, Condition1 and Condition2, can be identifiers, literals, conditional expressions arithmetic expressions, or TRUE /FALSE return values. For example, the conditional statement, DiffCondition, can be a literal, identifier, or arithmetic expression. Statements1 can be one or more COBOL statements. The ALSO phrase used with EVALUATE END-EVALUATE construct evaluates more than one conditional expressions.

All statements such as condition1, the ALSO phrase, and the condition 2 elements after the EVALUATE verb and before the first occurrence of WHEN clause are called subjects. The elements present between a WHEN clause and its Statement are called objects. For example, all the elements between the WHEN clause and Statements1 are objects. In EVALUATE END EVALUATE construct, the number of subjects should be equal to the number of objects and the type of each subject should be same as that of its respective object. The code for using EVALUATE verb is:
EVALUATE value1 ALSO value2 > 5
WHEN 0 THRU 10 ALSO TRUE DISPLAY ‘one’
WHEN 10 THRU 20 ALSO FALSE DISPLAY ‘two’
WHEN 30 THRU 40 ALSO ANY DISPLAY ‘three’
WHEN OTHER DISPLAY ‘error’

In this code, value1 and value2 > 5 are the subjects, where value1 consists of integer value and value2 > 5 represents a conditional expression. The first object, 0 THRU 10 TRUE, specifies the range of values for the conditional expression in the EVALAUTE statement. The second object, ALSO TRUE, specifies whether the subject, value2 > 5 is TRUE or FALSE. When run, this code displays one if value1 ranges from 0 to 10 and value2 > 5 is TRUE.

The code displays two if value1 is from 10 to 20 and value2 is false and it displays three if value1 is from 30 to 40. The object, ALSO ANY specifies that the value three is displayed when the object, 30 THRU 40 is run regardless of the value of the subject, value2 > 5.

The code displays an error using the WHEN OTHER clause if the values assigned to objects in the WHEN clauses do not match with their corresponding subjects.

Nested Programming

Example of COBOL program

IDENTIFICATION DIVISION.
PROGRAM-ID. MainProgram.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 GlobalItem PIC X(25) IS GLOBAL.
PROCEDURE DIVISION.
CALL ‘ FirstSubPrg’
CALL ‘Second’.
STOP RUN.

IDENTIFICATION DIVISION.
PROGRAM-ID. FirstSubPrg.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 LocalItem PIC X(25).
PROCEDURE DIVISION.
DISPLAY ‘Program Name is First’.
END PROGRAM FirstSubPrg.
IDENTIFICATION DIVISION.
PROGRAM-ID. Second.
PROCEDURE DIVISION.
DISPLAY ‘Program Name is Second’.
END PROGRAM Second.
END PROGRAM MainProgram.

This listing shows that MainProgram is the outermost program that has two sub programs: FirstSubPrg and Second. Each sub- program has its own END PROGRAM statement. GlobalItem is the data item defined in the WORKING-STORAGE SECTION in the MainProgram. GlobalItem is declared as GLOBAL and is available for use in both sub programs.

If you do not declare GlobalItem of the MainProgram as GLOBAL, it will not be available to the FirstSubPrg- and Second- programs. LocalItem, the data item defined in the FirstSubPrg sub-program, is used as a local variable. As a result, its scope of use is limited to the FirstSubPrg sub-program only. FirstSubPrg cannot call Second and Second cannot call FirstSubPrg.

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.

Comments are closed.