Any Questions?.

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

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
Modules, Hierarchy Charts, and Documentation
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and SI Iteration Logical Files Positioning the file pointer.
Structured COBOL Programming, Stern & Stern, 9th edition
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.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
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.
Agenda Reporting Work on Assignment 4! Printing on power systems.
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.
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
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.
13-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)
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
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.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
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.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
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)
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.
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.
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)
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.
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!
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Submitting Instructions on web site CS 1024 students Read guide
How’s assignment 1 coming? Winter 2007
IBC233 Week 6.
Completing the Problem-Solving Process
Structured Programming
The Selection Structure
Programming in COBOL.
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Chapter 3 The DATA DIVISION.
Agenda Test next Week! SI or no SI? File Update Techniques – Review.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Iteration: Beyond the Basic PERFORM
Programming in COBOL-85 For IBM Mainframe System 390
Agenda Collating sequence / Sorting data
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Please use speaker notes for additional information!
Chapter 2: Input, Processing, and Output
Any Questions?.
Topics Introduction to File Input and Output
IBC233 Week 5.
Programming in COBOL.
Presentation transcript:

Any Questions?

Agenda Please review your marks Procedure Division. Chapter 3 – Working with Files Chapter 4 – Printing!

Picture Clause Review Define Variables Define how Variables are displayed

Editing Functions Function Character Printing of a / as a separator / Printing of Decimal Point in an integer . Suppress Leading Zeros in an integer Z Print a Dollar Sign in front of an integer $ Print a Comma in an integer , Printing of + or – signs + or - Printing of ‘Debit’ or ‘Credit’ symbols DB or CR Printing of Spaces as separators B Printing of Zeros as separators Print Leading asterix *

Examples Trans-Amount PIC 9(6)V999 Value 4565.78. Report-Item Edited Results PIC 9(6)V999 PIC $999999V999 PIC $ZZZ,ZZZ.99 PIC $ZZZ,ZZZ.9

Examples Trans-Amount PIC 9(6)V999 Value 4565.78. Report-Item Edited Results PIC $ZZZ,ZZZ.99- PIC $ZZZ,ZZZ.99CR PIC $ZZZZZZB99 PIC $ZZZZZZ.99+

Procedure Division Program Logic Statements are executed in the order that they appear. Logic can be divided into paragraphs (sub-routines) Some advice: Make sure a logical paragraph is terminated with a period at the end of the last statement line in the paragraph.

The Procedure Division It contains all the instructions the program will execute Any variable or data field referred by any instruction must have been defined in the DATA DIVISION The instructions are known as ‘statements’

Procedure Division (Syntax) paragraph-name. statements.

Procedure Division Structure 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. EJECT 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 MOVE DETAIL-LINE TO PRINT-LINE COMPUTE DET-PAY = EMP-HOURS * EMP-RATE WRITE PRINT-LINE Paragraph.( Pos 8-….) A sentence/statement starts at pos 12 till …. Statement or Instruction Sentence or group of Statement

Coding a COBOL Program Column based 3 parts to a COBOL source line Continuation (-) (in col 7) Area A (col. 8) Area B (col 12)

Program Comments (*) * to start a comment line Generally placed in column 7 but could be used anywhere at the end of a statement preceded by a space. i.e. …–name. *

Area A (col 8) Division Names Section Names Paragraph Names

Area B Everything else (anywhere from col 12 to 72)

Frequently Used COBOL Verbs

Types of Statements Arithmetic: Add, Subtract, Compute Input/Output: Read file records Data Manipulation: Move Selection: If..Then..Else Iteration: Perform…Until Case Structure: Evaluate..When Selection, Iteration, Case: Structured Programming Constructs

Working With Files (Procedure Division) (rest of Chapter 3)

Opening A File OPEN STATEMENT A File must be open before its records are processed The OPEN process makes the record buffer available to the program The buffer is named in the File Section as the DATA RECORD An OPEN will determine how to read or write in the file

Opening A File OPEN STATEMENT A Sequential File can be opened in different modes: Input: Records are only read - not modified Output: Records are new or written over. I-O read and or update existing records. Extend - New records to be appended after the last record When open as output new blank record space is assigned and all fields should be populated!

OPEN Statement Usually the first statement in a program Open files for processing Terminator is a period

OPEN STATEMENT OPEN mode file-name OPEN INPUT MASTER-FILE OPEN OUTPUT NEW-PAYROLL OPEN EXTEND NEW-PAYROLL

OPEN, CLOSE, and STOP RUN STATEMENTS PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. ========= CLOSE PAYROLL-FILE PRINT-FILE. STOP RUN. Each file gets an OPEN. Each OPEN has a CLOSE: File has to be closed before to end the program

CLOSE Statement Closes the files used in the program Usually the second to last set of statements executed in the program Terminator is .

STOP RUN Statement Terminates the program The last statement executed in the program. Terminator is .

OPEN Statement Usually the first statement in a program Open files for processing Terminator is a period

READ Statement Used to Read a Record from a File End of File Logic Not End of File Logic Terminator - END-READ.

