Data Division
This chapter explains the structure of the data division.
1. Overview
The following describes the data division structure, data unit, and data relationship.
-
FILE SECTION
Defines the data file structure. It must start with the "FILE SECTION." header.
Classification Description file-description-entry
Defines the physical file structure and identifier, and contains records related to the file.
record-description-entry
A set of data description entries related to the file.
The record must be alphabetic, alphanumeric, DBCS, numeric elementary item, or alphanumeric group item.
-
WORKING-STORAGE SECTION
Defines the structure of data records used in a program that are not part of a file. It must start with the "WORKING-STORAGE SECTION." header.
Classification Description record-description-entry
Consists of records with a hierarchical structure.
data-item-description-entry
Independent data item, which is not grouped, with the level of 77 or 01.
-
LOCAL-STORAGE SECTION
Defines storage that is allocated and freed at every invocation. Each data item with a VALUE clause is initialized to the value specified in the clause. It must start with the "LOCAL-STORAGE SECTION." header.
-
LINKAGE SECTION
Defines data that can be used through another program.
Data Relationships
-
Levels of data
-
Data record’s level number must be a number between 01 and 49, 66, 77, or 88.
Level Number Description 01
An alphanumeric group item or a 01-level elementary item.
02 - 49
A record elementary item included in a group, or a group.
Data hierarchy can be determined through the relationship between level-number items.
The following defines the hierarchical relationship for the same level number.
01 GROUP. 05 SUB01. 10 ELEM01 PIC X(10). 10 ELEM02 PIC X(5). 05 SUB02. 10 ELEM03 PIC 999. 10 ELEM04 PIC 999.
The following defines the same hierarchical relationship for different level numbers.
01 GROUP. 05 SUB01. 10 ELEM01 PIC X(10). 10 ELEM02 PIC X(5). 04 SUB02. 08 ELEM03 PIC 999. 08 ELEM04 PIC 999.
-
Special level-numbers
Level Number Description 66
Used to regroup and reuse previously defined data item. Must be used with a RENAMES clause.
77
Used to specify an independent item without subdivisions of data.
88
Used with a condition-name condition.
-
Classes and Categories of Data
COBOL data and literals can be classified into a specific category or class.
-
Class, category, and usage of elementary data Items
Class Category Usage Alphabetic
Alphabetic
DISPLAY
Alphanumeric
Alphanumeric
DISPLAY
Alphanumeric-edited
DISPLAY
Numeric-edited
DISPLAY
DBCS
DBCS
DISPLAY-1
Numeric
NUMERIC
DISPLAY
PACKED-DECIMAL, COMP-3
BINARY, COMP, COMP-4, COMP-5
Internal floating-point
COMP-1
COMP-2
External floating-point
DISPLAY
-
Classes and categories of functions
Function-type Class and Category Alphanumeric
Alphanumeric
DBCS
DBCS
Numeric, Integer
Numeric
-
Classes and categories of literals
Literal Class and Category Alphanumeric
Alphanumeric
DBCS
DBCS
Numeric(fixed, floating)
Numeric
Data Item Category Descriptions
The following describes each category of data items. For more information about each category, refer to PICTURE Clause.
-
Alphabetic
Items defined as alphabetic by its PICTURE character.
-
Alphanumeric
Items defined as alphanumeric by its PICTURE character.
-
Alphanumeric group item.
-
Alphanumeric function.
-
-
Alphanumeric-edited
Items defined as alphanumeric-edited by its PICTURE character.
-
DBCS
Items defined as DBCS by its PICTURE character. A USAGE DISPLAY-1 clause must be specified.
-
External floating-point
Items defined as external floating-point by its PICTURE character.
-
Internal floating-point
Items defined as internal floating-point by specifying a USAGE COMP-1 or COMP-2 clause.
-
Numeric
Items defined as numeric-edited by its PICTURE character (without the BLANK WHEN ZERO clause).
-
Elementary data items defined with a USAGE of the type BINARY, COMP, COMP-4, COMP-5, COMP-3, or PACKED-DECIMAL.
-
numeric or integer function.
-
-
Numeric-edited
Items defined as numeric by its PICTURE character or numeric items defined with the BLANK WHEN ZERO clause.
2. File Description Entry
The file description entry represents the start of descriptions for files defined in the SELECT clause of the environment division. A file name must be specified after FileDescription (FD) or SortFileDescription (SD).
-
Format 1
File Description Entry Format 1File Description Entry Format 1 - Clause1File Description Entry Format 1 - Clause2 -
Format 2
File Description Entry Format 2File description entry Format 2 - Clause -
Format 3
File Description Entry Format 3File Description Entry Format 3 - Cluase -
Format 4
File Description Entry Format 4File Description Entry Format 4 - Clause1File Description Entry Format 4 - Clause2
2.1. File Section
The file section includes a level-indicator (FD, SD) for each input and output file.
Item | Description |
---|---|
file-name |
Must be specified after a level-indicator (FD, SD) in the relevant SELECT clause. file-name must be unique in a program. |
FD (format 1, 2, and 3) |
The file section must include the FD entry for all files except for sort/merge files. The last clause in the FD entry must be followed by a period (.). |
SD (format 4) |
The files section must include the SD entry for sort/merge files. The last clause in the SD entry must be followed by a period (.). |
A record in the file section must be an alphanumeric group item or an alphabetical, alphanumeric, DBCS, or numeric elementary data item. |
2.1.1. EXTERNAL Clause
The EXTERNAL clause is specified so that different programs can share files in a COBOL program’s run unit.
2.1.2. GLOBAL Clause
The GLOBAL clause is specified so that a program and its nested programs can share files.
2.1.3. BLOCK CONTAINS Clause
The BLOCK CONTAINS clause is specified to define the physical length of a record. It is syntax checked, but does not affect the program execution.
2.1.4. RECORD Clause
When the RECORD clause is used, the record length must be specified with the number of bytes needed to store the record regardless of the USAGE of the data items specified in the record. For example, for a record that consists of 10 DBCS characters, the RECORD clause must be described as RECORD CONTAINS 20 CHARACTERS. If the RECORD clause is omitted, the compiler determines the record lengths based on the record descriptions.
Format 1
Format 1 specifies the length of fixed-length records.
Item | Description |
---|---|
integer-3 |
Specifies the record length with a positive integer. |
Format 2
Format 2 specifies the length of fixed-length or variable-length records.
Item | Description |
---|---|
integer-4 |
Specifies the minimum value of the record length with a positive integer. |
integer-5 |
Specifies the maximum value of the record length with a positive integer. |
If integer-4 and integer-5 are the same, the record has a fixed length. |
Format 3
Format 3 specifies the length of variable-length records.
Item | Description |
---|---|
integer-6 |
Specifies the minimum value of the record length with a positive integer. |
integer-7 |
Specifies the maximum value of the record length with a positive integer. |
data-name-1 |
Must be an elementary data item of the unsigned integer type. data-name-1 must contain the record length before a RELEASE, REWRITE, or WRITE statement can be executed. data-name-1 is not changed due to the execution of a DELETE, RELEASE, REWRITE, START, or WRITE statement or the failed execution of a READ or RETURN statement. data-name-1 is changed to the record length that was just read if a READ or RETURN statement is successfully executed. |
2.1.5. LABEL RECORDS Clause
The LABEL RECORDS clause is specified to define whether labels exist. It is syntax checked, but does not affect the program execution.
2.1.6. VALUE OF Clause
The VALUE OF clause is specified to define a label record related to the file. It is syntax checked, but does not affect the program execution.
2.1.7. DATA RECORDS Clause
The DATA RECORDS clause is specified to define a data name related to the file. It is syntax checked, but does not affect the program execution.
2.1.8. LINAGE Clause
The LINAGE clause specifies the logical page size by the number of lines. It optionally specifies the start position of the footing area and the top and bottom margins.
The LINAGE clause is available for sequential files opened with OUTPUT or EXTEND.
Item | Description |
---|---|
data-name-5, integer8 |
Specifies the number of lines in a logical page. The page area represented by the lines is called the page body. This value must be greater than zero. |
WITH FOOTING AT |
integer-9 or the value of data-name-6 specifies the first line number of the footing area in the page body. The value must be greater than zero and not greater than the last line number of the page body. |
LINES AT TOP |
integer-10 or the value of data-name-7 specifies the top margin of the logical page. This value must be equal to or greater than zero. |
LINES AT BOTTOM |
integer-11 or the value of data-name-8 specifies the bottom margin of the logical page. This value must be equal to or greater than zero. |
Descriptions for each part of the LINAGE clause are as follows:
-
If the LINES AT TOP or LINES AT BOTTOM phrase is not specified, the default value is zero.
-
If the FOOTING phrase is omitted, the value is the same as that of the page body (integer-8 or data-name-5).
-
If the values of integer-8, integer-9, integer-10, and integer-11 are specified when an OPEN OUTPUT statement is executed, they are used to configure the logical pages while the program is executing.
-
If the values of data-name-5, data-name-6, data-name-7, and data-name-8 are specified when an OPEN OUTPUT statement is executed, they configure the first logical page. When a page is turned due to a WRITE statement being executed, the values of data-name-5, data-name-6, data-name-7, and data-name-8 configure the next new logical page.
-
The LINAGE clause in an SD is syntax checked, but does not affect the execution of the program.
-
A LINAGE-COUNTER special register exists for each file.
3. Data Description Entry
The data description entry specifies properties of data items. The group of data description entries is called the record description entry. A data description entry that defines a single independent data item is called a data item description entry.
The data description entry has the following three formats.
Format 1
Each clause can be specified in any order except in the following cases.
-
If data-name-1 and FILLER are specified, they must immediately follow level-number. The level number is a number between 01 and 49, or 77.
-
The REDEFINES clause must follow data-name-1 or FILLER. If data-name-1 or FILLER is not specified, the REDEFINES clause must follow level-number.
Format 2
Item | Description |
---|---|
level-66 entry |
Cannot rename another level-66 entry, or a level-01, level-77, or level-88 entry. A level-66 entry related to the record must follow the record. |
Format 3
Item | Description |
---|---|
level-88 entry |
Must immediately follow the data description entry for a condition variable. |
condition-name-1 |
A user-defined name for associating a condition value with a single value, multiple values, or a range value. |
3.1. Level Number Clause
The level-number clause represents a hierarchy of data in a record or specifies a renamed entry, redefined item, or condition-name entry.
-
level-number
-
level-number is a number between 1 and 49, 66, 77, or 88.
-
Level numbers 01 and 77 must start in Area A and be separated from their related data-name, FILLER, or data description clause.
Level numbers 02 through 49 can start in Area A or Area B and must be separated from their related data-name, FILLER, or data description clause.
Level numbers 66 and 88 can start in Area A or Area B and must be separated from its related data-name, FILLER, or data description clause.
-
The single-digit level-numbers 1 through 9 are the same as level-numbers 01 through 09.
-
The data description entry must start in the same column as the first entry or can be indented based on the level-number. The indentation is for readability, and does not affect the level-number. The number of indented columns cannot exceed the size of Area B.
-
-
data-name-1
-
data-name-1 identifies a data item in a program. It must be immediately preceded by a level-number.
-
data-name-1 must be specified for level-66 and level-88.
-
-
FILLER
-
FILLER is used for memory alignment. An item specified with FILLER cannot be referenced by a program.
-
The FILLER keyword is optional. If FILLER is specified, it must be immediately preceded by a level-number.
-
FILLER can be specified in a condition variable, but cannot be in a condition-name.
-
FILLER is ignored when a MOVE CORRESPONDING, ADD CORRESPONDING, SUBTRACT CORESPONDING statement is handled. FILLER is ignored in an INITIALIZE statement.
-
If data-name-1 or FILLER is not specified, the item is handled as if FILLER was specified. |
3.2. BLANK WHEN ZERO Clause
The BLANK WHEN ZERO clause makes data that has the value 0 be saved as a space instead of zero.
This clause is specified according to the following rules.
-
The BLANK WHEN ZERO clause can be specified for a numeric-edited or numeric category elementary data item.
-
The 'S' or '*' character cannot be used in the picture string, and only the USAGE DISPLAY clause can be used.
-
If the BLANK WHEN ZERO clause is specified for a numeric data item, it is treated as a numeric-edited data item.
3.3. JUSTIFIED Clause
The JUSTIFIED clause is specified for right alignment when data is copied in an alphabetical or alphanumeric category item.
The JUSTIFIED clause can be specified only for an elementary data item. JUST is an abbreviation for JUSTIFIED.
The JUSTIFIED clause cannot be specified in the following cases.
-
Numeric, numeric-edited, or alphanumeric-edited items.
-
Index data items.
-
When USAGE FUNCTION-POINTER, USAGE POINTER, or USAGE PROCEDURE-POINTER is specified.
-
External floating-point or internal floating point items.
-
Level-66 (RENAME), level-88 (conditional-name) data items.
When data is copied to an item in which the JUSTIFIED clause is specified, characters in the data are aligned to the right. If the length of the original data to be copied is longer than that of the target data, the leftmost characters are truncated. If the length of the original data to be copied is shorter than that of the target data, the remaining space is filled with space characters.
But, if the system locale is ja_JP.sjis, ja_JP.SJIS, or ja_JP, and 'JUST RIGHT' option is set in G type variable, the space must be filled with double-byte spaces (0x8140).
3.4. EXTERNAL Clause
The EXTERNAL clause is specified so that different programs can share data items in a COBOL program’s run unit. In the UNIX environment, this clause is used so that programs that are separately compiled as shared libraries can share data.
The EXTERNAL clause can be specified for a level-01 data description entry in the working-storage section.
If a level-01 data item that has the external attribute is a record item, sub-data items that are included in the record have the external attribute, except for indexes.
If different programs share data by specifying the external attribute, records with the external attribute must have the same names and the same memory size.
3.5. GLOBAL Clause
The GLOBAL clause is specified so that programs and their nested programs can share data.
If a nested program specifies a data item that has the same name as that of an item that has the global attribute, the data item in the nested program no longer has the global attribute. Data items, condition names, and index items included in a record item that has the global attribute can have a global name.
The GLOBAL clause can be specified for the working-storage, linkage, local-storage, or file section. It can only be used for level-01 data description entries.
If there are data items that have the same name within a data division, the items cannot include the GLOBAL clause. A program, which is directly or indirectly included within another program that specifies a global name, can reference the name without specifying it again.
3.6. OCCURS Clause
The OCCURS clause defines a table that references elements that use an index or subscript.
The data name of a data item for which the OCCURS clause is specified is the subject of the OCCURS clause. To reference the OCCURS clause’s subject or subitems, an index or subscript must be used, depending on the data item. However, they are not used in the following cases.
-
When the subject is used as the subject of a SEARCH statement.
-
When the subject or the data item that depends on the subject is the object of an ASCENDING/DESCENDING key phrase.
-
When a data item that depends on the subject is the object of the REDEFINES clause.
The OCCURS clause cannot be specified in the following data description entries.
-
Data items with a level of 01, 66, 77, or 88.
-
Redefined data items (objects).
A table is configured based on whether it has a fixed or variable length.
Fixed-Length Tables
Fixed-length tables are specified by defining the table size in the OCCURS clause with a character constant.
-
integer-2
-
integer-2 specifies the table size. It must be a positive integer greater than zero.
-
-
ASCENDING KEY and DESCENDING KEY phrases
-
Data is aligned in ascending or descending order, depending on whether ASCENDING or DESCENDING is specified.
-
A detailed description of data-name-2 is as follows:
Item Description data-name-2
The subject entry or the data item that depends on the subject entry.
If data-name-2 is the subject entry, all entries are ASCENDING KEY or DESCENDING KEY. This is the unique key for the table.
If data-name-2 is not the subject entry, it must be a subitem that depends on the subject. The OCCURS clause cannot be specified for itself and the subitem.
-
When the ASCENDING KEY or DESCENDING KEY phrase is specified, the following rules apply.
-
Keys are specified from left to right according to their significance.
-
The number of keys cannot exceed 12.
-
Data in a table must be aligned in ascending or descending order.
-
Data items specified as a key can be one of the following: BINARY, DISPLAY, DISPLAY-1, PACKED-DECIMAL, COMP, COMP-1, COMP-2, COMP-3, COMP-4, or COMP-5.
-
-
-
INDEXED BY phrase
-
The INDEXED BY phrase specifies an index to be used for a table.
Item Description index-name-1
The name of an index created by the compiler. A separate data description does not need to be specified in the program. The scope of index-name-1 is the same as that of the table in which the index is specified.
-
Variable-Length Tables
Variable-length tables are specified using OCCURS DEPENDING ON.
Item | Description |
---|---|
integer-1 |
Specifies the minimum size of a variable-length table. This must be a positive integer and be equal to or less than integer-2. If integer-1 is omitted, the minimum size of a variable-length table is 1. |
integer-2 |
Specifies the maximum size of a variable-length table. It must be equal to or greater than integer-1. |
data-name-1 |
Identifies the object of the OCCURS DEPENDING ON clause. The data item’s current value determines the number of tables. The object must be an integer data item. It cannot use any memory space in the table. That is, a sub-data item of the subject cannot be specified. The OCCURS DEPENDING ON clause cannot be specified for the data item specified as the object. If the OCCURS clause is subitem of an item that contains the GLOBAL clause, the object must also be a global name. |
3.7. PICTURE Clause
The PICTURE clause specifies an elementary item’s category, data size, and editing attribute.
Item | Description |
---|---|
PICTURE or PIC |
PIC is an abbreviation for PICTURE. The PICTURE clause must be specified for element data items except for the following.
|
character-string |
The picture symbol. This determines the category of the element data item and the data size. |
Picture Symbol
The following characters can be used as picture symbols. The alphabetical characters are case-insensitive.
A B E G P S V X Z 9 0 / , . + - *
If DECIMAL-POINT IS COMMA is specified in the SPECIAL-NAMES paragraph, the functions of the decimal point (.) and the comma are exchanged.
The following table describes each picture symbol’s function and the size of a single character in a data item.
Symbol | Function |
---|---|
A |
|
B |
|
E |
|
G |
|
P |
|
S |
|
V |
|
X |
|
Z |
|
9 |
|
/ |
|
0 |
|
, |
|
. |
|
+/- |
|
CR/DB |
|
* |
|
cs(currency sign) |
|
The order for specifying picture string symbols is as follows:
Symbol | Description |
---|---|
â—Ź |
This symbol can be immediately preceded by the symbol specified at the top. |
{} |
Symbols enclosed in braces cannot be specified together. |
Symbol that appears repeatedly |
Nonfloating insertion symbol {+ -}, floating insertion symbol {Z *}, {+ -}, cs, and P can be specified repeatedly. The leftmost or topmost symbol is the symbol used in the left of the decimal point, and the next symbol is the symbol used to the right of the decimal point. |
Data Categories
PiEach following item’s data category is determined by the combination of picture symbols.
-
Alphabetical Items
-
The picture string can include only the symbol A. The item can include only Latin alphabetical characters, the space character, and the symbolic-characters of a figurative constant.
-
Alphabetical items explicitly specify USAGE DISPLAY or assume that USAGE DISPLAY is implicitly specified.
-
-
Numeric Items
-
The picture string can include the symbols 9, P, V, and S.
-
The numeric item types are the following: binary, packed decimal (internal decimal), and zoned decimal (external decimal).
-
A numeric item’s type is defined by the USAGE clause as follows:
Type USAGE clause Binary
BINARY, COMP, COMP-4, COMP-5
Internal decimal
PACKED-DECIMAL, COMP-3
Zoned decimal(external decimal)
DISPLAY
-
The symbol S must be the leftmost specified character in the picture string.
-
The symbol V must be specified only once in the picture string.
-
For binary types, up to 18 digits can be specified.
-
-
For internal decimal and zoned decimal types, up to 31 digits can be used.
-
Numeric literal or figurative constant ZERO item can be specified as a value.
-
Examples of the valid range for each PICTURE string are as follows:
PICTURE String Range of Values 9999
0 ~ 9999
S99
-99 ~ +99
S9999V99
-9999.99 ~ +9999.99
PPP999
0 ~ 0.000999
S999PPP
-1000 ~ -999000, 1000 ~ 999000, 0
-
-
Numeric-Edited Items
-
Due to a symbol specified in the picture string, a specific character is inserted in a specific position or a specific character is replaced.
-
The symbols B, P, V, Z, 9, 0, /, ,, ., +, -, CR, DB, *, and cs can be specified in the picture string.
-
The following rules apply.
-
The BLANK WHEN ZERO clause must be specified
-
At least one of the following symbols must be specified in the picture string: B, /, Z, 0, ,, ., *, +, -, CR, DB, or cs
-
Only one of the following symbols is specified in the picture string: +, -, CR, or DB
-
-
Up to 31 digits can be used.
-
The PICTURE string length can be up to 249.
-
If USAGE DISPLAY is specified, an alphanumeric literal or a figurative constant must be specified in the VALUE clause.
-
-
Alphanumeric Items
-
Only the symbol X is specified or a combination of the symbols X, A, and 9 can be specified in the picture string. The item can include any characters that can be specified by the character set of the computer. The item is treated as if it consists of only X symbols.
-
Alphanumeric items explicitly specify USAGE DISPLAY or assume that USAGE DISPLAY is implicitly specified.
-
Alphanumeric characters or figurative constants, such as ZERO, SPACE, QUOTE, HIGH-VALUE, LOW-VALUE, symbolic-character, and ALL alphanumeric-literal can be specified In the VALUE clause.
-
-
Alphanumeric-Edited Items
-
The symbols A, X, 9, B, /, and 0 can be specified in the picture string.
-
The picture string must include at least one of A or X, and at least one of B, 0, or /.
-
Alphanumeric-edited items explicitly specify USAGE DISPLAY or assume that USAGE DISPLAY is implicitly specified.
-
Alphanumeric characters or figurative constants, such as ZERO, SPACE, QUOTE, HIGH-VALUE, LOW-VALUE, symbolic-character, and ALL alphanumeric-literal can be specified in the VALUE clause.
-
-
DBCS Items
-
The symbol G is specified in the picture string. The single character corresponding to G takes 2 bytes.
-
If the symbol G is specified in the picture paragraph, DBCS items explicitly specify USAGE DISPLAY-1 or assume that USAGE DISPLAY-1 is implicitly specified.
-
A DBCS literal, figurative constant SPACE, or figurative constant ALL DBCS-literal must be specified in the VALUE clause.
-
-
External Floating-Point Items
-
External floating-point Items have the following format for their floating-point notation.
Item Description + -
-
A sign immediately followed by a mantissa is the sign of the external floating-point number. + indicates a positive value, and - indicates a negative value.
-
A sign immediately followed by an exponent is the sign of the exponent. + indicates a positive exponent, and - indicates a negative exponent.
-
If the symbol + is specified, + is displayed to represent a positive value, and - is displayed to represent a negative value.
-
If the symbol - is specified, a space is displayed to represent a positive value, and - is displayed to represent a negative value.
mantisa
-
The mantissa. The following symbols can be used: 9, ., and V.
-
Either the symbol V or . must be used for a decimal point.
-
A mantissa can be up to 16 characters.
E
Indicates the start of an exponent.
exponent
An exponent. This must be specified with the symbol 99.
-
-
If USAGE DISPLAY is specified, it indicates that the item is a display floating-point data item.
-
Each character takes space except for V.
-
The OCCURS, REDEFINES, and RENAME clauses can be specified together.
-
The BLANK WHEN ZERO, JUSTIFED, and VALUE clauses cannot be specified together.
-
If the SIGN or SYNCHRONIZED clause is specified, the corresponding clause is ignored.
-
Alignment Rules
The following alignment rules apply to data that will be copied, depending on the item category.
-
Numeric Items
-
Data is aligned based on the assumed decimal point. If necessary, data may be truncated or padded with 0s.
-
If the assumed decimal point is not specified, it is assumed that the decimal point is specified in the rightmost position of the data.
-
-
Numeric-Edited Items
-
Data is aligned based on the decimal point. If necessary, data may be truncated or padded with 0s from the leftmost or rightmost character.
-
-
Internal Floating-Point Items
-
It is assumed that a decimal point is in the leftmost position of a field. The digits preceded by the decimal point are aligned to the left.
-
-
External Floating-Point Items
-
Data is aligned to the left. The exponent is adjusted based on the aligned data.
-
-
Alphanumeric, Alphanumeric-Edited, Alphabetical, and DBCS Items
-
Data is aligned to the left. If necessary, data may be truncated or padded with spaces.
-
If the JUSTIFIED clause is specified, data is aligned according the JUSTIFIED rules.
-
String and Item Size
Each elementary item use a different amount of memory based on the PICTURE, SIGN, or USAGE clause.
USAGE Clause | The Space Each Item Takes |
---|---|
USAGE DISPLAY |
If SIGN IS SEPARATE is specified, each character in the item’s PICTURE string and any sign symbol uses 1 byte. |
USAGE DISPLAY-1 |
Each character in the item’s PICTURE string uses 2 bytes. |
USAGE COMP, COMP-4, BINARY |
References the size of the data item of the BINARY type in the USAGE clause. |
USAGE COMP-1 |
Uses 4 bytes. |
USAGE COMP-2 |
Uses 8 bytes. |
USAGE COMP-3, PACKED-DECIMAL |
References the size of the data item of the PACKED-DECIMAL type in the USAGE clause. |
USAGE COMP-5 |
References the size of the data item of the native type in the USAGE clause. |
Sign Data
A detailed description of sign data follows.
Sign Data | Description |
---|---|
Operational Sign |
A sign, for signed numeric items. Mathematically, + indicates a positive value and - indicates a negative value. Internal expressions depend on the USAGE or SIGN clause, or the OS. |
Editing Sign |
A sign for numeric-edited items. This indicates that the + or - will be used when data is displayed using the DISPLAY statement. |
Editing the PICTURE Clause
There are two methods to edit the PICTURE clause.
-
Insertion Editing
-
Simple insertion
A character specified in a picture string is inserted in the same position in a data item.
This can be used for alphanumeric-edited, numeric-edited, and DBCS data items.
The following are examples of simple insertion.
Picture String Data Value Result Value X(10)/XX
ALPHANUMER01
ALPHANUMER/01
X(5)BX(7)
ALPHANUMERIC
ALPHA NUMERIC
99,B999,B000
1234
01, 234, 000
99,999
12345
12,345
GGBBGG
-
Special insertion
This can be used for numeric-edited and external floating-point data items. A period (.) is inserted in data items to represent a decimal point.
The following are examples of special insertion.
Picture String Data Value Result Value 999.99
1.234
001.23
999.99
12.34
012.34
999.99
123.45
123.45
999.99
1234.5
234.50
+999.99E+99
12345
+123.45E+02
-
Fixed insertion
A currency sign and a sign such as +, -, CR, and DB can be specified in a string.
This can be used for numeric-edited data items.
-
If the symbol + or - is not specified, the currency sign must be specified in the leftmost position in a string. If the symbol + or - is specified, the currency sign must be specified in the leftmost or rightmost position in a string.
-
CR and DB must be specified in the rightmost position in a string using 2 bytes.
Each editing symbol has a different result, based on the value of the data item, as follows:
Editing Symbol Result value when a data item is a positive value or zero Result value when a data item is a negative value +
+
-
-
space
-
CR
2 spaces
CR
DB
2 spaces
DB
The following are examples of fixed insertion (the symbol b represents a space).
Picture String Data Value Result Value 999.99+
+6555.556
555.55+
+9999.99
-6555.555
-6555.55
9999.99
+1234.56
1234.56
$999.99
-123.45
$123.45
-$999.99
-123.45
-$123.45
-$999.99
+123.456
b$123.45
$9999.99CR
+123.45
0123.45bb
$9999.99CR
-123.45
$0123.45CR
-
-
Floating insertion
Symbols such as cs, +, and - can be specified in a numeric-edited data item.
Floating insertion is performed as follows:
-
If a floating insertion symbol is specified for all or a part of the digits to the left of the decimal point, a specified sign character, +, or - is inserted to the immediate left of the first nonzero digit.
The left part of the inserted character is padded with spaces. If there are no digits to the right of the decimal point, the necessary number of characters are inserted as zeros.
If the whole string is specified as insertion characters, at least one floating insertion symbol must be placed at the left of the decimal point.
-
f the entire picture string is specified as a floating insertion symbol, the following is performed depending on the data value.
If the data value is zero, a number of spaces equal to the number of floating insertion symbols in the picture string are inserted.
If the data value is nonzero, step 1 is performed.
The following are examples of floating insertion (the symbol b represents a space).
Picture String Data Value Result Value $$$$.99
.123
bbb$.12
$$$9.99
.12
bb$0.12
$,$$$,999.99
-1234.56
bbb$1,234.56
+,+++,999.99
-123456.789
bb-123,456.78
$$,$$$,$$$.99CR
-1234567
$1,234,567.00CR
++,+++,+++.+++
0000.00
bbbbbbbbbbbbbb
++,+++,+++.+++
123456
bbbb+12,345.000
-
-
-
Zero Suppression and Replacement Editing
-
In zero suppression and replacement editing, zeros to the left of a nonzero number are replaced by spaces or *. The symbols Z, *, +, -, or cs are specified for a picture string. These symbols are mutually exclusive in a single picture string.
-
If all or a part of the digits to the left of the decimal point are specified as a zero suppression symbol, zero suppression editing is performed until the first nonzero digit appears.
-
If all digits to the left and right of the decimal point are specified as zero suppression symbols and the data item’s value is 0, zero suppression editing is performed for the specified zero suppression symbols.
-
The following rules apply for zero suppression and replacement editing.
-
If the symbol Z is specified, a data item is filled with spaces.
-
If the symbol * is specified, a data item is filled with * except for at the decimal point position.
-
-
The following are examples of the zero suppression (the symbol b represents a space).
Picture String Data Value Result Value ****.**
0000.00
****.**
ZZZZ.ZZ
0000.00
bbbbbbb
ZZZZ.99
0000.00
bbbb.00
****.99
0000.00
****.00
ZZ99.99
0000.00
bb00.00
Z,ZZZ.ZZ+
+123.456
bb123.45+
*,***.**+
-123.45
**123.45-
**,***,***.**+
+12345678.9
12,345,678,90+
$Z,ZZZ,ZZZ.ZZCR
+12345.67
$bbb12,345.67bb
$B*,***,***.**BBDB
-12345.67
$b***12,345.67bbDB
-
3.8. REDEFINES Clause
The REDEFINES clause redefines the same memory space with different data descriptions. Therefore, data items that have different data descriptions can share the same memory space.
-
data-name-1, FILLER
-
Identifies a different description for the data area from that of data-name-2. data-name-1 is the redefining item or the REDEFINES subject.
-
Neither data-name-1 nor subitems that depend on data-name-1 may specify a VALUE clause.
-
Unless data-name-1 or FILLER is specified, the REDEFINES clause must be specified immediately after the level-number.
-
-
data-name-2
-
data-name-2 is the redefined item or the REDEFINES object.
-
data-name-2 can specify the REDEFINES clause, but cannot specify the OCCURS clause. However, items that data-name-2 is subordinate to can specify the OCCURS clause.
-
The following rules apply to setting items.
-
Both data-name-1 and data-name-2 cannot specify the OCCURS DEPENDING ON clause.
-
data-name-1 and data-name-2 are in the same level in the hierarchy, but do not need to have the same level number.
-
Both data-name-1 and data-name-2 cannot specify level-66 and level-88.
-
data-name-1 and subitems that depend on data-name-1 are all redefinitions.
-
The REDEFINES clause and the EXTERNAL clause cannot be specified at the same time.
Considerations for the REDEFINES Clause
The following must be considered when configuring the REDEFINES clause.
-
If the REDEFINES clause and the GLOBAL clause are specified at the same time, only the redefining data item has the GLOBAL attribute.
-
The REDEFINES clause and the EXTERNAL clause cannot be specified at the same time.
-
If the external attribute is specified for the redefined data item, the size of the redefining data item cannot be larger than that of the redefined data item.
-
The data size of the redefining item can be larger than that of the redefined item.
-
The redefining item must be immediately followed by the redefined item. That is, an item that is not related to the REDEFINES clause cannot be specified between the redefining and the redefined items.
However, other items can be specified if the same item is redefined consecutively as follows:
05 ITEM-A PICTURE 999999. 05 ITEM-B REDEFINES ITEM-A PICTURE 99999. 05 ITEM-C REDEFINES ITEM-A PICTURE 99999.
-
The redefined item and the redefining item do not need to specify the same USAGE clause. Even if they specify different USAGE clauses, their data formats and contents do not change.
-
Moving the redefined item to the redefining item or copying the redefining item to the redefined item may cause unexpected behaviors.
3.9. RENAMES Clause
The RENAMES clause specifies a single data item or multiple data items as a group in order to define a new record item.
Data description entries for which the RENAMES clause is specified must start with level-66. Multiple RENAMES entries can be specified for one record.
-
data-name-1
-
Identifies a new grouping of data items.
-
A level-66 entry cannot specify level-01, level-77, level-88, or another level-66 entry. In addition, data-name-2 and data-name-3 must not specify the OCCURS cluase.
-
data-name-1 can be qualified by a 01-level entry and cannot be used as another entry’s qualifier.
-
-
data-name-2, data-name-3
-
data-name-2 and data-name-3 identify the first data item and the last data item for a new grouping, respectively. They can identify elementary data items or alphanumeric group items.
-
Both data-names cannot specify the same item and can be qualified.
-
data-name-2 or data-name-3 in which the OCCURS clause is specified or is subordinate to an item that contains the OCCURS clause cannot be specified. The OCCURS DEPENDING clause must not be specified for any item defined between data-name-2 and data-name-3.
-
-
THRU
-
An abbreviation for THROUGH.
-
Note
Note the following when both data-name-2 and data-name-3 are specified.
-
data-name-1 defines a new alphanumeric group item that includes items from data-name-2 to data-name-3.
-
If data-name-2 is an elementary item, data-name-2 is the first item.
-
If data-name-2 is a group item, the first elementary item included in data-name-2 is the first item.
-
If data-name-3 is an elementary item, data-name-3 is the last item.
-
If data-name-3 is a group item, the last item included in data-name-3 is the last item.
-
-
The storage area that saves items from the first item to the last item becomes the storage area occupied by data-name-1.
-
data-name-3 cannot be positioned before data-name-2.
-
data-name-3 cannot be subordinate to data-name-2.
Note the following when only data-name-2 is specified.
-
The storage area occupied by data-name-2 becomes the storage area occupied by data-name-1.
-
data-name-1 has the same attributes that are specified for data-name-2.
-
If data-name-2 is an alphanumeric group item, data-name-1 becomes an alphanumeric group item.
-
If data-name-2 is an elementary item, data-name-1 becomes an elementary item.
3.10. SIGN Clause
The SIGN clause specifies the position and representation method of the sign for a signed numeric item.
The SIGN clause can be specified for elementary numeric items for which the symbol S is specified in the picture string and USAGE DISPLAY is specified, or group items that include such an elementary item.
If the SIGN clause is specified for a group item and an elementary item included in the group item, the clause for the elementary item takes priority. If the SEPARATE CHARACTER phrase is specified, the symbol S specified in the picture string uses 1 byte of storage.
3.11. SYNCHRONIZED Clause
The SYNCHRONIZED clause specifies the alignment by inserting unused slack bytes according to the storage structure boundary.
SYNC is an abbreviation for SYNCHRONIZED and can be used interchangeably. The SYNCHRONIZED clause is not mandatory, but can be used to improve performance when using binary items. It can be used for elementary items. LEFT and RIGHT do not affect the execution of the program.
The following are the effects of the SYNCHRONIZED clause on other elements.
-
OCCURS clause
Each occurrence is synchronized.
-
USAGE DISPLAY, PACKED-DECIMAL, COMP-3 ,DBCS, external floating point
The clause has no effect.
-
USAGE COMP, COMP-4, COMP-5, BINARY
The first elementary item included in an item that has the REDEFINES clause does not require additional character positions.
If the SYNCHRONIZED clause is not used for a subordinate data item, alignment displacement that is a multiple of 2 is applied for S9 - S9(4) and a multiple of 4 is applied for S9(5) - S9(18).
-
USAGE COMP-1
Fullword boundary alignment is applied to the data.
-
USAGE COMP-2
Doubleword boundary alignment is applied to the data.
-
REDEFINES clause
An object that has the REDEFINES clause must have a proper boundary alignment.
Slack byte
The following rules apply when adding a slack byte.
-
Assume that s is the sum of bytes of all elementary data items that precede the binary item.
-
Divide s by m, where m = 2 for binary items with the length of 4 or less digit(s), m = 4 for binary items with the length of 5 or more digit(s) and data items of COMP-1, INDEX, POINTER, PROCEDURE-POINTER, or FUNCTION POINTER, and m= 8 for data item of COMP-2.
-
Insert as many slack bytes as m - r, where r is the remainder of the division.
The following inserts slack bytes by using the SYNCHRONIZED clause.
01 GROUP-A. 05 SUB-A PICTURE X(5). 05 SUB-B . 10 ELEM-A PICTURE X(2). [ 10 SLACK-BYTES PICTURE X. (The compiler inserts.) ] 10 ELEM-B USAGE BINARY PICTURE S9(6) SYNC.
3.12. USAGE Clause
The USAGE clause specifies the format of data items saved in memory. The USAGE clause can be specified for all data items except for level-66 and level-88 data items. Only USAGE DISPLAY and COMP-3 can be specified in a data item in which the DATE FORMAT clause is specified.
If the USAGE clause is specified for a group item, it is applied to elementary data items included in the group item. However, if USAGE is specified for one of the elementary items, the elementary item must not contradict the USAGE clause. If the USAGE clause is not specified, it is assumed that the USAGE clause is implicitly specified as follows:
If a symbol other than G is specified in the picture string, it is assumed that USAGE DISPLAY is specified.
Computational Items
A computational item is a value used to process arithmetic operations. It must be a numeric item.
The symbols 9, S, V, and P can be used for computational items. COMPUTATIONAL-1 and COMPUTATIONAL-2 cannot specify PICTURE strings.
The maximum number of digits in a computational item is 31.
-
BINARY
-
BINARY USAGE represents binary data items. Negative numbers are represented as the two’s complement of the positive number that has the same absolute value.
-
The following all represent BINARY data: BINARY, COMPUTATIONAL, COMP, COMPTATIONAL-4, and COMP-4.
-
BINARY data is big-endian. The sign of signed BINARY data is included in the leftmost bit.
-
The amount of storage used to save BINARY data is determined by the number of digits in the PICTURE clause.
Digits in the PICTURE clause Storage 1 - 4
2 bytes
5 - 9
4 bytes
10 - 18
8 bytes
-
-
PACKED-DECIMAL
-
An internal decimal item. Two digits are saved in 1 byte. The sign is saved in the last 4 bits of the last byte.
-
The following all represent PACKED-DECIMAL data: PACKED-DECIMAL, COMPUTATIONAL-3, and COMP-3.
-
-
floating-point
-
An internal floating-point item that has single precision. It uses 4 bytes of storage.
-
COMPUTATIONAL-1 and COMP-1 also represent internal floating-point data.
-
-
long floating-point
-
An internal floating-point item that has double precision. It uses 8 bytes of storage.
-
COMPUTATIONAL-2 and COMP-2 are the same methods for representing long floating-point data.
-
-
Native binary
-
Items specified with USAGE COMP-5 are represented like binary data.
Unlike USAGE COMP, the maximum number of digits is determined by the native binary representation limit, not by the number of nines specified in the picture.
When a number is saved as COMP-5 data, truncation is determined by the maximum or minimum value that COMP-5 data can represent, not by the PICTURE clause.
COMP-5 data is referenced with the native binary representation unit (2, 4, or 8 bytes).
-
The following table shows examples of picture strings, their storage, and their range of values.
Picture Storage Minimum and Maximum Values S9(1) - S9(4)
2 bytes
-32,768 - +32,768
S9(5) - S9(9)
4 bytes
-2,147,483,648 - +2,147,483,647
S9(10) - S9(18)
8 bytes
-9,223,372,036,775,808 - +9,223,372,036,775,807
9(1) - 9(4)
2 bytes
0 - 65535
9(5) - 9(9)
4 bytes
0 - 4,294,967,295
9(10) - 9(18)
8 bytes
0 - 18,446,744,073,709,551,615
-
The COMP-5 type is usually used to send and receive data to and from non-COBOL programs. The byte-order is the same as the byte-order of the computer in which the program is executed.
-
COMP-5 data item can specify a scaling factor. For example, the range of values for the data item, PICTURE S99V99 COMP-5, is from -327.68 to +327.67.
-
DISPLAY Phrase
The DISPLAY phrase saves a single character in 1 byte of storage to use data as output characters.
USAGE IS DISPLAY can be specified for items of the following categories.
-
Alphabetic
-
Alphanumeric
-
Alphanumeric-edited
-
Numeric-edited
-
External floating-point
-
External decimal
-
An external decimal item is also called a zoned decimal item. A single number takes 1 byte of memory. The upper 4 bits in each byte are called zone bits. The zone bits of a low-order byte represent the sign of a number. The lower 4 bits in each byte includes the number.
-
The number of digits in an external decimal item can be up to 31.
-
Only 9, S, V, and P can be used for the PICTURE character string of an external decimal item.
-
DISPLAY-1 Phrase
The following rules apply to the DISPLAY-1 phrase.
-
The DISPLAY-1 phrase is specified to save DBCS data items.
-
A single character takes 2 bytes of storage.
INDEX Phrase
The following rules apply to the INDEX phrase.
-
The INDEX phrase defines index data items used to save index-name values.
-
Each index data item takes 4 bytes of storage.
-
An index data item can be referenced by a SEARCH statement, a SET statement, a relational condition, the USING phrase of the procedure division, or the USING phrase of a CALL or ENTRY statement. If an index data item is subordinate to an alphanumeric group, it can be indirectly referenced through a MOVE statement or an input/output-related statement.
-
The USAGE IS INDEX phrase can be specified at any level. If the INDEX phrase is specified in an alphanumeric group item, SEARCH or SET statements or relational conditions cannot be used because the group item itself is not an index data item. Each elementary item included in the group is an index data item. An elementary item cannot specify the USAGE clause that contradicts the USAGE clause of the group.
-
USAGE IS INDEX cannot be used with the DATE FORMAT, JUSTIFIED, PICTURE, BLANK WHEN ZERO, and VALUE clauses. However, SYNCHRONIZE can be used with index data.
-
An index data item cannot be a conditional variable.
POINTER Phrase
The following rules apply to the PONITER phrase.
-
The POINTER phrase defines a POINTER data item to manage limited virtual storage using addresses.
-
Each POINTER data item uses 4 bytes of storage.
-
A POINTER data item can be referenced by a SEARCH statement, a SET statement, a relational condition, the USING phrase of the procedure division, or the USING phrase of the CALL or ENTRY statement.
-
The USAGE IS POINTER clause can be specified in any level except level 88. If the USAGE IS POINTER clause is specified for a group item, each elementary data item included in the group becomes a pointer data item and the group itself becomes an alphanumeric group item. Therefore, an elementary data item cannot specify a USAGE clause that contradicts the group item.
-
A POINTER data item can be used as a item that is subordinate to a group item that is referenced by a MOVE statement or an input/output-related statement. However, if the corresponding statement is executed, data is not changed.
-
A POINTER data item cannot be a conditional variable.
-
USAGE IS POINTER cannot be used with the DATE FORMAT, JUSTIFIED, PICTURE, and BLANK WHEN ZERO clauses.
-
The POINTER data item can be used as a redefined or redefining item. It can be used along with the SYNCHRONIZED clause. Only NULL or NULLS can be specified for the POINTER data item with the VALUE clause.
-
The POINTER data item cannot be used as a conditional variable. It is excluded from the CORRESPONDING target when data is moved.
3.13. VALUE Clause
The VALUE clause specifies initial values of data items or the value of a condition-name. This clause is used differently depending on the data division section.
If the VALUE clause is specified for data items in the linkage or file section, it is internally syntax checked except for the condition-name entry. However, this does not affect the execution of the program.
In the working-storage section and local-storage section, the VALUE clause is used for a condition-name entry of the corresponding data item or an initial value of any data item. The value specified in the VALUE clause is saved for a data item at the beginning of program execution. If a value is not specified in the VALUE clause, the value is not predictable.
The value clause used in likage section is treated as a comment.
Format 1
Format 1 specifies the initial value of a data item.
-
VALUE
-
Figurative constants such as SPACE and ZERO are replaced by the characters and numbers represented by the figurative constant.
-
Values of the VALUE clause specified for numeric items must be numeric. If the VALUE clause is specified for working-storage or local-storage items, the values specified in the VALUE clause are aligned according the numeric move rule.
A value that needs truncation of nonzero digits cannot be specified. If a value has a sign, a sign symbol must be specified in the picture string.
-
A number specified as a value in the VALUE clause must be in the range specified in the PICTURE clause.
For example, if PICTURE 99PPP is specified, values can be between 1000 and 99000.
However, COMP-5 cannot specify P in the PICTURE clause. Its value can be any value in the range of the native binary representation.
-
When the VALUE clause is specified for alphabetical, alphanumeric, alphanumeric-edited, and numeric-edited items described with USAGE DISPLAY, the value must be an alphanumeric literal or a figurative constant. The number of characters in the specified value must not exceed the size of the item.
Specified values are aligned according to the alphanumeric alignment rule.
-
When the VALUE clause is specified for an alphanumeric group item, the value must be an alphanumeric literal or a figurative constant. The number of characters in the specified value must not exceed the size of the group item.
-
When the VALUE clause is specified for DBCS items, the value must be a DBCS, SPACE, or ALL DBCS literal. The number of characters in the specified value must not exceed the size of the item.
-
When the VALUE clause is specified for internal floating-point COMP-1 and COMP-2 items, the value must be a floating-point literal, figurative constant ZERO, integer zero, or a zero that includes a decimal point.
-
The following rules apply to the literal value.
-
Initialization is not dependent on a specified BLANK WHEN ZERO or JUSTIFIED clause.
-
If the OCCURS clause is specified or the VALUE clause of format 1 is specified for an item that is subordinate to a table item, the value specified in the VALUE clause is applied to all elements in the table.
-
The edited characters in a PICTURE clause are ignored when determining the initial value. However, the edited characters that determine the item size are used to determine the initial value. That is, if the PICTURE clause includes edited characters, the VALUE literal must include the editing characters. For example, if an item is PIC +999.99 and the desired value is +12.34, the VALUE clause must be specified as VALUE "+012.34".
-
The VALUE clause cannot be specified in an entry or a subordinate of an entry with an EXTERNAL or REDEFINES clause. This rule does not apply to a condition-name entry.
-
The VALUE clause can be specified for alphanumeric group items and elementary data items.
If the VALUE clause is specified in a group level, all elementary data items included in the group are initialized with the same value regardless of their types. If the VALUE clause is specified for a group item, another VALUE clause cannot be specified for the elementary data items included in the group item.
-
The VALUE clause must not be specified for a group item that includes any item for which the JUSTIFIED or SYNCHRONIZED clause is specified.
-
If the VALUE clause is specified for an alphanumeric group item, it is assumed that USAGE DISPLAY is explicitly or implicitly specified for all elements included in the group.
The VALUE clause cannot be specified for external floating-point items. |
Format 2
Format 2 specifies a value, multiple values, or ranges of values specified with a literal in condition-name.
Each entry must be specified with a separate level-88 to specify a value for different condition-names.
Item | Description |
---|---|
condition-name-1 |
A user-defined name to associate a value with a conditional variable. If this is a conditional variable table item, references to condition-name must use a subscript or an index. |
literal-1 |
A single value associated with condition-name. |
literal-1 through literal-2 |
Associates values from literal-1 to literal-2 with condition-name. literal-1 and literal-2 must be the same class. literal-1 must be less than literal-2. If a conditional variable is a DBCS, literal-1 and literal-2 must be DBCS literals. A figurative constant or ALL DBCS literal can be specified. If literal-1 and literal-2 are DBCSs, the collating sequence of literal-1 and literal-2 is determined based on the binary order of the hexadecimal values of literal-1 and literal-2. |
The following rules apply to set condition-name entries.
-
A conditional variable entry must be specified before a condition-name entry is specified.
When multiple condition-name entries are specified for a single conditional variable, each condition-name entry must be specified consecutively. Each condition-name entry must be delimited by a period (.).
-
THRU is an abbreviation for THROUGH.
-
Any elementary data item can be used as a conditional variable except in the following cases.
-
When an elementary data item is a condition-name of another conditional variable.
-
When the RENAMES clause is specified.
-
When USAGE INDEX, USAGE POINTER, USAGE PROCEDURE-POINTER, or USAGE FUNCTION-POINTER is specified.
-
-
condition-name can be specified in a group level or a group’s subordinate level.
-
If condition-name is specified for alphanumeric group data, literal-1 or literal-2 must be specified as an alphanumeric literal or figurative constant. The group can include items of any usage.
-
If condition-name is specified for an alphanumeric group data, the size of the specified value must not exceed the total size of all items that are included in the group, and JUSTIFIED or SYNCHRONIZED must not be specified for the items included in the group.
-
If a DBCS literal is specified in the VALUE clause, related condition-name must be of the same class.
Format 3
Format 3 specifies null as the initial value of an item defined with USAGE POINTER, USAGE PROCEDURE-POINTER, or USAGE FUNCTION-POINTER.