The SET statement sets the values of various types of data items, allows you to control the current and active windows, and allows you to set the priority of a thread.
SET {result} ... TO value
SET {result} ... {UP } BY value
{DOWN}
SET { {cond-name} ... TO {TRUE } } ...
{FALSE}
SET { {switch-name} ... TO {ON } } ...
{OFF}
SET FILE-PREFIX TO file-prefix
SET {CONFIGURATION} { env-name TO env-value } ...
{ENVIRONMENT }
SET pointer TO { ADDRESS OF data-item }
{ NULL }
SET result-item TO SIZE OF data-item
SET ADDRESS OF linkage-item TO { pointer }
{ ADDRESS OF data-item}
{ NULL }
SET {INPUT } WINDOW TO window-1
{INPUT-OUTPUT}
{I-O }
{OUTPUT }
SET {handle-1} ... TO HANDLE OF {screen-1 }
{CONTROL ID id-1}
SET THREAD {thread-id} PRIORITY TO priority
SET EXCEPTION {VALUE } { exc-value TO {ITEM-HELP } } ...
{VALUES} {HELP-CURSOR }
{CUT-SELECTION }
{COPY-SELECTION }
{PASTE-SELECTION }
{DELETE-SELECTION }
{UNDO }
{SELECT-ALL-SELECTION}
Each result is set to value. This assignment is done such that the numeric values of result and value will be the same.
value is either added to (UP BY) or subtracted from (DOWN BY) each result item. No size error checking is done.
Format 4 of the SET statement alters the on/off status of external switches. These switches are initially off unless otherwise specified when the program is run.
SET ENVIRONMENT "FILE-PREFIX" TO file-prefix
If the ADDRESS OF option is used, then the address of data-item is stored in pointer. If the NULL option is used, then pointer is set to point to no data item.
Note that the -Zm compiler option Causes the compiler to generate code that tells the runtime the size of a data item specified in the SET statement. See Miscellaneous Options for details on the -Zm option.
The number of standard character positions occupied by data-item is stored in result-item.
Format 9 is helpful if you want to allocate a sizable piece of memory for temporary use, access this memory via a COBOL table, and then free the memory. For example:
The code sample that follows shows how Format 9 works.
identification division.
program-id. sample-program.
data division.
working-storage section.
linkage section.
* item-a and ptr-a are passed in by the calling
* program
01 item-a pic x(10).
* ptr-a is set to the address of item-a
* in the calling program
01 ptr-a usage pointer.
* item-b is used in the SET Statement.
* It is not passed in by the calling program.
01 item-b pic x(10).
procedure division using item-a, ptr-a.
main-logic.
* Assuming item-a has a value of "ABCDEFGHIJ",
* and ptr-a points to item-a,
* the following will display "ABCDEFGHIJ" three
* times
display item-a.
* "ABCDEFGHIJ" is displayed
set address of item-b to ptr-a.
display item-b.
* "ABCDEFGHIJ" is displayed
set address of item-b to address of item-a.
display item-b.
* "ABCDEFGHIJ" is displayed
stop run.
A Format 11 SET statement retrieves the handle to the control described by screen-1 or Id-1 and stores it in handle-1. Id-1 must specify a value greater than zero. If a matching control is found, handle-1 is set to the handle of that control. If no matching control is found, handle-1 is set to NULL. If more than one control has a matching ID, then handle-1 is arbitrarily set to one of those controls. Note that the handle can be used in any statement that can use control handles. One reason you might want this handle is if you need to pass a control to a subprogram. You cannot pass Screen Section names to subprograms, but you can pass the handle instead.
A Format 13 SET statement associates the exception value specified in exc-value with an automated action that the runtime can perform. Any keystroke, menu item, or control that produces the exc-value exception value will automatically cause the associated action to be performed (you do not have to code the action; it happens automatically). If the runtime handles the exception in this way, then the exception is not passed on to the COBOL program.
The ITEM-HELP action produces context-sensitive help for the control with the current input focus. The HELP-CURSOR action places the mouse into help mode. For a description of the ITEM-HELP and HELP-CURSOR actions, see The Help Processor in ACUCOBOL-GT User Interface Programming.
The remaining actions take effect if the current control is an entry field (otherwise, they have no effect). These actions cause the entry field to do the following:
| CUT-SELECTION | Cuts the current selection to the clipboard |
| COPY-SELECTION | Copies the current selection to the clipboard |
| PASTE-SELECTION | Pastes the clipboard into the entry field at the current location (replaces any existing selection) |
| DELETE-SELECTION | Deletes the current selection |
| UNDO | Undoes the last change |
| SELECT-ALL-SELECTION | Selects all the text in the entry field. In a multi-line entry field, this includes the text in all lines. |
The cut, copy, paste, delete, and undo effects are accomplished automatically via the ACTION property of entry fields. Usually, you will want to assign these exception values to various menu items and toolbar push buttons. When you are setting up a push button to correspond to one of these actions, you should ensure that you make the push button a SELF-ACT button (otherwise the act of pushing the button makes the button the current control, not the entry field).