Using STOQ Through COBOL85 Statements

COBOL85 supports STOQ communications through various language extensions. It is not necessary for a COBOL85 program to import procedures from the EVASUPPORT library.

STOQ parameter blocks are declared in COBOL85 in the same way as in COBOL74. The STOQ parameter block must be a group item. All subordinate items are passed as part of the STOQ parameter block.

All subqueue names used with that STOQ parameter block must be the same length as the subordinate item declared to store the subqueue name. One simple way to handle this requirement is by padding all subqueue names with blanks to bring them to the same length. For example, all subqueue names used with the following STOQ parameter block should be padded with blanks to bring them to 10 characters in length:

01  STOQ-BLOCK.
    03  STOQ-QUEUE         PIC X(6).
    03  STOQ-SUBQ-LENGTH   PIC 9(2) COMP VALUE 10.
    03  STOQ-SUBQ          PIC X(10).
    03  STOQ-DATA-LENGTH   PIC 9(4) COMP.
    03  STOQ-DATA          PIC X(9999).

The subqueue name item should be declared with the number of digits specified by the subqueue name length item. Thus in the preceding example, STOQ-SUBQ-LENGTH is declared with a value of 10, and STOQ-SUBQ is declared as PIC X(10).

In COBOL85, the SEND statement for a STOQ follows one of the following two formats:

SEND TO <top or bottom> <STOQ parameter block>.

SEND TO <top or bottom> <STOQ parameter block> ON EXCEPTION <statement>.

In COBOL85, the RECEIVE statement for a STOQ follows one of the following two formats:

RECEIVE FROM <top or bottom> <STOQ parameter block>.

RECEIVE FROM <top or bottom> <STOQ parameter block>
   ON EXCEPTION <statement>.

RECEIVE FROM <top or bottom> <STOQ parameter block>
   NOT ON EXCEPTION <statement>.

In the preceding statements,

  • The <top or bottom> clause consists of the keyword TOP or BOTTOM and specifies the end of the STOQ or subqueue at which the message should be inserted.

  • The <STOQ parameter block> clause is the identifier of a STOQ parameter block declared in the program.

  • The ON EXCEPTION clause specifies a statement to be executed if the SEND or RECEIVE statement cannot be completed immediately. A SEND statement incurs a delay if the specified STOQ is full. A RECEIVE statement incurs a delay if there are no messages in the specified STOQ or subqueue.

    If there is no ON EXCEPTION clause and a delay occurs, the process waits until the SEND or RECEIVE statement can be completed.

  • The NOT ON EXCEPTION clause specifies an action to be taken if the SEND or RECEIVE statement finishes successfully.

To poll the message count in a STOQ, the syntax is:

ACCEPT <STOQ parameter block> MESSAGE COUNT.

The following COBOL85 program declares a STOQ parameter block and uses the SEND, RECEIVE, and ACCEPT statements.

IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  STOQ-BLOCK.
    03  STOQ-QUEUE         PIC X(6).
    03  STOQ-SUBQ-LENGTH   PIC 9(2) COMP.
    03  STOQ-SUBQ          PIC X(6).
    03  STOQ-DATA-LENGTH   PIC 9(4) COMP.
    03  STOQ-DATA          PIC X(9999).

PROCEDURE DIVISION.
BEGIN-PARA.
    MOVE “QUEUE1” TO STOQ-QUEUE.
    MOVE 6 TO STOQ-SUBQ-LENGTH.
    MOVE “SUBQ01” TO STOQ-SUBQ.
    MOVE 11 TO STOQ-DATA-LENGTH.
    MOVE “HELLO THERE” TO STOQ-DATA.
  SEND TO TOP STOQ-BLOCK.
    ACCEPT STOQ-BLOCK MESSAGE COUNT.
    DISPLAY STOQ-DATA-LENGTH.
    RECEIVE FROM TOP STOQ-BLOCK ON EXCEPTION GO ERR-HANDLER.
    STOP RUN.

ERR-HANDLER.
    DISPLAY “ERROR OCCURRED”.
    STOP RUN.