In this topic, we described about the below sections -
In this chapter, we discuss about the terms that helps a non-COBOL programmer can relate with other programming languages for a better understanding. It introduces COBOL fundamentals for variables, structures, literals and constants, assigning and displaying values; intrinsic (built-in) functions and tables (arrays).
Variables, structures, literals and constants -
In COBOL also, the data being represented as variables, structures (group items), literals or constants. The data in a COBOL program can be alphabetic, alphanumeric or numeric.
Variables Usage - A variable is a data item whose value can change during the execution of a program. The value is restricted to the data type defined while specifying a name and a length for the data item.
Elementary data items and group items Usage - Data items can be parts of a hierarchical data structure. A data item that does not have subordinate data items is called an elementary item. A data item that is composed of one or more subordinate data items is called a group item.
literals Usage - A literal is a character string. If the value of the data item known before, use a literal representation of the data value in the PROCEDURE DIVISION.
constants Usage - A constant is a data item that has only one value. COBOL does not define standards for constants. However, a data item can define with an initial value by coding a VALUE clause in the data definition.
figurative constants Usage - Certain commonly used constants and literals are available as reserved words called figurative constants. In COBOL, the figurative constants are ZERO, SPACE, HIGH-VALUE, LOW-VALUE, QUOTE, NULL and ALL literal.
Assigning values to data items -
After a data item defined, a value can assign to it at any time. Assignment takes many forms in COBOL, depending on the assigning requirements during the execution of the program. Below table shows the task and how to do the task –
|Task||How to do it|
|Assign values to a data item or large data area.||Using one of these ways -|
|Assign the results of arithmetic.||Using COMPUTE , ADD, SUBTRACT , MULTIPLY or DIVIDE statements|
|Examine or replace characters or groups of characters in a data item.||Using the INSPECT statement|
|Receive values from a file.||Using the READ or READ INTO statement .|
|Receive values from a system input device or a file.||Using the ACCEPT statement|
|Create a constant.||Using the VALUE clause in the definition of the data item|
|One of these actions -
||Using the SET statement|
Displaying values on a screen or in a file -
- DISPLAY statement - Used to display the value of a data item on a screen or write it to a file.
- Using intrinsic functions (built-in functions) - COBOL have some built-in functions to get the desired results and these functions are called intrinsic functions. They have the capabilities for manipulating strings and numbers. Because the value of an intrinsic function is derived automatically at the time of reference and don't need to define functions in the DATA DIVISION. Define and use only the non-literal data items as arguments. Figurative constants are not allowed as arguments.
- Using tables (arrays) - In COBOL, arrays are called tables. A table is a set of logically consecutive data items that defines in the DATA DIVISION by using the OCCURS clause