CICS RETURN with Examples

RETURN IN CICS is to return the control back to the next higher level which is either main program or CICS(Operating System).It is very useful in programs where there are sub programs involved in exchanging the data Or screens involved where there is a need to preserve the data and use it after the user response.

CICS RETURN has various options While returning the control back to the calling program.

  • Simple return where it just gives control back
  • Return with Transaction ID.
  • COMMAREA – generally this option is used along with the TRANSID option to send data back to program which executes the Transaction ID so that it is used while executing that transid.
  • CHANNEL – A channel name can be supplied to send some data back.

Syntax:

-RETURN------------------------------------------------------->
----TRANSID(name)--+---------------------------------------------
               +-COMMAREA(data-area)------+-+ '-IMMEDIATE-'
|             '-LENGTH(data-value)-' |
'              -CHANNEL(data-value)-------------------------'
'-INPUTMSG(data-area)--+-------------------------+-'
'-INPUTMSGLEN(data-value)-'

Simple return without any sub parameters retuns the control back to the next higher level(either to the main program or to the OS).

TRANSID Option is to indicate te next transaction that needs to be run after the user inputs on the terminal.It has options to send the data using COMMAREA and Channels. If COMMAREA is specified, its length needs to be mentioned.

IMMEDIATE – If it is specified along with the transid, then it is to give the control to the specified transaction immediately irrespective of any transactions enqueued by ATI.

INPUTMSG also used to send some data back on to the main program but in this case the main program should be coded with RECEIVE to get this data.

RETURN IMMEDIATE – This is used when a sequence of tasks needs to be executed without the user intervention so that the OS does not allow any user input at the terminal allowing the existing transaction to be continued.

Scenarios:

Main program called the sub program using LINK and the sub program just returned with out any sub options.

Below is coded in the main program to call the sub program.

EXEC CICS LINK
     PROGRAM(WA-PGM)
     COMMAREA(WL-COMMAREA)
     LENGTH(COMM-LGTH)
     RESP(WD-RESPONSE)
END-EXEC

Simple Return:
Sub program has just issued a RETURN without any options as below.

EXEC CICS RETURN END-EXEC

If some data needs to be send back to the calling program, it can be passed back via commarea. For this required data needs to be filled in DFHCOMMAREA before issuing the return.

MOVE WW-CUST-DATA TO DFHCOMMAREA
EXEC CICS RETURN END-EXEC

Return with Transaction ID Option:

EXEC CICS RETURN
     TRANSID(CUST-TRAN-ID)
     COMMAREA(CUST-COMM-AREA)
     LENGTH(COMM-LGTH)
END-EXEC.

This option is generally used in programs where screens are involved. Once the initial screen sends the control back on to the screen and when the user enters any attention identifier keys the specified transaction id gets active and the commarea sent would be used in that process.

Few Notes:

  • RETURN always returns the control back to the next Higher Level
  • PROGA —->(link) PROGB ===> return in PROGB gives control back to PROGA
  • PROGA —->(xctl) PROGB ===> return in PROGB gives control back to OS
  • PROGA —->(link) PROGB —->(xctl) PROGC ===> return in PROGC GIVES CONTROL to PROGA
  • PROGA —->(call) PROGB ===> REturn in progn gives control back to OS where as a GOBACK in PROGB returns control back to PROGA.

You can search in this blog for page up & down logic where there is some sample code available which gives real time usage.

Also look in this blog for LINK, CALL & XCTL to get some idea on how there are used in programs.

Add a Comment

Your email address will not be published. Required fields are marked *