Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

SET statement

Function

The SET statement offers the following options with its various formats:

Format 1

sets an integer data item, index or index data item to a specified value.

Format 2

increments or decrements the value of an index-name to represent a new occurrence number.

Format 3

changes the status of external switches

Format 4

sets the value of conditional variables

Format 5

assigns object references

Format 6

assigns data pointer

Format 7

works with data pointers

Format 8

assigns program pointers

Format 9

reset the last exception status

Format 1


SET {index-1 | identifier-1}... TO {index-2 | identifier-2 | integer-1}


Syntax rules

In the following notes, all references to index-1 and identifier-1 apply equally to all recursions thereof.

  1. Each index must be specified in an INDEXED BY phrase of an OCCURS clause.

  2. Each identifier must reference either an index data item or a fixed-point numeric elementary item described as an integer.

  3. The value of integer-1 or identifier-2 must be a valid occurrence number in the corresponding table. The compiler does, however, permit other integer values (e.g. 0 or negative numbers) within the permissible value range for index-1 (see section "Indexing" ).

  4. Indices or identifiers preceding the TO specify the item whose value is to be set.

  5. index-2, identifier-2 and integer-1 (which follow the TO) specify the value to which the receiving item (e.g. index-1) is to be set.

  6. When the SET statement is executed, one of the following actions occurs:

    1. index-1 is set to a value causing it to refer to the table element that corresponds in occurrence number to the table element referenced by index-2, identifier-2, or integer-1.

      If identifier-2 references an index data item, or if index-2 is related to the same table as index-1, no conversion takes place.
    2. If identifier-1 is an index data item, it is set equal to either the contents of index-2 or identifier-2, where identifier-2 is also an index data item. No conversion takes place. integer-1 cannot be used in this case.

    3. If identifier-1 is not an index data item, it is set to an occurrence number that corresponds to the value of index-2. Neither identifier-2 nor integer-1 can be used in this case.

      This process is repeated for each recurrence of index-1 or identifier-1. Each time, the value of index-2 or identifier-2 is used as it was at the beginning of the execution of the statement. Any subscripting or indexing associated with identifier-1 is evaluated before the value of the respective data item is changed.
  7. The table below indicates the validity of various operand combinations in the SET statement. The letters following the slashes refer to the rules listed above under point 7; for example, valid/c indicates that a combination of items is valid according to rule c) above.


    Sending item

    Receiving item

    Integer data item
    PIC9(n)

    Index-name
    INDEXED BY

    Index-name
    USAGE IS INDEX

    Integer literal

    no/c

    valid/a

    no/b

    Integer data item

    no/c

    valid/a

    no/b

    Index-name

    Index data item

    valid/c

    no/c

    valid/a

    valid/a*

    valid/b*

    valid/b*

    Table 31: Valid uses of the SET statement

    * = no conversion takes place.

  8. If index-2 is used, its value prior to execution of the SET statement must correspond to an occurrence number of an element in the associated table

Example 8-70

Data Division entries:


    02 TABLE-A PICTURE XXX OCCURS 50,
               INDEXED BY IN-A1, IN-A2, IN-A3.
    02 TABLE-B PICTURE XX OCCURS 55,
               INDEXED BY IN-B.
77 ID-1 USAGE IS INDEX.
77 D-1 PICTURE IS S999, USAGE IS COMPUTATIONAL-3.


The Procedure Division statements are shown in the tabular presentation below:

Statement

Operands used

Action taken 1

SET IN-A2 TO IN-A1

Index-name set to index-name

Simple move (displacement to displacement).

SET IN-A1 TO D-1

Index-name set to numeric data item

Multiply (numeric item minus 1) by item length to get displacement.

SET IN-A1 TO ID-1

Index-name set to index data item

Simple move (displacement to displacement).

SET IN-A1 TO 4

Index-name set to literal

Multiply (literal minus 1) 2 by item length to get displacement.

SET ID-1 TO IN-A1

Index data item set to index-name

Simple move (displacement to displacement)

SET D-1 TO IN-A1

Numeric data item set to index-name

Divide displacement by item length and add 1, to get occurrence number.

SET IN-B TO IN-A1

Index-name set to index-name (different tables)

Divide displacement (i.e., contents of IN-A1) by item length for TABLE-A and add 1, to get occurrence number. Then, multiply (occurrence number minus 1) by item length for TABLE-B, to get displacement.

