1 Inside Module 4 Selecting Records with Suprtool Page n Using the If command 2 n Comparing fields4 n Selecting by pattern-matching 7 n Let’s do a crossword.

Slides:



Advertisements
Similar presentations
CC SQL Utilities.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Customer Service Module Course Contents Table of Contents Enter A Request Search A Request Create Invoice (Funeral home request) Search Invoice Manage.
Introduction to Structured Query Language (SQL)
1 Inside Module 5 Working with Files Page n Copying files 2 n Working with ordinary disc files3 n Defining fields 4 n New or existing files7 n Writing.
Guide To UNIX Using Linux Third Edition
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Exploring Formulas.
1 Inside Module 2 Working with Databases Page n Choosing input from databases2 n Reading an entire dataset serially6 n Determining fields in a dataset8.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
1 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and Custom Forms.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
Advanced Shell Programming. 2 Objectives Use techniques to ensure a script is employing the correct shell Set the default shell Configure Bash login and.
Tutorial 14 Working with Forms and Regular Expressions.
XP New Perspectives on Microsoft Access 2002 Tutorial 51 Microsoft Access 2002 Tutorial 5 – Enhancing a Table’s Design, and Creating Advanced Queries and.
1 Dbedit Editing TurboIMAGE Datasets Page n How can Dbedit help me with my work?3 n Accessing Dbedit 4 n Finding entries with a known key 6 n What if I.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
1 Inside Module 9 Latest Features in Suprtool n Variable Substitution n $Counter n $Clean and $FindClean n $Total and $Subtotal n $SPLIT n $EDIT n $NUMBER.
Inside Module 7 Exporting Data to the World Page n Exporting data to other applications2 n STExport converts the data4 n Running STExport5 n Dates and.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
Running a Report.  List Bibliography Report  Found under: All Titles Purpose : Creates customized bibliographies by catalog, call number, or item characteristics.
Microsoft Visual Basic 2005 BASICS Lesson 4 Mathematical Operators.
Visual Basic.NET BASICS Lesson 4 Mathematical Operators.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
Input, Output, and Processing
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Flow of Control Part 1: Selection
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Relational Databases. Relational database  data stored in tables  must put data into the correct tables  define relationship between tables  primary.
Verification & Validation. Batch processing In a batch processing system, documents such as sales orders are collected into batches of typically 50 documents.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
1 Homework –Continue Reading K&R Chapter 2 –We’ll go over HW2 at end of class today –Continue working on HW3 Questions?
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 3 – Inventory Application: Introducing Variables,
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Lesson 4 Mathematical Operators! October 6, 2009.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction ABAP Fields and Variables. Slide 2 Fields (Introduction) In ABAP, fields (or data objects) are named locations in memory Variables store.
Extracting Information from an Excel List The purpose of creating a database, or list in Excel, is to be able to manipulate the data elements in ways that.
Microsoft Visual Basic 2012 CHAPTER FOUR Variables and Arithmetic Operations.
1 Inside Module 8 Extracting Data Page n Using the Extract command2 n Coercion3 n $-functions4 n Extract from a table7.
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
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.
MS-EXCEL PART 3. Use data validation in Excel to make sure that users enter certain values into a cell. Data Validation Example In this example, we restrict.
Do-more Technical Training
Unit 16 – Database Systems
The Selection Structure
Other Kinds of Arrays Chapter 11
Variables and Arithmetic Operations
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.
Chapter 2 Variables.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Inside Module 8 Extracting Data Page Using the Extract command 2
Presentation transcript:

1 Inside Module 4 Selecting Records with Suprtool Page n Using the If command 2 n Comparing fields4 n Selecting by pattern-matching 7 n Let’s do a crossword puzzle 9 n Dates as selection criteria10 n Selecting on partial fields18 n Using tables to select records23 n Using Tables with Keyed reads32

2 Selecting records n You can use the IF command to choose records by selecting ranges of numbers, dates, or multiple criteria >if sales-qty >= 100 and sales-qty < 5000 >if cust-status = 10,20,30,35 n Only one IF command is permitted per task Suprtool uses short-circuit evaluation. e.g. > if age > 70 and sex = “M” should be faster than: > if sex = “M” and age > 70

