8/12/2019 Cob Basics 3
1/16
8/12/2019 Cob Basics 3
2/16
TITLE : Divisions of COBOL
Purpose:
To introduce how to declare data items in COBOL
To introduce data types in COBOL
OBJECTIVES:
Be aware of data types in COBOL
Be aware of how to declare data items in COBOL
Be aware of Picture clause
Understand grouping of data items
Declare sample record structure
Unit3
8/12/2019 Cob Basics 3
3/16
Categories of Data
There are three categories of data item used in COBOL
programs:
Variables.
Literals. Figurative Constants
A variable is a named location in memory into which a
program can put data, and from which it can retrieve data.
A literal is a data-item that consists only of the data-item valueitself.
Figurative Constant is assigned to a data-item it fills the whole
item overwriting everything in it
8/12/2019 Cob Basics 3
4/16
Variables
Every variable used in a COBOL program must be describedin the DATA DIVISION.
Variable declaration also defines the type of data to be stored
in the variable
In COBOL, there are really only three data types
Numeric (Only numbers)
Alphanumeric (Combination of Characters and numbers) Alphabetic (Only Characters)
8/12/2019 Cob Basics 3
5/16
Literals
Literals are constant data-items.
There are two types of literals
String/Alphanumeric Literals
Numeric Literals
String/Alphanumeric literals are enclosed in quotes and consistof alphanumeric characters
"Michael Ryan",
Numeric literals may consist of numerals, the decimal point,
and the plus or minus sign. Numeric literals are not enclosed inquotes
123, 123.45
8/12/2019 Cob Basics 3
6/16
Figurative Constants
SPACEor SPACES Acts like one or more spaces
ZEROor ZEROSor
ZEROES
Acts like one or more zeros
QUOTEor QUOTES Used instead of a quotationmark
HIGH-VALUEor HIGH-
VALUES
Uses the maximum value
possible
LOW-VALUEor LOW-
VALUES
Uses the minimum value
possible
ALLliteral Allows a ordinary literal to act
as Figurative Constant
8/12/2019 Cob Basics 3
7/16
Declaring Data
In COBOL, a variable declaration consists of a line in the
DATA DIVISION that contains the following items:
A level number.
A data-name or identifier. A Picture clause.
The level-number specifies the hierarchy of data within a
record
The PICTURE clause specifies the general characteristics andediting requirements of an elementary item.
8/12/2019 Cob Basics 3
8/16
Picture Clause
9 The digit nine is used to indicate the occurrence of a digit
at the corresponding position in the picture.X The character X is used to indicate the occurrence of any
character from the character set at the corresponding
position in the picture.
A The character A is used to indicate the occurrence of anyalphabetic character (A to Z plus blank) at the
corresponding position in the picture.
V The character V is used to indicate the position of the
decimal point in a numeric value. It is often referred to asthe "assumed decimal point".
S The character S indicates the presence of a sign and can
only appear at the beginning of a picture.
8/12/2019 Cob Basics 3
9/16
Level Numbers
An "elementary item" is the name we use in COBOL todescribe a data-item that has not been further subdivided
Elementary items musthave a picture clause because theyactually reserve the storage required for the item. The amount
of storage reserved is specified by the item's picture clause 01 CustomerName PIC X(20)
01 GrossPay PIC 9(5)V99
A group item consists of elementary items
the hierarchical relationship between the various subordinateitems of the group is expressed using level numbers
The higher the level number, the lower the item is in thehierarchy
8/12/2019 Cob Basics 3
10/16
Level Numbers
A group item cannot have a picture clause because it does notactually reserve any storage.
The size of a group item is the sum of the sizes of itssubordinate elementary items
The type of a group item is always assumed to be PIC X
because a group item may have several different data itemsand types subordinate to it and an X picture is the only onewhich could support such collections.
Level numbers 01 through 49 are general level numbers
Level 77's can only be used to define individual elementaryitems.
Level 88's are used to define Condition Names
Level 66's (RENAMES clause) are used to apply a new nameto an identifier or group of identifiers.
8/12/2019 Cob Basics 3
11/16
Value Clause
The VALUE clause specifies the initial contents of a data item
If the VALUE clause is specified at the group level, the literal
must be a nonnumeric literal or a figurative constant.
01 NetPay PIC 9(5)V99 VALUE ZEROS
01 CustDiscount PIC V99 VALUE .25
8/12/2019 Cob Basics 3
12/16
Usage Clause
The USAGE clause is used to specify how a data item is to bestored in the computer's memory
The USAGE clause may be used with any data descriptionentry except those with level numbers of 66 or 88
When the USAGE clause is declared for a group item, theusage specified is applied to every item in the group
The picture clause used for COMP or PACKED-DECIMALitems must be numeric.
When the USAGE clause is not specified at either the group orelementary level, it is assumed that the usage is DISPLAY.
8/12/2019 Cob Basics 3
13/16
Usage Clause
PIC 9(1 to 4) 1 Word (2 Bytes)
PIC 9(5 to 9) 1 Long Word (4 Bytes)PIC 9(10 to 18) 1QuadWord (8 Bytes)
8/12/2019 Cob Basics 3
14/16
Editing Characters
Printing of decimal points where decimal alignment is implied.
Suppression of leading zeros.
Printing of dollar signs and commas.
Printing of asterisks for check protection. Printing of plus or minus signs.
Printing of debit or credit symbols for accounting applications.
Printing of spaces or zeros as separators within fields.
8/12/2019 Cob Basics 3
15/16
Editing Characters
The appropriate report-item that will print a decimal point willhave a PICTURE of 99.99
The edit symbol Z is used to suppress leading zeros and toreplace them with blanks or spaces.
The dollar sign and comma are placed in the positions inwhich they are desired, as in the case with decimal points.
To print a minus sign for a negative sending field, we use theedit symbol -
The edit symbols DB , for debit, or CR , for credit, may beused in place of the minus sign
The edit symbol B in a PICTURE clause of a report-item willcause a space to be inserted in the corresponding position
8/12/2019 Cob Basics 3
16/16
Editing Characters
Sending Field Report Item
PICTURE Contents PICTURE Contents
99V99 02^38 ZZ.99 b2.38
9(4)V99 3812^34 $9,999.99 $3,812.34
S999 123 - - 999 - 123
S999 123 + 999+ 123+
S999 123 - 999CR 123CR
S999 123 - 999DB 123DB
9(9) 089743456 999BB99BB9999 089 74 3456