Communication Facility COBOL

The communication facility provides the ability to access, process, and create messages or portions thereof. It provides the ability to communicate through a Message Control System (MCS) with local and remote communication devices.

Message Control System

The implementation of the communication facility requires that an MCS be present in the operating environment of the object program.

The MCS is the logical interface to the operating system under which the object program operates. The primary functions of the MCS are the following:

  • To act as an interface between the object program and the network of communication devices, in much the same manner as an operating system acts as an interface between the object program and such devices as card readers, magnetic tapes, mass storage devices and printers.
  • To perform line discipline, including such tasks as dial-up, polling and synchronization.
  • To perform device-dependent tasks, such as character translations and insertion of control characters, so that the user can create device-independent programs.

The first function that of interfacing the object program with the communication devices, is the most obvious to the user. In fact, the user may be unaware that the other two functions exist. Messages from communication devices are placed in input queues by the MCS while awaiting disposition by the object program. Output messages from the object program are placed in output queues by the MCS while awaiting transmission to communication devices. The structures, formats, and symbolic names of the queues are defined by the user to the MCS at some time prior to the execution of the object program. Symbolic names for message sources and destinations are also defined at that time. The user must specify, in the program, symbolic names that are known to the MCS.

During the execution of an object program, the MCS performs all necessary actions to update the various queues as required.

Object Program

The object program interfaces with the MCS when it is necessary to send data, receive data, or to interrogate the status of the various queues that are created and maintained by the MCS.In addition, the object program may direct the MCS to establish or break the logical connection between the communication device and a specified portion of the MCS queue structure. The method of handling the physical connection is a function of the MCS.

Relationship of the Object Program to the Message Control System and Communication Devices

The interfaces that exist in a communication environment are established by the use of a CD and associated clauses in the Communication Section of the Data Division. There are two such interfaces:

  1. The interface between the object program and the MCS.
  2. The interface between the MCS and the communication devices.

The source program uses four statements to control the interface with the MCS:

  1. The RECEIVE statement, which causes data in a queue to be passed to the object program
  2. The SEND statement, which causes data associated with the object program to be passed to one or more queues
  3. The ACCEPT statement with the MESSAGE COUNT phrase, which causes the MCS to indicate to the object program the number of complete messages in the specified queue structure
  4. The PURGE statement, which causes the MCS to eliminate a partial message which has been released by one or more SEND statements

The source program uses two statements to control the interface between the MCS and communication devices:

  1. The ENABLE statement, which establishes a logical connection between the MCS and one or more communication devices
  2. The DISABLE statement, which breaks a logical connection between the MCS and one or more communication devices

Invoking the Object Program

There are two methods of invoking an object program that makes use of the communication facility:

  1. Scheduled initiation
  2. MCS invocation

The only operating difference between the two methods is that MCS invocation causes the areas referenced by the symbolic queue and subqueue names in the specified CD to be filled.

Scheduled Initiation of the Object Program

An object program using the communication facility may be scheduled for execution through the normal means available in the operating environment of the program, such as job control language. In that case, the program can use three methods to determine what messages, if any, are available in the input queues:

  1. ACCEPT statement with the MESSAGE COUNT phrase
  2. RECEIVE statement with a NO DATA phrase
  3. RECEIVE statement without a NO DATA phrase (in which case a program wait is implied if no data is available)

Invocation of the Object Program by the Message Control System

It is sometimes desirable to schedule an object communication program only when there is work available for it to do. Such scheduling occurs if the MCS determines what object program is required to process the available message and subsequently causes that program to be scheduled for execution. Each object program scheduled by the MCS establishes a run unit. Prior to the execution of the object program, the MCS places the symbolic queue and subqueue names in the associated data items of the communication description entry that specifies the FOR INITIAL INPUT clause, or the MCS places the symbolic terminal name in the associated data item of the communication description entry that specifies the FOR INITIAL I-O clause.

A subsequent RECEIVE statement directed to that CD will result in the available message being passed to the object program.

Determining the Method of Scheduling

