The SET Statement

ANS85The SET statement is used to alter the status of external switches.

ANS85The SET statement is used to alter the value of conditional variables.

VSC2MFThe SET statement is used to assign the address of a data item to a pointer data item. It is also used to adjust the contents of a pointer data item.

The SET statement establishes reference points for table handling operations by setting indices associated with table elements.

MFThe SET statement is used to assign the address of a program or an entry-point in a program to a procedure-pointer data item.

ISO2002MFThe SET statement is used to assign the address of a pointer to a program-pointer data item.

ISO2002MFThe SET statement is used to assign object references.

MFThe SET statement is used to alter the value of a synchronization data item.

MFThe SET statement is used to assign the address of a synchronization data item to another synchronization data item.

General Formats
ANS85Format 1

ANS85

ANS85Format 2

ANS85

VSC2MFFormat 3

VSC2MF

ISO2002MFFormat 4

ISO2002MF

Format 5

Format 6

MFFormat 7

MF

ISO2002MFFormat 8

ISO2002MF

MFFormat 9 (Value of Event-pointer)

MF

MFFormat 10 (Address of Event-pointer)

MF

MFFormat 11 (Value of Monitor-pointer)

MF

MFFormat 12 (Address of Monitor-pointer)

MF

MFFormat 13 (Value of Mutex-pointer)

MF

MFFormat 14 (Address of Mutex-pointer)

MF

MFFormat 15 (Value of Semaphore-pointer)

MF

MFFormat 16 (Address of Semaphore-pointer)

MF

Directives
  1. In addition to Compiler directives which provide flagging and modify the reserved word list, the following directives may impact either the syntax or the semantics described in this section.
