PERFORM statement transfers control to a block of code that will be executed just once. This could either be a paragraph or a section. Alternatively, it could execute several blocks of code contained in a number of consecutive paragraphs by using the PERFORM THRU construct.
If a set of statements is used only in one place then we can merge all of them within PERFORM & END-PERFORM structure and it is called INLINE PERFORM.
Syntax:
PERFORM
<statemens>
END-PERFORM
Example:
PERFORM
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT
END-PERFORM
PERFORM VARYING COUNT FROM 1 BY 1
UNTIL COUNT > 100 OR END-OF-FILE = ‘Y’
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT
READ NEXT RECORD
END-PERFORM
PERFORM 10 TIMES
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT
READ NEXT RECORD
END-PERFORM A set of STATEMENTS merged together and placed in different and will call them using a paragraph when required is called OUTLINE PERFORM. i.e. we are calling paragraphs depending on our requirement.
This is used to execute a paragraph or section. On completion of paragraph execution, control is returned back to the next statement following PERFORM.
Syntax: PERFORM Para-Name
PERFORM TOTAL-ITEM-PARA
TOTAL-ITEM-PARA.
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT This is used to execute a set of paragraphs. On completion of paragraph execution, control is returned back to the next statement following the last PERFORM.
Syntax: PERFORM Para-Name-X THRU Para-Name-Y
PERFORM TOTAL-ITEM-PARA THRU TOTAL-AMOUNT-PARA
TOTAL-ITEM-PARA.
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT.
TOTAL-AMOUNT-PARA.
ADD ITEM-AMOUNT TO ITEM-AMOUNT
DISPLAY ‘TOTAL AMOUNT’ ITEM-AMOUNT. In ‘PERFORM TIMES’, a paragraph will be executed the number of times specified.
Syntax: PERFORM Para-Name N TIMES
PERFORM TOTAL-ITEM-PARA 5 TIMES
TOTAL-ITEM-PARA.
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT. PERFORM UNTIL phrase acts like a WHILE LOOP where the statements within the loop are executed repeatedly until a value is reached. In other words, the loop terminates as soon as a certain value is reached or the condition is satisfied. ‘WITH TEST BEFORE’ is the default condition and it indicates that the condition is checked before the execution of statements in a paragraph.
Syntax: PERFORM Para-Name UNTIL COUNT=N PERFORM Para-Name WITH TEST BEFORE UNTIL COUNT=N PERFORM Para-Name WITH TEST AFTER UNTIL COUNT=N
In either case, if the condition is true, control is transferred to the next executable statement after PERFORM statement.
PERFORM TOTAL-ITEM-PARA WITH TEST AFTER UNTIL WS-COUNT > 5.
TOTAL-ITEM-PARA.
ADD ITEM-COUNT TO ITEM-COUNT
DISPLAY ‘TOTAL ITEM’ ITEM-COUNT. This format is similar to the “FOR loop” of other programming languages. Like FOR loop it has a start and an end value. With each iteration, the value is incremented by a certain number until it reaches the end value. This process will continue until the condition is met and evaluated to be true. Once the condition evaluates to be true then the loop is braked and the next statement following PERFORM will be executed.
PERFORM procedure-name-1 [THRU/THROUGH procedure-name-2] [TESTBEFORE/TESTAFTER]
VARYING FROM BY UNTIL condition-1
[ AFTER FROM BY AFTER codition-2 ]
[ AFTER FROM BY AFTER codition-3 ] ...
d - data-item
I - index-name
l - literal It is very similar to ( PERFORM… UNTIL ), except in this format it allows us to increase one or more data-item values automatically.
Example:
PERFORM TOTAL-ITEM-PARA VARIYING WS-I FROM 1 BY 2
UNTIL WS-I > 10 In the above example, all statements in TOTAL-ITEM-PARA are executed till the condition associated with UNTIL becomes true. For the first iteration, WS-I contains the value of 1 ( as it is specified after FROM ), for the second iteration WS-I value increase by 2 ( as it is specified after BY keyword) and the condition will be tested, if false statements in TOTAL-ITEM-PARA will get executed and control comes back to PERFORM, Now WS-I value increased again by 2 and condition will be tested, if it is false, statements in TOTAL-ITEM-PARA will get executed again. This loop continues till the condition becomes true.
This kind of PERFORM browses through each element of a multi-dimensional array.
Example:
PERFORM TOTAL-ITEM-PARA
VARIYING WS-I FROM 1 BY 2
UNTIL WS-I > 10
AFTER WS-J FROM 1 BY 3
UNTIL WS-J > 20 In this example, in addition to WS-I, WS-J value also gets changed. For every valid value in WS-I, WS-J value start from 1 till WS-J > 20 becomes true. PERFORM statement execution ends only when WS-I > 10 becomes true.
PERFORM TOTAL-INV-PARA THRU PARA-EXIT
VARYING COUNT-I FROM 1 BY 1
UNTIL COUNT-I > 3
AFTER VARYING COUNT-J 1 BY 1
UNTIL COUNT-J > 2.
TOTAL-INV-PARA.
DISPLAY ‘COUNT: ’ ITEM-COUNT(COUNT-I)
DISPLAY ‘AMOUNT: ’ ITEM-AMOUNT(COUNT-I, COUNT-J)
PARA-EXIT.
EXIT. The Product Owner role has shifted from just being a requirements proxy to a strategic,…
Business Value: In the world of Agile development, the user story has long been the…
The SAFe Scrum Master certification has become one of the most sought-after credentials for Agile…
The Professional Scrum with Kanban (PSK) course enhances your organization's ability to deliver value efficiently…
Effective User interviews play a crucial role in Scrum methodology, helping Product Owners and Scrum…
Product Owners should be well-versed in various user research tools and techniques to effectively understand…