COBOL Perform Types and Usage with examples

Perform Verb in COBOL is used to execute a set of COBOL statements. There exists different types of performs based on the way that is being used. It is vital in keeping a cobol program structured by making it possible to call different paragraphs or sections from another paragraph or section.

Following are some of the PERFORM types depending upon their usage

1.  Inline perform.
2.  Simple Perform.
3.  PERFORM VARYING.
4.  PERFORM VARYING…. UNTIL….
5.  PERFORM THRU
6.  PERFORM TIMES

Inline Perform:
It performs a set of Cobol statements between Perform & END-Perform. Basically this is to keep a particular logic in a boundary and execute it in a loop or number of times or execute depending upon a condition. This is useful if that set of code is only used once in thAT program. If it is used multiple times ‘Outline perform’ is the best choice.

Ex:

Ex: Inline perform based on a condition

In the above perform the loop executes until the count reaches 100, after that it comes out the loop.
Inline perform can also be performed number of times depending upon the requirement.

Ex:

Simple Perform:
This is used to execute a paragraph or section.

PERFORM VARYING:
This format can be used both in inline and out line performs.
It is useful to limit the execution of a set of statements depending on any condition.
Ex: inline perform

Ex: For Outline perform

Here it also gives the possibility to
– give the initial value for the WW-COUNT1
– Increment the ww-count1 by any other value
Ex:

Here COUNT1’s initial value is 10 and each time it gets incremented by 2.

PERFORM THRU :
It is useful to execute a continuous set of paragraphs/sections.

Should be cautious to use ‘perform thru’ as it executes any new paragraph added in between these para’s.

Perform with TIMES:
It can be used to execute a piece of code ‘n’ number of times.

PERFORM WITH TEST BEFORE/TEST AFTER:
With Test Before option, program checks the condition first, if the condition false it executes the piece of code. So with Test Before there is a possibility of not executing the code for at least once.Where as in Test After(which is the default one) the code gets executes at least once.
Ex:

Leave a Reply

Your email address will not be published. Required fields are marked *

Bitnami