Syntax Rules
    All Formats
  1. The figurative constant NULL or NULLS or the data item referenced by pointer-name-2 or procedure-pointer-name-2 represents the sending area. ADDRESS OF identifier-2, ENTRY identifier-8, ENTRY literal-1 or the value held in the sending area, represents the sending value.

    The data item referenced by pointer-name-1, pointer-name-3 or procedure-pointer-name-1 or the COBOL system area implied by ADDRESS OF identifier-1 represents the receiving area.

    Identifier-3, integer-1 or LENGTH OF identifier-4 represents the increment value.

  2. ANS85Format 1
  3. ANS85Mnemonic-name-1 must be associated with an external switch, the status of which can be altered.

    MFSee the topic The Special-Names Paragraph for details of which external switches can be referenced in the SET statement.

  4. ANS85Format 2
  5. ANS85Condition-name-1 must be associated with a conditional variable.
  6. MFIf the FALSE phrase is specified, the FALSE phrase must be specified in the VALUE clause of the Data Description entry for condition-name-1.
  7. MFEach FALSE or TRUE phrase applies to the occurrences of condition-name-1 that precede that phrase and follow a previous FALSE or TRUE phrase, if any.
  8. VSC2MFFormat 3
  9. VSC2MFIdentifier-1 must reference a level 01 or level 77 data item that is declared in the Linkage Section.
  10. ISO2002VSC2MFOS390Identifier-2 must reference a data item with a level of 77 or between 01 and 49 inclusive.

    ISO2002VSC2Identifier-2 must be declared in the Linkage Section.

    OS390Identifier-1 must be declared in the Linkage Section, the Local-Storage Section or the Working-Storage Section

  11. VSC2MFPointer-name-1, pointer-name-2 must each be an identifier that references an elementary data item with USAGE IS POINTER.
  12. ISO2002MFFormat 4
  13. MFPointer-name-3 must be an identifier that references an elementary data item with USAGE IS POINTER.
  14. MFIdentifier-3 must be an elementary numeric integer.
  15. MFInteger-1 may be signed.
  16. Format 5
  17. Identifier-5 and identifier-6 must each reference an index data item or an elementary item described as an integer. If both are specified, they must not both reference an elementary item.
  18. Formats 5 and 6
  19. Integer-2 and integer-3 may be signed. Integer-2 must be positive.
  20. Format 6
  21. Identifier-7 must reference an elementary numeric integer.
  22. MFFormat 7
  23. MF Procedure-pointer-name-1 and procedure-pointer-name-2 must each be an identifier that references an elementary data item with USAGE IS PROCEDURE-POINTER.
  24. MFIdentifier-8 must be defined as an alphanumeric data item such that its value can be a COBOL or a non-COBOL program name.
  25. MFLiteral-1 must be a nonnumeric literal.
  26. ISO2002MFFormat 8
  27. ISO2002MFIdentifier-9 must be any item of class object that is permitted as a receiving item.
  28. ISO2002MFIdentifier-10 must be a class-name or an object reference; the predefined object reference SUPER must not be specified.
  29. ISO2002MFIf the data item referenced by identifier-9 is a universal object reference, the only predefined object references that may be specified for identifier-10 are SELF and NULL.
  30. ISO2002MFIf the data item referenced by identifier-9 is described with an interface-name that identifies the interface int-1, the data item referenced by identifier-10 must be one of the following:
    1. An object reference described with an interface-name that identifies int-1 or an interface inheriting from int-1.
    2. An object reference described with a class-name, subject to the following rules:
      1. If described with a FACTORY phrase, the factory object of the specified class must implement int-1
      2. If described without a FACTORY phrase, the instance objects of the specified class must implement int-1.
    3. An object reference described with an ACTIVE-CLASS phrase, subject to the following rules:
      1. If described with a FACTORY phrase, the factory object of the class containing the data item referenced by identifier-10 must implement int-1.
      2. If described without a FACTORY phrase, the instance objects of the class containing the data item referenced by identifier-10 must implement int-1.
    4. A class-name whose factory object implements int-1.
    5. The predefined object reference SELF, subject to the following rules:
      1. If the SET statement is contained in a method within the factory definition of the class, that factory definition must be described with an IMPLEMENTS clause that references int-1.
      2. If the SET statement is contained in a method within the instance definition of the class, that instance definition must be described with an IMPLEMENTS clause that references int-1.
    6. The predefined object reference NULL
  31. ISO2002MFIf the data item referenced by identifier-9 is described with a class-name, the data item referenced by identifier-10 must be one of the following:
    1. An object reference described with a class-name, subject to the following rules:
      1. If the data item referenced by identifier-9 is described with an ONLY phrase, the data item referenced by identifier-10 must be described with the ONLY phrase, and the class-name specified in the description of the data item referenced by identifier-10 must be the same as the class-name specified in the description of the data item referenced by identifier-9
      2. If the data item referenced by identifier-9 is described without an ONLY phrase, the class-name specified in the description of the data item referenced by identifier-10 must reference the same class or a subclass of the class specified in the description of the data item referenced by identifier-9
      3. The presence or absence of the FACTORY phrase must be the same as in the description of the data item referenced by identifier-9
    2. An object reference described with an ACTIVE-CLASS phrase, subject to the following rules:
      1. The data item referenced by identifier-9 must not be described with the ONLY phrase
      2. The class containing the data item referenced by identifier-10 must be the same class or a subclass of the class specified in the description of the data item referenced by identifier-9
      3. The presence or absence of the FACTORY phrase must be the same as in the description of the data item referenced by identifier-9
    3. The predefined object reference SELF, subject to the following rules:
      1. The data item referenced by identifier-9 must not be described with the ONLY phrase
      2. The class of the 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-9
      3. If the data item referenced by identifier-9 is described without a FACTORY phrase, the object containing the SET statement must be an instance object
      4. If the data item referenced by identifier-9 is described with a FACTORY phrase, the object containing the SET statement must be a factory object
    4. A class-name, provided the data item referenced by identifier-9 is described with the FACTORY phrase, and class-name references the same class or a subclass of the class specified in the description of the data item referenced by identifier-9
    5. The predefined object reference NULL
  32. ISO2002MFIf the data item referenced by identifier-9 is described with an ACTIVE-CLASS phrase, the data item referenced by identifier-10 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-9
    2. The predefined object reference SELF, subject to the following rules:
      1. If the data item referenced by identifier-9 is described without a FACTORY phrase, the object containing the SET statement must be an instance object
      2. If the data item referenced by identifier-9 is described with a FACTORY phrase, the object containing the SET statement must be a factory object
    3. The predefined object reference NULL
  33. MFFormat 9 (Value of Event-pointer)
  34. MF Event-pointer-1 must be defined as a data item with USAGE EVENT-POINTER.
  35. MFFormat 10 (Address of Event-pointer)
  36. MFEvent-pointer-1 and event-pointer-2 must be defined as data items with USAGE EVENT-POINTER.
  37. MFFormat 11 (Value of Monitor-pointer)
  38. MF Monitor-pointer-1 must be defined as a data item with USAGE MONITOR-POINTER.
  39. MFIf the NOT phrase is specified, then the CONVERTING phrase must not be specified.
  40. MFFormat 12 (Address of Monitor-pointer)
  41. MFMonitor-pointer-1 and monitor-pointer-2 must be defined as data items with USAGE MONITOR-POINTER.
  42. MFFormat 13 (Value of Mutex-pointer)
  43. MF Mutex-pointer-1 must be defined as a data item with USAGE MUTEX-POINTER.
  44. MFFormat 14 (Address of Mutex-pointer)
  45. MFMutex-pointer-1 and mutex-pointer-2 must be defined as data items with USAGE MUTEX-POINTER.
  46. MFFormat 15 (Value of Semaphore-pointer)
  47. MF Semaphore-pointer-1 must be defined as a data item with USAGE SEMAPHORE-POINTER.
  48. MFIdentifier-11 must reference an integer.
  49. MFFormat 16 (Address of Semaphore-pointer)
  50. MFSemaphore-pointer-1 and semaphore-pointer-2 must be defined as data items with USAGE SEMAPHORE-POINTER.
