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.
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…