Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
29 views6 pages

COBOL Data Usage Explained

DISPLAY usage represents characters in a byte with numbers in zoned decimal format. COMP/COMP-4 usage represents numbers in pure binary with the sign in the leftmost bit and number of bytes depending on the picture size. COMP-1/COMP-2 represent single/double precision floating point numbers with bits used for sign, exponent, and mantissa. COMP-3/PACKED-DECIMAL uses packed decimal format to store two digits per byte except the last to reduce space. COMP-5 behaves like COMP but allows values up to the native binary size regardless of picture size.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

COBOL Data Usage Explained

DISPLAY usage represents characters in a byte with numbers in zoned decimal format. COMP/COMP-4 usage represents numbers in pure binary with the sign in the leftmost bit and number of bytes depending on the picture size. COMP-1/COMP-2 represent single/double precision floating point numbers with bits used for sign, exponent, and mantissa. COMP-3/PACKED-DECIMAL uses packed decimal format to store two digits per byte except the last to reduce space. COMP-5 behaves like COMP but allows values up to the native binary size regardless of picture size.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

 DISPLAY usage

 DISPLAY is default usage.


 A byte is used to represent each character of data item. Thus, the
number of bytes required equals to the size of data item
 When USAGE IS DISPLAY used for signed numeric data item, it
is represented in zoned decimal representation.
 COMP & COMP-4 usage
 COMPUTATIONAL, COMPUTATIONAL-4 is same as COMP &
COMP-4
 COMP data items are represented in pure binary form. The
number of bytes required for data items described as COMP or
COMP-4 are as follows:-
Number of bytes required in
PICTURE
storage

S9(01) to S9(04) 2 bytes

S9(05) to S9(09) 4 bytes

S9(10) to S9(18) 8 bytes

 The left most bit of the storage is used to store sign. (1 for
negative and 0 for positive)
 The PICTURE of COMP data item should not contain any
character other than 9 and S.
 COMP-1 or COMPUTATION-1 usage
 COMP-1 data item is represented as single precision floating point
number (32-bits).
 Out of these 32-bits, first left most bit is used to represent sign,
next 7 bits to represent exponent and last (right most) 23 bits are
used to represent Mantissa.
 Suitable for arithmetic operations
 The PICTURE clause cannot be specified for COMP-1
 For conditional expressions, the class condition cannot be used
for COMP-1 or COMPUTATIONAL-1 internal floating-point data
items
 COMP-2 or COMPUTATION-2 usage
 COMP-2 data item is represented as double precision floating
point number (64-bits).
 Out of these 64-bits, first left most bit is used to represent sign,
next 11 bits to represent exponent and last (right most) 52 bits are
used to represent Mantissa.
 Used for high precision calculations
 The PICTURE clause cannot be specified for COMP-2
 For conditional expressions, the class condition cannot be used
for COMP-2 or COMPUTATIONAL-2 internal floating-point data
items
 COMP-3 or PACKED-DECIMAL usage
 This is the equivalent of PACKED-DECIMAL.
 COMP-3 data item is represented in packed decimal format.
 A packed decimal representation uses the first four bits of each
byte to store one digit and last four bit of each byte(except last
byte) to store another digit. The sign is stored in last four bits (X‘C’
for positive, X‘D’ for negative) of last byte. Thus in case of packed
decimal representation it occupies less space compared to zoned
decimal representation as each byte(except last byte) can store
two digits.
 Example:-
Picture clause Decimal Value Hex Representation

PIC S9(4) COMP-3 -1234 X’1234D’

PIC S9(4) COMP-3 +1234 X’1234C’

PIC 9(4) COMP-3 1234 X’1234F’

 PIC 9(N) USAGE IS COMP-3 will require (N+1)/2 bytes.


 COMP-5 usage
 COMP-5 data item are represented as binary data like COMP and