General Rules
    ANS85Format 1
  1. ANS85The status of each external switch associated with the specified mnemonic-name-1 is modified such that the truth value resulting 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. (See the topic Switch-Status Condition in the chapter Procedure Division.)
  2. ANS85Format 2
  3. ANS85The literal in the VALUE clause associated with condition-name-1 is placed in the conditional variable according to the rules of the VALUE clause (see the section 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.
  4. ANS85If multiple condition-names are specified, 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.
  5. MFIf 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. (See the topic The VALUE Clause.)
  6. VSC2MFFormat 3
  7. VSC2MFThe sending value represents the address of a data item. If pointer-name-2 is specified, the sending value is the value contained with the data item referenced by pointer-name-2. If ADDRESS OF identifier-2 is specified, the sending value represents the address of identifier-2.
  8. VSC2MFIf pointer-name-1 is specified, the sending value is moved to the data name referenced by pointer-name-1.
  9. VSC2MFIf ADDRESS OF identifier-1 is specified, the sending value is moved to a COBOL system area and the runtime element subsequently operates such that the area of storage referenced by identifier-1 is located at the address represented by the sending value.

    MFWhether or not the link is retained between invocations of a subprogram is dependent on the STICKY-LINKAGE Compiler directive.

  10. ISO2002MFFormat 4
  11. MFBefore execution of the SET statement, the value of the data item referenced by pointer-name-3 must represent the address of a data item within a logical record, the original address. After execution of the SET statement, the value of the data item referenced by pointer-name-3 represents the new address. If the original address and the new address do not both lie within the same logical record, (or, for environments in which address space is segmented, within the same segment) then the results of using the value of the data item referenced by pointer-name-3 are undefined.
  12. MFIf the UP clause is specified, the new address is formed by adding the number of bytes given by the increment value to the original address.
  13. MFIf the DOWN clause is specified, the new address is formed by subtracting the number of bytes given by the increment value from the original address.
  14. Format 5
  15. The following steps are repeated for each recurrence of index-name-1 or identifier-5. Each time, the value of index-name-2 or identifier-6 is used as it was at the beginning of the execution of the statement. Any subscripting or indexing associated with identifier-5 is evaluated immediately before the value of that data item is changed.
    1. If index-name-1 is specified, index-name-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-name-2, identifier-6, or integer-2. If identifier-6 references an index data item, or if index-name-2 is related to the same table as index-name-1, no conversion takes place.
    2. If identifier-5 references an index data item, it can be set equal to either the contents of index-name-2 or identifier-6 where identifier-6 also references an index item; no conversion takes place in either case.
    3. If identifier-5 does not reference an index data item, it can be set only to an occurrence number that corresponds to the value of index-name-2. Neither identifier-6 nor integer-2 can be used in this case.
  16. The following table represents the validity of various operand combinations in the SET statement. The general rule reference indicates the applicable general rule.
    Sending Item Receiving Item
    Integer Data Item Index-Name Index Data Item
    Integer Literal No/11c Valid/11a No/11b
    Integer Data Item No/11c Valid/11a No/11b
    Index-Name Valid/11c Valid/11a Valid/11b1
    Index Data Item No/11c Valid/11a1 Valid/11b1
    Table 1: SET Index Statement Valid Operand Combinations

    1 = No conversion takes place.

  17. Formats 5 and 6
  18. Index-names are associated with a given table by being specified in the INDEXED BY phrase of the OCCURS clause for that table.
  19. 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 table associated with index-name-1. The value of the index associated with an index-name after the execution of a PERFORM or SEARCH statement may be set to an occurrence number that is outside the range of its associated table. (See the topic The PERFORM Statement and the topic The SEARCH Statement.)

    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 table associated with index-name-1.

    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 table associated with index-name-3.

  20. Format 6
  21. The contents of 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-3 or the data item referenced by identifier-7; thereafter, the process is repeated for each recurrence of index-name-3. For each repetition, the value of the data item referenced by identifier-7 is used as it was at the beginning of the execution of the statement.
  22. MFFormat 7
  23. MFThe sending value represents the address of the start of a procedure within a COBOL or non-COBOL program.
  24. MFThe sending value is moved to the data item referenced by procedure-pointer-name-1.
  25. MFIf procedure-pointer-name-2 is specified, the sending value is the value contained within the data item referenced by procedure-pointer-name-2.
  26. MFLiteral-1 or the content of the data item referenced by identifier-8 is the name of the referenced procedure. If the referenced procedure is a COBOL procedure, the name of the referenced procedure must contain the program-name contained in the Program-ID paragraph of the referenced program or the entry-name contained in the ENTRY statement of the referenced procedure.

    MFIf the program being called is not a COBOL program, the rules for the formation of the program or procedure name are given in your COBOL system documentation on interfacing.

    MFIf the referenced procedure has been previously made available and remains available at the time of execution of the SET statement, then the sending value represents the address of the referenced procedure.

    MFIf the referenced procedure is not available at the time of execution of the SET statement, then the sending value represents the address of a COBOL system error procedure.

  27. ISO2002MFFormat 8
  28. ISO2002MFIf identifer-10 is an object reference, a reference to the object identified by identifier-10 is placed into each data item referenced by identifier-9 in the order specified.
  29. ISO2002MFIf identifier-10 is a class-name, a reference to the factory object of the class identified by identifier-10 is placed into each data item referenced by identifier-9 in the order specified.
  30. MFFormats 9 and 10
  31. MFIf more than one event-pointer-1 is specified, the results are the same as if a separate SET statement had been written for each event-pointer-1 in the same order as specified in the SET statement.
  32. MFFormat 9 (Value of Event-pointer)
  33. MFThe execution of the SET statement sets the value of the event referenced by event-pointer-1 to TRUE or FALSE.

    MFNote: When an event is set to FALSE, the execution of any thread which executes a WAIT statement which references that event suspends until the event is set to TRUE in another thread.

  34. MFFormat 10 (Address of Event-pointer)
  35. MFEvent-pointer-1 is set to reference the same event data item that event-pointer-2 references.
  36. MFFormats 11 and 12
  37. MFIf more than one monitor-pointer-1 is specified, the results are the same as if a separate SET statement had been written for each monitor-pointer-1 in the same order as specified in the SET statement.
  38. MFFormat 11 (Value of Monitor-pointer)
  39. MFIf the NOT phrase is not specified, the value of the monitor referenced by monitor-pointer-1 is set to one of BROWSING, READING, or WRITING, thus establishing the corresponding form of lock. This specific lock type for this specific monitor must be eventually released by a SET statement either with a matching NOT phrase or a matching CONVERTING FROM phrase.

    For example, the lock established by

     SET mon-1 TO READING 

    can be cleared by

     SET mon-1 TO NOT READING
  40. MFThe CONVERTING phrase is used to change the current type of lock established on a monitor. The lock type specified in the FROM phrase must be currently established by that thread and upon successful execution of the statement, that lock will have been changed, in one atomic operation, to the lock type specified in the TO phrase.
  41. MFNested locks can be obtained by the execution of successive SET monitor statements with no intervening SET statement that releases the lock. Once a READING lock is established, no BROWSING or WRITING lock is allowed to nest within that thread. Once a BROWSING lock or a WRITING lock is established, any other level of lock is allowed to nest within that thread.
  42. MFFormat 12 (Address of Monitor-pointer)
  43. MFMonitor-pointer-1 is set to reference the same monitor data item that monitor-pointer-2 references.
  44. MFFormats 13 and 14
  45. MFIf more than one mutex-pointer-1 is specified, the results are the same as if a separate SET statement had been written for each mutex-pointer-1 in the same order as specified in the SET statement.
  46. MFFormat 13 (Value of Mutex-pointer)
  47. MFThe execution of the SET statement sets the value of the mutex referenced by mutex-pointer-1 to ON or OFF.
  48. MFWhen a mutex is set to ON, the execution of any thread that attempts to set that mutex to ON suspends until the mutex is set to OFF in the thread that set it ON.
  49. MFFormat 14 (Address of Mutex-pointer)
  50. MFMutex-pointer-1 is set to reference the same mutex data item that mutex-pointer-2 references.
  51. MFFormats 15 and 16
  52. MFIf more than one semaphore-pointer-1 is specified, the results are the same as if a separate SET statement had been written for each semaphore-pointer-1 in the same order as specified in the SET statement.
  53. MFFormat 15 (Value of Semaphore-pointer)
  54. MFThe contents of the semaphore data item referenced by semaphore-pointer-1 are incremented (UP BY) or decremented (DOWN BY) by a value that corresponds to the value of integer-4 or the data item referenced by identifier-11; thereafter, the process is repeated for each recurrence of semaphore-pointer-1. For each repetition, the value of the data item referenced by identifier-11 is used as it was at the beginning of the execution of the statement.
  55. MFIf a semaphore is set DOWN BY n and the semaphore is less than n, the thread is suspended until another thread raises the semaphore to above n.
  56. MFFormat 16 (Address of Semaphore-pointer)
  57. MFSemaphore-pointer-1 is set to reference the same semaphore data item that semaphore-pointer-2 references.