introduction to query part 2. query topics joining files defining result fields complex record...
TRANSCRIPT
Introduction to QueryPart 2
Query Topics Joining Files
Defining Result Fields
Complex Record Selection
Formatting Output
Creating Reports Using Multiple Files
Joining Files
Define the Query Query . . . . . . : Option . . . . . : CREATE Library . . . . : KARENQRY CCSID . . . . . . : 37 Type options, press Enter. Press F21 to select all. 1=Select Opt Query Definition Option 1 Specify file selections Define result fields Select and sequence fields Select records Select sort fields Select collating sequence Specify report column formatting Select report summary functions Define report breaks Select output type and output form Specify processing options F3=Exit F5=Report F12=Cancel F13=Layout F18=Files F21=Select all
Joining Files
Data is stored in different files Customer Name
Master Files Customer Master
Transaction Files U4TRND – AR Detail File
How to Join Files
Join Key Fields and ‘Like Fields’ in both files Prevents duplicate data
Transaction File is the primary file U4TRND should be primary file Queries run faster
Use Correct type of join
Joining FilesTypes of Joins
1 – Matched Records Selects only records that have matching records in ALL
the files.
2 - Matched Records with Primary File Selects every record from the primary file and includes
all the matching records from all other files.
3 Unmatched Records with Primary File Selects every primary record that does not have a match
in all the secondary files.
Joining Files
Join files by key fields:
U4CSTMR U4TRND U4TRNHTDBTCH THBTCH
BATCH NO CSCNO TDCNO THCNO CUSTOMER NO.
TDINV THINV# INVOICE NO.TDIVDT THIVDT INVOICE DATETDTYPE THTYPE TRANS TYPETDTMCD THTMCD
TERM CODETDLC THLC LOCATION
Define Result Fields Define the Query Query . . . . . . : Option . . . . . : CREATE Library . . . . : KARENQRY CCSID . . . . . . : 37 Type options, press Enter. Press F21 to select all. 1=Select Opt Query Definition Option Specify file selections 1 Define result fields Select and sequence fields Select records Select sort fields Select collating sequence Specify report column formatting Select report summary functions Define report breaks Select output type and output form Specify processing options F3=Exit F5=Report F12=Cancel F13=Layout F18=Files F21=Select all
Define Result Fields
Define Result Fields Type definitions using field names or constants and operators, press Enter. Operators: +, -, *, /, SUBSTR, ||, DATE... Field Expression Column Heading Len Dec AMOUNT TDAMT*-1 AMOUNT 9 2 COMM AMOUNT*.001 COMMISSION 9 2
Bottom ____________________________________________________________________________________
Field Text Len Dec T01.TDDEPT Dept Number 3 0 T02.DPDESC Department Description 20 T01.TDITEM Item Number 14 T01.TDCNO Customer Number 7 0 More... F3=Exit F5=Report F9=Insert F11=Display names only F12=Cancel F13=Layout F20=Reorganize F24=More keys
Select Records Define the Query
Query . . . . . . : Option . . . . . : CREATE
Library . . . . : KARENQRY CCSID . . . . . . : 37
Type options, press Enter. Press F21 to select all.
1=Select
Opt Query Definition Option
Specify file selections
Define result fields
Select and sequence fields
1 Select records
Select sort fields
Select collating sequence
Specify report column formatting
Select report summary functions
Define report breaks
Select output type and output form
Specify processing options
F3=Exit F5=Report F12=Cancel
F13=Layout F18=Files F21=Select all
Complex Record Selection
Select Records
Type comparisons, press Enter. Specify OR to start each new group. Tests: EQ, NE, LE, GE, LT, GT, RANGE, LIST, LIKE, IS, ISNOT... AND/OR Field Test Value (Field, Number,Characters', or ...)
_______ _____ ________________________________________
_____ ________ _____ ________________________________________
_____ ________ _____ ________________________________________
AND’s connect OR’s separate
Complex Record SelectionAND’s connect All statements must be true!
TDITEM EQ ‘HORSECHOW’AND TDLOC EQ 001
OR’s separate Only 1 statement must be true!
TDITEM EQ 'HORSECHOW' OR TDLOC EQ 001
TDITEM EQ ‘HORSECHOW’AND TDLOC EQ 001OR TDITEM EQ ‘PIG FEED'AND TDLOC EQ 002
Record Selection Tips
U4TRND file (A/R Transaction Detail)
TDTRAN – Transaction code field 1, 2, 3, 5, 7, 8, 9
TDOFFS field – Offset records NE to 1 Used only when selecting just transaction codes Don’t need if selecting item No or G/l No.
Formatting Output
Define the Query Query . . . . . . : Option . . . . . : CREATE Library . . . . : DAWNQRY CCSID . . . . . . : 37 Type options, press Enter. Press F21 to select all. 1=Select Opt Query Definition Option Specify file selections Define result fields Select and sequence fields Select records Select sort fields Select collating sequence 1 Specify report column formatting Select report summary functions Define report breaks Select output type and output form Specify processing options F3=Exit F5=Report F12=Cancel F13=Layout F18=Files F21=Select all
Formatting Output
Specify Report Column Formatting Type information, press Enter. Column headings: *NONE, aligned text lines Column Field Spacing Column Heading Len Dec Edit T01.TDIVDT 0 Invoice 8 0 * Date T01.TDCNO 2 Customer 7 0 Number T03.CSLKNM 2 Customer 15 Lookup Name = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Field Text Len Dec T01.TDIVDT Invoice Date 8 0 T01.TDCNO Customer Number 7 0 T03.CSLKNM Customer Lookup Name 50 T01.TDINV Invoice Number 7 0 T01.TDQTY Quantity 9/4 11 4
Formatting Output
Define Numeric Field Editing Field . . . . . . . . : T01.TDIVDT Text . . . . . . . . : Invoice Date Heading 1 . . . . . . : Invoice Heading 2 . . . . . . : Date Heading 3 . . . . . . : Length . . . . . . . : 8 Decimal . . . . . . . : 0 Sample . . . . . . . : 99,999,999 Type choice, press Enter. Edit option . . . . . 4 1=Numeric editing choices 2=Date or time editing choice 3=Edit code 4=Edit word F3=Exit F5=Report F10=Process/previous F11=Change sample F12=Cancel F13=Layout F16=Remove edit F18=Files 30
Formatting Output
Specify Edit Word Field . . . . . : T01.TDIVDT Heading 1 . . . . : Invoice Length . . . . : 8 Heading 2 . . . . : Date Decimal . . . . : 0 Heading 3 . . . . : Type information, press Enter. (Put quotes around edit words.) (Each blank replaced by a digit, each '&' with a blank.) Edit word . . . . . ' / / '
Edit word for summary total . .
F3=Exit F5=Report F10=Process/previous F12=Cancel F13=Layout F16=Remove edit F18=Files Date not formatted Formatted Date 20,080,306 2008/03/06 20,080,306 2008/03/06
Formatting Reports Define the Query Query . . . . . . : Option . . . . . : CREATE Library . . . . : KARENQRY CCSID . . . . . . : 37 Type options, press Enter. Press F21 to select all. 1=Select Opt Query Definition Option Specify file selections Define result fields Select and sequence fields Select records Select sort fields Select collating sequence Specify report column formatting Select report summary functions Define report breaks 1 Select output type and output form Specify processing options F3=Exit F5=Report F12=Cancel F13=Layout F18=Files F21=Select all
Formatting Reports Define Printer Output Type choices, press Enter. Printer . . . . . . . . . *PRINT *PRINT, name Form size: Length . . . . . . . . . 66 Blank, 1-255 Width . . . . . . . . . 198 Blank, 1-378 Start line . . . . . . . . Blank, 1-255 End line . . . . . . . . . Blank, 1-255 Line spacing . . . . . . . 1 1, 2, 3 Print definition . . . . . N Y=Yes, N=No
F3=Exit F5=Report F10=Process/previous F12=Cancel F13=Layout F18=Files
NOTE: 66 Length = Portrait51 Width = Landscape
Query Exercises
Exercise 3 Create sales report
Thanks for attending!