the memory usage is also same. But these data item can contain
values up to the capacity of the native binary representation (2, 4
or 8 bytes), rather than being limited to the value implied by the
number of nines in the picture for the item (as is the case for
USAGE BINARY data).
 When numeric data is moved or stored into a COMP-5 item,
truncation occurs at the binary field size rather than at the COBOL
picture size limit. When a COMP-5 item is referenced, the full
binary field size is used in the operation.
 The following table shows several PICTURE clause, number of
bytes required in storage, and the range of values it can store

 It is important to note that COMP or COMP-4 also can store till


32767 if the program is compiled with TRUC(BIN) whereas
COMO-5 behaves so independent of compiler option. This is
useful when the data is coming from non-COBOL compilers

EDITING Code characters


 While creating reports, sometimes there is necessity to edit the data
before it is written on the actual report. For example, you want to add
currency sign ‘$’ in salary field, you want to suppress leading zeroes
from amount field etc.
 For this purpose we can use editing characters of PICTURE clause
to represent data in the user expected format
 COBOL programming provides below Editing code characters:-
Code character Description

Z Used to suppress leading zeroes in numeric


data item. The leading zeroes will be replace
with spaces. Z character has no effect on
trailing zeroes. Please refer examples in next
table

* Similar to code character ‘Z’ except that the


leading zeroes will be replaced by asterisk
instead of space characters. Please refer
examples in next table

$ A single $ character will appear on leftmost


position of a numeric value. Please refer
examples in next table
- A minus sign will appear either at the leftmost
or rightmost position of numeric value. If data
in negative, a minus sign will appear but if data
is positive, a space will appear. Please refer
examples in next table

+ A plus sign is similar to minus sign except that


the plus sign will appear when data is positive
instead of space. If data is negative a minus
sign(-) will appear. Please refer examples in
next table

CR A ‘CR’ – Credit sign will appear only at


rightmost position of the numeric value. If data
in negative, a ‘CR’ will appear but if data is
positive, two space will appear. Please refer
examples in next table

DB A ‘CR’ – Debit sign will appear only at


rightmost position of the numeric value. If data
in negative, a ‘DB’ will appear but if data is
positive, two space will appear. Please refer
examples in next table. Please refer examples
in next table

. A period sign or decimal point is used to


represent decimal point position in numeric
value. Please refer examples in next table

, A comma sign is used as delimiter to represent


numeric values. One or more comma allowed
in picture clause of numeric data item. Please
refer examples in next table

B Represents Blank insertion. The position


where ‘B’ appears in picture clause, blank
character (space) will be inserted in that
position. Please refer examples in next table

0 Represents Zero insertion. The position where


‘0’ appears in picture clause, zero ‘0’ will be
inserted in that position. Please refer examples
in next table

/ Represents Slash insertion. The position


where ‘/’ appears in picture clause, slash ‘/’ will
be inserted in that position. Mostly it is used to
represent date values. Please refer examples
in next table

BLANK WHEN ZERO This will set entire data item to blanks if data
item contains zero value. Please refer
examples in next table
COBOL Editing character examples:-
 Important points need to remember while using Editing code
characters:-
o For Alphabetic data item only editing character ‘B’ can be used
o For Numeric data item any editing character can be used
o For Alphanumeric data item only editing characters ‘B’, ‘0’ and
‘/’ can be used
o Both the period and V cannot appear in the same picture

De-editing
 Using MOVE verb, we can move numeric edited data item to the
numeric data item. This is allowed in COBOL-85. Moving numeric
edited item to numeric data item referred to as De-editing of the
value. Let’s understand with example.
 Below declaration in done in DATA DIVISION:-
 01 EDITED-DATA PIC ZZ999.999.
01 UNEDITED-DATA PIC 9(5)V99.

 In procedure division, below statement is valid in COBOL-85


 MOVE 4356.12 TO EDITED-DATA.
MOVE EDITED-DATA TO UNEDITED-DATA.
 Once these statements are executed, EDITED-DATA will have value
‘b4356.12’ and UNEDITED-DATA will have value ‘04356.12

You might also like