Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.

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

DT266/2 COBOL Basics – Declaring Data Basic Operations.
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)
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
COBOL COmmon Business Oriented Language  Work began in 1959 and has never stopped.
COBOL for the 21st Century
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and SI Iteration Logical Files Positioning the file pointer.
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
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)
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)
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.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
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)
Introduction to COBOL. COBOL  COBOL is an acronym which stands for Common Business Oriented Language.  The name indicates the target area of COBOL applications.
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
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.
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.
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.
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.
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.
IBC233 Lecture 2 Updated Winter 2008 Agenda Test next Week – Jan 23 ISeries Architecture CL (Control Language) Library Lists Operations Navigator.
Structured Programming
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
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.
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.
IBM-Mainframes COBOL Class-1. Background and History  COBOL is an acronym for: Common Business Oriented Language  COBOL was developed in 1959 by the.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
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!
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.
371 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Random update Please use speaker notes for additional information!
Submitting Instructions on web site CS 1024 students Read guide
Structured Programming
Programming in COBOL.
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Chapter 14 Sorting and Merging.
Agenda Collating sequence / Sorting data
CHAPTER 17 The Report Writer Module
Programming in COBOL.
Presentation transcript:

Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data

 Creating a source Physical File  Creating a Physical/Logical File  What is PDM ?  How does a compiler work?  Creating a COBOL Program  Parts of a COBOL Program  The Perform Statement  Defining Files  Defining Variables  COBOL Verbs

 Source Physical File is like a container that consists of Source Code called member.  You can have source code for Physical File, Logical File, Cobol, RPG or Java programs.  Command to create a source physical file is CRTSRCPF QCBLSRC

 PDM stands for Program Development Manager  This is the environment used to develop code for the AS/400 iSeries system  The editor used in PDM is called SEU (Source Entry Utility)  To start PDM the command is STRPDM  Then take option 3 for Members and get into your QCBLSRC source file to create your programs

 Translate programs written by humans into Machine Language Code.

COBOL Compiler Source Code QCBLSRC (PGM1) Compiled Listing (PGM1) in a spool file format Program Object (PGM1) as an executable

1. Create a Source Physical File - QCBLSRC 2. Create a Source Member in the Source Physical file with the type CBL 3. Type in the COBOL code using SEU 4. Exit & Save 5. Compile (Option 14 on the Work with members screen)

 Designed by the US defense department  Meant to be English like for ease of maintenance COmmon Business Oriented Language

ColumnsUseExplanation 1-6Sequence numbers or Page and Line numbers (Optional) Are added automatically by CODE/400 when the program is being entered into the system 7Continuation, comment, or starting a new page Used to denote a line as a comment (an * in column 7), to cause the printer to skip to a new page when printing the source listing (a / in column 7), or to continue nonnumeric literals (discussed later in the book) 8-11Area ASome entries, such as DIVISION SECTION, and paragraph-names, must begin in Area A 12-72Area BMost COBOL entries, including PROCEDURE DIVISION sentences, are specified in Area B 73-80Program Identification (Optional) Used to identify the program. This entry is omitted in this book Blank LineSeparate COBOL LinesBlank lines are permitted anywhere in a COBOL program to make the program easier to read

 Identification Division  Environment Division  Data Division  Procedure Division

IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] … ] [INSTALLATION. [comment-entry] …] [DATE-WRITTEN. [comment-entry] …] [DATE-COMPILED. [comment-entry] …] [SECURITY. [comment-entry] …] Example: IDENTIFICATION DIVISION. PROGRAM-ID. CPCH02A.

 Required ◦ Identifies the program to the computer system. It also provides some documentation about the program. ◦ Name of the Program in the Program-ID paragraph.  Optional ◦ Author ◦ Installation ◦ Date-Written ◦ etc.

 Required ◦ Identifies the input and output files that are used by the program and assigns these files to specific devices.  Optional ◦ None

[ENVIRONMENT DIVISION.] [CONFIGURATION SECTION.] [SOURCE-COMPUTER. AS/400.] [OBJECT-COMPUTER. AS/400.] [INPUT-OUTPUT SECTION.] [FILE-CONTROL.] [SELECT nice-file-name ASSIGN to DISK/PRINTER/WORKSTATION- physical-file-name.]

 INPUT-OUTPUT SECTION is only required if your program uses files. ◦ Contains the FILE-CONTROL paragraph  DISK  PRINTER  DATABASE  WORKSTATION  FORMATFILE ◦ similar to setting up file pointers

