Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

Programming Logic and Design Sixth Edition
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
Lesson 5 Packed-Decimal or Computational-3 (COMP-3) MOVE TO WS-AMOUNT ====> 4 bytes instead of 7. Significant storage saving. On the.
Chubaka Producciones Presenta :.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
Two and three dimension tables Please use speaker notes for additional information!
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and SI Iteration Logical Files Positioning the file pointer.
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)
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)
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.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Modifications to program Addda.cbl Please use speaker notes for additional information!
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.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
COBOL Cobol is one of the most robust language in the software field, so far Cobol turned 50, in 2009 Cobol has stood the test of time Common Business.
Totals on the Screen Please use speaker notes for additional information!
Agenda Reporting Work on Assignment 4! Printing on power systems.
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
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.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Indexed and Relative File Processing
1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.
Initial Steps in Program Development [Using problem defined in Ch. 1 of Stern & Stern]
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.
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
COBOL Screens Please use speaker notes for additional information!
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
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.
Any Questions? Agenda Level 77 Initialize Display & Accept Arithmetic Verbs Compute statement String/Unstring Inspect.
One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.
Any Questions!. Agenda Fun with Functions –how to get the system date –How to get the next service date INDARA and SI Condition Names Iteration Logical.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
This is It! It’s been a pleasure! Final Exam – format True / false 5 Multiple choice 5 Short answers10 Data manipulation10 SQL 3 Array’s12 File processing25.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Any Questions! 2 Agenda Moving data Arithmetic Verbs Compute statement.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Any Questions!. Agenda Fun with Functions Externally Described Files Condition Names Iteration Logical Files Random Reads.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Random update Please use speaker notes for additional information!
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
TIMELINES PHOTOS This is an example text
TIMELINES PHOTOS This is an example text
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
Any Questions?.
Chapter 14 Sorting and Merging.
McDonald’s Kalender 2009.
Agenda Collating sequence / Sorting data
McDonald’s calendar 2007.
McDonald’s calendar 2007.
2015 January February March April May June July August September
Presentation transcript:

Any Questions!

Test Coming Up!

Agenda Printing with Externally Described Printer Files Arrays

Printing with Externally Described Printer Files New addition to the select statement – FORMATFILE! select report-file assign to formatfile-filename.

Writing to an Externally Described Printer File Write record-name format is ‘RECORD’ eop perform print-heading End-write. (eop means end of page)

What is an array?

Example January February March April May June July August September October November December

Example 2 1January 3March 5May 7July 9September 11November 2February 4April 6June 8August 10October 12December

Example 1 January February March April May June July August September October November December

Coding Example 01 Month-Names. 05 Month1 PIC X(15) VALUE ‘January’. 05 Month2 PIC X(15) VALUE ‘February’. ….. 05 Month12 PIC X(15) VALUE ‘December’.

Coding Example - Arrays 01 Month-Names-Array. 05 Month-Names OCCURS 12 TIMES PIC X(15). Use Subscripts (position) to access information in arrays.

Example 2 1January 3March 5May 7July 9September 11November 2February 4April 6June 8August 10October 12December

Coding Example 01 Month-Names. 05 Month1. 10 Month1-Number PIC 9(2) VALUE Month1-Name PIC X(15) VALUE ‘January’. 05 Month2. 10 Month2-Number PIC 9(2) VALUE Month2-Name PIC X(15) VALUE ‘February’ ….. 05 Month Month12-Number PIC 9(2) VALUE Month12-Number PIC X(15) VALUE ‘December’.

Coding Example - Arrays 01 Month-Names-Array. 05 Month-Entries OCCURS 12 TIMES. 10 Month-Number PIC 9(2). 10 Month-Name PIC X(15). Use Subscripts (position) to access information in arrays.

Loading Arrays - Redefines 01 Month-Names. 05 Month-String PIC X(36) VALUE ‘JanFebMarAprMayJunJul… 05 Month-Entries REDEFINES Month-String OCCURS 12 TIMES PIC X(3).

Loading Arrays - Redefines MOVE ‘January’ TO Month-Entries (1). MOVE ‘February’ TO Month-Entries (2). MOVE ‘March’ TO Month-Entries (3). MOVE ‘April’ TO Month-Entries (4). MOVE ‘May’ TO Month-Entries (5). MOVE ‘June’ TO Month-Entries (6). MOVE ‘July’ TO Month-Entries (7).