1  See section "Indexing" for the relationships between occurrence number and displacement.

2  Calculated at compilation time; simple move during program run.

Example 8-71

02  TABLE-A OCCURS 50 TIMES
              INDEXED BY IND-1,IND-2,PIC 999.
 .
 .
 .
SET IND-1 TO 5.
SET IND-2 TO 7.
SET IND-1,TABLE-A (IND-1) TO IND-2.

The third SET statement is equivalent to the following two statements, which are executed in the order in which they appear:

Statement

Action

SET IND-1 TO IND-2

IND-1 is set to the occurrence number 7, the current value of IND-2.

SET TABLE-A (IND-1) TO IND-2

Since the first SET statement sets IND-1 to 7,
TABLE-A (IND-1) = TABLE-A (7).
Thus, this statement sets TABLE-A (7) to 7.

Format 2


SET {index-3}... {UP BY | DOWN BY} {identifier-3 | integer-2}


Syntax rules

  1. Each index must be specified in an OCCURS clause with INDEXED BY phrase.

  2. index-3... specifies the storage index whose value is to be changed.

  3. identifier-3 must be a fixed-point numeric elementary item described as an integer.

  4. integer-2 must be a non-zero integer and may contain a positive sign.

  5. The UP BY or DOWN BY phrase specifies that the contents of the index specified is to be either incremented (UP BY) or decremented (DOWN BY) by a value which corresponds to the occurrence number representing the value of identifier-3 or integer-2.

Example 8-72


02  TABLE-A PICTURE X(20) OCCURS 5 INDEXED BY IND-1.
    .
    .
    .
SET IND-1 TO 4.
SET IND-1 UP BY 2.
SET IND-1 DOWN BY 3.

The first SET statement sets index IND-1 to occurrence number 4; the second, to 6 (i.e. 4 + 2); and the third, to 3 (i.e. 6 - 3).

Format 3


SET { {mnemonic-name-1}... TO {ON | OFF} }...


Syntax rule

  1. Each mnemonic-name must be associated with an external switch whose status can be altered (see section "Condition-name condition").

Format 4


SET { {condition-name-1}... TO {TRUE | FALSE } }...


Syntax rules

  1. condition-name-1 must be associated with a conditional variable (see section "Condition-name condition").

  2. If FALSE is specified in the SET statement, it must also be specified in the VALUE clause of the condition-name.

General rules

  1. The literal specified in the VALUE clause and associated with condition-name-1 is entered in the conditional variable according to the rules governing the VALUE clause (see section "VALUE clause").
    However, if a group is subordinate to the conditional variable, its length is determined in accordance with the rules of the OCCURS clause (see section "OCCURS clause").

    If more than one literal is specified in the VALUE clause, the conditional variable is set to the value of the first literal appearing in the VALUE clause.
  2. If two or more condition-names are specified, they are treated as though a SET statement had been written for each individual condition-name.

  3. For "SET...TO FALSE", the literal specified with FALSE in the VALUE clause which is associated with condition-name is entered in the conditional variable according to the rules governing the VALUE clause (see "SET condition-name TO TRUE").

Example 8-73

IDENTIFICATION DIVISION.
PROGRAM-ID. DAYSET.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
    TERMINAL IS T.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  EXAMPLE1.
    02  WORKDAY  PICTURE X.
        88 MONDAY  VALUE "1".
        88 FRIDAY VALUE "5".
01 EXAMPLE2.
   02   WEEKDAY PIC X.
        88 WORKDAYS VALUE "1" "2" "3" "4" "5".
PROCEDURE DIVISION.
P1 SECTION.
SETTING.
    SET FRIDAY TO TRUE.
    DISPLAY "Workday =" WORKDAY UPON T.
    SET WORKDAYS TO TRUE.
    DISPLAY "Weekday =" WEEKDAY UPON T.
FINISH-PAR.
    STOP RUN.

Once the first SET statement has been performed, the data item WORKDAY (conditional variable) will contain the literal assigned in the VALUE clause to the condition-name FRIDAY: "5".
Once the second SET statement has been performed, the data item WEEKDAY will contain the literal "1".


Format 5


SET {identifier-5}... TO identifier-6


