Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • DSA
  • Practice Problems
  • C
  • C++
  • Java
  • Python
  • JavaScript
  • Data Science
  • Machine Learning
  • Courses
  • Linux
  • DevOps
  • SQL
  • Web Development
  • System Design
  • Aptitude
  • GfG Premium
Open In App
Next Article:
COBOL - Data Types
Next article icon

COBOL - Data Types

Last Updated : 05 Apr, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

A Datatype is a classification by the programmer to tell the compiler/interpreter how data will be used inside a program. For example, the roll number of the student defined as the number will take input as a number only if other values are supplied instead of the number it will raise an abend inside the program.

SymbolShort Description

Description

Value example  
9NumericInclude Digits 0 to 9Phone_number: 9898989898
AAlphabeticInclude only Letter A to A/a-zName:   GeekForGeeks
XAlphanumericInclude both digits and lettersGift_voucher:  ABZ445
SSignedInclude integers value Balance:  -458 
PAssumed DecimalUsed to find value on the left or right side of the decimalAssumed_dec:  

Example Program: We will be using this program to explain the concepts of this article.

Cobol
IDENTIFICATION DIVISION.        PROGRAM-ID. YOUR-PROGRAM-NAME.        DATA DIVISION.        FILE SECTION.        WORKING-STORAGE SECTION.                    01 GROUP01.             02 PHONE_NUMBER            PIC 9(10) VALUE 7845955477.             02 ST_NAME                 PIC A(20) VALUE 'GeekForGeeks'.                         01 GIFTVOUCHER              PIC X(6) VALUE 'ABZ445'.            01 BALANCE                  PIC S9(3) VALUE -458.            01 ASSUMED_DEC              PIC P9(2) VALUE 23.458.        PROCEDURE DIVISION.        MAIN-PROCEDURE.             DISPLAY GROUP01             DISPLAY GIFTVOUCHER             DISPLAY BALANCE             DISPLAY ASSUMED_DEC                          STOP RUN. 


Explanation: To understand the concept of Datatype, we need to know about the basic term used.

  •  Data Name
  •  Level Number
  •  Picture Clause
  •  Value Clause

1. Data Name

A Data name is like a User-defined variable used in the program which will be used to hold different values in it and must contain only digits(0-9), letters(A-Z), minus signs, and Hyphens(-), a data name cannot use reserved words such as MOVE, COMPUTE.

Some Valid data names:   PHONE_NUMBER  ST_NAME  WS-POS1  BOOK   Invalid data names:   MOVE          : it is reserved keyword COMPUTE          : it is reserved keyword     $VAR          : $ char not allowed 100              : only number not allowed

2. Level Number

A level number is a one-digit or two-digit integer between 01 and 49, or one of three special level numbers: 66, 77, or 88. The following level numbers are used to structure records:

  • Group Item: A group item consists of one or more elementary items, in the below example GROUP01 is a group item.
  • Elementary item: It is an individual defined item, in the above example PHONE_NUMBER is an elementary item.
Level NumberDescriptionType
01Record Description or Title for GroupGeneral Level Number
02 to 49For Group/Elementary items
66Rename Clause ItemsSpecial Level Number
77Fixed cannot be subdivided to declare an elementary item
88Condition name entry (mainly used for flag purposes)

Example:

DATA DIVISION. WORKING-STORAGE SECTION.      01 GROUP01.                                                        /*GROUP ELEMENT*/     02 PHONE_NUMBER            PIC 9(10) VALUE 7845955477.            /*ELEMENTARY ELEMENT*/    02 ST_NAME                 PIC A(20) VALUE 'GeekForGeeks'.        /*ELEMENTARY ELEMENT*/    02 GIFTVOUCHER              PIC X(6) VALUE 'ABZ445'.    02 BALANCE                  PIC S9(3) VALUE 458.       66 WS-VAR2 RENAMES PHONE_NUMBER THROUGH ST_NAMES                   /*RENAME ELEMENT*/         77  ASSUMED_DEC              PIC P9(2) VALUE 23.458.                      /*INDEPENDENT ELEMENT*/       01 WS-GENDER                 PIC X(01).                             /*CONDITIONAL ELEMENT*/    88 WS-MALE                   VALUE "M".     88 WS-FEMALE                   VALUE "F".

3. Picture Clause

In the above code different datatype variables such as PHONE_NUMBER, ST_NAME, GIFT VOUCHER  are defined with the help of the Picture clause also known as PIC there are 5 symbols(9, A, X, S, P) which can be used with the help of picture clause which is already explained.

Example:

02 PHONE_NUMBER            PIC 9(10) VALUE 7845955477.        /*the PHONE_NUMBER is initialised as a numberic value with the help of picture clause using symbol 9 which can hold 10 digits*/

02 ST_NAME                 PIC A(20) VALUE 'GeekForGeeks'.  /*the ST_NAME is initialised as a Alphabetic value with the help of picture clause using symbol A which can hold 20 characters*/

4. Value Clause 

It is used to initialize the data item example in the above code PHONE_NUMBER is having a default value of 785955477, defined with the help of the value clause.it is optional to use the value clause.

When we compile and execute the above code, it will display the values defined using the Values clause

Example:

02 PHONE_NUMBER            PIC 9(10) VALUE 7845955477. /* PHONE_NUMBER is holding default value 7845955477 which will be displayed if not other values is assigned */

02 ST_NAME                 PIC A(20) VALUE 'GeekForGeeks'. /* ST_NAME is holding default string value "GeekForGeeks" defined with keyword VALUE*/


Next Article
COBOL - Data Types

B

bankay55555
Improve
Article Tags :
  • COBOL
  • COBOL-Basics

Similar Reads

    Boolean Data Type
    In programming languages, we have various data types to store different types of data. Some of the most used data types are integer, string, float, and boolean. The boolean data type is a type of data that stores only two types of values i.e. True or False. These values are not case-sensitive depend
    13 min read
    R Data Types
    Data types in R define the kind of values that variables can hold. Choosing the right data type helps optimize memory usage and computation. Unlike some languages, R does not require explicit data type declarations while variables can change their type dynamically during execution.R Programming lang
    5 min read
    SAP ABAP | Data Types
    Before Understanding the Data type first understand the Data object. Data objects are variables that we declare in the program. It occupies some memory where you can store the data from external sources. Data can be of different types, so data types are responsible for defining the type of data of t
    6 min read
    Data Layout in COBOL
    COBOL is a programming language that was developed in the 1950s for business and financial applications. In COBOL, the data layout is the arrangement of data items in a program. It specifies how the data is organized and how it is accessed.  COBOL programs are organized into four divisions: the iden
    8 min read
    C++ Numeric Data Type
    There are mainly 3 types of Numeric Data Types in C++ int unsigned intshort intunsigned short int long intunsigned long intlong long intunsigned long long intfloat double long double1. Integer (int) An integer is a type of datatype that can store integer values. Integer acquires 4 bytes in memory an
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences