EXIT  [TO program [COMMAREA (data)]| CLEAR]

Synonyms XCTL, TRANSFER

FUNCTION

Causes an immediate exit from the program. 

·         In a batch program: -

            If a GETUPDATE is pending, the final update is done

            Final subtotals and grand totals are printed

            Files are closed.

·         In a CICS program and the EXIT statement does not use the TO or CLEAR option: -

            If a GETUPDATE is pending, the final update is done

TO program [COMMAREA (data)] | CLEAR

These options are only valid in CICS programs.  If used, then the exit is immediate so if an update is pending it will be abandoned.

 

TO program causes transfer to be passed to the program named.  Jazz cannot check that this program exists.

 

COMMAREA(Data)  passes data to the program named in TO.  This option is not valid if TO is absent.   See notes below about “Jazz-created programs and Commareas”

 

CLEAR behaves like the default handing when the Clear key is clicked: -

            If the PROGRAM statement has an EXIT option, then control is immediately transferred to that program,

            Else the CICS screen is cleared, “Enter transaction code” is displayed, and CICS awaits another transaction code.

Jazz-created Programs, Commarea, and Exit

You don’t have to think about this UNLESS you are mixing Jazz and Non-Jazz programs.

 

Each program has its own unique screen and commarea format, and errors will result if they are mixed up.  For example with

PROGRAM CICS3 CICS INSCREEN(CICS3S) TRANSID(TRN3) COMMAREA(CICS3C) EXIT(menu1);

you can expect errors if program CICS3 reads a screen that is not in the CICS3S format, or attempts to read data from a commarea that is not formatted like CICS3C. 

 

Programs are normally started with neither a screen nor a commarea: the first thing that they do is to invoke themselves, sending themselves an empty screen map, and an empty commarea.  Logic is

            IF there is no commarea

                Send input screen map and empty commarea to self

            ELSE

                Read input screen and Commarea

 

However if program CICS3 contains a statement like

        EXIT TO CICS4 COMMAREA(CICS4C);

then the logic above won’t work in CICS4.  If logic in CICS4 sent screen CICS4S with empty commarea CICS4C then it would loose all the data passed to it from program CICS3.  On the other hand, if it simply read the input screen it would abend because the screen format would be CICS3S, not CICS4S. 

 

Jazz wants to make it easy for you: it doesn’t want you to have to distinguish between programs like CICS4 that are invoked by EXIT and programs like CICS3 that are invoked by a menu.  So Jazz manages this problem like this: -

1.                  When Jazz generates a commarea (as in New/CICS Program) the commarea always contains a flag called “JZ-XCTL” with default value “N”.

2.                  EXIT statements set this to “Y” before they transfer control

3.                  In all Jazz programs the logic is like this: -

            IF there is no commarea

                Send input screen map and empty commarea to self

            ELSE IF the flag is “Y”

                Set it to “N” and send the input screen map and received commarea to self

            ELSE

                Read input screen and Commarea

 

You only have to think about this if you are mixing Jazz and Non-Jazz programs.

A.                 Invoking a Jazz program from a non-Jazz program.  The Commarea must contain a field called JZ-XCTL (PIC X VALUE ‘N’).   Set this to ‘Y’ in the Commarea passed to the Jazz program.  Unless you do this, your Jazz program will fail when it is invoked by XCTL.

B.                  Invoking a non-Jazz program from a Jazz program.  Your Jazz program will contain EXIT TO XXXX COMMAREA(XXXXC);  


Jazz will NOT generate the logic

            MOVE ‘Y’ TO JZ-XCTL OF XXXXC

unless it can find JZ-XCTL within the data definition XXXXC.  

 

 

If XXXX is ALWAYS invoked by XCTL from other programs then there is no problem.  It can be written with the correct code to start from XCTL, and while it will fail if it is invoked directly from CICS this never happens.

 

If XXXX might be invoked from the system or from XCTL then it will need another way of distinguishing whether to send itself the empty map with a passed commarea.  You may need to code assignments to some other flag variable just before the EXIT statement.