A source program can be written so that its object program can operate with either of the two modes of scheduling. The following technique may be used to determine which method was used to load the object program:

  • One CD must contain a FOR INITIAL INPUT clause or a FOR INITIAL I-O clause.
  • When the program contains a CD with the FOR INITIAL INPUT clause, the Procedure Division may contain statements to test the initial value of the symbolic queue name in that CD. If it is space filled, the object program was activated by the normal runtime invocation process. If it is not space filled, the MCS has invoked the object program and initialized the data item with the symbolic name of the queue containing the messages to be processed.
  • When the program contains a CD with the FOR INITIAL I-O clause, the Procedure Division may contain statements to test the initial value of the symbolic terminal name in that CD. If it is space filled, the object program was activated by the normal runtime invocation process. If it is not space filled, the MCS has invoked the object program and initialized the data item with the symbolic name of the communication terminal that is the source of the message to be processed.

Concept of Messages and Message Segments

A message consists of an arbitrary amount of information, usually character data, whose beginning and end are defined or implied. As such, messages comprise the fundamental but not necessarily the most elementary unit of data to be processed in a communication environment.

Messages may be logically subdivided into smaller units of data called message segments, which are delimited within a message by means of end of segment indicators (ESI). A message consisting of one or more segments is delimited from the next message by means of an end of message indicator (EMI). In a similar manner, a group of several messages may be logically separated from succeeding messages by means of an end of group indicator (EGI). When a message or message segment is received by the program, a communication description interface area is updated by the MCS to indicate which, if any, delimiter was associated with the text transferred during the execution of that RECEIVE statement. On output the delimiter, if any, to be associated with the text released to the MCS during the execution of a SEND statement is specified or referenced in the SEND statement. Thus, the presence of these logical indicators is recognized and specified both by the MCS and by the object program; however, no indicators are included in the message text processed by programs.

A precedence relationship exists between the indicators EGI, EMI and ESI. EGI is the most inclusive indicator and ESI is the least inclusive indicator. The existence of an indicator associated with message text implies the association of all less inclusive indicators with that text. For example, the existence of the EGI implies the existence of EMI and ESI.

Concept of Queues

The following discussion applies only when the communication environment is established using a CD without the FOR I-O clause.

Queues consist of one or more messages from or to one or more communication devices. They form the data buffers between the object program and the MCS. Input queues are logically separate from output queues.

The MCS logically places in queues or removes from queues only complete messages. Portions of messages are not logically placed in queues until the entire message is available to the MCS. That is, the MCS does not pass a message segment to an object program until all segments of that message are in the input queue, even though the source program uses the SEGMENT phrase of the RECEIVE statement.For output messages, the MCS does not transmit any segment of a message until all of its segments are in the output queue. The number of messages that exist in a given queue reflects only the number of complete messages that exist in the queue.

The process by which messages are placed into a queue is called enqueueing. The process by which messages are removed from a queue is called dequeueing.

Independent Enqueueing and Dequeueing

It is possible that a message may be received by the MCS from a communication device prior to the execution of the object program. In this case, the MCS enqueues the message in the proper input queue until the object program requests dequeueing with the RECEIVE statement. It is also possible that an object program will cause the enqueueing of messages in an output queue, which are not transmitted to a communication device until after the object program has terminated. Two common reasons for such occurrences are as follows:

  1. The output queue is disabled.
  2. The object program creates output messages at a speed faster than the destination can receive them.

Enabling and Disabling Queues

Usually, the MCS enables and disables queues based on circumstances not necessarily related to the program, such as time of day or message activity. However, the program has the ability to enable and disable queues itself by using the ENABLE and DISABLE statements.

A key is required in both statements in order to prevent indiscriminate use of the facility by a user who is not aware of the total network environment, and who may, therefore, disrupt system functions by the untimely issuance of ENABLE and DISABLE statements. However, this action never interrupts a transmission.

Queue Hierarchy

In order to control more explicitly the messages being enqueued and dequeued, it is possible to define in the MCS a hierarchy of input queues, that is, queues comprising queues. Four levels of queues are available. In order of decreasing significance, the queue levels are named queue, sub-queue-1, sub-queue-2 and sub-queue-3.


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

COBOL Topics