Introduction to Query Part 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 Files Types 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: U4CSTMRU4TRNDU4TRNH TDBTCHTHBTCH BATCH NO CSCNOTDCNOTHCNOCUSTOMER NO. TDINVTHINV#INVOICE NO. TDIVDTTHIVDTINVOICE DATE TDTYPETHTYPETRANS TYPE TDTMCDTHTMCDTERM CODE TDLCTHLCLOCATION
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 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 connectOR’s separate
Complex Record Selection AND’s connect All statements must be true! TDITEMEQ‘HORSECHOW’ ANDTDLOCEQ001 OR’s separate Only 1 statement must be true! TDITEM EQ 'HORSECHOW' OR TDLOC EQ 001 TDITEMEQ‘HORSECHOW’ ANDTDLOCEQ001 ORTDITEMEQ‘PIG FEED' ANDTDLOCEQ002
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 : Invoice Heading : Date Heading : Length : 8 Decimal : 0 Sample : 99,999,999 Type choice, press Enter. Edit option =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 : Invoice Length.... : 8 Heading : Date Decimal.... : 0 Heading : 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 formattedFormatted Date 20,080, /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 Blank, Width Blank, Start line Blank, End line Blank, Line spacing , 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 = Portrait 51 Width = Landscape
Query Exercises Exercise 3 Create sales report
Thanks for attending!