The SET statement is used to perform one of the following operations:
Index-names are related to a given table through the INDEXED BY phrase of the OCCURS clause; they are not further defined in the program.
When the sending and receiving fields in a SET statement share part of their storage (that is, the operands overlap), the result of the execution of that SET statement is undefined.
When this form of the SET statement is executed, the current value of the receiving field is replaced by the value of the sending field (with conversion).
| Format 1: SET (basic table handling) |
|---|
|
Must name an index that is specified in the INDEXED BY phrase of an OCCURS clause.
Must name either an index data item or an elementary numeric integer item. A receiving field cannot be a windowed date field.
Must name an index that is specified in the INDEXED BY phrase of an OCCURS clause. The value of the index before the SET statement is executed must correspond to an occurrence number of its associated table.
Must name either an index data item or an elementary numeric integer item. A sending field cannot be a windowed date field.
Must be a positive integer.
The following table shows valid combinations of sending and receiving fields in a format-1 SET statement.
| Sending field | Index-name
receiving field |
Index data item receiving field | Integer data item receiving field |
|---|---|---|---|
| Index-name* | Valid | Valid** | Valid |
| Index data item* | Valid** | Valid** | Invalid |
| Integer data item | Valid | Invalid | Invalid |
| Integer literal | Valid | Invalid | Invalid |
| *An index-name refers
to an index named in the INDEXED BY phrase of an OCCURS clause. An index
data item is defined with the USAGE IS INDEX clause.
**No conversion takes place. |
|||
Receiving fields are acted upon in the left-to-right order in which they are specified. Any subscripting or indexing associated with identifier-1 is evaluated immediately before that receiving field is acted upon.
The value used for the sending field is the value at the beginning of SET statement execution.
The value of an index after execution of a SEARCH or PERFORM statement can be undefined; therefore, use a format-1 SET statement to reinitialize such indexes before you attempt other table-handling operations.
If index-name-2 is for a table that has a subordinate item that contains an OCCURS DEPENDING ON clause, then undefined values can be received into identifier-1.
For more information about complex OCCURS DEPENDING ON, see the COBOL for Windows Programming Guide.
When this form of the SET statement is executed, the value of the receiving index is increased (UP BY) or decreased (DOWN BY) by a value that corresponds to the value in the sending field.
| Format 2: SET (adjusting indexes) |
|---|
|
The receiving field is an index specified by index-name-3. The index value both before and after the SET statement execution must correspond to an occurrence number in an associated table.
The sending field can be specified as identifier-3, which must be an elementary integer data item, or as integer-2, which must be a nonzero integer. identifier-3 cannot be a windowed date field.
When the format-2 SET statement is executed, the contents of the receiving field are increased (UP BY) or decreased (DOWN BY) by a value that corresponds to the number of occurrences represented by the value of identifier-3 or integer-2. Receiving fields are acted upon in the left-to-right order in which they are specified. The value of the incrementing or decrementing field at the beginning of SET statement execution is used for all receiving fields.
If index-name-3 is for a table that has a subordinate item that contains an OCCURS DEPENDING ON clause, and if the ODO object is changed before executing a format-2 SET Statement, then index-name-3 cannot contain a value that corresponds to an occurrence number of its associated table.
For more information about complex OCCURS DEPENDING ON, see the COBOL for Windows Programming Guide.
When this form of the SET statement is executed, the status of each external switch associated with the specified mnemonic-name is turned ON or OFF.
| Format 3: SET (external switches) |
|---|
|
When this form of the SET statement is executed, the value associated with a condition-name is placed in its conditional variable according to the rules of the VALUE clause.
| Format 4: SET (condition-names) |
|---|
|
If more than one literal is specified in the VALUE clause of condition-name-1, its associated conditional variable is set equal to the first literal.
If multiple condition-names are specified, the results are the same as if a separate SET statement had been written for each condition-name in the same order in which they are specified in the SET statement.
When this form of the SET statement is executed, the current value of the receiving field is replaced by the address value contained in the sending field.
Must be described as USAGE IS POINTER.
identifier-5 must be level-01 or level-77 items defined in the linkage section. The addresses of these items are set to the value of the operand specified in the TO phrase.
identifier-5 must not be reference-modified.
Must be described as USAGE IS POINTER.
Cannot contain an address within the program's own working-storage section, file section, or local-storage section.
Sets the receiving field to contain the value of an invalid address.
The following table shows valid combinations of sending and receiving fields in a format-5 SET statement.
| Sending field | USAGE IS POINTER receiving field | ADDRESS OF
receiving field |
NULL/NULLS
receiving field |
| USAGE IS POINTER | Valid | Valid | Invalid |
| ADDRESS OF | Valid | Valid | Invalid |
| NULL/NULLS | Valid | Valid | Invalid |
When this format of the SET statement is executed, the current value of the receiving field is replaced by the address value specified by the sending field.
At run time, function-pointers and procedure-pointers can reference the address of the primary entry point of a COBOL program, an alternate entry point in a COBOL program, or an entry point in a non-COBOL program; or they can be NULL.
COBOL function-pointers are more easily used than procedure-pointers for interoperation with C functions.
identifier-8 or literal-1 must refer to one of the following types of entry points:
The program-name referenced by the SET ... TO ENTRY statement can be affected by the PGMNAME compiler option. For details, see the COBOL for Windows Programming Guide.
The following example demonstrates a COBOL CALL to a C function that returns a function-pointer to a service, followed by a COBOL CALL to the service:
IDENTIFICATION DIVISION.
PROGRAM-ID DEMO.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 FP USAGE FUNCTION-POINTER.
PROCEDURE DIVISION.
CALL “c-function” RETURNING FP.
CALL FP.
When this format of the SET statement is executed the value in the receiving item is replaced by the value in the sending item.
| Format 7: SET (object reference data items) |
|---|
|
object-reference-id-1 and object-reference-id-2 must be defined as USAGE OBJECT REFERENCE. object-reference-id-1 is the receiving item and object-reference-id-2 is the sending item. If object-reference-id-1 is defined as an object reference of a certain class (defined as “USAGE OBJECT REFERENCE class-name”), object-reference-id-2 must be an object reference of the same class or a class derived from that class.
If the figurative constant NULL is specified, the receiving object-reference-id-1 is set to the NULL value.
If SELF is specified, the SET statement must appear in the procedure division of a method. object-reference-id-1 is set to reference the object upon which the currently executing method was invoked.