Any Questions? Week 1 - 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

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
Cobol application using ODBC or File processing Vandana Janeja CIS 365 With COBOL OR PowerCobol.
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)
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.
Modules, Hierarchy Charts, and Documentation
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.
Advanced Sequential Files 1.. Single Record Type Files  In a file which contains only one record type (the kind we have examined so far) the record structure.
Structured COBOL Programming, Stern & Stern, 9th edition
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;
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.
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)
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.
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.
UNIT 1 UNIT 1 Stephen S. Linkin Houston Community College System 8/28/ Copywrite © Houston Community College System 2007 Graphics Courtesy of IBM.
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.
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.
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.
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.
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.
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.
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.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Any Questions! 2 Agenda Moving data Arithmetic Verbs Compute statement.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Introduction to Sequential Files. COBOL's forte  COBOL is generally used in situations where the volume of data to be processed is large.  These systems.
Submitting Instructions on web site CS 1024 students Read guide
Structured Programming
Programming in COBOL.
Any Questions?.
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Programming in COBOL-85 For IBM Mainframe System 390
Agenda Collating sequence / Sorting data
CHAPTER 17 The Report Writer Module
Any Questions?.
Programming Languages and Paradigms
Programming in COBOL.
Presentation transcript:

Any Questions?

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

What is COBOL? Designed by the US defense department Meant to be English like for ease of maintenance COmmon Business Oriented Language

Agenda How does a compiler work? Creating a COBOL Program Parts of a COBOL Program The Perform Statement Defining Files Defining Variables COBOL Verbs

Compilers Translate programs written by humans into Machine Language Code directly executable code vs 2 step translate and execute programs ie Basic, C, C++, HTML etc.

COBOL Compiler on the iSeries COBOL Compiler Source Code QCBLLESRC (PGM1) Compiled Listing (PGM1) Program Object (PGM1)

Steps to Create a COBOL Program Working in the Source Physical File – QCBLLESRC (created previously) 1. Create a Source Member in the Source Physical file with the type CBLLE 2. Type in the COBOL code syntax statements using an editor i.e. RDS, SEU 3. Save & Exit 4. Compile and generate the executable code 5. Repeat 1 through 4 for each program required

8 Defining Files and Processing Data Cobol Program Structure Common Elements

9 A source program consists of FOUR DIVISIONS PROCEDURE DIVISION. Instructing the computer to work with the data IDENTIFICATION DIVISION. Identifying the program ENVIRONMENT DIVISION. Defining the files, peripherals, etc. DATA DIVISION. Defining the variables to use in the program

10 Identifying The Program PT001F Payroll Records PAYREP The Cobol Program PRINTER FILE Payroll Report

11 IDENTIFICATION DIVISION. PROGRAM-ID. PAYREP. AUTHOR. Barake, Juan - DB344E40. * TO PRINT PAYROLL REPORT Column 7 Comment Lines Ignored by the Compiler Column 8 To start Division, Paragraph

Identification Division Required –Name of the Program in the Program-ID paragraph. Optional –Author –Installation –Date-Written –etc.

Identification Division (Syntax) IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [AUTHOR. [comment-entry] … ] [INSTALLATION. [comment-entry] …] [DATE-WRITTEN. [comment-entry] …] [DATE-COMPILED. [comment-entry] …] [SECURITY. [comment-entry] …]

Environment Division Defines the operational environment and connecting a programs internal file / device requirements to the physical system environment.

Environment Division [ENVIRONMENT DIVISION.] [CONFIGURATION SECTION.] Identifies the computer used to write / create the program and the computer it is intended to operate / execute on. [INPUT-OUTPUT SECTION.] [FILE-CONTROL.] Connects the programs internally declared devices / files to the operating system devices / files.

Environment Division (Syntax) [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.]

Environment Division 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

18 THE ENVIRONMENT The Data File PT001F Payroll Records PAYREP The Cobol Program PRINTER FILE Payroll Report

19 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAYROLL-FILE ASSIGN TO DATABASE-PT001F ORGANIZATION IS SEQUENTIAL. As known to the AS400 File System As known to the Cobol Program Syntax can use up to 30 char names AS400 system only 10 Easier to maintain links internal cobol structure to system

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

21 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAYROLL-FILE ASSIGN TO DATABASE-PT001F ORGANIZATION IS SEQUENTIAL. Data File = Collection of Records Each Record = One employee Info Records have same length (bytes) Records made up of fields Sequential means that records are organized in arrival sequence

Select Statement for a Printer (Spooled) File Select Product-Report assign to printer-qprint. Select Product-Report assign to printer-qsysprt.

23 ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT PAYROLL-FILE ASSIGN TO DATABASE-PT001F ORGANIZATION IS SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. PRINT-FILE is just a user-defined name PRINTER is a device name The Cobol program will refer to PRINT -FILE

Select Statement for an Externally Described Printer File Select Product-Report assign to formatfile-qsysprt.

Select Statement for a Interactive-Display-File Select Display-File assign to workstation-PRDSPF organization is transaction. Select Display-File assign to workstation-PRDSPF-SI organization is transaction.

Data Division Further divided into sections Declare / define the structure of ALL data objects used within a program.

Data Division (Syntax) [DATA DIVISION.] [FILE-SECTION.] All objects imported into the program from external (Global) sources. [WORKING-STORAGE SECTION.] All objects required local to the program. [LINKAGE-SECTION.] All parameter objects (fields) received from another programs or bi- directionally passed between programs.

