Conditions.. IF Syntax.   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names 

Slides:



Advertisements
Similar presentations
8-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)
Advertisements

Module 7 Sorting.  The StudentFile is a sequential file sequenced upon ascending StudentId.  How to sort the file by StudentId? DATA DIVISION. FILE.
- Kav Shrestha.  Introduction  History  Features  COBOL Usage  Characteristics  Structure of COBOL Programs  COBOL Divisions  Data Items  Variable.
1 CSC103: Introduction to Computer and Programming Lecture No 8.
BY: JOSHUA THOMAS IGNATIUS TOWERS COBOL. Overview What is COBOL History Design Implementations What did it do Program structure Data types Syntax Sample.
True or false A variable of type char can hold the value 301. ( F )
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Conditions What if?. Flow of Control The order of statement execution is called the flow of control Unless specified otherwise, the order of statement.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
C++ for Engineers and Scientists Third Edition
CONTROL STATEMENTS Lakhbir Singh(Lect.IT) S.R.S.G.P.C.G. Ludhiana.
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.
COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Introduction to COBOL. COBOL  COBOL is an acronym which stands for Common Business Oriented Language.  The name indicates the target area of COBOL applications.
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
CMSC 104, Version 8/061L11Relational&LogicalOps.ppt Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else.
Selection Control Structures Simple Program Design Third Edition A Step-by-Step Approach 4.
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).
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.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
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.
Controlling Execution Programming Right from the Start with Visual Basic.NET 1/e 8.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Figure 9.9Duplicate Data Names 01 STUDENT-RECORD. 05 STUDENT-NAMEPIC X(20). 05 SOCIAL-SECURITY-NUMPIC 9(9). 05 STUDENT-ADDRESS. 10 STREETPIC X(15). 10.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
BACS 287 Programming Logic 2. BACS 287 Sequence Construct The sequence construct is the default execution mode for the CPU. The instructions are executed.
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.
Chapter 5: Making Decisions
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 8 Decision Making Using the IF and EVALUATE Statements.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
Sort and Merge.  The StudentFile is a sequential file sequenced upon ascending StudentId.  Write a program to display the number of students taking.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
1 Review for test 2 Chapters 7, 8, 9, 11, What is wrong with the following paragraphs? PARA-A. PARA-B. ADD A TO B MOVE 0 TO X PERFROM PARA-A PERFORM.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 4 Making Decisions.
Sections © Copyright by Pearson Education, Inc. All Rights Reserved.
Review for Final (Part 2) School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 15, Friday 5/2/2003)
An Object-Oriented Approach to Programming Logic and Design Chapter 5 Making Decisions.
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.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 4: Making Decisions 1.
CMSC 104, Version 9/011 Relational and Logical Operators Topics Relational Operators and Expressions The if Statement The if-else Statement Nesting of.
Lecture 6 – Selection FTMK, UTeM – Sem /2014.
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
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.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
LOGICAL CONTROL STRUCTURES (chp. 8)
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
The Selection Structure
Objectives After studying this chapter, you should be able to:
Selection Statements.
Agenda Collating sequence / Sorting data
Chapter 5: Control Structure
Boolean Expressions to Make Comparisons
Primitive Types and Expressions
Any Questions?.
Relational and Logical Operators
Using C++ Arithmetic Operators and Control Structures
Relational and Logical Operators
Decision Making Using the IF and EVALUATE Statements
REPETITION Why Repetition?
Presentation transcript:

Conditions.

IF Syntax.   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names   Simple Conditions l Relation Conditions l Class Conditions l Sign Conditions   Complex Conditions   Condition Names C ONDITION T YPES

Relation Conditions

Class Conditions.  Although COBOL data items are not ‘typed’ they do fall into some broad categories, or classes, such a numeric or alphanumeric, etc.  A Class Condition determines whether the value of data item is a member of one these classes.

Sign Conditions  The sign condition determines whether or not the value of an arithmetic expression is less than, greater than or equal to zero.  Sign conditions are just another way of writing some of the Relational conditions.

