RECEIVE Statement COBOL

The RECEIVE statement makes available to the program a message or a message segment and pertinent information about that data.

RECEIVE Statement

cd-name-1 must reference an input CD or an input-output CD.

If cd-name-1 references an input CD, the contents of the data items specified by data-name-1 (SYMBOLIC QUEUE) through data-name-4 (SYMBOLIC SUB-QUEUE-3) of the area referenced by cd-name-1 designate the queue structure containing the message.

If cd-name-1 references an input-output CD, the contents of the data item specified by data-name-3 (SYMBOLIC TERMINAL) of the area referenced by cd-name-1 designates the source of the message.

The message, message segment, or portion of a message or segment, is transferred to the receiving character positions of the area referenced by identifier-1 aligned to the left without space fill.

The data items identified by cd-name-1 are appropriately updated by the MCS at each execution of a RECEIVE statement.

A single execution of a RECEIVE statement never returns to the data item referenced by identifier-1 more than a single message (when the MESSAGE phrase is used) or a single segment (when the SEGMENT phrase is used).However, the MCS does not return any portion of a message to the object program until the entire message is available to the MCS, even when the SEGMENT phrase of the RECEIVE statement is specified.

Once the execution of a RECEIVE statement has returned a portion of a message, only subsequent execution of RECEIVE statements in that run unit can cause the remaining portion of the message to be returned.

NO DATA and WITH DATA Phrases

NODATA imperative -statement-1

WITH DATAimperative -statement-2

When, during the execution of a RECEIVE statement, the MCS makes data available in the data item referenced by identifier-1, the NO DATA phrase, if specified, is ignored and control is transferred to the end of the RECEIVE statement or, if the WITH DATA phrase is specified, to imperative-statement-2.In the latter case, execution continues according to the rules for each statement in imperative-statement-2.If a procedure branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-2, control is transferred to the end of the RECEIVE statement.

When, during the execution of a RECEIVE statement, the MCS does not make data available in the data item referenced by identifier-1, one of the following actions occurs:

  • If the NO DATA phrase is specified in the RECEIVE statement, the RECEIVE operation is terminated with the indication that action is complete and control is transferred to imperative-statement-1.Execution then continues according to the rules for each statement in imperative-statement-1.If a procedure branching or conditional statement that causes explicit transfer of control is executed, control is transferred in accordance with the rules for that statement; otherwise, upon completion of the execution of imperative-statement-1, control is transferred to the end of the RECEIVE statement and the WITH DATA phrase, if specified, is ignored.
  • If the NO DATA phrase is not specified in the RECEIVE statement, execution of the object program is suspended until data is made available in the data item referenced by identifier-1.
  • If one or more queues or subqueues are unknown to the MCS, the appropriate status key value is stored and control is then transferred as if data had been made available.

MESSAGE Phrase

MESSAGE

If the MESSAGE phrase is used, end of segment indicators are ignored, and the following rules apply to data transfer:

  1. If a message is the same size as the area referenced by identifier-1, the message is stored in the area referenced by identifier-1.
  2. If a message size is less than the area referenced by identifier-1, the message is aligned to the leftmost character position of the area referenced by identifier-1 with no space fill.
  3. If the message size is greater than the area referenced by identifier-1, the message fills the area referenced by identifier-1 left to right starting with the leftmost character of the message.The remainder of the message can be transferred to the area referenced by identifier-1 with subsequent RECEIVE statements that specify the same queue structure.The remainder of the message is treated as a new message.
  4. If an end of group indicator is associated with the text accessed by the RECEIVE statement, the existence of an end of message indicator is implied.

SEGMENT Phrase

SEGMENT

If the SEGMENT phrase is used, the following rules apply:

  1. If a segment is the same size as the area referenced by identifier-1, the segment is stored in the area referenced by identifier-1.
  2. If the segment size is less than the area referenced by identifier-1, the segment is aligned to the leftmost character position of the area referenced by identifier-1 with no space fill.
  3. If a segment size is greater than the area referenced by identifier-1, the segment fills the area referenced by identifier-1 left to right starting with the leftmost character of the segment.The remainder of the segment can be transferred to the area referenced by identifier-1 with subsequent RECEIVE statements that specify the same queue structure.The remainder of the segment is treated as a new segment.
  4. If the text to be accessed by the RECEIVE statement has associated with it an end of message indicator or end of group indicator, the existence of an end of segment indicator associated with the text is implied and the text is treated as a message segment.

RECEIVE Statement Examples


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

COBOL Topics