The Inter-Program Communication module provides a facility by which a program can communicate with one or more programs. This communication is provided by the following:
The Inter-Program Communication module also permits communication between two programs by the sharing of data and the sharing of files.
Nested Source Programs
A source program is a syntactically correct set of COBOL statements.A source program may contain other source programs; these contained programs may reference some of the resources of the program within which they are contained.
A program may be directly or indirectly contained in another program. Program B is directly contained in program A if there is no program contained in program A that also contains program B. Program B is indirectly contained in program A if there exists a program contained in program A that also contains program B.
A file connector is a storage area that contains information about a file and is used as the linkage between a file-name and a physical file and between a file-name and its associated record area.
Global Names and Local Names
A data-name names a data item. A file-name names a file connector.These names are classified as either global or local.
A global name may be used to refer to the object with which it is associated either from within the program in which the global name is declared or from within any other program which is contained in the program which declares the global name.
A local name,however,may be used only to refer to the object with which it is associated from within the program in which the local name is declared. Some names are always global; some are always local; and some are either local or global depending upon specifications in the program in which the names are declared.
A record-name is global if the GLOBAL clause is specified in the record description entry by which the record-name is declared or, in the case of record description entries in the File Section,if the GLOBAL clause is specified in the file description entry for the file-name associated with the record description entry. A data-name is global if the GLOBAL clause is specified either in the data description entry by which the data-name is declared or in another entry to which that data description entry is subordinate. A condition-name declared in a data description entry is global if that entry is subordinate to another entry in which the GLOBAL clause is specified. However,specific rules sometimes prohibit specification of the GLOBAL clause for certain data description, file description or record description entries.A file-name is global if the GLOBAL clause is specified in the file description entry for that file-name.
A split-key-name is global if the GLOBAL clause is specified in the file description entry for the file-name of the file with which the split-key-name is associated.If a condition-name declared in a data description entry, a data-name, a file-name or a split-key-name is not global, the name is local.A constant-name is always global.Global names are transitive across programs contained within other programs.
External Objects and Internal Objects
Accessible data items usually require that certain representations of data be stored. File connectors usually require that certain information concerning files be stored.The storage associated with a data item or a file connector may be external or internal to the program in which the object is declared.
A data item or file connector is external if the storage associated with that object is associated with the run unit rather than with any particular program within the run unit. An external object may be referenced by any program in the run unit that describes the object. References to an external object from different programs using separate descriptions of the object are always to the same object. In a run unit,there is only one representative of an external object.
An object is internal if the storage associated with that object is associated only with the program that describes the object.External and internal objects may have global or local names.
A data record described in the Working-Storage Section is given the external attribute by the presence of the EXTERNAL clause in its data description entry. Any data item described by a data description entry subordinate to an entry describing an external record also attains the external attribute. If a record or data item does not have the external attribute,it is part of the internal data of the program in which it is described.
A file connector is given the external attribute by the presence of the EXTERNAL clause in the associated file description entry.A file connector without the external attribute is internal to the program in which the associated file-name is described.
The data records described subordinate to a file description entry which does not contain the EXTERNAL clause or a sort-merge file description entry,as well as any data items described subordinate to the data description entries for such records,are always internal to the program describing the file-name.If the EXTERNAL clause is included in the file description entry,the data records and the data items attain the external attribute.
Data records,subordinate data items and various associated control information described in the Linkage and Communication Sections of a program are always considered to be internal to the program describing that data.Special considerations apply to data described in the Linkage Section whereby an association is made between the data records described and other data items accessible to other programs.
Common Programs and Initial Programs
All programs which form part of a run unit may possess neither,one,or both of the attributes common and initial.
A common program is one which,even though it is directly contained within another program,may be called by any program directly or indirectly contained in that other program.The common attribute is attained by specifying the COMMON clause in the Identification Division of the program.The COMMON clause facilitates the writing of subprograms that are to be used by all the programs contained within a program.
An initial program is one whose program state is initialized when the program is called.Thus,whenever an initial program is called,its program state is the same as when the program was first called in that run unit.During the process of initializing an initial program that program’s internal data is initialized;thus,an item of the program’s internal data whose description contains a VALUE clause is initialized to that defined value,but an item whose description does not contain a VALUE clause is initialized to an undefined value.Files with internal file connectors associated with the program are not in the open mode.The control mechanisms for all PERFORM statements contained in the program are set to their initial states.The initial attribute is attained by specifying the INITIAL clause in the Identification Division of the program.
Sharing Data in a Run Unit
Two programs in a run unit may reference common data under the following circumstances:
Sharing Files in a Run Unit
Two programs in a run unit may reference common file connectors under the following circumstances:
Scope of Names
When programs are directly or indirectly contained within other programs,each program may use identical user-defined words to name objects independent of the use of these user-defined words by other programs.When identically named objects exist,a program’s reference to such a name,even when it is a different type of user-defined word,is to the object which that program describes rather than to the object possessing the same name but described in another program.
The following types of user-defined words may be referenced only by statements and entries in the program in which the user-defined word is declared:
The following types of user-defined words may be referenced by a program,provided that the compiler environment supports the associated library and the entities referenced are known to that system:
The following types of user-defined words when they are declared in a Communication Section may be referenced only by statements and entries in the program which contains that section:
The following types of names,when they are declared within a Configuration Section, may be referenced only by statements and entries either in the program that contains a Configuration Section or in any program contained within the program:
Specific conventions for declarations and references apply to the following types of user-defined words when the conditions listed above do not apply:
A program-name of a program is declared in the PROGRAM-ID paragraph of the Identification Division. A program-name may be referenced only by the CALL statement, the CANCEL statement,and the end program header.The program-names allocated to programs constituting a run unit are not necessarily unique but,when two programs in a run unit are identically named,at least one of those two programs must be directly or indirectly contained within another separately compiled program that does not contain the other of those two programs.
The following rules regulate the scope of a program-name.
Condition-Names,Constant-Names,Data-Names,File-Names,Record-Names and Split-Key-Names
Condition-names, constant-names, data-names, file-names, record-names, and split-key-names—when declared in a source program—may be referenced only by that program except when one or more of the names are global and the program contains other programs.
See the discussion of user-defined words for the requirements governing the uniqueness of the names allocated by a single program to be condition-names,constant-names,data-names,file-names,record-names,and split-key-names.
A program cannot reference any condition-name, constant-name, data-name,file-name, record-name, or split-key-name declared in any program it contains.
A global name may be referenced in the program in which it is declared or in any programs which are directly or indirectly contained within that program.
When a program,program B,is directly contained within another program,program A, both programs may define a condition-name, constant-name, a data-name, a file-name, a record-name, or a split-key-name using the same user-defined word.When such a duplicated name is referenced in program B,the following rules are used to determine the referenced object.
If a data item possessing either or both the external or global attributes includes a table accessed with an index,that index also possesses correspondingly either or both attributes.Therefore,the scope of an index-name is identical to that of the data-name which names the table whose index is named by that index-name and the scope of name rules for data-names apply.Index-names cannot be qualified.
Initial State of a Program
The initial state of a program is the state of a program the first time it is called in a run unit.
The internal data of the program contained in the Working-Storage Section and the Communication Section is initialized.If a VALUE clause is used in the description of the data item,the data item is initialized to the defined value.If a VALUE clause is not associated with a data item,the initial value of the data item is undefined.
Files with internal file connectors associated with the program are not in the open mode.The control mechanisms for all PERFORM statements contained in the program are set to their initial states.A GO TO statement referred to by an ALTER statement contained in the same program is set to its initial state.
A program is in the initial state:
End Program Header
The end program header indicates the end of the named source program.
program-name-1must conform to the rules for forming a user-defined word andliteral-1must be a nonnumeric literal.
A constant-name may not be used for literal-1.A constant-name used in place of literal-1will be treated as a program-name;the literal value assigned to the constant-name will not be used.
program-name-1orliteral-1must be identical to a program-name declared in a preceding PROGRAM-ID paragraph.
If a PROGRAM-ID paragraph declaring a specific program-name is stated between the PROGRAM-ID paragraph and the end program header declaring and referencing, respectively, another program-name, the end program header referencing the former program-name must precede that referencing the latter program-name.
The COPY statement provides the facility for copying text from user-specified library files into the source program. The effect of the interpretation of the COPY statement is to insert text into the source program, where it is treated by the compiler as part of the source program.
Library text is placed in the library as a function independent of the compiler, using any text-manipulation utilities that are available. Library text must conform to the same formatting rules that apply to source text.
A constant-name may not be used for literal-1 or literal-2. A constant-name used in place of literal-1 will be treated as a text-name; the literal value assigned to the constant-name will not be used.A constant-name used in place of literal-2 will be treated as a library-name; the literal value assigned to the constant-name will not be used.
literal-1, literal-2, literal-3 , or literal-4 may not be a concatenation expression.
A COPY statement may appear anywhere in a source program that a character-string or separator is allowed, except that a COPY statement may not be embedded within another COPY statement. The COPY statement may be embedded in the text referenced by the COPY statement.
A COPY statement must always be immediately followed by a period separator. That separator functions solely as a part of the COPY statement and does not terminate any sentence or entry in which the COPY statement may be embedded.
The first (or only) operand of a COPY statement may be written as a text-name or as a nonnumeric literal. If the file access name of the text file being referred to conforms to the requirements of a valid COBOL word— and it is not a reserved word—it may be written as a text-name;if it does not form a COBOL word and is made up of the following characters,it may still be a text-name:
In other words, writing the operand of a COPY statement as a nonnumeric literal is always permissible, but is required when the file access name is a reserved word, is longer than 30 characters or contains special characters other than those listed above.
In environments in which the concept of file libraries or directories has meaning, the first operand of a COPY statement may optionally be qualified by a library-name-1. Library-names are treated as the leading part of a file access name;the concatenation of the two values is used to locate the file to be copied. The interpretation of the concatenation of library-name-1 and text-name-1 is system dependent. The second operand of a COPY statement, when present, may be written as a word or as a nonnumeric literal, subject to the same considerations that apply to the first operand.
A COPY statement may be followed by additional text in area B of a source record. Multiple COPY statements may occur on a single source record.
Copy files may be nested up to five levels deep; they may contain a COPY statement. This nesting limit may be exceeded when a COPY statement appears as the last statement on the last record in a source or copy file; in such cases,the nesting level limit is raised to nine.The limit of five applies to open copy files; a COPY statement appearing at the end of a file allows the compiler to close that source or copy file before opening the one referenced in the COPY statement (that is, the compiler chains from one file to the next). The copy nesting level indicator is incremented when a COPY statement appears at the end of a file to indicate the logical nesting of the copied text. As a result,the copy level indicator does not always indicate the number of open input files and may, therefore, exceed five.
In the discussion that follows, a text word is considered a character or sequence of contiguous characters in columns 8 through 72 of records in a library, source program or in pseudo-text. These characters may be:
Library text is copied into the source program without change unless a REPLACING phrase is specified. When the REPLACING phrase is specified,the following rules apply.
For purposes of matching, a quoted string nonnumeric literal matches any other quoted string nonnumeric literal with the same value regardless of whether quotes or apostrophes were used as the delimiter. For purposes of matching, any form of a hexadecimal literal matches any other form of a hexadecimal literal that has the same value, regardless of whether an X or H is used for the initial character, whether quotes or apostrophes were used for delimiters and whether uppercase or lowercase letters are used to specify the value. A hexadecimal literal does not match a quoted string nonnumeric literal even if the actual values would be the same in the native character set.
For purposes of matching, each operand and operator of a concatenation expression is a separate text-word.
COPY Statement Examples
The REPLACE statement provides the ability to selectively replace source text within specified regions of the source program.
Format 1:Begin or Change Replacement)
Format 2:End Replacement
A Format 1 REPLACE statement specifies that within its scope each occurrence of pseudo-text-1 is to be replaced by the corresponding pseudo-text-2.
The scope of a Format 1 REPLACE statement begins with the first text word in the source program following the REPLACE statement,and it continues up to the next REPLACE statement or the end of the program.
A Format 2 REPLACE statement terminates the scope of any preceding Format 1 REPLACE statement.
A REPLACE statement may appear anywhere in a source program that a character-string may appear.It must be preceded by a separator period except when it is the first statement in a separately compiled program.It must be terminated by a separator period.
REPLACE statements are processed after COPY statements. The text produced by the action of a REPLACE statement must not contain a REPLACE statement. The source program that results from resolution of all COPY and REPLACE statements must form a syntactically correct source program,as defined in the rest of this manual.
The word REPLACE appearing in a comment-entry or in a position where a comment-entry may appear is considered part of the comment-entry.
pseudo-text-1must contain one or more text words. It must not consist entirely of a separator comma or a separator semicolon.
pseudo-text-2may contain zero, one, or more text words.
Character-strings within pseudo-text-1 and pseudo-text-2 may be continued.
The comparison operation that determines text replacement is done as follows:
pseudo-text-1 is equal, character for character, to the ordered sequence of source program text words. For purposes of matching,each occurrence of a separator comma, semicolon or space in pseudo-text-1 or in the source program text is considered to be a single space. Each sequence of one or more space separators is considered to be a single space.
For purposes of matching,a quoted string nonnumeric literal matches any other quoted string nonnumeric literal with the same value regardless of whether quotes or apostrophes were used as the delimiter. For purposes of matching,any form of a hexadecimal literal matches any other form of a hexadecimal literal that has the same value, regardless of whether an X or H is used for the initial character, whether quotes or apostrophes were used for delimiters and whether uppercase or lowercase letters are used to specify the value. A hexadecimal literal does not match a quoted string nonnumeric literal even if the actual values would be the same in the native character set.
For purposes of matching, each operand and operator of a concatenation expression is a separate text-word.
Comment lines and blank lines occurring in the scope or in pseudo-text-1 are ignored for purposes of matching, and the sequence of text words in the source program text and in pseudo-text-1 is determined by the rules for source format. Comment lines and blank lines appearing in pseudo-text-2 are copied into the source program unchanged whenever pseudo-text-2 is placed into the source program as a result of text replacement.
A comment or blank line in the scope is not replaced if it appears within the sequence of text words that match pseudo-text-1.
Debugging lines may appear within pseudo-text. Text words within a debugging line participate in the matching rules as if the D did not appear in the indicator area.
Text words inserted into the source program as a result of processing a REPLACE statement are placed in the source program according to the rules for source format. When copying text words of pseudo-text-2 into the source program, additional spaces may be introduced between text words where there is already a space, including the space that implicitly falls between source lines.
If additional lines are introduced into the source program as a result of the processing of REPLACE statements, the indicator area of the introduced lines contains the same character as the line on which the text being replaced begins unless that line contains a hyphen, in which case the introduced line contains a space.
If any literal withinpseudo-text-2 is too long to be accommodated on a single line without continuation to another line in the source program and the literal is not being placed on a debugging line, additional continuation lines are introduced to contain the remainder of the literal. A replacement literal may not be continued onto a debugging line.
REPLACE Statement Examples
COBOL Related Interview Questions
|VSAM Interview Questions||IBM - VSAM Interview Questions|
|IBM-CICS Interview Questions||JCL Interview Questions|
|IBM DB2 Interview Questions||IBM-JCL Interview Questions|
|DB2 Using SQL Interview Questions||IBM-JCL&VSAM Interview Questions|
|IBM Mainframe Interview Questions||COBOL, CICS, JCL, VSAM, DB2 Interview Questions|
|DB2 SQL Programming Interview Questions||IMS/DB Interview Questions|
|Mainframe DB2 Interview Questions|
Procedure Division Statements
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.