The SET statement is used to establish reference points for table handling operations, alter the status of external switches, and alter the value of conditional variables.
Format 1:Set Index
Format 2:Set Index Up/Down
Format 3:Set Switch On/Off
Format 4:Set Condition-Name True/False
Format 5:Set Pointer
Format 6:Set Pointer Up/Down
identifier-1 and identifier-2 must name either index data items, or elementary items described as an integer.
identifier-3 and identifier-7 must refer to elementary data items described as an integer.
integer-1 and integer-2 may be signed. integer-1 must be positive.
mnemonic-name-1 must be identified in the SPECIAL-NAMES paragraph of the Environment Division as one of the permissible switch-names SWITCH-1, SWITCH-2, . . ., SWITCH-8, or UPSI-0, UPSI-1, . . ., UPSI-7.
condition-name-1 must be associated with a conditional variable.
data-name-1 must be the name of a level 01 or level 77 data description entry that is described in the Linkage Section.
identifier-4 and identifier-6 must refer to elementary data items described with POINTER usage.
In Format 4, if the TRUE phrase is specified, the Format 2 VALUE clause, which is described, for the condition-name must either not specify a relational operator prior to the first listed literal or that first relational operator must be one that includes an equality relation. see “Condition-Name Rules (Format 2 VALUE Clause) ” for additional information regarding the use of a relational operator in the VALUE clause and the existence of a true value for purposes of the SET statement.
In Format 4, if the FALSE phrase is specified, the FALSE phrase must be specified in the VALUE clause of the data description entry for condition-name-1.
The general rules that apply to the SET statement are as follows:
Index-names are considered related to a given table and are defined by being specified in the INDEXED BY clause.
If index-name-2 is specified, the value of the index before the execution of the SET statement must correspond to an occurrence number of an element in the associated table.
If index-name-3 is specified, the value of the index both before and after the execution of the SET statement must correspond to an occurrence number of an element in the associated table. If index-name-1 is specified, the value of the index after the execution of the SET statement must correspond to an occurrence number of an element in the associated table. The value of the index associated with an index-name after the execution of a PERFORM statement may be undefined.
In Format 1, the following action occurs:
In Format 2, the contents of each index-name-3 are incremented (UP BY) or decremented (DOWN BY) by a value that corresponds to the number of occurrences represented by the value of integer-2 or of the data item referenced by identifier-3. Each time the value of identifier-3 is used as it was at the beginning of the execution of the statement.
Note:Standard COBOL does not require conversion of an index value (that is, the character offset within the table to a specific occurrence of a table element) to or from the occurrence number in either case. It is an error to code the following sequence when index-name-4 and index-name-5 are not associated with the same table:
SET index-data-item TO index-name-4.
SET index-name-5 TO index-data-item.
Generally, RM/COBOL cannot detect such errors. It treats index data items as if they contained occurrence numbers and converts to or from index values as necessary in SET statements. Programs that depend on this conversion will not necessarily execute correctly on other implementations of standard COBOL.
Table shows the validity of various operand combinations in the SET statement.
SET Statement Operand Validity
In Format 3, the status of each external switch associated with the specified mnemonic-name-1 is modified such that the truth value resultant from evaluation of a condition-name associated with that switch reflects an on status if the ON phrase is specified, or an off status if the OFF phrase is specified.
In Format 4 if the TRUE phrase is specified, the literal in the VALUE clause associated with condition-name-1 is placed in the conditional variable according to the rules for the VALUE clause. If more than one literal is specified in the VALUE clause, the conditional variable is set to the value of the first literal that appears in the VALUE clause.
In Format 4 if the FALSE phrase is specified, the literal in the FALSE phrase of the VALUE clause associated with condition-name-1 is placed in the conditional variable according to the rules for the VALUE clause.
If multiple condition-names are specified in Format 4, the results are the same as if a separate SET statement had been written for each condition-name-1 in the same order as specified in the SET statement.
In Format 5, the sending value represents the address of a data item. If identifier-6 is specified, the sending value is the value of the pointer data item referred to by identifier-6. If ADDRESS OF identifier-5 is specified, the sending value represents the address of the data item referred to by identifier-5. If NULL or NULLS is specified, the sending value is the null pointer value, which is not the address of any data item.
In Format 5, the receiving data item is either a pointer data item or the base address of a based linkage record. If identifier-4 is specified, the receiving data item is a pointer data item into which the sending value is stored. If ADDRESS OF data-name-1 is specified, the receiving data item is a system-defined base address pointer data item for the based linkage record. In the latter case, the object program subsequently operates as if the based linkage record identified by data-name-1 were located at the address represented by the sending value.
In Format 6, the UP phrase increments and the DOWN phrase decrements the offset field of a pointer receiving data item identified by identifier-4 r the base address of a based linkage record identified by data-name-1 by a given number of character positions. The number of character positions to increment or decrement the receiving value is given by integer-3, the value of the data item referred to by identifier-7, or the value returned by the LENGTH special register for identifier-8. If the receiving item initially has a null value, the Format 6 SET statement has no effect. If after the operation of the Format 6 SET statement, the offset exceeds the length field of the receiving pointer value no action is taken. However, if that resultant pointer value is used unchanged to reference a based linkage record, the run unit will be terminated with a data reference error 104. Note that, because the offset field of a pointer value is an unsigned quantity, setting it down below zero will generally result in a large positive number that exceeds the length field of the pointer value. Again, no error occurs until a later attempt is made to use the resultant pointer value.
SET 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.