The END Statement

END closes a “block”, i.e. a group of logically-related statements. 

Format:

END statement-keyword [File-Name] {[UPDATE] | [ADD] | [REWRITE]}

[RESPOND Message]

[RESETFUNCTION]

[EXIT (condition)];

 

For example: -

PROCESS File1 WHERE (File1.Balance > 1000);

    PRINT (File1.Name, File1.Balance);

END PROCESS File1;

 

Jazz checks that the END is correctly matched: for example END IF must follow an unclosed IF statement. Code like this is incorrect and will produce error messages: -

PROCESS File1 WHERE (File1.Balance > 1000);

    PRINT (File1.Name, File1.Balance);

    IF File1.Previous-Balance > File1.Balance THEN;

        PRINT (‘Customer is loosing money’);

END PROCESS File1;

 

The File-Name is not given if the END closes IF, CASE, or FOR, i.e. a statement that is not associated with a particular file. It is required when END closes a PROCESS or GET block.

 

EXIT is only valid with END PROCESS statements.

 

UPDATE, ADD, or REWRITE may be given when the END statement closes a GET block, and the GET statement has an UPDATE option. Refer to the GET statement for a description of how these options work.

 

UPDATE is also valid with an END PROCESS statement, but only when the input file has type VSAM or SQL.

RESPOND message

Only valid in a Web Service program.  This option names the message format that will be sent back to the web service requestor.  For example, RESPOND OJSPG2A with each of the END GET Employee statements causes data from EMPLOYEE to be put into the output message OJSPG2A so that it will be sent back to the requestor by the program’s REPLY.

PROGRAM JSPG2A WEBSERVICE MyJSv CONTAINER DFHWS-DATA DATABASE sample DB2 JSON;

CASE (IJSPG2A.Function);

    WHEN (Enquiry);

        ACCEPT (EMPLOYEE.EMPNO = IJSPG2A.EMPNO OR EMPLOYEE.WORKDEPT = IJSPG2A.WORKDEPT) MESSAGE OJSPG2A.ERROR;

        GET Employee KEY(EMPLOYEE.EMPNO OR EMPLOYEE.WORKDEPT) SAVESUM OJSPG2A.JZ-Employee.Checksum;

            #628 W GENERIC assumed for WORKDEPT

        END GET Employee RESPOND OJSPG2A;

    WHEN (Update);

        ACCEPT (EMPLOYEE.EMPNO=IJSPG2A.EMPNO) MESSAGE OJSPG2A.ERROR;

        GET Employee KEY(EMPLOYEE.EMPNO) UPDATE CHECKSUM IJSPG2A.JZ-Employee.Checksum;

            ACCEPT (IJSPG2A.JZ-Employee.*) EXCEPT(EMPLOYEE.EMPNO) MESSAGE OJSPG2A.ERROR;

        END GET Employee UPDATE RESPOND OJSPG2A;

    WHEN (Add);

        GET Employee FREEKEY CREATE;

            #221 E EMPLOYEE.EMPNO used as key field(s).  It/they will be set to next available value.

            ACCEPT (IJSPG2A.JZ-Employee.*) EXCEPT(EMPLOYEE.EMPNO) MESSAGE OJSPG2A.ERROR;

        END GET Employee CREATE RESPOND OJSPG2A;

END CASE;

REPLY;

RESETFUNCTION

Following the GET for enquiry a program typically sets the next function to U/Update if the record was found, A/Add if not, and sets the message field to tell the user what do to.  There is similar code setting the next function and a message for the Update, Add, and Delete cases.   This requires a few lines of Jazz logic after the END GET statement for each case.  With RESETFUNCTION Jazz will write standard logic for you: -

*# Last Updated by JAZZUSER at 30/04/2018 4:01:35 p.m.

PROGRAM CICS2 CICS INSCREEN(CICS2S) TRANSID(TRN2) COMMAREA(CICS2C) EXIT(menu1);

ACCEPT (CICS2S.Function);

#562 I CICS2S.Error used as message field

CASE (CICS2C.Function);

    WHEN (Enquiry);

        ACCEPT (CICS2S.Account OR CICS2S.Name);

        #562 I CICS2S.Error used as message field

        DEFINE TS1 TS DATA(

            Account LIKE CustF.Account);

        GET Custf KEY(CustF.Account OR CustF.Name) SAVECOPY CICS2C.SAVE TS(1);

            #373 I GET statement returns one record at a time for Name

        END GET Custf RESETFUNCTION;

    WHEN (Update);

        GET Custf WHERE(CustF.Account=CICS2C.SAVE.Account) REWRITE CHECKCOPY(CICS2C.SAVE);

            COPY JZSMth;

            COPY JZMDays;

            COPY JZDTVS;

            ACCEPT (CICS2S.Region,CICS2S.District,CICS2S.Name,CICS2S.SalesThisMonth,CICS2S.SalesYTD,CICS2S.Billingcycle,

                   CICS2S.DateCommenced);

            #562 I CICS2S.Error used as message field

        END GET Custf REWRITE RESETFUNCTION;

    WHEN (Add);

        CustF.Account = CustF.$LastKey + 1; [Will need to be changed if key is not a number

        #361 E Assignment to a key field

        GET Custf KEY(CustF.Account) CREATE;

            ACCEPT (CICS2S.Region,CICS2S.District,CICS2S.Name,CICS2S.SalesThisMonth,CICS2S.SalesYTD,CICS2S.Billingcycle,

                   CICS2S.DateCommenced) SETMDT;

            #562 I CICS2S.Error used as message field

        END GET Custf CREATE RESETFUNCTION;

    WHEN (Delete);

        DELETE Custf WHERE(CustF.Account=CICS2C.SAVE.Account) CHECKCOPY(CICS2C.SAVE) RESETFUNCTION;

END CASE;

SEND Inscreen;

 

The RESETFUNCTION option is only valid in classical CICS programs. The PROGRAM statement must name the input screen with INSCREEN, and this screen must contain a message field called “Error” in the screen, and a field called “Function” in the Commarea defined like this: -

DEFINE CICS2C TYPE(COMMAREA) DATA(

    Function CHAR(1) CODES (E:Enquiry,U:Update,A:Add,D:Delete) VALUE 'E',

 

For Function E:Enquiry
            If the record is found then Error is set to “Record Found. Use Function U to update it”.  Function is not automatically reset.

If the record is not found then Error is set to “Record not found. Use Function A to add it”, and Function is set to “A”

For Function U:Update 

Error is set to “Record Updated”, Function is set to “E”

For Function A:Add

Error is set to “Record Added”, Function is set to “E”

For Function D:Delete

            Error is set to “Record Deleted”, Function is set to “E”