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.

Slides:



Advertisements
Similar presentations
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Advertisements

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.
Programming Logic and Design Fourth Edition, Introductory
Modules, Hierarchy Charts, and Documentation
Chapter 2: Introduction to C++.
CHAPTER 6 FILE PROCESSING. 2 Introduction  The most convenient way to process involving large data sets is to store them into a file for later processing.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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;
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs.
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)
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
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.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
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.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
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++
1 The Procedure Division Chapter 4. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage.
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
1 IDENTIFICATION and ENVIRONMENT DIVISIONS. 2 Objectives Basic Structure of COBOL Programs General Coding and Formatting Rules Identification and the.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
INPUT / OUTPUT STATEMENTS
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.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
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.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
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!
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
CSC201: Computer Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Structured Programming
Variables and Arithmetic Operations
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
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++.
Topics Introduction to File Input and Output
Presentation transcript:

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 accumulators, counters, subscripts, flags, tables, etc. –All constant records, such as print header records and other constant or near-constant records. But first:

3 User-Defined Data Name Formation 1. 1 TO 30 CHARACTERS; LETTERS, DIGITS, HYPHENS 2. MUST NOT BEGIN (OR END) WITH A HYPHEN 3. NO EMBEDDED BLANKS 4. MUST CONTAIN AT LEAST ONE ALPHABETIC CHARACTER 5. CAN'T BE A COBOL RESERVED WORD. E.G., CAN'T SAY "DATA" AS A DATA-NAME (FIELD NAME) BUT CAN SAY "DATA-IN" OR "IN-DATA", ETC. A TRADITION IS TO ADD THE SUFFIX -IN OR -OUT TO INPUT AND OUTPUT FIELDS. ALSO: -WK AND -S (SORT) ETC. AND OTHERS, AS IN TOTAL-WK... BETTER APPROACH: USE FIRST TWO CHARACTERS OF FILE NAME / RECORD NAME AS “PREFIXES.” `E.G.: 01 EMPLOYEE-REC. 05ER-NAME... 05ER-ADDRESS... 05ER-PHONE WHY BETTER?? MUST CONFORM TO A CORPORATION’S “STANDARDS!” ONCE A FILE, RECORD, OR FIELD IS NAMED, THAT EXACT SAME NAME MUST BE USED THROUGHOUT THE PROGRAM UNIT TO REFER TO THAT ITEM. E.G., IF YOU USE "SSAN" - CAN'T USE "SN" OR "SSN" TO REFER TO THE SAME ITEM! (syntax error)

4 Sections FILE SECTION INPUT AND OUTPUT FILES DEFINED HERE. ALL FILES DEFINED HERE. WORKING-STORAGE SECTION TEMPORARY DATA ITEMS TABLES, FLAGS, COUNTERS, ACCUMULATORS PRINT LINE HEADERS / TRAILERS MOST COBOL PROGRAMS HAVE AT LEAST ONE INPUT AND ONE OUTPUT FILE.. CAN HAVE MANY!! CONSIDER OLD-MASTER, TRANSACTION-FILE, NEW-MASTER FILE SCENARIO: A PERSONNEL FILE (OLD MASTER FILE) WITH ADD, CHANGE, AND DELETE TRANSACTIONS “AGAINST IT” PRODUCES A NEW MASTER FILE. MAY OPTIONALLY PRODUCE ACCOMPANYING REPORTS: TRANSACTION REGISTER, ERROR LIST CHANGE LIST. ALL ARE FILES IN COBOL AND MUST EACH BE DESCRIBED.

5 User-Defined Data Name Formation 1. 1 TO 30 CHARACTERS; LETTERS, DIGITS, HYPHENS 2. MUST NOT BEGIN (OR END) WITH A HYPHEN 3. NO EMBEDDED BLANKS 4. MUST CONTAIN AT LEAST ONE ALPHABETIC CHARACTER 5. CAN'T BE A COBOL RESERVED WORD. E.G., CAN'T SAY "DATA" AS A DATA-NAME (FIELD NAME) BUT CAN SAY "DATA-IN" OR "IN-DATA", ETC. A TRADITION IS TO ADD THE SUFFIX -IN OR -OUT TO INPUT AND OUTPUT FIELDS. ALSO: -WK AND -S (SORT) ETC. AND OTHERS, AS IN TOTAL-WK... BETTER APPROACH: USE FIRST TWO CHARACTERS OF FILE NAME / RECORD NAME AS “PREFIXES.” `E.G.: 01 EMPLOYEE-REC. 05ER-NAME... 05ER-ADDRESS... 05ER-PHONE WHY BETTER?? MUST CONFORM TO A CORPORATION’S “STANDARDS!” ONCE A FILE, RECORD, OR FIELD IS NAMED, THAT EXACT SAME NAME MUST BE USED THROUGHOUT THE PROGRAM UNIT TO REFER TO THAT ITEM. E.G., IF YOU USE "SSAN" - CAN'T USE "SN" OR "SSN" TO REFER TO THE SAME ITEM! (syntax error)