Loading Arrays – Read from a File Create a physical file (Month-File) with the fields: –Month Number –Month Name Create an array as follows 01 Month-Table. 05 Month-Entries occurs 12 times. 10 Month-Number PIC 9(2). 10 Month-Name PIC X(15).

Loading Arrays – Read from a File PERFORM 120-Read-Table-Rtn VARYING Sub FROM 1 by 1 UNTIL Sub > Read-Table-Rtn. READ Month-File into Month-Entries (sub) AT END DISPLAY ‘Not enough table records’ END-READ.

Searching Arrays January February March April May June July August September October November December

Searching Arrays 01 Sub PIC 9(2). 01 Month-Names-Array. 05 Month-Names OCCURS 12 TIMES PIC X(15). MOVE 11 TO Sub. MOVE Month-Names (sub) to Month-Name-Out.

Searching Arrays 1January 3March 5May 7July 9September 11November 2February 4April 6June 8August 10October 12December

Searching Arrays – Using Sub- Scripts 01 Sub PIC 9(2). 01 Month-Names-Array. 05 Month-Entries OCCURS 12 TIMES. 10 Month-Number PIC 9(2). 10 Month-Name PIC X(15). PERFORM 120-Get-Month-Name Until Month-Number (Sub) = 11. MOVE Month-Name (SUB) to Month-Name-Out. 120-Get-Month-Name. Add 1 to Sub.

Searching Arrays – Using Indexes and the Search Verb 01 Month-Names-Array. 05 Month-Entries OCCURS 12 TIMES INDEXED BY Sub. 10 Month-Number PIC 9(2). 10 Month-Name PIC X(15). SET Sub to 1. SEARCH Month-Entries AT END MOVE ‘Error’ to Month-Name-out WHEN Month-Number (Sub) = 11 MOVE Month-Name (Sub) to Month-Name-Out END-SEARCH.

Searching Arrays – Sorted Arrays 1January 2February 3March 4April 5May 6June 7July 8August 9September 10October 11November 12December

Searching Arrays – Sorted Arrays (Binary Sort) 01 Month-Names-Array. 05 Month-Entries OCCURS 12 TIMES INDEXED BY Sub ASCENDING KEY IS MONTH-NUMBER. 10 Month-Number PIC 9(2). 10 Month-Name PIC X(15). SEARCH ALL Month-Entries AT END MOVE ‘Error’ to Month-Name-out WHEN Month-Number (Sub) = 11 MOVE Month-Name (Sub) to Month-Name-Out END-SEARCH.

26 Review of some Basics

27 Moving Data Basics The MOVE

28 MOVE ident1 TO ident2 It copies the contents of a field, variable, or literal into another field or variable The fields and variables must be defined in the data division accordingly Ident1 = any variable defined in the data division or any literal Literal: Numeric constant such as and Alphanumeric constant such as ‘JOHN’ and ’OFFICE’

29 MOVE ident1 TO ident2 Ident2= any variable defined in the data division or any literal Ident1is called the sending variable Ident2 is called the receiving variable Ident1 and Ident2 are expected to be of the same type (both alphanumeric or both numeric) Size can be different but programmer should be aware of abnormal results

30 MOVE Examples WORKING-STORAGE SECTION. ==== 01 WORKING-VARIABLES. 05 PLANT1-DEPART PIC X(4). 05 PLANT2-DEPART PIC X(6). 05 PLANT1-STAFF PIC PLANT1-SALARY PIC 9999V PLANT2-STAFF PIC PLANT2-SALARY PIC 9999V99. PROCEDURE DIVISION. === MOVE ‘OFFI’ TO PLANT1-DEPART MOVE ‘PRODUC’ TO PLANT2-DEPART MOVE PLANT2-STAFF TO PLANT1-STAFF === MOVE TO PLANT1-SALARY MOVE 340 TO PLANT2-STAFF MOVE PLANT1-SALARY TO PLANT2-SALARY

31 MOVE SENDING-FIELD TO RECEIVING-FIELD Content of the Receiving field after MOVE execution

32 MOVE SENDING-FIELD TO RECEIVING-FIELD Contents of Receiving fields after MOVE execution

33 NUMERIC EDITED FIELDS Variable used as a MASK that present the contents of a variable in a meaningful way to the user Used as output variables: sent to a printer, monitor, etc. Basic editing: $ decimal point sign suppression of leading zeros

