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.

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.
1 Chapter 2 The Digital World. 2 Digital Data Representation.
1-1 Copyright © 2015, 2010, 2007 Pearson Education, Inc. Chapter 13, Slide 1 Chapter 13 From Randomness to Probability.
CS16 Week 2 Part 2 Kyle Dewey. Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Introduction to Computers and Programming Lecture 9: For Loops New York University.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Object References. Objects An array is a collection of values, all of the same type An object is a collection of values, which may be of different types.
Modules, Hierarchy Charts, and Documentation
Chapter 2: Introduction to C++.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
Introduction to C Programming
Fortran- Subprograms Chapters 6, 7 in your Fortran book.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Spreadsheet Modeling of Linear Programming (LP). Spreadsheet Modeling There is no exact one way to develop an LP spreadsheet model. We will work through.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
1-1 Copyright © 2015, 2010, 2007 Pearson Education, Inc. Chapter 13, Slide 1 Chapter 13 From Randomness to Probability.
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.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Input, Output, and Processing
Project 1 Due Date: September 25 th Quiz 4 is due September 28 th Quiz 5 is due October2th 1.
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.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Copyright © 2002, Systems and Computer Engineering, Carleton University a-JavaReview.ppt * Object-Oriented Software Development Unit.
Chapter 8: Arrays.
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.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Chapter 11: Pointers Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 11 Pointers.
WHAT IS A DATABASE? A DATABASE IS A COLLECTION OF DATA RELATED TO A PARTICULAR TOPIC OR PURPOSE OR TO PUT IT SIMPLY A GENERAL PURPOSE CONTAINER FOR STORING.
Pointers: Basics. 2 What is a pointer? First of all, it is a variable, just like other variables you studied  So it has type, storage etc. Difference:
COMPUTER PROGRAMMING. Functions’ review What is a function? A function is a group of statements that is executed when it is called from some point of.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
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.
Chapter 14 Formatting Readable Output. Chapter Objectives  Add a column heading with a line break to a report  Format the appearance of numeric data.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Java Software Solutions Lewis and Loftus Chapter 6 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects for Organizing Data.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 Scope Lifetime Functions (the Sequel) Chapter 8.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
Gator Engineering Google Code Jam 2015 Copyright © 2008 W. W. Norton & Company. All rights reserved. 1.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
User-Written Functions
EGR 2261 Unit 10 Two-dimensional Arrays
Chapter 4 C Program Control Part I
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
The Selection Structure
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Chapter 3 The DATA DIVISION.
CISC101 Reminders Quiz 1 grading underway Assn 1 due Today, 9pm.
Hello World! Syntax.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CISC101 Reminders All assignments are now posted.
四時讀書樂 (春) ~ 翁森 山光照檻水繞廊,舞雩歸詠春風香。 好鳥枝頭亦朋友,落花水面皆文章。 蹉跎莫遣韶光老,人生唯有讀書好。
Chapter 4: Writing and Designing a Complete Program
Presentation transcript:

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

Structured Data THE-WHOLE-MESSAGE is a structure variable or simply a structure. It is occasionally referred to as a compound variable or compound data. In a structure variable, the highest-level variable (the one that includes all the individual variables) has the level number 01. The 01 level must appear in Area A (columns 8 through 12). The structure variable name appears in Area B (columns 12 through 72), and it does not have a PICTURE. The variables that fall within the structure begin with numbers higher than 01, and start in Area B (columns 12 through 72). 3

Structured Data You can use the individual variables within a structure in the program as though they still were level 01 variables. In addition, you can use the structure variable as a variable. – For example, if all the variables within a structure variable can be displayed, the structure variable itself can be displayed as a variable 4

Structured Data 5

Filler and How to use it? 6

They are used to format part of the display and are assigned values in the definition, but nothing is ever moved to these values in the program. They exist only to fill out THE-WHOLE- MESSAGE. this type of value in a structure variable can be defined as a filler by using the COBOL reserved word FILLER. 7

Filler and How to use it? 8

A FILLER cannot be treated as a variable. It is used to reserve space in a structure variable. You can assign a PICTURE and a VALUE to a FILLER when it is defined, but you cannot use MOVE with FILLER. 9

Calculating length of Data Structure A data structure is actually a series of individual variables, laid end to end in memory. The length of a simple data structure, such as this one (see example at next slide) used to create a displayable message, is the sum of all the lengths of the individual parts. 10

