Control Sequence Verbs COBOL Training Class8 Control Sequence
Control Sequence Verbs COBOL Training Class-8
Control Sequence Verbs • STOP RUN • EXIT PROGRAM • GOBACK • EXIT • GOTO • PERFORM
CONTROL VERBS § STOP RUN is used to stop programs and return the control back to OS (MVS). Do not use STOP RUN in sub programs. § EXIT PROGRAM is used to exit a subprogram and return the control to MAIN program § GOBACK is used to exit programs. when used in main program works as STOP RUN. When used in called program it has the same effect of EXIT-PROGRAM statement and § EXIT is used to exit paragraph. if EXIT is used the its must be the only entry in that paragraph. § GOTO is used to transfer control to another part of the program and the Control will not return back.
PERFORM IN DETAIL PERFORM: Passes the control to specified paragraph, But control will return back. Perform is of two types: 1. INLINE PERFORM 2. OUTLINE PERFORM INLINE PERFORM: The statements lie In between the scope of perform ( PERFORM & END-PERFORM ) OUTLINE PERFROM: The statement lie’s with-in a paragraph and the control is passed to the first statement of the paragraph.
Types Of Performs: 1. Simple perform is used to execute the referenced code one time 2. Perform N times is used to execute the code multiple times. the actual number of times is indicated by identifier or integer. 3. Perform Until condition is used to execute the code multiple times but dependent upon the UNTIL condition. The condition will be tested before the code is actually testes unless the WITH TEST AFTER is included. 4. Perform Thru is used to execute code from one particular paragraph to another in sequence. 5. Perform varying is used to execute multiple times by using
INLINE PERFORM Syntax : PERFORM N TIMES PERFORM UNTIL CONDITION STATEMENT 1 STATEMENT 2. . . END-PERFORM. Note: No Implicit terminator in between the scope.
OUTLINE PERFORM § OUTLINE perform statement causes the program to transfer control to another paragraph, execute all the statement within the paragraph, and return to the statement following the PERFORM statement. § Syntax § PERFORM PARANAME N TIMES. § PERFORM PARANAME UNTIL CONDITION. § PERFORM PARANAME 1 THRU PARANAME 2. § PARANAME. STATEMENT 1. STATEMENT 2.
TEST BEFORE & AFTER § If TEST BEFORE is specified, the condition is tested at the beginning of each repeated execution of the specified PERFORM range. § If TEST AFTER is specified, the condition is tested at the end of the each repeated execution of the PERFORM range. With TEST AFTER, the range is executed at least once.
EXAMPLE-1 ID DIVISION. PROGRAM-ID. EMPDETPG. ENVIROMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-EMPDET. 05 EMPID PIC 05 ENAME PIC 05 ELOC PIC 05 ESAL PIC PROCEDURE DIVISION. MAIN-PARA. PERFORM ACCEPT EMPID ACCEPT ENAME ACCEPT ELOC ACCEPT ESAL DISPLAY WS-EMPDET END-PERFORM. STOP RUN. X(5) VALUE SPACES. X(10) VALUE SPACES. 9(5)V 9(2) VALUE ZE
EXAMPLE-2 PROCEDURE DIVISION. MAIN-PARA. PERFORM ACCEPT-PARA. PERFORM DISPLAY-PARA. STOP RUN. ACCEPT-PARA. ACCEPT EMPID. ACCEPT ENAME. ACCEPT ELOC. ACCEPT ESAL. DISPLAY-PARA. DISPLAY WS-EMPDET.
Few Tips to Remember 1. Use the outline PERFORM statement to access code which needs to be executed from more than one location. 2. Use the PERFORM statement to structure your program. Make a main PARA from which you can perform other routines. 3. Use the WITH TEST AFTER option to force the code to perform at least once. 4. If the number of lines in the routine is relatively small. Use an in-line PERFORM instead of outline PERFORM.
Try Out WORKING-STORAGE SECTION. 01 WS-N PIC 9(2) VALUE ZERO. PROCEDURE DIVISION. MAIN-PARA. MOVE 5 TO WS-N. PERFORM DISPLAY-PARA THRU EXIT-PARA WS-N TIMES. DISPLAY-PARA. MOVE 10 TO WS-N. DISPLAY WS-N. EXIT-PARA. EXIT. How many times DISPLAY-PARA will be executed ?
Thank You Polsani Anil Kumar
- Slides: 13