COBOL Basics 2. H E N N E S S Y R M 9 2 3 0 1 6 5 L M 5 1 0 5 5 0 F Group Items/Records StudentDetails WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26).

Slides:



Advertisements
Similar presentations
DT266/2 COBOL Basics – Declaring Data Basic Operations.
Advertisements

6-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)
Chapter 6 Structured Data 1. A data structure, or record, in COBOL is a method of combining several variables into one larger variable. – Example: 2.
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)
- Kav Shrestha.  Introduction  History  Features  COBOL Usage  Characteristics  Structure of COBOL Programs  COBOL Divisions  Data Items  Variable.
Conditions.. IF Syntax.   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names 
BY: JOSHUA THOMAS IGNATIUS TOWERS COBOL. Overview What is COBOL History Design Implementations What did it do Program structure Data types Syntax Sample.
COBOL COmmon Business Oriented Language  Work began in 1959 and has never stopped.
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
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
Programming in COBOL-85 For IBM Mainframe System 390
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;
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.
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 in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
Totals on the Screen Please use speaker notes for additional information!
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.
Module 4 Constants Copy Statement Perform Verb Part 1.
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.
Module 2 Defining Data Revised Defining Data All definitions of data for COBOL takes place in the DATA DIVISION. All data defined are visible to.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
To familiarize you with  Options of MOVE statement  Rules for moving fields and literals  Printing edit symbols  Designing and printing reports 1.
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.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
Arithmetic and Edited Pictures. Arithmetic Verb Template  Most COBOL arithmetic verbs conform to the template above. For example; ADD Takings TO CashTotal.
Chapter 3 Decision Making. What is IF? The primary method of changing the flow of a program is by making decisions using the IF verb. The following example.
Structured Programming
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
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)
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.
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.
Module 1 1. Cobol Hierarchy Revised on COBOL Hierarchy There are four DIVISIONS:- IDENTIFICATION DIVISION. ENVIRONMENT DIVISION. DATA DIVISION.
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.
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!
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.
Any Questions! 2 Agenda Moving data Arithmetic Verbs Compute statement.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
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.
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Submitting Instructions on web site CS 1024 students Read guide
Structured Programming
Programming in COBOL.
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
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Using screens and adding two numbers - addda.cbl
Any Questions?.
Programming in COBOL.
Presentation transcript:

COBOL Basics 2

H E N N E S S Y R M L M F Group Items/Records StudentDetails WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26). WORKING-STORAGE SECTION. 01StudentDetailsPIC X(26).

H E N N E S S Y R M L M F StudentDetails StudentNameStudentIdCourseCodeGrant Gender Group Items/Records WORKING-STORAGE SECTION. 01StudentDetails. 02StudentNamePIC X(10). 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X. WORKING-STORAGE SECTION. 01StudentDetails. 02StudentNamePIC X(10). 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X.

H E N N E S S Y R M L M F StudentDetails SurnameInitials WORKING-STORAGE SECTION. 01StudentDetails. 02StudentName. 03 SurnamePIC X(8). 03 InitialsPIC XX. 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X. WORKING-STORAGE SECTION. 01StudentDetails. 02StudentName. 03 SurnamePIC X(8). 03 InitialsPIC XX. 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X. StudentNameStudentIdCourseCodeGrant Gender Group Items/Records

LEVEL Numbers express DATA hierarchy  In COBOL, level numbers are used to decompose a structure into it’s constituent parts.  In this hierarchical structure the higher the level number, the lower the item is in the hierarchy. At the lowest level the data is completely atomic.  The level numbers 01 through 49 are general level numbers but there are also special level numbers such as 66, 77 and 88.  In a hierarchical data description what is important is the relationship of the level numbers to one another, not the actual level numbers used.

LEVEL Numbers express DATA hierarchy  In COBOL, level numbers are used to decompose a structure into it’s constituent parts.  In this hierarchical structure the higher the level number, the lower the item is in the hierarchy. At the lowest level the data is completely atomic.  The level numbers 01 through 49 are general level numbers but there are also special level numbers such as 66, 77 and 88.  In a hierarchical data description what is important is the relationship of the level numbers to one another, not the actual level numbers used. 01StudentDetails. 02StudentName. 03 SurnamePIC X(8). 03 InitialsPIC XX. 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X. 01StudentDetails. 02StudentName. 03 SurnamePIC X(8). 03 InitialsPIC XX. 02StudentIdPIC 9(7). 02CourseCodePIC X(4). 02GrantPIC 9(4). 02GenderPIC X. 01StudentDetails. 05StudentName. 10 SurnamePIC X(8). 10 InitialsPIC XX. 05StudentIdPIC 9(7). 05CourseCodePIC X(4). 05GrantPIC 9(4). 05GenderPIC X. 01StudentDetails. 05StudentName. 10 SurnamePIC X(8). 10 InitialsPIC XX. 05StudentIdPIC 9(7). 05CourseCodePIC X(4). 05GrantPIC 9(4). 05GenderPIC X. =

Group and elementary items.  In COBOL the term “group item” is used to describe a data item which has been further subdivided. l A Group item is declared using a level number and a data name. It cannot have a picture clause. Where a group item is the highest item in a data hierarchy it is referred to as a record and uses the level number 01.  The term “elementary item” is used to describe data items which are atomic; that is, not further subdivided.  An elementary item declaration consists of;  a level number,  a data name  picture clause. An elementary item must have a picture clause.  Every group or elementary item declaration must be followed by a full stop.

PICTUREs for Group Items  Picture clauses are NOT specified for ‘group’ data items because the size a group item is the sum of the sizes of its subordinate, elementary items and its type is always assumed to be PIC X.  The type of a group items is always assumed to be PIC X because group items may have several different data items and types subordinate to them.  An X picture is the only one which could support such collections.