Syntax rules

  1. identifier-5 must be an object reference that is permitted as a receiving operand.

  2. identifier-6 must be a class-name or object reference; the predefined object reference SUPER may not be specified.

  3. If the data item referenced by identifier-5 is a universal object reference, all data of the class “object“ are permitted for identifier-6.

  4. If the data item referenced by identifier-5 is described with an interface-name that identifies the interface int-1, the data item referenced by identifier-6 must be one of the following:

    1. an object reference that specifies an interface-name for an interface that conforms with int-1;

    2. an object reference described with a class-name, subject to the following rules:

      • if described with a FACTORY phrase, the interface of the factory object of the specified class must conform with int-1;

      • if described without a FACTORY phrase, the interface of the objects of the specified class must conform with int-1;

    3. an object reference described with an ACTIVE-CLASS phrase, subject to the following rules:

      • if described with a FACTORY phrase, the interface of the factory object of the specified class containing the data item referenced by identifier-6 must conform with int-1;

      • if described without a FACTORY phrase, the interface of the objects of the specified class containing the data item referenced by identifier-6 must conform with int-1;

    4. a class, where the interface of its factory object conforms with int-1;

    5. the predefined object reference SELF, where the interface of the source unit containing the SET statement conforms with int-1;

    6. the predefined object reference NULL.

  5. If the data item referenced by identifier-5 is described with a class-name, the data item referenced by identifier-6 must be one of the following:

    1. an object reference described with a class-name, subject to the following rules:

      • If the data item referenced by identifier-5 is described with an ONLY phrase, the data ntifier-6 must also be described with the ONLY phrase. Furthermore, the class-name specified in the description of the data item referenced by identifier-6 must be the same as the class-name specified in the description of the data item referenced by identifier-5.

      • If the data item referenced by identifier-5 is described without an ONLY phrase, the class-name specified in the description of the data item referenced by identifier-6 must reference the same class or subclass specified in the description of the data item referenced by identifier-5.

      • The presence or absence of the FACTORY phrase must be the same as in the description of the data item referenced by identifier-5.

    2. an object reference described with an ACTIVE-CLASS phrase, subject to the following rules:

      • The data item referenced by identifier-5 must not be described with the ONLY phrase.

      • The class containing the data item referenced by identifier-6 must be the same class or a subclass of the class specified in the description of the data item referenced by identifier-5.

      • The presence or absence of the FACTORY phrase must be the same as in the description of the data item referenced by identifier-5.

    3. the predefined object reference SELF, subject to the following rules:

      • The data item referenced by identifier-5 must not be described with the ONLY phrase.

      • The class of an object containing the SET statement must be the same class or a subclass of the class specified in the description of the data item referenced by identifier-5.

      • If the data item referenced by identifier-5 is described without a FACTORY phrase, the source unit containing the SET statement must be an object instance.

      • If the data item referenced by identifier-5 is described with a FACTORY phrase, the source unit containing the SET statement must be a factory object.

    4. a class-name, provided the following applies:

      • The description of the data item referenced by identifier-5 contains a FACTORY phrase.

      • If the data item to which identifier-5 refers is described with the ONLY phrase, the class name must be the same. Otherwise, it can be a subclass of the class by means of which the data item to which identifier-5 refers is described.

    5. the predefined object reference NULL.

  6. If the description of the data item referenced by identifier-5 is described with an ACTIVE-CLASS phrase, the data item referenced by identifier-6 must be one of the following:

    1. an object reference described with the ACTIVE-CLASS phrase, where the presence or absence of the FACTORY phrase is the same as in the data item referenced by identifier-5;

    2. the predefined object SELF, subject to the following rules:

      • if the data item referenced by identifier-5 is described without a FACTORY phrase, the object containing the SET statement must be an object instance;

      • if the data item referenced by identifier-5 is described with a FACTORY phrase, the object containing the SET statement must be a factory object.

    3. the predefined object reference NULL.

General rules

  1. If identifier-6 is an object reference, a reference to the data item identified by identifier-5 is placed into each data item referenced by identifier-5 in the order specified.

  2. If identifier-6 is a class-name, a reference to the factory object of the class identified by identifier-5 is placed into each data item referenced by identifier-5 in the order specified.

Conformance of SET object references

The table below provides a summary of the combinations of object references in the sending and receiving items.

Combination

always permitted

o.k.

permitted conditionally

condition

forbidden

----

Notation of conditions

A > B

interface A is conformant to interface B:

A >> B

class A is subclass of B:

A == B

class A is the same class as class B:

