Data Field Definitions

COBOL data fields are basically defined using a level-number field-name PICture 'ppppp' usage uuuuu VALUE vvvvv format. The actual method of storing the data that the field refers to and its interpretation by the program are determined by the picture and usage clauses.

Let's begin by considering the usage clause. The word usage is itself optional as there are only a set number of values that this clause can have.

DISPLAY
this indicates that the field is stored in an uncompressed, displayable format. This is actually the default USAGE type and will be assumed if the field is omitted entirely. A value of 15000 will be stored in a field of this type as x'f1f5f0f0f0' which is the ebcdic equivalent to 15000. To calculate the length of a display field count one for each occurrence of A X 9 Z * - + B / , . $ and two for each occurrence of G CR DB.
INDEX
A four byte binary field is used to store an index. The value of an index field should not be directly accessed. An index is incremented and decremented in multiples of the size of the field that the index is on.
POINTER
A four byte binary field is also used to store a pointer.
BINARY or COMP or COMP-4
These are all equivalent and define a field as being stored in a binary compressed format. A binary field to hold 1-4 digits will take up two bytes, one to hold 5-9 digits will take four bytes, and one to hold 10-18 digits will take eight bytes. A value of 15000 will be stored in a field of this type as x'00003a98' which is the hexadecimal equivalent of 15000.
PACKED-DECIMAL or COMP-3
These are equivalent and define the field as having two digits compressed into each byte (with the last half byte reserved for the sign). A value of 15000 will be stored in a field of this type as x'15000C'. To calculate the length of a packed decimal field add 1 to the number of digits (9s in the pic'999' field) divide by two and round halves up to the next byte.
COMP-1
Identifies the field as a single precision floating point number.
COMP-2
Identifies the field as a double precision floating point number.

 

go to top

Now on to considering the PICture clause (which can be abbreviated to just PIC). The content of this field determines the length of the data field as well as the interpretation of its contents. The symbols that can be placed within the picture clause are as follows.

A
corresponds to a single alphabetic character. The content of this position within the data field is allowed to be any uppercase of lowercase alphabetic character or a blank. Numerics and other symbols are not allowed
X
corresponds to a single alphanumeric character. Any character from within the entire ebcdic character set can be contained in this field.
G
corresponds to two bytes in the field which are being used to hold a double byte character. For example in Japan this definition would be used for fields that hold Kanji characters.
9
corresponds to a numeric character. Only the numeric values of zero through nine can be contained in this character.
E
indicates that the following digits are the exponential for a floating point number. For example PIC '9v99999e99'.
S
used to indicate that a numeric field is signed. The sign is always contained within the upper half byte of the last character of a display field or the lower half byte of a packed decimal field. A value of 'C' (12) representing positive and 'D' (13) negative. Binary fields represent negative numbers using the twos complement method.
T
used to indicate that a display numeric field should only insert the sign into the upper half of the last byte if the value is negative.
R
used to indicate that a display numeric field should only insert the sign into the upper half of the last byte if the value is positive.
P
represents a virtual digit in a number that has no storage allocated to it. For example PIC '99ppp' can contain the value 15000 as x'f1f5' with the number being assumed to represent thousands.
V
used to indicate the position of a virtual decimal point. For example PIC '99999v99' can contain the value 15000 as x'f1f5f0f0f0f0f0' with the last two digits being assumed to represent hundredths.
Z
corresponds to a leading numeric digit that if zero will be replaced by blank. Usually used to suppress leading zeros on numbers being printed.
*
corresponds to a leading numeric digit that if zero will be replaced by *. Usually used to suppress leading zeros on numbers being printed on cheques.
-
formatting character used with numeric fields. This will display as a blank if the number is zero or positive and will display as shown if the number is negative.
+
formatting character used with numeric fields. This will display as shown if the number is zero or positive and will display as a - if the number is negative.
CR
formatting character used with numeric fields. This will display as a blank if the number is zero or positive and will display as shown if the number is negative.
DB
formatting character used with numeric fields. This will display as shown if the number is zero or positive and will display as CR if the number is negative.
B
corresponds to a character that is always blank. Usually used to insert a blank into the middle of a field that is about to be output.
/ or , or . or $
formatting characters used in display fields being output. These values will display exactly as shown. For example the field PIC '99,999' containing the value x'f1f5f0f0f0' will print as '15,000'.

 

This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow
Donate