6 System Flow Chart Transaction File Old Master File Personnel Edit/Update Program New Master Fle (updated) Transaction Register Change List Error List

7 Given this System Flow Chart: FD ENTRIES. (FILE DESCRIPTIONS…) EACH FILE IN PROGRAM MUST BE NAMED IN A SELECT STATEMENT. SELECT STATEMENTS FOUND WITHIN: FILE-CONTROL PARAGRAPH INPUT-OUTPUT SECTION ENVIRONMENT DIVISION. EACH FILE NAMED IN FILE-CONTROL PARAGRAPH (ABOVE) MUST BE DESCRIBED IN THE FILE SECTION IN THE DATA DIVISION. Given: FILE-CONTROL. SELECT OLD-MSTR-FILE ASSIGN TO DISK1. SELECT NEW-MSTR-FILE ASSIGN TO DISK2. SELECT TRANS-FILE ASSIGN TO DISK3. SELECT TRANS-REGISTER-FILE ASSIGN TO PRINTER. SELECT ERROR-LIST-FILE ASSIGN TO PRINTER. SELECT CHANGE-LIST-FILE ASSIGN TO PRINTER. REQUIRES SIX FILE DESCRIPTIONS IN THE DATA DIVISION – ONE FOR EACH NAMED FILE:

8 FD Clauses File Description (FD) entries - clause. all FD clauses are optional in COBOL 85.. Label records clause Label Record is omitted Label Records are Standard Label Record is Undefined if using the clause, then select one. Often may be very helpful and most organizations will likely have standard labels…. Label Records are the first and last records of a tape file and present file-id information about the file that follows. Labels on files on disk in VTOC…or FAT or other directory type of structure. can contain much other information: data last written to LRECL (logical record length) BLKSIZE DSN (data set name) Security OPR (office of primary responsibility) and more. In Cobol 85, not a required clause; defaults to "standard“; In Cobol 74, clause was required.. FD Employee-File Label Records Standard. (a b areas)

9 FD Clauses Record Contains clause.... Record contains {integer-1} characters. This is the size of the logical record!. This is the record you get via a read or write.. e.g. Record contains 80 characters. Could say, Record 80.. Always optional Advantage: if you include the record contains clause in your FD entries, every read and write operation causes the computer to check the length of the record you are reading or writing. If an error, it will let you know. Also, if the record description doesn’t match the number of characters specified in the record contains clause, you will get a compilation “warning.” Highly desirable! Use this..... It may save you time in diagnosing run time errors.

10 FD CLAUSES Block Contains clause... Block contains {integer-1} records. Blocking speeds up i/o operations dramatically - but, of course, there is a cost..... Blocking increases efficiency of utilization of tapes and disks.. Costs memory space; buffer space.. Explain a tape with 6250 bpi - Note that this is very old technology!!!! one 80 character records requires.0128" Blocked at 100, ==> requires 1.28" per 100 logical. Records per physical record (block) on tape. IBG or IRG is fixed by hardware -.75" is normal.. Optional clause.. Most assuredly will use in an operational environment!!!.. There will likely be a “standard” here...

11 Logical and Physical Reads (and Writes) Discuss:. When your program executes a read (or write) (Logical read).. The “01" = “the process area”.. Buffers and physical reads.. Pointer to “active” record.. Double buffering.. Storage cost.. contention for cpu cycles... Recognize that there is a difference between a logical and a physical read (or write). Devices only deal with physical records (blocks / sectors, …). The logical part is in your program.

