ENDBR


The CICS ENDBR (End Browse) statement is used to terminate an active browse session that was started with the STARTBR (Start Browse) statement. This command should be executed after you have finished sequentially retrieving records using either READNEXT or READPREV. The ENDBR statement releases the system resources associated with the browse session. It is not necessary to use ENDBR if the STARTBR command was unsuccessful.

Syntax -

EXEC CICS ENDBR
     FILE('file-name')
	 [REQID(value)]
	 [SYSID(system-name)]
     [RESP(response-field)]
     [RESP2(response-field2)]
     END-EXEC.
  • FILE('file-name') - Specifies the VSAM file name whose browse session is being closed.
  • REQID(value) - Specifies unique request identifier for a browse.
  • SYSID(system-name) - Specifies the system name to which the request is directed.
  • RESP(response-variable) - Optional. It captures the response code of the ENDBR operation and used to check if the command executed successfully or encountered an error.
  • RESP2(response2-variable) - Optional. It captures the response2 code of the ENDBR operation when the error occured.

How it works?

  • A STARTBR (Start Browse) command is issued to begin browsing the file.
  • Records are retrieved using READNEXT or READPREV.
  • Once all required records have been processed, ENDBR is executed to end the browse session.
  • The system releases file browse resources, preventing unnecessary resource consumption.

Short Examples -


Scenario - Browsing a KSDS File from a Specific Key.

...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-CUSTOMER-RECORD.
   05 WS-CUST-ID        PIC X(10).
   05 WS-CUST-NAME      PIC X(30).
   05 WS-CUST-ADDRESS   PIC X(50).
   05 WS-CUST-PHONE     PIC X(15).
   
...
PROCEDURE DIVISION.

    MOVE "12345" TO WS-CUST-ID.

    EXEC CICS STARTBR
         FILE('CUSTFILE')
		 RIDFLD(WS-CUST-ID)
         RESP(WS-RESP)
         END-EXEC.

    IF WS-RESP = DFHRESP(NORMAL) THEN
       PERFORM READ-NEXT-REC 
	      THRU READ-NEXT-EXIT
		 UNTIL EOF-CUST-FILE
	END-IF.

    EXEC CICS ENDBR
         FILE('CUSTFILE')
         END-EXEC.
		 
	...
READ-NEXT-REC.

    EXEC CICS READNEXT
         FILE('CUSTFILE')
         INTO(WS-CUST-RECORD)
         RESP(WS-RESP)
         END-EXEC.

    IF WS-RESP = DFHRESP(NORMAL) THEN
        ...
    ELSE IF WS-RESP = DFHRESP(ENDFILE) THEN
         SET EOF-CUST-FILE      TO TRUE
    ELSE
         ...
    END-IF.	
	
READ-NEXT-EXIT
     EXIT.
    ...

The STARTBR command starts the browse session for sequential access. The READNEXT command retrieves records one by one. The loop continues until the last record is reached (ENDFILE). The ENDBR command is issued to close the browse session.

Error Conditions -


Eror Condition RESP RESP2 Reason
FILENOTFOUND 12 1 A file name in the FILE option is not defined to CICS.
INVREQ 16 35 The REQID, SYSID or file name does not match any successful STARTBR command.
IOERR 17 120 There is an I/O error during the ENDBR operation.
ILLOGIC 21 110 VSAM error occurs that is not in one of the other CICS response categories.
53 SYSIDERR 53 130 The SYSID name specified is neither the local region nor a remote system or the link to the remote system is closed.
ISCINVREQ 54 70 The remote system indicates a failure that does not correspond to a known condition.
70 NOTAUTH 70 101 A resource security check has failed on FILE (filename).