Calculating length of Data Structure 11

Calculating length of Data Structure A structure variable is treated as an alphanumeric variable. It has an implied PICTURE of X(nn), where nn is equal to the length of the structure variable. THE-WHOLE-MESSAGE has an implicit PICTURE of X(61). 12

Calculating length of Data Structure You can move a value to a structure variable, but the move will affect the entire length of the variable. A structure variable and the variables that are the elements of a structure occupy the same memory area. When a variable is created by the compiler, it sets aside a number of bytes in memory that can be used to hold data. 13

Calculating length of Data Structure 14

Calculating length of Data Structure Compare figure 8.2 and figure 8.3 The two fillers, as well as EMP-NUMBER and EMP- HOURLY, occupy some bytes that are in the same space in memory as the structure variable EMPLOYEE-DATA. When you use a command in COBOL to modify a variable in memory, the command looks at variables in memory as individual units. If you move a value to EMP-NUMBER, or use ADD 1 TO – EMP-NUMBER, COBOL acts on EMP-NUMBER as if it were a single variable and ignores the fact that EMP-NUMBER is part of the structure EMPLOYEE-DATA. 15

Calculating length of Data Structure If you move a message to EMPLOYEE-DATA, the command treats EMPLOYEE-DATA as if it were a PIC X(20) (the implied picture) and ignores the fact that EMPLOYEE-DATA has smaller variables within it. – Example 16

Calculating length of Data Structure The variables in EMPLOYEE-DATA do not disappear, but the MOVE affects all 20 bytes of memory. The individual variables might no longer contain data that is correct for that variable type. From the figure: – EMP-NUMBER now contains ore, which certainly is not valid numeric data. – This isn't a problem as long as you don't use a command on EMP-NUMBER, such as ADD 1 TO EMP- NUMBER. I'll return to this issue in a moment. 17

Calculating length of Data Structure This use of a structure variable is fairly common in display and print programs that might use a structure to format and display information line by line, and then at the end of the program might move a message to the entire structure and display it. 18

Nested Structure Variables Any structure can contain another structure. The indention makes it clear that these variables are subordinate to THE-MESSAGE. 19

Nested Structured Variables 20 Refer to coding 1. To calculate the length of a structure variable containing one or more other structure variables.

Misusing Structures 21 It is common to find programs that define data structures in WORKING-STORAGE that never are used as structures. Grouping variables together under a structure variable because they are similar or to keep things tidy isn't a good practice. It is better to use comments in WORKING- STORAGE to separate groups of variables used for different purposes.

Level When you see data in a structure in a program, you assume that the structure is used somewhere in the program as a structure, and you can be confused if it is not. A variable that is not a structure can be given a level number of 77 instead of 01: – For examples, see next slide

Level 77 23

Level Level 88 is a special level number used to improve the readability of COBOL programs and to improve IF tests. A level 88 looks like a level under another variable, – It does not have a PICTURE, – but it does have a value.

Level A level 88 is always associated with another variable and is a condition name for that variable. Both of the following conditions test whether YES-NO is equal to "Y":

Level 88 26

Level 88 27

Level 88 28

Level 88 29

Level 88 30

Level 88 31

Q&A 32 Q What happens if I move to a FILLER? – A You can't. The compiler does not recognize FILLER as a variable name; it is used only to reserve space in a structure variable. – If you include a command such as MOVE 1 TO FILLER in a program, it will not compile and produces an error. – You can move values to a structure variable that contains a FILLER. – The MOVE will affect the structure variable and all of the variables within the structure, but you cannot directly move values to a FILLER.

Q&A 33 Q Why do I need to know the lengths of structures? – A You don't yet, but you will need to know how to calculate this when you start creating printed reports (in Day 10, "Printing").

Quiz 34 1.What is the length of THE-WHOLE-MESSAGE in the following example?

Quiz 35 2.What is the implied PICTURE of THE-WHOLE- MESSAGE in question 1? 3.What is a data structure? 4.If you move a value to a structure variable, what happens to the values in the individual variables within the structure? 5.In the following code, what is another way of performing the test at line ?

Quiz 36 6.In the following code, what is another way of performing the test at line ?

Quiz 37 7.In the following code, what is another way of performing the test at lines and ?

Quiz 38 8.Devise a level 88 condition name for YES-NO that would simplify the tests at lines through in the following code: