Quantcast
Channel: Visual COBOL Knowledge Base
Viewing all articles
Browse latest Browse all 214

Overlapping PERFORM...THRU...EXIT

$
0
0
Current Revision posted to Visual COBOL Knowledge Base by dewamigo on 12/16/2014 1:55:59 PM

Problem:

My program appears to be losing its ability to perform thru exit. It falls to the next para instead of returning to the location where it was performed from. .

Resolution:

This customer's program presumably has some mainframe heritage, and was coded in such a way as to rely on implementation-specific behaviour that the mainframe gives. 

Fortunately we can emulate this behavior using the checker directive PERFORM-TYPE(OSVS).

It specifies the behavior of return jumps from nested PERFORM statements.

PERFORM-TYPE"OSVS" provides compatibility with the mainframe behavior of OS/VS COBOL and DOS/VS COBOL.

The following program demonstrates having an inner PERFORM (paragraph TESTER) fall into a new SECTION instead of returning to the controlling SECTION: 

       IDENTIFICATION DIVISION.
       PROGRAM-ID. PROGRAM1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  COUNTER           PIC 9       VALUE 0.
       01  SUB               PIC 9.

       PROCEDURE DIVISION.
       MAIN SECTION.
       BEGIN.
           PERFORM PROCESS
           DISPLAY "NORMAL TERMINATION"
           STOP RUN.
     
       PROCESS SECTION.
           DISPLAY "STARTING PROCESS SECTION".

       PROCESS-LOOP.
           PERFORM TESTER VARYING SUB FROM 1 BY 1 UNTIL SUB >= 10
           GO TO PROCESS-EXIT.     
       TESTER.
           IF (COUNTER = 6) 
               GO TO PROCESS-EXIT
           ELSE 
               ADD 1 TO COUNTER
           END-IF.
       PROCESS-EXIT.
           EXIT.
     
       FALL-THROUGH SECTION.
       ALERT.
           DISPLAY "*** FALL THROUGH CODE ***"
           STOP RUN.
       END PROGRAM PROGRAM1.


The program falls through when compiled using cob -vug Program1.cbl 
[support@rhsupv2 100500]$ cobrun Program1
STARTING PROCESS SECTION
*** FALL THROUGH CODE ***

The program succeeds when compiled using cob -vug demo.cbl  -C'PERFORM-TYPE(OSVS)'
[support@rhsupv2 100500]$ cobrun Program1
STARTING PROCESS SECTION
NORMAL TERMINATION

Viewing all articles
Browse latest Browse all 214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>