12 Record Descriptions A RECORD IS A COLLECTION OF RELATED DATA FIELDS WITHIN A FILE. MOST FILES: RECORDS ARE OF SAME LENGTH AND SAME FORMAT.. CALLED FIXED-LENGTH RECORDS.. HAVE “VARIABLE LENGTH RECORDS” TOO. CAN HAVE RECORDS OF THE SAME SIZE BUT OF DIFFERENT FORMAT IN THE SAME FILE..... CAN HAVE A SALARY HISTORY RECORD ( OF, SAY, SIZE 80) AND A PERSONNEL RECORD (ALSO OF SIZE 80) IN THE SAME FILE.. WOULD SAY: FD MF-SALARY-HIST-REC MF-PERSONNEL-REC......

13 Record Descriptions A very common occurrence.... Discuss: when reading a record, how does a program “know” which record format was read? Similarly for output:. Print files normally have multiple output formats:.. Report headers... Column headers.. Detail records.. Summary records.. Trailer records (at bottom of page).... These are different record types (formats) belonging to the same file (print file). Each type requires a separate 01 record description, as you would expect.. Will return to this when we discuss “Working Storage Section.”

14 Record Formats For each named file (Select statement), we have an FD. For each FD, we have one record descriptions for each record format in the file.. Each record format (record “description”): Names the record (the 01 level) Names the data fields in order in the record Shows any dependencies (group / elementary items). File name is specified at the “FD level.". Record name is specified at the "01 level.". Each FD (file definition) is followed by a description of the record formats..

15 Record Formats Record formats are named and described "at the 01 level.. Record name = highest level of data - the 01 level.. Other levels (higher numbers: 02-49) A field is a group of consecutive storage positions reserved for a data item Example: Let name for record be:. 01 Employee-Record-In. 05 ER-name-in ER-annual-salary-in ER-job-description-in.... Note the name of the record Note the number and names of the individual fields Note the relative position of the fields in the record Note that there will be additional info for each field (Coming) Note 01 is in the A-margin, while all other higher-numbered (but subordinate) fields will fall in the B-margin. These are sometimes referred to as a-area and b-area. Note: all 05's are not subordinate to each other, but they do follow each other in the record... Related only by relative position in the record.

16 01 EF-EMPLOYEE-RECORD. 05 ER-NAME. 10 ER-INITIAL1PIC X. 10 ER-INITIAL2PIC X. 10 ER-LAST-NAMEPIC X(15). 05 ER-ANNUAL-SALARYPIC 9(6). 05 ER-JOB-DESCRIPTION. 10ER-TITLE. 15ER-LEVEL PIC ER-POSITIONPIC X(4). 10ER-DUTIES PIC X(15). 05 PIC X(35) Unused

17 Hierarchy of Level Numbers INDENT FOR SUCCESSIVE LEVELNUMBERS PIC CLAUSES - SIZE AND CLASSIFICATION. CLASS (A,X,9) A ===> ? X ===> WHAT? 9 ===> ? SIZE X(4) OR XXXX OR 9(6)V99. GROUP AND ELEMENTARY ITEMS - DEFINITIONS... ELEMENTARY ITEMS MUST HAVE PIC CLAUSES GROUP ITEM WILL NOT HAVE PIC CLAUSES. STANDARD NAMES EACH DESCRIPTION ENDS WITH A PERIOD. THE ENTIRE RECORD MUST BE ACCOUNTED FOR......

18 A numeric pic clause can only contain.. Valid numeric characters and a sign (later on the sign) An alphanumeric field can contain any characters (including numbers) in the language. An alphabetic field can contain letters of the alphabet plus the space. Numbers in PIC X fields cannot be used directly in computations. These numbers are characters and not numbers!!! Discuss: Usage is Display. “Other usages... Later” 01 - record name only fields within the record 01 is an a-area entry are b-area entries. Review group and elementary items PIC clauses on elementary items only!!! Summary of Picture Specifications

19 Implied Decimal Implied decimal example: 05 field-1 PIC 999V99.. A five position numeric field (not used for printing). Used to house a number to be used in computations.. Used for storage of ‘numeric’ data with implied decimals. Used primary for inputs and storage –. Can be used for outputs too, but not normally used for outputs that are printed. If printed, 999V99 may be reformatted as (five position, numeric field; six position report-item field…. More later…).. Inputting values such as 1234 into a 99V99 will cause the inputted number to be ultimately treated as Note: this (999V99) is considered a numeric field. Printing out a field with PIC 999V99 will result in displaying four numbers only. Normally not done. Print? Use or similar edited field.

