Segmentation COBOL

Segmentation

Segmentation allows the user to segment the Procedure Division of a program, and to specify overlays among the segments.Thus, less runtime memory is required to execute the program.There is no provision for segmenting the data regions of a program.

Segments

When segmentation is used, the Procedure Division must be written as a series of sections.In addition, each section must be classified as belonging either to the fixed portion or to one of the independent segments of the object program as determined by the assignment of segment-numbers.All paragraphs that contain the same segment-number in their section headers are considered at object time to be one segment. Since segment-numbers can range from 0 through 127, it is possible to subdivide the object program into a maximum of 128 segments.Segmentation has no effect on the need to qualify procedure-names to ensure uniqueness.

Fixed Portion

The fixed portion of the object program is logically treated as if it were always in memory.All sections whose segment-number is less than 50 belong to the fixed portion. The fixed portion of the program is made up of two types of segments:fixed permanent segments and fixed overlayable segments.

A fixed permanent segment is a segment in the fixed portion that cannot be overlaid by any other part of the program. A fixed overlayable segment is a segment in the fixed portion that, although logically treated as if it were always in memory, can be overlaid by another segment so as to reduce memory utilization.Such a segment, if called for by the program, is always made available in its last-used state. Variation of the number of fixed permanent segments in the fixed portion can be accomplished by using the SEGMENT- LIMIT clause.

Independent Segments

An independent segment is defined as part of the object program that can overlay, and can be overlaid by, a fixed overlayable segment or another independent segment.An independent segment has a segment-number of 50 through 127.

An independent segment is in its initial state whenever control is transferred (either implicitly or explicitly) to that segment for the first time during the execution of the program.

On subsequent transfers of control to the segment, an independent segment is also in its initial state when:

  • Control is transferred to that segment as a result of the implicit transfer of control between consecutive statements from a segment with a different segment-number.
  • Control is transferred to that segment as the result of the implicit transfer of control between a SORT or MERGE statement, in a segment with a different segment-number, and an associated input or output procedure in that independent segment.
  • Control is transferred explicitly to that segment from a segment with a different segment-number.

On subsequent transfers of control to the segment, an independent segment is in its last-used state when:

  • Control is transferred implicitly to that segment from a segment with a different segment-number (except as noted previously).
  • Control is transferred to that segment as the result of the implicit transfer of control between a SORT or MERGE statement, in a segment with a different segment-number, and an associated input or output procedure in that independent segment.
  • Control is transferred explicitly to that segment as the result of the execution of an EXIT PROGRAM statement.

Segmentation Classification

Sections that are to be segmented are classified using a system of segment-numbers and the following criteria:

  • Logic Requirements.Sections that must be available for reference at all times, or are referred to very frequently, are normally classified as belonging to one of the permanent segments; sections that are used less frequently are normally classified as belonging either to one of the overlayable fixed segments or to one of the independent segments, depending on logic requirements.
  • Frequency of Use.Generally, the more frequently a section is referred to, the lower its segment-number; the less frequently it is referred to, the higher its segment-number.
  • Relationship to Other Sections. Sections that frequently communicate with one another should be given the same segment-numbers.

Segmentation Control

The logical sequence of the program is the same as the physical sequence except for specific transfers of control.Control may be transferred within a source program to any paragraph in a section; that is, it is not mandatory to transfer control to the beginning of a section.

Restrictions on Program Flow

When segmentation is used, the following restrictions are placed on the ALTER, PERFORM, MERGE and SORT statements.

ALTER Statement Restrictions

A GO TO statement in a section whose segment-number is greater than or equal to 50 must not be referred to by an ALTER statement in a section with a different segment-number.

PERFORM Statement Restrictions

A PERFORM statement in the fixed portion can have within its range, in addition to any declarative sections whose execution is caused within that range, only one of the following:

  • Sections or paragraphs wholly contained in the fixed portion.
  • Sections or paragraphs wholly contained in a single independent segment.

A PERFORM statement in an independent segment can have within its range, in addition to any declarative sections whose execution is caused within that range, only one of the following:

  • Sections or paragraphs wholly contained in the fixed portion.
  • Sections or paragraphs wholly contained in the same independent segment as that PERFORM statement.

MERGE Statement Restrictions

If a MERGE statement appears in the fixed portion, any output procedure referenced by that MERGE statement must be entirely within the fixed portion, or entirely within a single independent segment.

If a MERGE statement appears in an independent segment, any output procedure referenced by that MERGE statement must be entirely within the fixed portion, or entirely within the same independent segment as that MERGE statement.

SORT Statement Restrictions

If a SORT statement appears in the fixed portion, any input or output procedures referenced by that SORT statement must be entirely within the fixed portion, or entirely within a single independent segment.

If a SORT statement appears in an independent segment, any input or output procedures referenced by that SORT statement must be entirely within the fixed portion, or entirely within the same independent segment as that SORT statement.


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

COBOL Topics