Complex conditions.  Programs often require conditions which are more complex than single value testing or determining a data class.  Like all other programming languages COBOL allows simple conditions to be combined using OR and AND to form composite conditions.  Like other conditions, a complex condition evaluates to true or false.  A complex condition is an expression which is evaluated from left to right unless the order of evaluation is changed by the precedence rules or bracketing.

 Just like arithmetic expressions, complex conditions are evaluated using precedence rules and the order of evaluation may be changed by bracketing.  Examples IF Row > 0 AND Row 0 AND Row < 26 THEN DISPLAY “On Screen” END-IF IF VarA > VarC OR VarC = VarD OR VarA NOT = VarF DISPLAY “Done” END-IF ( ) ( ) ( ) ( ) ( ) Complex conditions have precedence rules too. Precedence Rules. Precedence Rules. 1.NOT 1.NOT=** 2.AND 2.AND=* or / 3.OR 3.OR=+ or - Precedence Rules. Precedence Rules. 1.NOT 1.NOT=** 2.AND 2.AND=* or / 3.OR 3.OR=+ or -

Implied Subjects.  When a data item is involved in a relation condition with each of a number of other items it can be tedious to have to repeat the data item for each condition. For example, IF TotalAmt > AND TotalAmt < THEN IF Grade = “A” OR Grade = “B+” OR GRADE = “B” THEN IF VarA > VarB AND VarA > VarC AND VarA > VarD DISPLAY “VarA is the Greatest” END-IF  In these situations COBOL provides an abbreviation mechanism called implied subjects.  The statements above may be re-written using implied subjects as; IF TotalAmt > AND < THEN IF Grade=“A” OR “B+” OR “B” THEN IF VarA > VarB AND VarC AND VarD DISPLAY “VarA is the Greatest” END-IF Implied Subjects TotalAmt Grade = VarA > Implied Subjects TotalAmt Grade = VarA >

Nested IFs IF ( VarA VarC ) THEN IF VarG = 14 THEN DISPLAY “First” ELSE DISPLAY “Second” END-IF ELSE DISPLAY “Third” END-IF IF ( VarA VarC ) THEN IF VarG = 14 THEN DISPLAY “First” ELSE DISPLAY “Second” END-IF ELSE DISPLAY “Third” END-IF VarAVarBVarCVarGDISPLAY VarAVarBVarCVarGDISPLAY T T T First T T T First T T F Second T T F Second T F Third T F Third F T Third F T Third

Condition Names.  Wherever a condition can occur, such as in an IF statement or an EVALUATE or a PERFORM..UNTIL, a CONDITION NAME (Level 88) may be used.  A Condition Name is essentially a BOOLEAN variable which is either TRUE or FALSE.  Example. IF StudentRecord = HIGH-VALUES THEN Action The statement above may be replaced by the one below. The condition name EndOfStudentFile may be used instead of the condition StudentRecord = HIGH-VALUES. IF EndOfStudentFile THEN Action

Defining Condition Names.  Condition Names are defined in the DATA DIVISION using the special level number 88.  They are always associated with a data item and are defined immediately after the definition of the data item.  A condition name takes the value TRUE or FALSE depending on the value in its associated data item.  A Condition Name may be associated with ANY data item whether it is a group or an elementary item.  The VALUE clause is used to identify the values which make the Condition Name TRUE.

01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. 01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF Dublin FALSE Limerick FALSE Cork FALSE Galway FALSE SligoTRUE Waterford FALSE UniversityCity FALSE City Code 5

01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. 01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF Dublin FALSE LimerickTRUE Cork FALSE Galway FALSE Sligo FALSE Waterford FALSE UniversityCityTRUE City Code 2

01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. 01CityCode PIC 9 VALUE 5. 88DublinVALUE 1. 88LimerickVALUE 2. 88CorkVALUE 3. 88GalwayVALUE 4. 88SligoVALUE WaterfordVALUE UniversityCityVALUE 1 THRU 4. IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF IF Limerick DISPLAY "Hey, we're home." END-IF IF UniversityCity PERFORM CalcRentSurcharge END-IF Dublin FALSE Limerick FALSE Cork FALSE Galway FALSE Sligo FALSE WaterfordTRUE UniversityCity FALSE City Code 6

