COBOL - Data LayoutCOBOL Layout is a description of the usage of each field and its values. The data description entries in COBOL are as follows:
Redefines EntriesThe Redefines clause defines storage with various descriptions of data. If one or more data items are used at the same time, the same storage for other data items can be used. Syntax:Here, data-name1/FILLER is the REDEFINING date item. And data-name2 is REDEFINED data item. Any number of times, a REDEFINED data item can be redefined. But it is not possible to redefine the REDEFINING item. Example:Here, A is the Redefined item and B and C is Redefining item. The level numbers of redefined items and redefining items must be the same, and the level numbers cannot be 66 or 88. With a redefining object, we cannot use the VALUE clause. Output: Renames ClauseThe Renames clause presents the existing data items with different names. It is used to reassemble the names of the data and to give them a new name. We may rename the new name of the data for elementary items or groups. The Renames clause is reserved at level 66. Syntax:Here, data-name-1 is the logical group's alternative name. Data-name-2 is a starting elementary item, and data-name-3 ends elementary data items in the basic group. The data-name-2 must be a group item if data-name-3 is not mentioned, and all elementary items under this RENAMED must be a data-name-1 item. There are some rules for RENAMES clause:
Example:Let's see one example through the COBOL program: Output: Usage ClauseThe usage clause is used to define the operating system where the data is stored in the file. With level numbers 66 or 88, we can use it. If the usage clause is mentioned in a group, the same usage clause will apply to all elementary items. The Usage clause decreases storage space, which implicitly increases the program's efficiency. The different options available with the usage clause are given below: DisplayThe Display clause is the default computation. The data item is stored in ASCII format in this clause and will take 1 byte for each character. The data is stored in the decimal form here. The display clause is applicable to all data types. The memory allocation for Display usage clause is given below:
Means, 1 digit/char = 1 byte The below example calculates the number of bytes required: COMP/COMPUTATIONWe can call the COMP usage clause as BINARY or COMPUTATION. The data item is stored in a binary format. Here, data items must be an integer. The memory allocation for the COMP Usage clause is given below:
Example: COMP-1/COMPUTATION-1 The data item equivalent to Float or Real is represented as a single-precision floating-point number. Data is stored internally in a hexadecimal format. The PIC clause is not accepted by COMP-1. Here one word is equal to 4 bytes. The COMP-1 memory calculations are given below:
COMP-2/ COMPUTATION-2 The data item is similar to long or double and is defined as a double-precision floating-point number. Data is stored internally in a hexadecimal format. COMP-2 does not define the PIC clause. Here 2 word is equal to 8 bytes.
COMP-3/ COMPUTATION-3 In packed decimal format, the data item is stored. Every digit takes half a byte (1 nibble), and the sign is stored in the nibble at the right.
The Formula to calculate the number of bytes required: CopybooksA COBOL copybook is a code selection specifying the structures of the data. If we use a specific data structure in many applications, we can use copybooks instead of writing the same data structure over and over again. To add a copybook to a program, we use the COPY statement. In the Working Storage Section, we can only use the COPY statement. The following example adds a copybook inside a COBOL program: Here, ABC is the copybook name. The following data items in ABC copybook can be used within a program: Next TopicCOBOL Conditional Statements |