In COBOL before using any data items we have to first declare the data item so it will stores in memory and then only we can use it in further program.
Suppose i haven’t declare data item customer number and in my procedure division section i am writing “Move 255 to Customer number “. It will not work as i haven’t assigned a memory for the data item customer.
Before declaring variable you should consider 3 things.
1)Name of data item relevant to operation.
2)Max memory space required for data item.
3)Data item type like numeric,alphabetic,alphanumeric.
What are the different types of Data item ?
There are 4 types of Data item that we used in COBOL program.
1)Variables
2)Structure
3)Literals
4)Constants
All these data item definition should placed in DATA Division.
If a data item is divided into different data items then it is a Structure or Group data items.
Identification of that DATA item is depends on group data item.
Ex:
Suppose a Student name has 3 fields.
1)Student F-Name
2)Student M-Name
3)Student L-Name
So to define student name like below:
Suppose i haven’t declare data item customer number and in my procedure division section i am writing “Move 255 to Customer number “. It will not work as i haven’t assigned a memory for the data item customer.
Before declaring variable you should consider 3 things.
1)Name of data item relevant to operation.
2)Max memory space required for data item.
3)Data item type like numeric,alphabetic,alphanumeric.
What are the different types of Data item ?
There are 4 types of Data item that we used in COBOL program.
1)Variables
2)Structure
3)Literals
4)Constants
All these data item definition should placed in DATA Division.
How to represent Numeric, Alphanumeric, and Alphabetic data type?
Suppose I have to declare a data item student-mobile-No which is completely numeric so no alphabetic and alphanumeric data inserted in this data item.
Declaration of all data item must start in Section A.
So to do this i have to declare this as Numeric data item.
I will declare it as follows:
If my Numeric data item has a 2 digit after decimal point so i have to declare data item as decimal data item to do this :
What is Level Number ?
For declaring variable first we have to declare it’s level number to define it’s structure whether it is individual data item or group data item etc.
Some important Level number.
01-49 -- Defines elementary data item (same like individual data item but can group data item)
77 -- Individual data item.
88 -- condition data item.
66 -- Rename clause.
What is DATA TYPE ?
Every digit or character requires 1 byte to store so my student-mobile-number field has 10 digit so i have declared memory which gives me a storage of 10 bytes to allocate this data item.
To represent Alphabetic data type:
Syntax:
Pic A(10) or
Pic X(10).
To represent Alphanumeric Data item :
Syntax:
Pic X(10).
Syntax of all data types:
What is Variable data item ?
As per the name a Variable data item whose value can be changed during a program. Value must satisfy the declared Variable data type and length criteria.
Ex:
01 customer-name pic X(10).
What is Structure Data item?
If a data item is divided into different data items then it is a Structure or Group data items.
Identification of that DATA item is depends on group data item.
Ex:
Suppose a Student name has 3 fields.
1)Student F-Name
2)Student M-Name
3)Student L-Name
So to define student name like below:
Ex:2
Ex:3
Ex:4
What is Literal data item?
A literal data item is a character string whose value is given by character themselves.
Use of this only in Procedure division.
Ex:
Move “ student name not found” to Student-name.
If student-no = 143 then display “student is fail”
What is constant Data item?
While defining data item in DATA DIVISION we defines it’s value also.
This is the initial value of the data item in program.
This will change after MOVE or any Arithmetic operation.
Syntax:
(Level no) then (Data item name) then (data type) then (value clause) then (value).
Ex:
03 student-no pic 9(10) value 1234567890.
03 student-name pic x(10) value “Avinash”.
What is figurative constant?
In COBOL there are some reserved words called figurative constant.
Ex:
ZERO, SPACE, HIGH-VALUE, LOW-VALUE, QUOTE, NULL, and ALL literal.
Because they represent fixed values, figurative constants do not require a
data definition.
How to initialize data item?
To initialize data items to blank or zero use INITIALIZE statement.
Syntax:
INITIALIZE data item or Group item.
How to define Signs like +ve , - ve etc. ?
To define sign value use below Syntax:
Pic S9(4)v9(2) is equivalent to S1234.56.
So ‘S’ is used to represent presence of sign and only appear at beginning of picture clause.
No comments:
Post a Comment