Hidden Gems Walter F. Blood Technical Director Information Builders, Inc Copyright 2007, Information Builders. Slide 1 Hidden Gems Where We Will Look … in Settings Coping with PDF and unix Simplifying and controlling echo DBA and connections … in Connections Combining tables based on ranges Connecting tables with nothing in common … in Expressions Working with more than one record instance at a time Writing to multiple files simultaneously Creating your own business related functions … in Sorting Automatic summary column creation Hidden Gems …In Settings Coping with PDF and unix Simplifying ECHO DBA and connections Copyright 2007, Information Builders. Slide 3 Hidden Gems …In Settings PDFLINETERM DEFECHO DBASOURCE Copyright 2007, Information Builders. Slide 4 Hidden Gems SET Parameters Switches that affect behavior – scope varies You can set at multiple levels EDASPROF Group/User Profile Focexec Request Look at the difference in behavior to see when to apply them Hidden Gems SET Parameters – PDFLINETERM PDF U N I X Corrupt PDF PDF SET PDFLINETERM=OFF | ON Truly hidden – not available currently in SET tool To eliminate corrupt PDF files that pass through UNIX systems in distribution. Adds additional space to account for the difference in new line indicator. Hidden Gems SET Parameters – DEFECHO &ECHO allows tracing of WebFOCUS execution -SET &ECHO – local variable requires setting in each script SET DEFECHO=OFF | ON | ALL | NONE Provides setting for default value of &ECHO Default value is used in all INCLUDEd and EXECuted fexes unless –SET issued Trace appears in View Source window Hidden Gems SET Parameters – DEFECHO SET DEFECHO=OFF | ON | ALL | NONE One setting controls all – NONE – Prevents unauthorized use of ECHO. Cannot be reset OFF – No tracing of WebFOCUS stack ON – Tracing of WebFOCUS stack only ALL – Tracing of WebFOCUS stack and Dialogue Manager (including &variable substitution) Hidden Gems SET Parameters – DBASOURCE Controls which DBA is applied to in JOIN structure HOST DBA1 JOIN XREF DBA2 Default value – HOST - Applies DBA from HOST file only Value – ALL – Applies DBA from both files if present Access control – FILE, SEGMENT, FIELD, VALUE DBA converted to selection criteria and optimized Hidden Gems …In Connections Connect files based on a range of values Connect files with NO apparent connection Copyright 2007, Information Builders. Slide 10 Hidden Gems Connection Employee Tax Rate EMPLOYEE ID LAST NAME FIRST NAME HIRE DATE CURRENT SALARY … TAX YEAR TAX RATE MINIMUM SALARY MAXIMUM SALARY • Standard JOIN based upon equality selection JOIN field IN file TO ALL field IN file AS name Copyright 2007, Information Builders. Slide 11 Hidden Gems Connect Based on Equality Copyright 2007, Information Builders. Slide 12 Hidden Gems Connect Based on Equality Copyright 2007, Information Builders. Slide 13 Hidden Gems Connect Based on Equality Copyright 2007, Information Builders. Slide 14 Hidden Gems Connect Based on Range of Values EMPLOYEE TAX RATE EMPLOYEE ID LAST NAME FIRST NAME HIRE DATE CURRENT SALARY … TAX YEAR TAX RATE MINIMUM SALARY MAXIMUM SALARY •Connection can also be based upon range • LE, LT, GE, GT, NE or FROM /TO JOIN FILE file AT field TO ALL FILE file AT field AS name WHERE condition Copyright 2007, Information Builders. Slide 15 Hidden Gems Connect Based on Range Copyright 2007, Information Builders. Slide 16 Hidden Gems Insurance Rates – Listing Problem: Selecting the correct insurance rate based upon age from a table with ranges--Minimum Maximum Age Age Insurance Rate 21 27 $ 8.00 28 34 $ 9.00 35 40 $10.00 41 44 $11.00 Copyright 2007, Information Builders. Slide 17 Hidden Gems In Connections - Insurance Rates Greater than Minimum Age JOIN FILE EMPDATA1 AT BIRTHDATE TO ALL FILE RATES AT AGE AS J1 WHERE EMPDATA1.BAGE GE RATES.AGE; WHERE EMPDATA1.BAGE LE RATES.EAGE; END TABLE FILE EMPDATA1 Less than HEADING Maximum Age "To: <FIRSTNAME <LASTNAME " "</1 Thank you for choosing our company for your <0X insurance needs." "Thank you for choosing our company for your insurance needs.” "Since your birth date is <BIRTHDTATE ,your current rate is<0X <RATE_PER_THOUSAND per" "unit of coverage. This is your rate through age <EAGE . “ ON TABLE SET PAGE OFF BY PIN NOPRINT PAGE-BREAK END Copyright 2007, Information Builders. Slide 18 Hidden Gems In Connections Connect files that have NO apparent connection Employee Salary History JOIN? New Car Finance Packages Copyright 2007, Information Builders. Slide 19 Hidden Gems In Connections Copyright 2007, Information Builders. Slide 20 Hidden Gems In Connections Employee Salary History JOIN? New Car Finance Packages Copyright 2007, Information Builders. Slide 21 Hidden Gems In Connections Conditional Join Considerations: Cartesian product WHERE condition controls selection Complex WHEREs supported Multiple WHERE conditions WHERE must contain fields from both files Remove WHERE – true cartesian product Range-based JOIN in the tool Join with no common fields in text mode Copyright 2007, Information Builders. Slide 22 Hidden Gems In Expressions Working with more than one record instance at a time Writing to multiple files simultaneously Creating your own business related functions Copyright 2007, Information Builders. Slide 23 Hidden Gems In Expressions Working with more than one record instance at a time THE FUNCTION Available in COMPUTE, DEFINE, WHERE References the field value in the previous record Works with real and virtual fields Copyright 2007, Information Builders. Slide 24 Hidden Gems In Expressions Copyright 2007, Information Builders. Slide 25 Hidden Gems In Expressions 1. Select LAST 2. Get Fieldname Copyright 2007, Information Builders. Slide 26 Hidden Gems In Expressions In DEFINE Copyright 2007, Information Builders. Slide 27 Hidden Gems In Expressions In DEFINE Copyright 2007, Information Builders. Slide 28 Hidden Gems In Expressions In COMPUTE Copyright 2007, Information Builders. Slide 29 Hidden Gems In Expressions Same as DEFINE Operates on matrix Processes same or fewer records than DEFINE In COMPUTE Copyright 2007, Information Builders. Slide 30 Hidden Gems In Expressions CAR.ORIGIN.COUNTRY NE LAST CAR.ORIGIN.COUNTRY In WHERE Copyright 2007, Information Builders. Slide 31 Hidden Gems In Expressions Failed? Multiple Country’s Why? Order is important DEFINE order is the order of READ In WHERE Copyright 2007, Information Builders. Slide 32 Hidden Gems In Expressions Data in matrix sorted WHERE TOTAL on COMPUTE Results? In WHERE Copyright 2007, Information Builders. Slide 33 Hidden Gems In Expressions Ta Da! In WHERE Copyright 2007, Information Builders. Slide 34 Hidden Gems In Expressions Using LAST: Detecting value changes of data in ordered sets Nested IF…THEN…ELSE Create new sort-able select-able groups Creating identifiers based on ordered fields DEFINE - BY / WHERE COMPUTE - BY TOTAL / WHERE TOTAL Creating running values on any fields Totals, Averages, Margins, Any calculation Holding preceding data values for calculation In DEFINE In COMPUTE In WHERE Copyright 2007, Information Builders. Slide 35 Hidden Gems In Expressions LAST Considerations: The order the data is processed is critical You may need to presort data to a hold file Not optimizable to relational databases DEFINES work with WHERE COMPUTES work with WHERE TOTAL In DEFINE In COMPUTE In WHERE Copyright 2007, Information Builders. Slide 36 Hidden Gems In Expressions Writing to multiple files simultaneously To create a log of specific data values read Which customers placed orders? To create of record of calculated values Will I go out of stock on any these orders? To create additional output What page number will this item be on? PUTDDREC Hidden Gems In Expressions PUTDDREC syntax: PUTDDREC(ddname, dd_len, record_string, record_len, outfield) ddname - ddname assigned by filedef to output file dd_len - length of the ddname record_string - string of characters to write to file or field containing that string record_len - length of the string to be included outfield - return code Output file must be filedef’d DEFINE/COMPUTE field format always I1 Handles open, write and close Hidden Gems In Expressions PUTDDREC in Action FILEDEF PUTDD1 DISK putdd1.dat TABLE FILE EMPLOYEE PRINT EMP_ID CURR_JOBCODE AS 'JOB' CURR_SAL COMPUTE SALA/A12 = EDIT(CURR_SAL); NOPRINT COMPUTE EMP1/A50= LAST_NAME|FIRST_NAME|EMP_ID|CURR_JOBCODE|SALA; NOPRINT COMPUTE OUT1/I1 = PUTDDREC('PUTDD1',6, EMP1, 50, OUT1); BY LAST_NAME BY FIRST_NAME END Hidden Gems In Expressions LAST_NAME --------BANNING BLACKWOOD CROSS GREENSPAN IRVING JONES MCCOY MCKNIGHT ROMANS SMITH STEVENS FIRST_NAME ---------JOHN ROSEMARIE BARBARA MARY JOAN DIANE JOHN ROGER ANTHONY MARY RICHARD ALFRED EMP_ID --------119329144 326179357 818692173 543729165 123764317 117593129 219984371 451123478 126724188 112847612 119265415 071382660 JOB --A17 B04 A17 A07 A15 B03 B02 B02 B04 B14 A01 A07 Report Created CURR_SAL -------$29,700.00 $21,780.00 $27,062.00 $9,000.00 $26,862.00 $18,480.00 $18,480.00 $16,100.00 $21,120.00 $13,200.00 $9,500.00 $11,000.00 OUT1 ---0 0 0 0 0 0 0 0 0 0 0 0 Hidden Gems In Expressions Sequential File Created BANNING BLACKWOOD CROSS GREENSPAN IRVING JONES MCCOY MCKNIGHT ROMANS SMITH SMITH STEVENS JOHN ROSEMARIE BARBARA MARY JOAN DIANE JOHN ROGER ANTHONY MARY RICHARD ALFRED 119329144A17000000029700 326179357B04000000021780 818692173A17000000027062 543729165A07000000009000 123764317A15000000026862 117593129B03000000018480 219984371B02000000018480 451123478B02000000016100 126724188B04000000021120 112847612B14000000013200 119265415A01000000009500 071382660A07000000011000 Hidden Gems In Expressions PUTDDREC Considerations: Create fixed data file to fit a specific Master file Create comma-delimited data file for loading System and User &variables are available &MDYY, &FOCCPU, &FOCUSER, etc Write control at any point or multiple points Write to multiple PUTDDREC files in a request Hidden Gems In Expressions Creating an Index in PDF with PUTDDREC 1. Create a filedef for the index output file. 2. Create request that you want to index. 1. Including HOLD to PDF 2. Including all styling required 3. Add NOPRINTED COMPUTE that – 1. Tests for a change of sort break 2. Uses PUTDDREC to put values in file &TABPAGENO Sort Break Value 4. Create pdf index request using index output 5. Run original request as compound pdf, followed by index request , creating single pdf. Hidden Gems In Expressions Creating your own business related functions Standardization Corporate business logic FOCUS/WebFOCUS coding standards Simplification Complicated groups of expressions Repeated groups of expressions Creation New subroutines currently unavailable Customization of existing functions Based on the FOCUS/WebFOCUS language Hidden Gems In Expressions The Syntax of FUNCTIONS - 1 DEFINE FUNCTION name (arg1/format,…argn/formatn) [tempvariablea/formata = expressiona;] . . [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END Arguments and formats that are used when the function is called. Name of function = Last field calculated in function. Returns value to calling procedure. Fields actually used in call must match the type indicated – alpha or numeric. Alpha Too short – space padded Too long – truncated Hidden Gems In Expressions The Syntax of FUNCTIONS - 2 DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;] . . [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END Intermediate fields use in calculation of final result. Unlimited number Use arguments, constants and other temporary fields declared in the function. Use all operators and most functions Hidden Gems In Expressions The Syntax of FUNCTIONS - 3 DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;] . . [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END Final field defines the value returned. Name must match name of function. Format indicates the format returned. Hidden Gems In Expressions MARGIN Function DEFINE FUNCTION MARGIN CLEAR DEFINE FUNCTION MARGIN (RC/D7, DC/D7) NETPROFIT/D7=RC-DC; MARGIN/D5.2=(NETPROFIT*100)/DC; END TABLE FILE CAR PRINT COUNTRY CAR MODEL SALES AND COMPUTE MARGIN/D5.2 = MARGIN(RETAIL_COST,DEALER_COST); WHERE MARGIN(RETAIL_COST, DEALER_COST) GT 20 END Hidden Gems In Expressions Functions in Master Files? Easily accessed throughout WebFOCUS Connected to Master File? DF. Operator Dynamic load and run of function Function location indicated Additional characteristics available Description Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions Contents of dmfns.fex DEFINE FUNCTION DMDATFMT DESCRIPTION 'Convert date to 2008-JUL-04 format‘ (INDATE/YYMD) CONVDATE/A8YYMD=DATECVT(INDATE, 'YYMD', 'A8YYMD'); DMDATFMT/A11=CHGDAT( 'YYMD', 'YYMTD', CONVDATE, 'A11' ); END DEFINE FUNCTION DMPROPER DESCRIPTION 'Convert name to proper case and last, first format‘ (LASTNAME/A17, FIRSTNAME/A14) DMPROPER/A34V=LCWORD(17, LASTNAME, 'A17') || (', ' | LCWORD(14, FIRSTNAME, 'A14')); END Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions Hidden Gems In Expressions PROBLEM: We Need A Report That Reads Times In Seconds, AGENT1 AGENT_TALK AGENT_TALK1 TTIME TTIME1 ALLEN 200 300 00:03:20 00:05:00 BILL 300 400 00:05:00 00:06:40 CARL 620 520 00:10:20 00:08:40 DAN 400 901 00:06:40 00:15:01 --------------------------------------------------------TOTAL 1520 2121 00:25:20 00:35:21 Adds Them And Converts To Hours : Minutes : Seconds Hidden Gems In Expressions SOLUTION: DEFINE FUNCTION HRMISC (SEC/I10) -* CALCULATE HOURS HR/I2 = SEC/3600; HR_R/I2 = SEC -(HR* 3600) ; -* CALCULATE MIN MI/I2 = (HR_R / 60); -* CALCULATE SECONDS SC_D/I2 = SEC -((MI * 60) + HR); HRMISC/A8 = EDIT(HR) || ':' || EDIT(MI) || ':' || EDIT(SC_D) ; END Hidden Gems In Sorting Automatic summary column creation Copyright 2007, Information Builders. Slide 61 Hidden Gems In Sorting You know the effect of SUB-TOTAL on a BY field… TABLE FILE GGSALES SUM UNITS AS 'UNITS' DOLLARS AS 'DOLLARS' BY PRODUCT BY REGION BY DATE WHERE DATE FROM 19970801 TO 19971231; WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; ON DATE SUB-TOTAL AS 'REGION TOTAL' ON TABLE SUB-TOTAL Product Region END ------Capuccino -----Northeast REGION TOTAL 1997/08/01 . . REGION TOTAL 1997/12/01 *TOTAL REGION Northeast . Date ---1997/08/01 UNITS ----1473 DOLLARS ------19486 1473 19486 1188 11551 13668 144742 Hidden Gems In Sorting Now see the effect of SUB-TOTAL on an ACROSS field… TABLE FILE GGSALES SUM UNITS AS 'UNITS' OVER DOLLARS AS 'DOLLARS' OVER BY PRODUCT ACROSS REGION ACROSS DATE ON DATE SUB-TOTAL AS 'REGION' ON TABLE SUB-TOTAL WHERE DATE FROM 19970801 TO 19971231; WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; END Region Product ------Capuccino Espresso TOTAL UNITS DOLLARS UNITS DOLLARS UNITS DOLLARS Midwest MNTH NOV DEC ----. . . . 2186 1752 27526 22281 2186 1752 27526 22281 West REGION -----. . 3938 49807 3938 49807 TOTAL NOV DEC REGION ---------- ----2535 4051 6586 6586 31153 57421 88574 88574 3088 3732 6820 10758 36123 51400 87523 137330 5623 7783 13406 17344 67276 108821 176097 225904 Hidden Gems In Sorting You know the effect of SUMMARIZE on a BY field… TABLE FILE GGSALES SUM UNITS AS 'UNITS' DOLLARS AS 'DOLLARS' COMPUTE DOLLPER/I6 = DOLLARS/UNITS; AS 'UNIT PRICE' BY PRODUCT BY REGION BY DATE WHERE DATE FROM 19970801 TO 19971231; WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; ON DATE SUMMARIZE AS 'REGION TOTAL' ON TABLE SUMMARIZE END Product Region Date UNITS DOLLARS ------Capuccino -----Northeast REGION TOTAL 1997/08/01 . . . REGION TOTAL 1997/12/01 *TOTAL REGION Northeast ---1997/08/01 ----1473 ------19486 UNIT PRICE ---------13 1473 19486 13 1188 11551 13668 144742 11 12 Hidden Gems In Sorting Now see the effect of SUMMARIZE on an ACROSS field… TABLE FILE GGSALES SUM UNITS AS 'UNITS' OVER DOLLARS AS 'DOLLARS' OVER COMPUTE DOLLPER/I6 = DOLLARS/UNITS; AS 'UNIT PRICE' BY PRODUCT ACROSS REGION ACROSS DATE ON DATE SUMMARIZE AS 'REGION' ON TABLE SUMMARIZE Region Midwest West WHERE DATE FROM 19970801 TO 19971231; MNTH WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; Product NOV DEC REGION NOV DEC END ---------------- ----Capuccino Espresso TOTAL UNITS DOLLARS UNIT PRICE UNITS DOLLARS UNIT PRICE UNITS DOLLARS UNIT PRICE . . . 2186 27526 12 2186 27526 12 . . . 1752 22281 12 1752 22281 12 . . . 3938 49807 12 3938 49807 12 2535 4051 31153 57421 12 14 3088 3732 36123 51400 11 13 5623 7783 67276 108821 11 13 TOTAL REGION ------ ----6586 6586 88574 88574 13 13 6820 10758 87523 137330 12 12 13406 17344 176097 225904 13 13 Hidden Gems In Sorting TABLE FILE GGSALES SUM UNITS AS 'UNITS' OVER DOLLARS AS 'DOLLARS' OVER COMPUTE DOLLPER/I6 = DOLLARS/UNITS; AS 'UNIT PRICE' BY PRODUCT ACROSS REGION ACROSS DATE ON DATE SUMMARIZE AS 'REGION' ON TABLE SUMMARIZE WHERE DATE FROM 19970801 TO 19971231; WHERE PRODUCT EQ 'Capuccino' OR 'Espresso'; END Currently requires text mode Triggered with ON <field> SUMMARIZE AS ‘title’ Style as DATA, OBJECT, or COLUMN Hidden Gems Where We Looked Coping with PDF and unix Simplifying and controlling echo DBA and connections Combining tables based on ranges Connecting tables with nothing in common Working with more than one record instance at a time Writing to multiple files simultaneously Creating your own business related functions Automatic summary column creation Questions?