Assignment in COBOL  In “strongly typed” languages like Modula-2, Pascal or ADA the assignment operation is simple because assignment is only allowed between data items with compatible types.  The simplicity of assignment in these languages is achieved at the “cost” of having a large number of data types.  In COBOL there are basically only three data types,  Alphabetic (PIC A)  Alphanumeric (PIC X)  Numeric (PIC 9)  But this simplicity is achieved only at the cost of having a very complex assignment statement.  In COBOL assignment is achieved using the MOVE verb.

The MOVE Verb  The MOVE copies data from the source identifier or literal to one or more destination identifiers.  The source and destination identifiers can be group or elementary data items.  When the destination item is alphanumeric or alphabetic (PIC X or A) data is copied into the destination area from left to right with space filling or truncation on the right.  When data is MOVEd into an item the contents of the item are completely replaced. If the source data is too small to fill the destination item entirely the remaining area is zero or space filled.

MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. 01 SurnamePIC X(8). MOVEing Data C O U G H L A N

R Y A N MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. 01 SurnamePIC X(8). MOVEing Data

MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. MOVE “RYAN” TO Surname. MOVE “FITZPATRICK” TO Surname. 01 SurnamePIC X(8). MOVEing Data F I T Z P A T R I C K

MOVEing to a numeric item.  When the destination item is numeric, or edited numeric, then data is aligned along the decimal point with zero filling or truncation as necessary.  When the decimal point is not explicitly specified in either the source or destination items, the item is treated as if it had an assumed decimal point immediately after its rightmost character.

MOVE ZEROS TO GrossPay. MOVE 12.4 TO GrossPay. MOVE TO GrossPay. MOVE TO GrossPay. 01 GrossPayPIC 9(4)V     GrossPay

MOVE 1234 TO CountyPop. MOVE 12.4 TO CountyPop. MOVE 154 TO Price. MOVE TO Price. 01 CountyPopPIC PricePIC 999V99.   Price CountyPop   Price

Legal MOVEs Certain combinations of sending and receiving data types are not permitted (even by COBOL).

The DISPLAY Verb  From time to time it may be useful to display messages and data values on the screen.  A simple DISPLAY statement can be used to achieve this.  A single DISPLAY can be used to display several data items or literals or any combination of these.  The WITH NO ADVANCING clause suppresses the carriage return/line feed.

The ACCEPT verb 01 CurrentDatePIC 9(6). * YYMMDD 01 DayOfYearPIC 9(5). * YYDDD 01 Day0fWeekPIC 9. * D (1=Monday) 01 CurrentTime PIC 9(8). * HHMMSSss s = S/ CurrentDatePIC 9(6). * YYMMDD 01 DayOfYearPIC 9(5). * YYDDD 01 Day0fWeekPIC 9. * D (1=Monday) 01 CurrentTime PIC 9(8). * HHMMSSss s = S/100

PROCEDURE DIVISION. Begin. DISPLAY "Enter student details using template below". DISPLAY "NNNNNNNNNNSSSSSSSCCCCGGGGS ". ACCEPT StudentDetails. ACCEPT CurrentDate FROM DATE. ACCEPT DayOfYear FROM DAY. ACCEPT CurrentTime FROM TIME. DISPLAY "Name is ", Initials SPACE Surname. DISPLAY "Date is " CurrentDay SPACE CurrentMonth SPACE CurrentYear. DISPLAY "Today is day " YearDay " of the year". DISPLAY "The time is " CurrentHour ":" CurrentMinute. STOP RUN. PROCEDURE DIVISION. Begin. DISPLAY "Enter student details using template below". DISPLAY "NNNNNNNNNNSSSSSSSCCCCGGGGS ". ACCEPT StudentDetails. ACCEPT CurrentDate FROM DATE. ACCEPT DayOfYear FROM DAY. ACCEPT CurrentTime FROM TIME. DISPLAY "Name is ", Initials SPACE Surname. DISPLAY "Date is " CurrentDay SPACE CurrentMonth SPACE CurrentYear. DISPLAY "Today is day " YearDay " of the year". DISPLAY "The time is " CurrentHour ":" CurrentMinute. STOP RUN. $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. AcceptAndDisplay. AUTHOR. Michael Coughlan. DATA DIVISION. WORKING-STORAGE SECTION. 01 StudentDetails. 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. 01 CurrentDate. 02 CurrentYear PIC CurrentMonth PIC CurrentDay PIC DayOfYear. 02 FILLER PIC YearDay PIC 9(3). 01 CurrentTime. 02 CurrentHour PIC CurrentMinute PIC FILLER PIC 9(4). $ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. AcceptAndDisplay. AUTHOR. Michael Coughlan. DATA DIVISION. WORKING-STORAGE SECTION. 01 StudentDetails. 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 StudentId PIC 9(7). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. 01 CurrentDate. 02 CurrentYear PIC CurrentMonth PIC CurrentDay PIC DayOfYear. 02 FILLER PIC YearDay PIC 9(3). 01 CurrentTime. 02 CurrentHour PIC CurrentMinute PIC FILLER PIC 9(4). Enter student details using template below NNNNNNNNNNSSSSSSSCCCCGGGGS COUGHLANMS LM511245M Name is MS COUGHLAN Date is Today is day 024 of the year The time is 22:23 Enter student details using template below NNNNNNNNNNSSSSSSSCCCCGGGGS COUGHLANMS LM511245M Name is MS COUGHLAN Date is Today is day 024 of the year The time is 22:23 Run of Accept and Display program