Assigning values to data items

After you have defined a data item, you can assign a value to it at any time. Assignment takes many forms in COBOL, depending on what you want to do.

About this task

Table 1. Assignment to data items in a program
What you want to do How to do it
Assign values to a data item or large data area. Use one of these ways:
  • INITIALIZE statement
  • MOVE statement
  • STRING or UNSTRING statement
  • VALUE clause (to set data items to the values you want them to have when the program is in initial state)
Assign the results of arithmetic. Use COMPUTE, ADD, SUBTRACT, MULTIPLY, or DIVIDE statements.
Examine or replace characters or groups of characters in a data item. Use the INSPECT statement.
Receive values from a file. Use the READ (or READ INTO) statement.
Receive values from a system input device or a file. Use the ACCEPT statement.
Establish a constant. Use the VALUE clause in the definition of the data item, and do not use the data item as a receiver. Such an item is in effect a constant even though the compiler does not enforce read-only constants.
One of these actions:
  • Place a value associated with a table element in an index.
  • Set the status of an external switch to ON or OFF.
  • Move data to a condition-name to make the condition true.
  • Set a POINTER, PROCEDURE-POINTER, or FUNCTION-POINTER data item to an address.
Use the SET statement.

Examples: initializing data items