COBOL Manual for TNS/E Programs (H06.03+)
Process Initiation, Communication, and
Management
HP COBOL Manual for TNS/E Programs—520347-003
31-4
$RECEIVE
$RECEIVE
$RECEIVE is like one end of a communications conduit. It is similar to a courier who
brings you a message and can be dismissed or sent back with a reply.
From the perspective of a process, $RECEIVE appears to be a sequential file. The
syntax for communicating with $RECEIVE in an HP COBOL program is, therefore,
based on the syntax for communicating with an ordinary HP COBOL sequential file.
To receive a message from another process (including the operating environment), a
process must read $RECEIVE.
To reply to a message, a process must write to $RECEIVE. The operating environment
delivers the reply to the originator of the message. The process does not need to
determine where the message came from to reply to it.
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.
Topics:
•
$RECEIVE as Separate Input and Output Files
•
$RECEIVE as Input-Output File