34 NUMERIC EDITED FIELDS 01 DETAIL-LINE. 05 FILLER PIC X(8) VALUE SPACES. 05 DET-NAME PIC X(25). 05 FILLER PIC XX VALUE SPACES. 05 DET-HOURS PIC ZZZ. 05 FILLER PIC XX VALUE SPACES. 05 DET-PAY PIC $Z,ZZZ FILLER PIC X(92) VALUE SPACES. PROCEDURE DIVISION. === ==== PIC ZZZ Any leading zero is replaced by blanks after the MOVE PIC ZZZ Any leading zero is replaced by blanks after the MOVE 3 2 MOVE 032 TO DET-HOURS DET-HOURS

35 NUMERIC EDITED FIELDS AND THE MOVE STATEMENT 01 DETAIL-LINE. 05 FILLER PIC X(8) VALUE SPACES. 05 DET-NAME PIC X(25). 05 FILLER PIC XX VALUE SPACES. 05 DET-HOURS PIC ZZZ. 05 FILLER PIC XX VALUE SPACES. 05 DET-PAY PIC $Z,ZZZ FILLER PIC X(92) VALUE SPACES. PROCEDURE DIVISION. === ==== PIC $Z,ZZZ.99 Any leading zero is replaced by blanks and $ inserted to the left after the MOVE PIC $Z,ZZZ.99 Any leading zero is replaced by blanks and $ inserted to the left after the MOVE $ MOVE TO DET-PAY MOVE TO DET-PAY $1, DET-PAY

36 Moving Record To Record 01 PRINT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 HEADING-LINE. 05 FILLER PIC X(12) VALUE 'EMPLOYEE... '. 05 FILLER PIC X(110) VALUE SPACES. PROCEDURE DIVISION. MOVE HEADING-LINE TO PRINT-LINE The entire content of PRINT-LINE is moved to HEADING-LINE Size of both records should be the same; otherwise, truncation occurs The content is moved as ALPHANUMERIC: from left to right

37 PERFORM Basics The PERFORM…UNTIL

38 The PERFORM UNTIL Executes a paragraph (group of statements) until a condition is met The condition must be changed within the paragraph in order to allow the loop end Format: PERFORM paragraph-name UNTIL condition

39 PERFORM….UNTIL is equivalent to DO…WHILE MOVE ‘Y’ TO FLAG PERFORM UPDATE-FILE UNTIL FLAG = ‘N’ ==== UPDATE-FILE. COMPUTE SALES-TOTAL = SALES-WEEK + PREVIOUS-YEAR IF SALES-TOTAL MOVE ‘N’ TO FLAG. = ===

40 PROCESS APOST. IDENTIFICATION DIVISION. PROGRAM-ID. PAYREP. AUTHOR. ANDRE BERNS. DATE-WRITTEN. JAN/13. DATE-COMPILED. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAYROLL-FILE ASSIGN TO DATABASE-PT001F ORGANIZATION IS SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD PAYROLL-FILE RECORD CONTAINS 45 CHARACTERS DATA RECORD IS EMPLOYEE-IN. 01 EMPLOYEE-IN. 05 EMP-NAME PIC X(25). 05 EMP-HOURS PIC 9(03). 05 EMP-RATE PIC 99V9 USAGE COMP EMP-DEP PIC X(15). FD PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. 01 PRINT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 HEADING-LINE. 05 FILLER PIC X(12) VALUE 'EMPLOYEE... '. 05 FILLER PIC X(110) VALUE SPACES. 01 DETAIL-LINE. 05 FILLER PIC X(8) VALUE SPACES. 05 DET-NAME PIC X(25). 05 FILLER PIC XX VALUE SPACES. 05 DET-HOURS PIC ZZZ. 05 FILLER PIC XX VALUE SPACES. 05 DET-PAY PIC $Z,ZZZ FILLER PIC X(92) VALUE SPACES. 77 EOF-FLAG PIC X VALUE SPACES.

41 PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. PERFORM HEADER-LINE PERFORM PROCESS-RECORDS UNTIL EOF-FLAG = 'N'. CLOSE PAYROLL-FILE PRINT-FILE. STOP RUN. HEADER-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. PROCESS-RECORDS. MOVE EMP-NAME TO DET-NAME MOVE EMP-HOURS TO DET-HOURS COMPUTE DET-PAY = EMP-HOURS * EMP-RATE MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. Putting the pieces together