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
What you want to do | How to do it |
---|---|
Assign values to a data item or large data area. | Use one of these ways:
|
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:
|
Use the SET statement. |
Examples: initializing data items
Related tasks
Initializing a structure (INITIALIZE)
Assigning values to elementary data items (MOVE)
Assigning values to group data items (MOVE)
Assigning input from a screen or file (ACCEPT)
Joining data items (STRING)
Splitting data items (UNSTRING)
Assigning arithmetic results (MOVE or COMPUTE)
Tallying and replacing data items (INSPECT)
Processing data in an international environment
Initializing a structure (INITIALIZE)
Assigning values to elementary data items (MOVE)
Assigning values to group data items (MOVE)
Assigning input from a screen or file (ACCEPT)
Joining data items (STRING)
Splitting data items (UNSTRING)
Assigning arithmetic results (MOVE or COMPUTE)
Tallying and replacing data items (INSPECT)
Processing data in an international environment