Select Product-File Assign to disk-PRODPF. Select Product-file Assign to database-PRODPF Access is Sequential.

Select Display-File assign to workstation-PRDSPF organization is transaction. Select Display-File assign to workstation-PRDSPF-SI organization is transaction.

Select Product-Report assign to printer-qprint. Select Product-Report assign to printer-qsysprt.

Select Product-Report assign to formatfile-qsysprt.

 Required ◦ Describes the input and output formats to be used by the program. It also defines any constants and work areas necessary for the processing of data.  Optional ◦ NA

Types of COBOL EntriesMargin Rules Divisions Examples: IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION. PROCEDURE DIVISION. Division and Section Names 1.Begin in Area A (Columns 8-11) 2.End with a period. 3.Must appear on a line with no other entries. Sections Examples: FILE SECTION. WORKING-STORAGE SECTION. **Above section applies here as well Paragraphs Examples: PROGRAM-ID 200-PROCESS-RECORD-RTN. Paragraph-names 1.Begin in Area A (Columns 8-11) 2.End with a period, which must always be followed by at least one space. 3.May appear on lines by themselves or with other entries. Statements (Sentences) Examples: MOVE EP-LAST-NAME TO DL-LAST-NAME. ADD AMOUNT-IN TO TOTAL. Sentences 1.Begin in Area B (Columns 8-11) 2.End with a period or scope terminator. Sentences ending with a period must always be followed by at least one space. 3.May appear on lines by themselves or with other entries. 4.A sentence consists or a statement or series of statements.

 Define the files used in the program ◦ File Description ◦ Record Description  Program Described vs Externally Described.

 Label Clause ◦ Not used often ◦ Transmitting Data  Block Clause ◦ Optional ◦ I’ve never seen it used

 Records Clause ◦ Optional ◦ Used to double check that the record format

 Details the fields in each record

 Variables need by the program that are not described in the files and not parameters  Value clause used to initialize variables.

 Define Parameters

[DATA DIVISION.] [FILE-SECTION.] [FD nice-file-name] [RECORD CONTAINS 99 CHARACTERS]. [01 record-name.] [05 field-names PIC ????.] [WORKING-STORAGE SECTION.] [01 field-name PIC X(10).]

 Zoned Decimals (or signed integers)  Packed Decimal  Alphabetic  Alphanumeric  Boolean  Dates  Time  TimeStamp

 Variable Data Changes  Constant Data doesn’t  Figurative Constants ◦ ZERO, ZEROS, ZEROES ◦ SPACES

 Up to 30 Characters  Letters, numbers and hypens (-)  No blanks  At least one letter  Not a COBOL Reserved Word (see text for list of reserved words)  Meaning full names please

 9 - Number  X – Alphanumeric  A - Alphabetic  V - Decimal Point PACKED-DECIMAL = COMP-3

01 Todays-date format of date. 01 Todays-time format of time. 01 Todays-timestamp format of timestamp.

01 IN99 pic 1.

PIC Clauses (Group Items) Mix of Elementary Items. Used to break a variable into smaller portions

01 Student-Number PIC 9(9). 01 Student-Number-Edited. 05 Student-Number-Part-1 PIC 9(3). 05 Student-Number-Part-2 PIC 9(3). 05 Student-Number-Part-3 PIC 9(3).

 Required ◦ Contains the instructions necessary for reading input, processing it, and creating output.  Optional ◦ NA

PROCEDURE DIVISION. paragraph-name. statements.

 Program Logic  Statements are executed in the order that they appear.  Logic can be divided into paragraphs (sub- routines)  Cindy’s advice: put a period at the end of every line.

 COBOL’s version of the execute sub-routine command.  Works as follows: ◦ Goto the start of a paragraph. ◦ Repeat in sequence, all of the statements in the paragraph as many times as required.  UNTIL Clause ◦ Return to the calling statement.

 Column based  3 parts to a COBOL source line ◦ Continuation (-) ◦ Area A ◦ Area B

 * to start a comment line

 Division Names  Section Names  Paragraph Names

 Everything else

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

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.

 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)

Write display-record Format is ‘RECORD1’ end-write.

Write Product-record invalid key display ‘write failed’ not invalid key display ‘write ok’ End-write.

Write print-record-out.

 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.

 COBOL assignment verb MOVE name TO first-name.

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.

Device Specifications Type of DeviceImplementor-Name PrinterPRINTER DiskDISK, DATABASE Interactive input from a terminalWORKSTATION