READ Statement READ Employee-File AT END PERFORM 500-End-Of-File-Routine NOT AT END PERFORM 300-Process-Employee END-READ.

WRITE Statement Writes/Updates records in a file Terminator is .

CLOSE Statement Closes the files used in the program Usually the second to last set of statements executed in the program Terminator is .

STOP RUN Statement Terminates the program The last statement executed in the program. Terminator is .

Printing on the AS/400 Job Output Queue Program/ Command Spooled File Data Report Layout (Printer File) *FILE *FILE

A Good Report… Heading (a meaningful report name) Date and Page Number Column Headings (to identify data) Order column from left to right to highlight significant data Edit numbers for readability Include Totals at end of report and groups of items ** To identify the ‘level’ of a total Clearly indicate the end of the report.

Record Formats Each Record format is defined using it’s own Group-Item in the Working Storage Section. Record format name is defined using the 01 level Fields and literals are defined using subsequent levels with Picture & Values Clauses

Customer Accounts Customer Accounts Date: 05/04/00 Page: 999 Date Amount Customer: 1015 Cindy Laurin-Moogk 05/01/00 $100.00 05/02/00 $200.00 05/03/00 $300.00 * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer: 1016 Bruce Nugent * Totals: 1016 Bruce Nugent $100.00 ** Totals: All Customers $700.00 *** End of Report

How Many Record Formats? Heading Customer Accounts Date: 05/04/00 Page: 999 Column Heading Date Amount Customer Heading Customer: 1015 Cindy Laurin-Moogk Detail Line 05/01/00 $100.00 Detail Line 05/02/00 $200.00 Detail Line 05/03/00 $300.00 Customer Total * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer Heading Customer: 1016 Bruce Nugent Customer Total * Totals: 1016 Bruce Nugent $100.00 Report Total ** Totals: All Customers $700.00 End of Report *** End of Report

Page Number Manually Calculated Need to know how many lines print on a page Printer File Your programs must have: Line-Counter Variable Page-Counter Variable

Printer Spacing Charts Report Format Line Number 1 2 3 4 5 6 7 8 9 2 . . . . . . . . ..

REMEMBER to READ a file But WRITE a RECORD

Sequential READ Statement Used to Read the next Record from a File End of File Logic Not End of File Logic Terminator - END-READ.

Sequential READ Statement READ Employee-File AT END PERFORM 500-End-Of-File-Routine NOT AT END PERFORM 300-Process-Employee END-READ.

READ STATEMENT PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. 01 EMPLOYEE-IN. 05 EMP-NAME PIC X(25). 05 EMP-HOURS PIC 9(03). 05 EMP-RATE PIC 99V9 USAGE COMP-3. 05 EMP-DEP PIC X(15).

READing A FILE The READ statement ‘gets’ the next record in the file Format: READ file-name AT END statement. After execution the record is moved to the buffer declared in the file section as ‘record-name’

Display File Read Used to read information from a screen RECORD keyword is needed because display files usually have more than one record format. Read Display-file RECORD.

WRITE Statement Writes/Outputs records to a file Terminator is . Or END-WRITE. ‘Format is’ clause needed for display files Format is record format Needed because display files usually have more than one record format (screen)

The WRITE Statement It writes a record to a file An OPEN OUTPUT or OPEN EXTEND has been issued prior to the WRITE WRITE adds a record to a data file WRITE prints a record to a printer file Sequential Write: WRITE file-record-name

Writing to a Physical File Write Product-record invalid key display ‘write failed’ not invalid key display ‘write ok’ End-write.

Writing to a Report Write print-record-out.

Writing to a Display File Write display-record Format is ‘RECORD1’ end-write.

Changing Data - REWRITE Updates a record in a file File must be opened as I-O instead of input Record must be read first before rewrite REWRITE record-name (FROM variable-name) INVALID KEY perform error-rtn NOT INVALID KEY perform continue-rtn END-REWRITE.

Examples Customer Name PIC X(20) Value ‘Cindy Laurin-Moogk’ Report Item PIC X(20) PIX XXXXXXXXXXBXX

Customer Accounts 1 2 3 4 5 12345678901234567890123456789012345678901234567890123456789 Customer Accounts Date: 05/04/00 Page: 999 Date Amount Customer: 1015 Cindy Laurin-Moogk 05/01/00 $100.00 05/02/00 $200.00 05/03/00 $300.00 * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer: 1016 Bruce Nugent * Totals: 1016 Bruce Nugent $100.00 ** Totals: All Customers $700.00 *** End of Report

Printing in COBOL FILE SECTION FD Customer-Report. WORKING STORAGE. 01 Heading-1 05 PIC X(8) Value Spaces. 05 PIC X(17) Value ‘Customer Accounts’ 05 PIC X(5) Value Spaces. 05 PIC X(6) Value ‘Date: ‘ 05 WS-Date-Out PIC 99/99/99. 05 PIC X(1) Value Spaces. 05 PIC X(6) Value ‘Page: ‘. 05 WS-Page PIC 9(3). FILE SECTION FD Customer-Report. 01 Print-Record-Out.