3 More options to specify selection criteria You can also use these words and signs to select records: n AND, OR and NOT operators n parentheses: ) or ( n relational operators: = >= n pattern matching: == and ><

4 Comparing fields n You can compare one field to another >if deliv-date = purch-date n You can compare a numeric field to a calculation >if sales-total <> product-price * sales-qty n You can compare a field to a constant >if cust-status = "OK","DEAC"

5 Arithmetic If expressions n Select records based on arithmetic expressions >if unit-cost * sales-qty > >if sales-total < sales-qty * product-price + sales-tax n Use parentheses to keep things clear

6 Field types and sizes in comparisons n Byte and character fields can be different sizes, but... n comparison is for length of shorter field n comparison ignores last bytes of longer field

7 Selecting records by pattern-matching Pattern-matching n Includes or excludes values in specified fields using these operators == selects records that match pattern >< selects records that do not match pattern n Can be used only on character fields n Can specify multiple selection criteria n Can use special characters to define selection criteria

8 Special characters in pattern-matching n Use these special characters to match represents any string of characters ? represents one alphanumeric character # represents one numeric character ~ represents zero or more blanks & indicates the next character is literal

9 Exercise 1 Solve a crossword puzzle n Use Suprtool to solve this crossword puzzle: n an 8 letter word n meaning “most befuddled or dazed” n second letter is an “o” n fourth letter is a “z” n HINT: Suprtool has a spelling checker. Each word in its dictionary is stored as one record.

10 Identifying a field as a date n First use the ITEM command to identify a field as a date: >item transaction-date,date,mmddyy >item date-of-birth,date,phdate >item disbursement-date,date,ccyymmdd n Then use the IF command to select records: >if transaction-date = $today and & date-of-birth = & $date(*+5/*/*) 1999

11 $DATE - Supported Date Formats 1. YYMMDDMMDDYYDDMMYY YYYYMMDD / CCYYMMDDMMDDYYYYDDMMYYYY 2.YYMM YYYYMM / CCYYMM MMYYYY 3.CCYY 4.YYYMMDD 5. AAMMDD MMDDAA DDMMAA AAMM 6.YYDDD CCYYDDD 7.ASK, Calendar, HPCalendar, Oracle, PHDate, SRNChronos

12 Dates as selection criteria You can select records by specifying date criteria >item purch-date,date,phdate >if purch-date = $date(98/11/30) {Nov. 30, 1998} n You can also select a range of dates (e.g., all of December 1998) >if purch-date > $date(98/11/30) and & purch-date < $date(99/01/01) >if purch-date >= $date(98/12/01) and & purch-date <= $date(98/12/31)

13 Choosing records by relative date n The $TODAY function optionally accepts an argument that indicates the number of days before or after the current day >item expiry,date,yymmdd >if expiry = $today {today} >if expiry = $today(-1) {yesterday} >if expiry > $today(+14) {more than 2 weeks away} n Suprtool converts the $DATE function into a constant >item date-field,date,mmddyy >if date-field = $date(*/*-6/*) {six months ago} >if date-field = {if today is Mar. 18, 1999 (constant)}

14 Dates must collate correctly for > and < n $DATE gets converted to a constant n For ddmmyy or mmddyy dates, the constant is in that format n ddmmyy and mmddyy dates don't sort properly n Suprtool rejects greater than or less than comparisons for them n Error: Invalid date format for the comparison n Use $STDDATE for non-collating dates

15 Use $STDDATE for non-collating dates Turn a non-collating date into CCYYMMDD format: >item purch-date,date,mmddyy >if $stddate(purch-date) < $today Compare dates in two different formats by converting them both to CCYYMMDD format: >item purch-date,date,mmddyy >item deliv-date,date,ddmmyyyy >if $stddate(purch-date) <= $stddate(deliv-date) Dates must be valid for $stddate to work: >item purch-date,date,mmddyy >if not invalid(purch-date) and & $stddate(purch-date) < $today

16 Date Arithmetic n You can calculate the difference between 2 dates using the $days function $days converts a date to the juliandays date format. I.e. the number of days since a base date (4713 BC) item purch-date,date,YYYYMMDD item deliv-date,date,YYYYMMDD if $days(deliv-date) - $days(purch-date) > 5 n Invalid dates return value 0 (zero)

17 Converting days back to dates n Juliandays date format represents days offset from 4713 BC Combine juliandays with $stddate to convert result of $days calculations: >…. >extract latest-delivery = ($days(date-ord) + 7) >xeq >… >item latest-delivery,date,juliandays >item deliv-date,date,YYYYMMDD >extract deliv-date = $stddate(latest-delivery)

18 Verify that dates are valid Use $INVALID to select records with invalid dates >item purch-date,date,yymmdd >if $invalid(purch-date) >list standard title “Records with bad dates” Or use it to deselect invalid dates >if not $invalid(purch-date) and & purch-date > $date(*/*-6/*)

19 Year 2000 dates Some selections generate “invalid” date constants, if the date field cannot hold century information and the constant would be in the next century >item purch-date,date,yymmdd >if purch-date > $date(*+5/*/*) Error: Cannot use a date beyond 1999 for this format You can override this error condition >set date ifyy2000error off Or you can use $STDDATE to assume a century >set date cutoff 50 >if $stddate(purch-date) > $date(*+5/*/*)

20 $truncate, Mod mod and $abs functions $truncate returns “whole number”, I.e. drops decimals $truncate(127.2 / 12) = 10 Mod returns the remainder 7 mod 5 = 2 $abs returns the absolute value (no sign) $abs(-121) = 121

21 Selecting on parts of a number n You can select any part of a numeric field with the If command Use a divide operation to select on the high-order digits >if $truncate(ord-date-yymmdd / 100) = 9812 Use MOD to select on the low-order digits >if ord-date-yymmdd mod 100 <= 15 Use divide and MOD together to select on middle digits >if ($truncate(ord-date-yymmdd / 100) mod 100) <= 02

22 Calculating day of week n Juliandays measures offset from a Monday Combine $days with mod to calculate day-of-week >ite ord=date,date,YYYYMMDD >ext day = ($days(dt) mod 7) 0 = Monday 1 = Tuesday 2 = Wednesday …… 6 = Sunday

23 Comparing sub-fields n You can select any part of a character field with the IF command n If we define a street-address field as 2X25, any part of this field can be selected >if street-address(2) = "Canada" >if street-address(1,7,2) = "10" >if street-address(1,13) = "Marine Drive"

24 Testing byte type fields n You can test if a byte type field contains alpha, numeric, alphanumeric or special characters >if cust-account = numeric >if street-address <> alphanumeric n You can also check for an ASCII character by specifying its numeric value or control letter >define any-char,1,1,byte >if any-char = ^13 {if byte is a Return} >if any-char = ^G {if byte is a Bell}

25 Checking bits within a field n The IF command can select records based on bit values in a field >if cust-status.(3:1) = 1 >if cust-status.(3:2) = 0 n Bit checking only works for 16-bit words n Field must be Integer or Logical byte word Left Right bits

26 Extending the If command n You can extend the length of an IF command beyond the 256 character limit by using the $READ function >get m-customer >if $read -name-last == and -state-code = "BC" -and -cust-account > -12 -// n $READ prompts for the next line of the IF expression until it encounters a Return or a double slash (//)

27 Creating tables as selection criteria n The TABLE command creates a set of values that can be used as selection criteria: TABLE tablename, itemname, table-keyword, table- values >table select,transcode,item,"BUY","SELL" >table cust-table,cust-num,file,custfile n The source of input can be an item value or a file n The TABLE command sorts values as they are loaded into a table

28 Table characteristics n Only one key can be put into a table n Suprtool can handle up to ten tables n Each table can have up to two gigabytes of data on MPE n 500 Mbs in total on HP-UX n Tables are temporary structures that are reset when a task has been completed n You can hold a table so it is not reset n Table values are sorted

29 When would I use a table? n Instead of listing all the values >if field = value1,value2,value3 n When there are too many values to fit in an IF command n When the selection values change occasionally n When the selection is based on the results of a prior task

30 Loading a table with values from a file n If the file containing the values is not sorted, specify FILE as the keyword >table states,st-code,file,western.data >if qty-ship < qty-order and $lookup(states,st-code) n If the file is sorted, specify SORTED as the keyword >table states,st-code,sorted,western.data >if qty-ship < qty-order and $lookup(states,st-code) n The field selected from the input file must have exactly the same format as the table

31 How does the Table command find a field? n If the input file is self-describing, Suprtool finds the location of the field via the user label n If the file is not self-describing, or the named field is not found in the file label, Suprtool loads the requested data from the start of each record

32 Inserting items into a table n You can also use the TABLE command to insert hardcoded values n Specify ITEM as the table keyword >table states,st-code,item,"WA","OR","CA" >table states,st-code,item,"WI","ID","NE" >table states,st-code,item,"NM","AK","HI" >if cust-status = "OK" and $lookup(states,st-code)

33 Selecting input records that match a value in a table Use the $LOOKUP function with the IF command to select records that match a value in a table >if $lookup(cust-table,cust-acct) n If the $LOOKUP function finds a match, the expression is true If there are multiple conditions in the IF expression, the expression is evaluated faster when $LOOKUP is the last condition >if status = "10" and $lookup(cust-table,cust-acct) n Use NOT to select records which don’t match table values

34 Lookup and Data >get ord-details >table cust-table, cust-no, file, custlist,data(state-code) >if $lookup(cust-table, cust-no, state-code) = state-code >output orders >xeq

35 Saving and deleting tables n The HOLD option tells Suprtool to save a table after a task has been completed >table states,st-code,file,western.data >table parts,part-no,file,partin,hold n The RESET TABLE command clears all the tables. You cannot reset individual tables. >reset table

36 Can we find all the invoices for BC customers and sort them by customer ID? n The invoice records are in the sales detail dataset, but state- code is in the customer master record >get m-customer >if state-code = "BC" >extract cust-account >output bccust >xeq >table bc,cust-account,file,bccust >get d-sales >if $lookup(bc,cust-account) >sort cust-account >list standard >xeq customers invoices BC

37 Selecting records using the Chain command n Alternately, you can use the CHAIN command to find the required invoices after you have created an output file of British Columbia customers (Bccust) >table brit,cust-account,file,bccust >chain d-sales,cust-account=brit >list standard >xeq n The CHAIN command performs keyed retrievals for the values in the table. n No SORT command is necessary because the CHAIN command retrieves the records in the same order as they are found in the table

38 String Functions and Features n $TRIM,$RTRIM,$LTRIM n $UPPER,$LOWER n + Operator andTarget field

39 Summary n IF command n Field comparison n IF expressions (Boolean operators, parentheses) n Pattern-matching n Date fields n Sub-field comparisons n $READ function n Tables n Selecting from one file based on criteria in another file