Abbreviation

i5

Interface of receiving item

i6

Interface of sending item

c5

class of receiving item

c6

class of sending item

c

class corresponding to name

C

class containing SET statement1

FI(X)

interface of factory object of class X

OI(X)

interface of object object of class X

1 This refers to the method containing the SET statement is defined and not a class which inherits this method.



sending USAGE Object Reference


receiving
USAGE
Object Reference

universal

interface



i6

FACTORY
classname


c6

FACTORY
classname
ONLY

c6

classname



c6

classname
ONLY


c6

FACTORY
ACTIVE-
CLASS

C

ACTIVE-
CLASS


C

universal


o.k.

o.k.

o.k.

o.k.

o.k.

o.k.

o.k.

o.k.

interface

i5

----

i6 > i5

FI(c6)>i5

FI(c6)>i5

OI(c6)>i5

OI(c6)>i5

FI(C)>i5

OI(C)>i5

FACTORY
classname

c5

----

----

c6>>==c5

c6>>==c5

----

----

C>>==c5

----

FACTORY
classname
ONLY

c5

----

----

----

c6==c5

----

----

----

----

classname

c5

----

----

----

----

c6>>==c5

c6>>==c5

----

C>>==c5

classname
ONLY

c5

----

----

----

----

----

c6==c5

----

----

FACTORY
ACTIVE-
CLASS

C

----

----

----

----

----

----

o.k.

----

ACTIVE-
CLASS

C

----

----

----

----

----

----

----

o.k.

Table 32: combinations of object references in the sending and receiving items




sending

classname

SELF Object Reference

NULL

receiving
USAGE
Object Reference



c

in factory-method

C

in object-method

C


universal


o.k.

o.k.

o.k.

o.k.

interface

i5

FI(c)>i5

FI(C)>i5

OI(C)>i5

o.k.

FACTORY
classname

c5

c>>==c5

C>>==c5

----

o.k.

FACTORY
classname
ONLY

c5

c==c5

----

----

o.k.

classname

c5

----

----

C>>==c5

o.k.

classname
ONLY

c5

----

----

----

o.k.

FACTORY
ACTIVE-CLASS

C

----

o.k.

----

o.k.

ACTIVE-CLASS

C

----

----

o.k.

o.k.

Table 33: combinations of object references in the sending and receiving items

Format 6


SET {ADDRESS OF data-name-1 | identifier-7 ...} TO identifier-8


Syntax rules

  1. identifier-7 and identifier-8 must reference a data item of the category “data pointer”.

  2. data-name-1 must be a data item specified with the BASED clause.
    However, see also the compiler option PERMIT-STANDARD-DEVIATION.

  3. data-name-1 must not be defined with the ANY LENGTH clause.

  4. If identifier-7 is a type-specific pointer, identifier-8 must either be the predefined address NULL or a type-specific pointer to the same type. If data-name-1 is strongly typed, identifier-8 must be a type-specific pointer to the same type.

    If identifier-8 is a type-specific pointer, either identifier-7 must be a type-specific pointer to the same type or data-name-1 must be based on the type to which identifier-8 is linked.

General rules

  1. If identifier-7 is specified then the address specified by identifier-8 is stored in the data item referenced by identifier-7.

  2. If data-name-1 is specified then the address specified by identifier-8 is assigned to the data item referenced by data-name-1.

Format 7


SET identifier-9 ... {UP | DOWN} BY {identifier-10 | integer-3}


Syntax rules

  1. identifier-10 must be a numeric fixed-point item described as an integer.

  2. integer-3 must be an integer or 0 and may be signed.

  3. identifier-9 must belong to the class "data pointer”.

  4. identifier-9 may not be a type-specific pointer for which STRONG applies in the associated type declaration.

General rule

  1. The address present in the pointer item is incremented by the number of bytes defined in identifier-10 or integer-3 if UP is specified and decremented by the same value if DOWN is specified.

Format 8


SET {identifier-11}... TO identifier-12


Syntax rule of format 8

  1. identifier-11 must be a data item of the category “program pointer”. identifier-12 must be of the catefory “program pointer”.

General rule of format 8

  1. The address identified with identifier-12 is stored in the specified order in each identifier-11 data item.

Format 9


SET LAST EXCEPTION TO OFF


General rule of format 9

  1. The last exception condition is reset, i.e. it indicates that no exception condition was triggered.