COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

As with any other read operation, a process waiting to receive a message on $RECEIVE waits
until a message is delivered, the process is stopped, or a timeout occurs on the read operation.
Before a process can receive a message, some process must have sent a message to it.
To send a message, a process must have the name of the process that is to receive the message
(see Process Names). The sending process opens a file having the same name as the receiving
process (using an OPEN statement). Then the sending process can write to its file and cause the
operating environment to deliver the message to the receiving process. The receiving process then
can read the message on its $RECEIVE.
If a process tries to open a nonexistent process, both the operating environment and the HP COBOL
run-time routines issue error messages. If no declarative intercepts the error, the process terminates.
The sender of a message specifies whether a reply is expected or not. An HP COBOL process uses
a WRITE statement to send a message to which no reply is expected and a READ WITH PROMPT
statement to send a message that requests a reply. The READ WITH PROMPT statement reads the
reply to the message that is transmitted as the prompt. The READ WITH PROMPT statement lets
you write a requester in HP COBOL, because it enables you to send a request to a server and
await a reply from that server. For more information on READ WITH PROMPT, see PROMPT phrase.
$RECEIVE as Separate Input and Output Files
The most common way to use $RECEIVE is to open it in INPUT mode for one file, and in OUTPUT
or EXTEND mode for one or more other files.
Figure 40 $RECEIVE as Separate Input and Output Files
All files are assigned to $RECEIVE; however, when testing your system, you can assign all files to
disk files and then reassign them to $RECEIVE when testing is completed.
Example 300 Requester Code
...
SELECT TRANSACTIONS ASSIGN TO "$BAL"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL....
FD TRANSACTIONS
LABEL RECORDS ARE OMITTED
* Variable-length records
RECORD CONTAINS 1 TO 8 CHARACTERS.
01 BALANCE PICTURE 9(8).
01 ERROR-ON-TASK.
05 ERROR-CODE PICTURE 9.
05 ERR-MSG PICTURE X(7).
WORKING-STORAGE SECTION.
01 TRAN-REQUEST.
05 TRAN-CODE PICTURE 9.
05 TRAN-ACCOUNT-NUMBER PICTURE 9(6).
...
PROCEDURE DIVISION....
OPEN I-O TRANSACTIONS SYNCDEPTH 2....
MOVE TASK-CODE TO TRAN-CODE.
MOVE ACCOUNT-IN TO TRAN-ACCOUNT-NUMBER.
Communicating With a Process 917