Bringing the Outside IN

Working Storage Section Field or Variables needed by the program for internal processing Field or variable is not part of any Input or Output. Some examples: counters, flags, edited fields (masks), report lines, etc. Fields are defined the same way as in the file section Value clause used to initialize variables or literals (constants) used within the program.

30 OUR PRINTING LAYOUT * Payroll Monthly List Juan Barake 40 $ Mary O'Brian 375 $3, Berns, Andre 275 $1, HEADER RECORD HEADER DETAIL RECORD

31 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. HEADING-LINE: Temporary area to hold the print header. HEADING-LINE: Temporary area to hold the print header. DETAIL-LINE: Temporary area to hold the print fields DETAIL-LINE: Temporary area to hold the print fields EOF-FLAG: Just a variable used as a ‘loop control’ Used within the logic of the program EOF-FLAG: Just a variable used as a ‘loop control’ Used within the logic of the program

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

Variable Data vs Constant Data Variable Data Changes Constant Data doesn’t Figurative Constants –ZERO, ZEROS, ZEROES –SPACES

Data Division (Syntax) [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).] [LINKAGE-SECTION.] [01 ws-prog-parameters.] [05 ws-parm-1 pic x(5).] [05 ws-param-2 pic 9(6).]

35 DATA DEFINITIONS Variable Names: 1 to 30 characters Letters, digits, hyphen See rules in page 74 of your textbook EMPNAME is valid EMP NAME is invalid EMP3NAME is valid

36 DATA DEFINITIONS Data can be either a Constant or a Variable Constant are known as Literals Variables are known as Identifiers or Fields Constants can be Numeric (1, 200, -100, 1.5) Constants can be Alphanumeric (“CBL344 Course”) Variables can be keywords (Cobol defined names such as DATA) or they can be user-defined (user makes up the name such as BALANCE)

File Section Define the files used in the program –File Description –Record Description Program Described vs Externally Described.

File Section FD (file declaration) Label Clause –Not used often –Transmitting Data Block Clause –Optional –I’ve never seen it used

File Section - FD Records Clause –Optional –Used to double check that the record format

File Section - Record Description Starting at an 01 level and the subsequent field(s) detail(s) in each record

41 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). Level Numbers indicate field subordination 01 indicates the top level Located in pos 8 thru 11 Data Subordination

42 The Data PICture or PIC Data content is internally represented by EBCDIC (IBM internal representation of data equivalent to ASCII) It uses a byte (8 bits) to represent a single digit, a single letter, or any special character such as # See the EBCDIC table in page 19 of your textbook The content acceptable for a variable is defined by the clause PICTURE or simply PIC

43 The Data PICture or PIC PICture describes occurrences of each character: Numeric are represented by 9 Alphanumeric is represented by X Alphabetic is represented by A S represented the sign $ / - represent edited characters (for output)

44 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). Level Numbers indicate field subordination 01 indicates the top level Located in pos 8 thru 11

45 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). Elements of Data Definition Level Number Variable Name PICture Group level

46 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). 01 pr-header-line hd1-report name pic x(20). 03 filler pic x(15). 03 hd2-datepic 9999b99b filler pic x(15). 01 pr-detail-line. 03 filler pic x(10). 03 dt1-quantitypic z(5) fillerpic xxx. 03 dt1-descrpic x(30). etc THE PRINTER LINE DEFINITION Record formats

Optionally define the record format structure Working-Storage

48 THE DATA DEFINITIONS The Payroll File EACH EMPLOYEE RECORD LAYOUT: Data Field Buffer Buffer Field Column Field Type Length Length Position Usage Heading EMPNAME CHAR Both NAME Field text : NAME Alternative name : PT001F_NAME Coded Character Set Identifier..... : 37 EMPHOUR ZONED Both HOURS Field text : HOURS Alternative name : PT001F_HOURS EMPRATE PACKED Both RATE Field text : RATE Alternative name : PT001F_RATE EMPDEP CHAR Both DEPARTMENT Field text : DEPARTMENT Alternative name : PT001F_DEPART Coded Character Set Identifier..... : 37 PT001F = PAYROLL-FILE

COPY Importing DATA DEFINITIONS into your program LIBRARY - PF

Spoolfile printout Note: +’s on inserted lines

FFD External data record format structure

Linkage Section Define Parameters

Variable Names 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

Variable Name Examples

PICture Clauses (Elementary Items) 9 - Number X – Alphanumeric A - Alphabetic V - Decimal Point PACKED-DECIMAL = COMP-3

PIC Clauses

Date, Time, & TimeStamp fields 01 Todays-date format of date. 01 Todays-time format of time. 01 Todays-timestamp format of timestamp.

Boolean Variables 01 IN99 pic 1.

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

PIC Clauses (Group Item – Example) 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).

61 Picture Clause Review Define Variables Define how Variables are displayed

62 Editing Functions FunctionCharacter Printing of a / as a separator/ Printing of Decimal Point in an integer. Suppress Leading Zeros in an integerZ 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’ symbolsDB or CR Printing of Spaces as separatorsB Printing of Zeros as separators0 Print Leading asterix*

63 Examples Trans-Amount PIC 9(6)V999 Value Report-ItemEdited Results PIC 9(6)V999 PIC $999999V999 PIC $ZZZ,ZZZ.99 PIC $ZZZ,ZZZ.9

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

For Next Week Review Reserved words in Text Do your assignment!