01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". 01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF VowelTRUE Consonant FALSE Digit FALSE LowerCase FALSE ValidCharTRUE Input Char E

01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". 01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF Vowel FALSE Consonant FALSE DigitTRUE LowerCase FALSE ValidCharTRUE Input Char 4

01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". 01InputCharPIC X. 88VowelVALUE"A","E","I","O","U". 88ConsonantVALUE"B" THRU "D", "F","G","H" "J" THRU "N", "P" THRU "T" "V" THRU "Z". 88 DigitVALUE "0" THRU "9". 88 LowerCaseVALUE"a" THRU "z". 88ValidCharVALUE"A" THRU "Z","0" THRU "9". IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF IF ValidChar DISPLAY "Input OK." END-IF IF LowerCase DISPLAY "Not Upper Case" END-IF IF Vowel Display "Vowel entered." END-IF Vowel FALSE Consonant FALSE Digit FALSE LowerCaseTRUE ValidChar FALSE Input Char g

01EndOfFileFlagPIC 9 VALUE 0. 88EndOfFileVALUE 1. 01EndOfFileFlagPIC 9 VALUE 0. 88EndOfFileVALUE 1. READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ END-PERFORM READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ END-PERFORM EndOfFile EndOfFileFlag 0

01EndOfFileFlagPIC 9 VALUE 0. 88EndOfFileVALUE 1. 01EndOfFileFlagPIC 9 VALUE 0. 88EndOfFileVALUE 1. READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ END-PERFORM READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END MOVE 1 TO EndOfFileFlag END-READ END-PERFORM EndOfFileFlag 1 EndOfFile

Using the SET verb. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. EndOfFile 1 NotEndOfFile 0 FILLER 0

Using the SET verb. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. EndOfFile 1 NotEndOfFile 0 FILLER 1

Using the SET verb. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. 01FILLERPIC 9 VALUE 0. 88EndOfFileVALUE NotEndOfFileVALUE 0. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. READ InFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile Statements READ InFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM Set NotEndOfFile TO TRUE. EndOfFile 1 NotEndOfFile 0 FILLER 0

PROCEDURE DIVISION. Begin. OPEN INPUT StudentFile READ StudentFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile DISPLAY StudentId SPACE StudentName SPACE CourseCode READ StudentFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM CLOSE StudentFile STOP RUN. PROCEDURE DIVISION. Begin. OPEN INPUT StudentFile READ StudentFile AT END SET EndOfFile TO TRUE END-READ PERFORM UNTIL EndOfFile DISPLAY StudentId SPACE StudentName SPACE CourseCode READ StudentFile AT END SET EndOfFile TO TRUE END-READ END-PERFORM CLOSE StudentFile STOP RUN. FD StudentFile. 01 StudentDetails. 88 EndOfFile VALUE HIGH-VALUES. 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X. FD StudentFile. 01 StudentDetails. 88 EndOfFile VALUE HIGH-VALUES. 02 StudentId PIC 9(7). 02 StudentName. 03 Surname PIC X(8). 03 Initials PIC XX. 02 DateOfBirth. 03 YOBirth PIC 9(2). 03 MOBirth PIC 9(2). 03 DOBirth PIC 9(2). 02 CourseCode PIC X(4). 02 Grant PIC 9(4). 02 Gender PIC X.

The Evaluate

W I L L I A M S EVALUATE TRUEPosition WHEN L-Arrow 2 THRU 10PERFORM MoveLeft WHEN R-Arrow 1 THRU 9PERFORM MoveRight WHEN L-Arrow 1MOVE 10 TO Position WHEN R-Arrow 10MOVE 1 TO Position WHEN DeleteKey 1PERFORM CantDelete WHEN Character ANYPERFORM InsertChar WHEN OTHER PERFORM DisplayErrorMessage END-EVALUATE

Decision Table Implementation. EVALUATE Gender TRUE TRUE WHEN"M"Age 19 AND 19 AND 40Service 40Service 20MOVE 25 TO Bonus END-EVALUATE Gender Gender M F M F M F M F Age Age 40> etc Service Service Any Any <10 <10 <10 < etc % Bonus % Bonus