The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.

Slides:



Advertisements
Similar presentations
8-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Advertisements

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
7-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
Chapter 2: Introduction to C++.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
COBOL for the 21st Century
Structured COBOL Programming, Stern & Stern, 9th Edition
Chapter 2 Basic SQL SELECT Statements
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
COBOL Basics 1. COBOL coding rules  Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are known as;
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
2-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
1 The Data Division. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage Section –All.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Structured Programming
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Chapter 2 Using Variables and Constant. What is a Constant ? The data in COBOL programs falls in two broad categories: – Constants and Variables A constant.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
2-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
16- 1 Chapter 16.  To familiarize you with  COPY statement for copying parts of a program stored in a library  CALL statement for executing called.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Submitting Instructions on web site CS 1024 students Read guide
Structured Programming
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Chapter 2: Introduction to C++.
Any Questions?.
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

The DATA DIVISION Chapter 3

COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits in an amount Records - group of related fields –All fields related to customer File - group of related records –Customer file made up of customer records

DATA DIVISION Defines, describes storage for all data Two main sections –FILE SECTION Defines all input and output files, records, fields Required for any program that uses files, typically batch programs Must match the files listed in the SELECT statements –WORKING-STORAGE SECTION Defines constants, end-of-file indicators and work areas Defines fields not part of input or output files

File Description Entries Each file described with an FD (File Descriptor) sentence One FD for each SELECT statement in ENVIRONMENT DIVISION FD followed by File-name Optional clauses to describe file and format of its records

Data-Name Guidelines 1.Use meaningful data-names that describe contents of field Amount-Due-In instead of A1 2.Use prefixes or suffixes in data-names when appropriate -IN and -OUT for fields (Emp-Salary-IN and Emp-Salary-OUT) -FILE and -RECORD for file and record names (Emp-File and Emp-Record)

File Description clauses LABEL RECORDS clause –Used if labels stored in file BLOCKS CONTAINS clause –Indicates blocking factor for disk files Both labels and blocking usually handled by operating systems so clauses will be omitted

RECORD CONTAINS clause Indicates size of each record Optional but recommended since it provides check on record size Given this FD FD Sales-File Record Contains 75 Characters. If PICTURE clauses mistakenly add up to 76, compiler will report a syntax error

Defining a Record Each FD followed by record description entries for the file Data grouped in COBOL by levels Record-name defined at the 01 level Considered highest level of data Fields within a record defined at subordinate level with level numbers from 02 to 49

Record Description Example 01 Employee-Rec-In. 05 Name-In … 05 Annual-Salary-In … 05 Job-Description-In … Fields at 05 level subordinate to 01 level entry All fields at same level (05), independent or not subordinate to each other

Elementary and Group Items Items defined with a level number are one of two types –Elementary item - field that is not further subdivided Must include a PICTURE clause –Group item - field that is further subdivided Has no PICTURE clause

Elementary and Group Items 01 Employee-Rec-In. 05 Name-In … 10 First-Name-In (Picture clause) 10 Last-Name-In (Picture clause) 05 Annual-Salary-In (Picture clause) Name-In is group item since it is subdivided into first and last name Employee-Rec-In also group item First-Name-In is elementary item since it is not further subdivided

PICTURE (PIC) clauses Specify type of data stored in field Indicate size of field

Types of data fields Alphabetic - A Only letters or blanks For name, item description, etc. Archaic; no longer used Alphanumeric - X Any character - letters, digits, special characters For an address like 123 N. Main St. Numeric - 9 Only digits For fields used in arithmetic operations

Size of Data Fields Denote size of field by: Number of A’s, X’s or 9’s used in PICTURE 01 Cust-Rec-In. 05Cust-ID-InPicture XXXX. 05Amt-InPicture 9(5).

Defining Fields in Record Must account for all positions defined in record layout Must describe fields in order they appear in record Field names should be unique For fields not used by program –Data-name may be left blank (preferable) –May use reserved word FILLER as data-name –Positions must still be defined using PIC clause

Implied Decimal Point For fields used in arithmetic operations Symbol V used in PIC clause to denote location of implied decimal point Decimal point itself not stored as part of number To store value in field AMT-IN, code entry as 05 Amt-In Pic 99V99.

Types of Constants Numeric literal Examples: Constant used for arithmetic operations Nonnumeric (alphanumeric) literal Examples: “INVALID” “Enter your name” Constant used for all operations except arithmetic Figurative constant SPACES ZEROS Reserved word for commonly used values

Rules for Nonnumeric Literals Must be enclosed in quotation marks From 1 to 160 characters, including space Any character in COBOL character set except quotation mark Valid Nonnumeric Literals '123 Main St.' '$14.99' '12,342' " Enter a value from 1 to 10 "

Figurative Constants - ZERO ZERO, ZEROS or ZEROES means all zeros Move Zeros To Total-Out Fills each position in Total-Out with a zero May be used with both numeric and alphanumeric fields Example

Figurative Constants - SPACE SPACE or SPACES means all spaces or blanks Move Spaces To Code-Out Fills each position in Code-Out with a space or blank Use only with alphanumeric fields since blank is invalid numeric character Example

WORKING-STORAGE SECTION Follows FILE SECTION Begins with heading on line by itself Starts in Area A, ends with period All items must be defined at 01 level or in entries subordinate to 01 level entry Elementary items: –Must include PICTURE clause –May be assigned initial value with VALUE clause

VALUE clause To define initial value for field If omitted, field’s value undefined when program begins execution May be used only in WORKING- STORAGE SECTION

VALUE vs MOVE VALUE clause used in DATA DIVISION –Gives initial value before execution begins MOVE used in PROCEDURE DIVISION –Assigns value to field after program begins MOVE may change initial value of field