20 Types of Data Variable data So far, we've talked about files, which consist of records, which contain fields. These file and record descriptions cause primary memory (ram) to be reserved for the records as we read them into memory from, say, disk and build them in memory to output back to disk or to printer Called variable data (explain why) Each read causes new data to be brought into ram.. Data values are not known.. The data format is. Data values are read in or, perhaps, computed Constant data Oftentimes "non-variable" or constant data is needed. Constant data is data needed for processing but not a part of an input record (that is, it is not read in".) Example: Add 1 to counter. Constant variable Move “Record not found" to printline Constant variable

21 Two Ways to Get Constant Data into Program 1. By using the constant where needed in the Procedure Division Add 1 to counter Multiply 1.5 by rate giving over-time-rate 2. By defining “Working-Storage" data items with "value" clauses 01 one PIC 9 Value ot-factor PIC 9v9 Value 1.5. In usage: Add one to counter Multiply ot-factor by rate giving over-time-rate Constant variable variable But note: once we have a “data name”, we “can” change its value. Could say: move 3 to one. Then one has a value of 3! Very very poor programming - but can be done. Data declared in the working storage section within the data division can have value clauses (ahead...) Data defined in the file section of the data division cannot have Value clauses (exceptions coming). But this does not make sense!!!!

22 Constants – Three Kinds Kinds of constants: Numeric literals; Non-numeric literals; Figurative Constants Consider: Add 1 to counter This is an example of a numeric literal type of constant A numeric literal "is a constant used primarily for arithmetic operations." Rules: digits 2. +, -, Option on the left 3. Decimal point may be embedded or precede the number; not the last character. Can say: add 0.3 to amt add.3 to amt add 3.0 to amt add to result Subtract from sum Can not say: add 3. To amt Add $1000 to total (only numbers and sign allowed.) Add 1,000 to amt (no special characters) Note: for storage in files, we rarely store the decimal. We store the data as 999V999 data; that is, ‘implied decimal.’ In the constant, however, we must always include the decimal, if it is part of the number.

23 Constants – Three Kinds Kinds of constants: numeric literals; non-numeric literals; figurative constants Non-numeric literals (alphanumeric literals). Is a constant. Is text and cannot be used for arithmetic Rules: 1. Enclosed in double quotes characters (Check on this size…) 3. Includes any characters except quotes (Special rules for enclosing quotes: later) Examples "Code" "input" "abc**123 " "$1,000" Can say Move “ABC" to Outfield and this moves the characters A, B, and C to the field, Outfield.

24 Constants – Three Kinds Kinds of constants: numeric literals; non-numeric literals; figurative constants Alphanumeric literals must be enclosed in quotation marks. If not, it is not a non- numeric literal (constant). Cannot say: Move data to Outfield (data is reserved). Can say:Move "data" to Outfield. Can say Add 123 to Amt. Cannot say add "123" to amt. (Assumes amt is numeric field). Can contain any characters. Compiler does not check to see of any reserved words are contained within the quotes. It doesn't care. Compare:Move xyz to field2 Move "xyz" to field2 Move 789 to amt-field Move "789" to amt-field Discuss?

25 Constants – Three Kinds Kinds of constants: numeric literals; non-numeric literals; figurative constants Two main examples: zeroes, zeros and spaces and space There are several others: high values and low values zeroes and spaces are all reserved words meaning all spaces or all zeroes. Examples: Move spaces to printrec; (clears print area) Move zeroes to amt-field (resets amt-field to 0) Move zeroes to counter.(clears (sets to zero) counter) (Could say: Move 0 to Counter too)

26 Working-Storage Section Any data-field necessary for processing. Not directly part of an input or output record. Typically, these items found in working storage are. Constants Temporary variables containing temporary values. Counters. Flags used a lot for counters. Accumulators flags, accumulators,. Tables initializing variables. Others... and setting up Syntax: Working-Storage Section. tables and constants Col 8. Has individual working storage items within it. Example: 01 ws-stored-items. 05 f-are-there-more-recordspic xxx value “yes”. 05 c-input-record-countpic 99 value zeroes. 05 c-num-02-commissionspic 999 value c-num-03-commissionspic 999 value c-total-amt-commissionspic 9999 value 0.. Value clauses are used all the time in COBOL programming.