Printing or Writing to a Spooled File (using AFTER ADVANCING) Detail-Line-1 PIC X(80) VALUE ‘Cindy’s Test’. Detail-Line-2 PIC X(80) VALUE ‘COBOL Line of Code’. WRITE Print-Record-Out FROM Detail-Line-1. WRITE Print-Record-Out FROM Detail-Line-2 AFTER ADVANCING 1 LINE.

Printing or Writing to a Spooled File (using BEFORE ADVANCING) Detail-Line-1 PIC X(80) VALUE ‘Cindy’s Test’. Detail-Line-2 PIC X(80) VALUE ‘COBOL Line of Code’. WRITE Print-Record-Out FROM Detail-Line-1 BEFORE ADVANCING 1 LINE. WRITE Print-Record-Out FROM Detail-Line-2.

Printing or Writing to a Spooled File Detail-Line-1 PIC X(80) VALUE ‘Cindy’s Test’. Detail-Line-2 PIC X(80) VALUE ‘COBOL Line of Code’. WRITE Print-Record-Out FROM Detail-Line-1 AFTER ADVANCING 1 LINE. WRITE Print-Record-Out FROM Detail-Line-2 BEFORE ADVANCING 1 LINE.

Sorting Data Using Access Paths

Physical Files vs Logical Files EMPLOYEEPF *FILE EMPLOYEE *FILE Physical Files or Logical Files?

Externally Described Files Select Statement when physical/logical file has a key. SELECT Cobol-file-name ASSIGN TO database-actual-file-name [ORGANIZATION IS INDEXED] [ACCESS MODE IS SEQUENTIAL] RECORD KEY is data-element. (data-element could be EXTERNaLLY-DESCRIBED-KEY)

Externally Described Files Copying the record layout. FD Cobol-file-name. 01 Cobol-Record-Name. COPY DD-actualrecordname OF actualfilename. (DD can be replaced by DDS if you require the 10 char field names instead of the aliases)

Handy Physical File Commands DSPPFM – Display Physical File Member Displays the contents of a Physical File in arrival sequence. DSPFD – Display File Description Information about the file – eg access path. DSPFFD – Display File Field Description Displays the fields in the file.

Random Reads Used to retrieve a record based on the value of a key field Need an access path sorted by the key field needed Select statement changes

Defining a Random Access File SELECT Employee-File ASSIGN to DATABASE-EMPPF ORGANIZATION is INDEXED ACCESS MODE is RANDOM RECORD KEY is EXTERNALLY-DESCRIBED-KEY (with duplicates).

Random Reads If the key field to EMPPF is the Employee-Number then: Move 1 to Employee-Number. Read Employee-File Invalid Key Move ‘Error’ to Employee-Name-Out Not invalid key Move Employee-Name to Employee-Name- out End-Read.

Validating the Province Code Database object: PROVINCES

Problem FILENAME is a 10 character field in the file, FILELIST. FILELIST is a Physical file that contains a record for each of the physical files in QGPL. You are required to write a COBOL program that prints all of the files listed in FILELIST. What COBOL statement would list all of the Files in QGPL that start with ‘CHAP’?

ACCEPT Statement ACCEPT variable FROM DAY-OF-WEEK DATE DAY TIME DAY-OF-WEEK = 1-7 (Mon-Sun) DATE = YYMMDD DAY = Julian Date TIME = hhmmsshh

Convert YYMMDD to MMDDYY? 01 Heading-2. 01 WS-RUN-DATE 05 HL-RUN-MNTH 05 WS-RUN-YEAR 05 HL-RUN-DAY 05 WS-RUN-MONTH 05 HL-RUN-YEAR 05 WS-RUN-DAY ACCEPT WS-RUN-DATE FROM DATE. MOVE WS-RUN-MONTH TO HL-RUN-MONTH. MOVE WS-RUN-DAY TO HL-RUN-DAY. MOVE WS-RUN-YEAR TO HL-RUN-YEAR.

Indicators in Display Files

Option Indicators in COBOL Binary Values Working Storage Definition example 01 ws-indicator-list. 05 IN88 INDICATOR 88 PIC 1 value B’0’. Passed to display files in the write statement Write Display-record format is ‘RECORD1’ indicators are ws-indicator-list.

Example – Indicator 90 displays the message, Employee Name is invalid Working Storage. 01 ws-indicators. 05 IN90 INDICATOR 90 pic 1. Procedure Division. If scr-employee-name is equal to spaces move b’1’ to IN90 else move b’0’ to IN90 end-if.

Response Indicators in COBOL Stored as binary values in the display file and passed as PIC X(2) via the control Area. Select Display-file assign to workstation-dspfile-si organization is transaction control area is ws-control. Working Storage Section. 01 ws-control. 05 ws-function-key pic x(2).

Example – check to see if function key 3 was pressed. Select Display-file assign to workstation-dspfile-si organization is transaction control area is ws-control. Working Storage Section. 01 ws-control. 05 ws-function-key pic x(2). Procedure Division. if ws-function-key = ’03’ ….. end-if.