27 Example with Counter Example with Counters. If amount-of-sales-in > Multiply 0.03 by amount-of-sales-in giving amt-commission-out Add 1 to c-num-03-commissions Else Multiply 0.02 by amount-of-sales-in giving amt-commission-out Add 1 t0 c-num-02-commissions End-if At end of file, print out the total number of people who received 2% commission and total number of people receiving 3%. Note: how “if” statement terminated:. Period could end it as could a scope terminator.. Will use “scope terminators” later. Need to recognize both!

28 Example with Accumulators and Temporary Holding Variables Given: FD Printfile print-rec. Explain this 01 summary-rec. 05 filler pic x(10). 05 p-total-commissions pic filler pic x(118). Say you wanted to accumulate all the commissions and merely print out a single total amount of commission dollars saved in addition to the former totals... If amount-of-sales-in > Multiply 0.03 by amount-of-sales-in Giving amt-commission-out, a-commission Else Multiply 0.02 by amount-of-sales-in Giving amt-commission-out, a-commission End-if Add a-commission to a-tot-commission. (A-commission and a-tot-commission are data items - accumulators - in working storage.)

29 Example with EOF Indicators We have used the data name "are-there-more-records' as an end of file indicator. We have "initialized" it to "yes" Every time a record is read from the file, an end-of-file marker can be "tested for" by the read statement. Read some-file at end (that is, if we tried to read and no more records available) Move "no" to are-there-more-records. Or Read some-file at end Move “no” to are-there-more-records end-read Which do you like? Why? Which is more “error prone” to use? Why?. The eof of a file is sensed by computer reading the file.. We used “are-there-more-records” in working storage to hold a “yes” or “no.”.. Field is not part of record.. But needed for processing... We can set / reset at will... We can set its value and we can test its value and make the program do certain things based upon that test.

30 Example with Reads and Priming the Pump – One way to go… We can say: Read sales file at end move "no" to are-there-more-records. Perform 200-commission-rtn Until are-there-more-records = "no". Note: we tested it each iteration of 200-commission-rtn!! Assumes we had: Working-Storage Section. 01 are-there-more-records pic xxx value "yes". Last statement in 200 commission-rtn is 200-commission-trn.... Read sales file At end Move "no" to are-there-more-records end-Read.

31 Example with Reads and Priming the Pump – One way to go… Discuss: Priming the pump! Could also use "eof" as end of file E.G.: Working-Storage Section. 01 eof pic 9 value 0. ….. Read infile at end move 1 to eof end-read Perform 200-process-rtn until eof = process-rtn.... Read infile At end move 1 to eof. 220-next-para....

32 Value Clauses for Working-Storage Entries – Why?? When a program is loaded into storage, it occupies an area some other program used. Pic 999. reserves a three-byte area for numbers. Pic 999 value 0. Reserves a three byte area also and sets it to 0. This is why we set the print-rec to spaces before we build it. First time, we want to ensure it is clear.... If we did not clear the area out, we might have: junk |name-out| junk |commission-out| junk| Consider: 05 w-no-02-commissions pic 99. Note: no initial value in working- storage) Now execute: add 1 to w-no-02-commissions. Bomb!!! Why? Discuss... Fields you are moving into other fields do not required prior clearing. But if you are adding to a field, you are assuming that there is numeric data to add to.

33 Value Clauses for Working-Storage Entries - More… Can initialize at the group level: 01 w-counters value zeroes. 05 w-count1 pic w-count2 pic 9v99. Consistency in value clauses and picture clauses: Data in the value clauses must be the same type as picture clauses 05 w-total pic 999 value zeroes ok value 0 ok value spaces. No!! Why not?? 05 w-total pic 9v99 value 4.75.Okay Value 0. Value “ Value Value spaces. No! Note the value clause is the same as a procedure division statement: “Move” but better, actually. Why??? Are occasions where value clause is inefficient...Much later.

34 Value Clauses for Working-Storage Entries - More… Alphanumeric literals: 01 w-text-codes. 05 code-1 pic xxx value "abc“. Value "123" Value abc Value spaces Value " ". Are all okay??? Continuation of non-numeric literals 01 column-hdr pic x(123) value " " -" ".