Presentation is loading. Please wait.

Presentation is loading. Please wait.

FILTERS and FUNCTIONS: Hidden Gems Walter F. Blood Technical Director, FOCUS Division June, 2008.

Similar presentations


Presentation on theme: "FILTERS and FUNCTIONS: Hidden Gems Walter F. Blood Technical Director, FOCUS Division June, 2008."— Presentation transcript:

1 FILTERS and FUNCTIONS: Hidden Gems Walter F. Blood Technical Director, FOCUS Division June, 2008

2 FILTERS and FUNCTIONS FILTERs TWO Types of Filters  Visible  Stored in Master File  Activated by reference in a request  Invisible  Independent command  Executable in PROFILEs, or FOCEXECs  Active for the entire session  Added to every request using the Master

3 FILTERS and FUNCTIONS Visible FILTERs What is a visible FILTER?  Virtual Field stored in Master File.  Must evaluate to True or False – 1 or 0.  Format is always I1.  Only evaluated when referenced in your request.  Functional with  CHECK FILE  TABLE/TABLEF FILE  MATCH FILE  MORE  SQL

4 FILTERS and FUNCTIONS Visible FILTER Visible FILTER syntax FILTER = expression;$  Positioned anywhere in Master.  Use any expression legal for WHERE  Usable with Business View or Join.  Shortest unique truncation will access it.  FILTER TOPSELLERS = SALES GT 20000;$

5 FILTERS and FUNCTIONS Visible FILTER Expressions WHERE (expression) (operator) (expression) AND/OR … (field/literal/function) (operator) (field/literal/function)  Each expression has one or more operators  Can use real and virtual fields in the Master file.  Cannot use virtual fields created in the request or fields described in other files.  Selections based on fields from multiple files must be AND/OR in the WHERE phrase – not in the FILTER.  IF..THEN..ELSE and DECODE to Alpha are not supported in FILTERs.

6 FILTERS and FUNCTIONS Visible FILTER Referencing Visible FILTERs WHERE  No limit to the number of Filters.  FILTER from Master File is automatically included on reference in request.  Beware collisions– multiple WHEREs are ANDed together. From Master and Request!  Be precise not creative with the Filter Names – indicate what it does.

7 FILTERS and FUNCTIONS Visible FILTER Filter Naming  Think of your endusers and how they see the data!  Combine complex selection criteria into one filter!  Give the filter a meaningful name!  FILTER1 – probably useless  FROMLASTWEEK - better

8 FILTERS and FUNCTIONS Visible FILTER Examples REVIEW4RAISE = HIRE_DATE LT 810101 AND CURR_SAL LT 12500 AND CURR_JOBCODE CONTAINS ‘A’;$ REVIEW4RAISE = HIRE_DATE LT 810101 AND CURR_SAL LT 12500 AND CURR_JOBCODE CONTAINS ‘A’;$ GETWKLYBONUS=((WKLYSALES/DOLQUOTA) GT 1.200 AND (WKLYUNITS/UNTQUOTA) GT 1.100) OR ((TOTSALES/TOTDOLQUOTA) GT 1.500) OR ((TOTUNITS/TOTUNTQUOTA) GT 2.000);$ GETWKLYBONUS=((WKLYSALES/DOLQUOTA) GT 1.200 AND (WKLYUNITS/UNTQUOTA) GT 1.100) OR ((TOTSALES/TOTDOLQUOTA) GT 1.500) OR ((TOTUNITS/TOTUNTQUOTA) GT 2.000);$

9 FILTERS and FUNCTIONS Invisible FILTERs What is an invisible FILTER? And how is it different from a visible FILTER?  Activated anywhere in session.  Not referenced in request.  Controlled with commands  Declared with FILTER FILE command.  Activated/Deactivated with SET FILTER command.  Requires SET KEEPFILTERS to cross JOINs  Status of FILTER can be queried -? FILTER.  Supports Defines available only to FILTERs.  Allows both WHERE and IF syntax.

10 FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTERS and FUNCTIONS Invisible FILTERs FILTER FILE command

11 FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTERS and FUNCTIONS Invisible FILTERs FILTER FILE command Deletes existing FILTER phrases and defines for this file. Adds new filter phrases to existing FILTER phrases and defines for this file. Describes the filter and can be issued in profile, focexec, or command line

12 FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTERS and FUNCTIONS Invisible FILTERs FILTER FILE command Virtual fields used in Filters. More on this later! Only referenceable in Filters!

13 FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTER FILE [ CLEAR | ADD ] [filter-defines;] NAME=filtername1 [,DESC=text] where-if phrases. NAME=filternamen [,DESC=text] where-if phrases END FILTERS and FUNCTIONS Invisible FILTERs FILTER FILE command Any valid WHERE or IF screening conditions. Must reference filter defines, or real or virtual fields in Master only. Filter Name must be 8 characters or less and unique for the master file. Used by SET FILTER= Filter Name must be 8 characters or less and unique for the master file. Used by SET FILTER= Only one line of text allowed

14 FILTERS and FUNCTIONS Invisible FILTER Filter Define Limitations  Local to specific filter declaration  Cannot be used in DEFINE or TABLE  Supports standard DEFINE functionality  Unlike DEFINE, do not count toward display field limit  Must all be declared before first named filter  Cannot reuse another virtual field from the same file.

15 FILTERS and FUNCTIONS Invisible FILTER Activating and Deactivating FILTERs SET FILTER = * IN ON/OFF ALL declared filters. Be careful using this setting. SET FILTER = name1 name2 …namen IN <filename ON/OFF Only named declared filters will be affected.

16 FILTERS and FUNCTIONS Invisible FILTER Filter Declaration Example FILTER FILE CAR ADD PROFIT/D7=(RCOST-DCOST); MARGINPCT/D7.2=(PROFIT/DCOST)*100 ; NAME=HIMARGIN WHERE MARGINPCT GT 20.0 NAME=MDMARGIN WHERE MARGINPCT FROM 10.0 to 20.0 NAME=LOMARGIN WHERE MARGINPCT LT 10.0 END FILTER FILE CAR ADD PROFIT/D7=(RCOST-DCOST); MARGINPCT/D7.2=(PROFIT/DCOST)*100 ; NAME=HIMARGIN WHERE MARGINPCT GT 20.0 NAME=MDMARGIN WHERE MARGINPCT FROM 10.0 to 20.0 NAME=LOMARGIN WHERE MARGINPCT LT 10.0 END

17 FILTERS and FUNCTIONS Invisible FILTER > > set filter = himargin in car on > >> > table file car > print sales > by country > by car > by model > end NUMBER OF RECORDS IN TABLE= 8 LINES= 8 ACCESS LIMITED BY FILTERS PAUSE.. PLEASE ISSUE CARRIAGE RETURN WHEN READY > > set filter = himargin in car on > >> > table file car > print sales > by country > by car > by model > end NUMBER OF RECORDS IN TABLE= 8 LINES= 8 ACCESS LIMITED BY FILTERS PAUSE.. PLEASE ISSUE CARRIAGE RETURN WHEN READY PAGE 1 COUNTRY CAR MODEL SALES ------- --- ----- ----- ENGLAND JAGUAR XJ12L AUTO 12000 FRANCE PEUGEOT 504 4 DOOR 0 ITALY ALFA ROMEO 2000 GT VELOCE 12400 2000 SPIDER VELOCE 13000 2000 4 DOOR BERLINA 4800 MASERATI DORA 2 DOOR 0 W GERMANY BMW 3.0 SI 4 DOOR 14000 3.0 SI 4 DOOR AUTO 18940 END OF REPORT PAGE 1 COUNTRY CAR MODEL SALES ------- --- ----- ----- ENGLAND JAGUAR XJ12L AUTO 12000 FRANCE PEUGEOT 504 4 DOOR 0 ITALY ALFA ROMEO 2000 GT VELOCE 12400 2000 SPIDER VELOCE 13000 2000 4 DOOR BERLINA 4800 MASERATI DORA 2 DOOR 0 W GERMANY BMW 3.0 SI 4 DOOR 14000 3.0 SI 4 DOOR AUTO 18940 END OF REPORT

18 FILTERS and FUNCTIONS Invisible FILTER > set filter = himargin in car off > > set filter = lomargin in car on > > table file car > print sales > by country > by car > by model > end NUMBER OF RECORDS IN TABLE= 3 LINES= 3 ACCESS LIMITED BY FILTERS PAUSE.. PLEASE ISSUE CARRIAGE RETURN WHEN READY > set filter = himargin in car off > > set filter = lomargin in car on > > table file car > print sales > by country > by car > by model > end NUMBER OF RECORDS IN TABLE= 3 LINES= 3 ACCESS LIMITED BY FILTERS PAUSE.. PLEASE ISSUE CARRIAGE RETURN WHEN READY PAGE 1 COUNTRY CAR MODEL SALES ------- --- ----- ----- W GERMANY BMW 2002 2 DOOR 8950 2002 2 DOOR AUTO 8900 530I 4 DOOR 14000 END OF REPORT PAGE 1 COUNTRY CAR MODEL SALES ------- --- ----- ----- W GERMANY BMW 2002 2 DOOR 8950 2002 2 DOOR AUTO 8900 530I 4 DOOR 14000 END OF REPORT

19 FILTERS and FUNCTIONS Invisible FILTER ? FILTER [ {file | * } [ SET ] [ ALL ] ] Checking FILTER status With no parms ? FILTER * SET With no parms ? FILTER * SET Specify a single file or * for all files Show status of each declared filter Show description and WHERE/IF definition for each declared filter

20 > > ? FILTER CAR SET > > ? FILTER CAR SET SET FILE FILTER NAME DESCRIPTION --- -------- ----------- --------------------------------- CAR HIMARGIN MARGIN GREATER THAN 10% CAR MDMARGIN MARGIN BETWEEN 10 AND 20% * CAR LOMARGIN MARGIN BELOW 10% > > > ? FILTER CAR SET SET FILE FILTER NAME DESCRIPTION --- -------- ----------- --------------------------------- CAR HIMARGIN MARGIN GREATER THAN 10% CAR MDMARGIN MARGIN BETWEEN 10 AND 20% * CAR LOMARGIN MARGIN BELOW 10% > FILTERS and FUNCTIONS Invisible FILTER Checking FILTER status Active Filters indicated with * Use DESC to differentiate FILTERs since Filter Name only 8 characters

21 > > ? filter car all > > ? filter car all FILTER FILE CAR ADD PROFIT/D7=(RCOST-DCOST); MARGINPCT/D7.2=(PROFIT/DCOST)*100 ; NAME=HIMARGIN, DESC=MARGIN GREATER THAN 10% WHERE MARGINPCT GT 20.0 NAME=MDMARGIN, DESC=MARGIN BETWEEN 10 AND 20% WHERE MARGINPCT FROM 10.0 TO 20.0 NAME=LOMARGIN, DESC=MARGIN BELOW 10% WHERE MARGINPCT LT 10.0 END > > > ? filter car all FILTER FILE CAR ADD PROFIT/D7=(RCOST-DCOST); MARGINPCT/D7.2=(PROFIT/DCOST)*100 ; NAME=HIMARGIN, DESC=MARGIN GREATER THAN 10% WHERE MARGINPCT GT 20.0 NAME=MDMARGIN, DESC=MARGIN BETWEEN 10 AND 20% WHERE MARGINPCT FROM 10.0 TO 20.0 NAME=LOMARGIN, DESC=MARGIN BELOW 10% WHERE MARGINPCT LT 10.0 END > FILTERS and FUNCTIONS Invisible FILTER Checking FILTER status  Displays FILTER declarations.  Decrypts declarations for use and display. Be careful!

22 FILTERS and FUNCTIONS Invisible FILTER FILTERs, DEFINEs and JOIN FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR TABLE FILE CAR TABLE FILE CAR JOIN COUNTRY IN CAR TO ALL COUNTRY IN SALES AS J1 Context 1 Context 2 DEFINES and FILTERS From Context 1 cleared by JOIN DEFINES and FILTERS added in Context 2 cleared by JOIN CLEAR

23 FILTERS and FUNCTIONS Invisible FILTER FILTERs, DEFINEs and JOIN FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR FILTER FILE CAR … DEFINE FILE CAR … TABLE FILE CAR SET KEEPFILTERS=ON, KEEPDEFINES=ON JOIN COUNTRY IN CAR TO ALL COUNTRY IN SALES AS J1 Context 1 Context 2 DEFINES and FILTERS from Context 1 retained! DEFINES and FILTERS added in Context 2 cleared by JOIN CLEAR

24 FILTERS and FUNCTIONS Invisible FILTER

25 FILTERS and FUNCTIONS Functions The Path to FUNCTIONS  Virtual fields are linked to Master File or Synonym  DEFINE  COMPUTE  RECAP  Often contain logic common to many fields  Reformating dates, names, times  Calculating standard comparison – margin, percent  Use DEFINE FUNCTION to make that logic reusable  DEFINEd FUNCTIONS - callable like IB functions  DEFINEd FUNCTIONS - independent of Master File

26 FILTERS and FUNCTIONS Functions The Uses of FUNCTIONS  Standardizing  Corporate business logic  FOCUS/WebFOCUS coding standards  Simplifying  Complicated groups of expressions  Repeated groups of expressions  Creating  New subroutines currently unavailable  Customization of existing functions  Based on the FOCUS/WebFOCUS language

27 FILTERS and FUNCTIONS Functions The Syntax of FUNCTIONS - 1 DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;]. [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;]. [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END  Name of function.  Last field calculated in function.  Returns value to calling procedure.  Name of function.  Last field calculated in function.  Returns value to calling procedure.  Arguments and formats that are used when the function is called.  Fields actually used in call must match the type indicated – alpha or numeric.  Alpha  Too short – padded with spaces  Too long – truncated  Arguments and formats that are used when the function is called.  Fields actually used in call must match the type indicated – alpha or numeric.  Alpha  Too short – padded with spaces  Too long – truncated

28 FILTERS and FUNCTIONS Functions The Syntax of FUNCTIONS - 2 DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;]. [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END 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 argments, constants and other temporary fields declared in the function.  Intermediate fields use in calculation of final result.  Unlimited number  Use argments, constants and other temporary fields declared in the function.

29 FILTERS and FUNCTIONS Functions The Syntax of FUNCTIONS - 3 DEFINE FUNCTION name (argument1/format,…argumentn/formatn) [tempvariablea/formata = expressiona;]. [tempvariablen/formatn = expressionn;] name/format = [result_expression]; END 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.  Final field defines the value returned.  Name must match name of function.  Format indicates the format returned.

30 FILTERS and FUNCTIONS Functions Using DEFINEd FUNCTIONS  DEFINE Functions can be called by other DEFINE Functions.  DEFINE FUNCTION Unlimits  Number of Functions used in session  Number of arguments used in a function.  DEFINE FUNCTION Limits  Can not call themselves.  Names must be 8 characters or less.  Argument names must be 12 characters or less.

31 FILTERS and FUNCTIONS Functions MKMARGIN Function DEFINE FUNCTION MKMARGIN CLEAR DEFINE FUNCTION MKMARGIN (RC/D7, DC/D7) NETPROFIT/D7=RC-DC; MKMARGIN/D5.2=(NETPROFIT*100)/DC; END TABLE FILE CAR PRINT COUNTRY CAR MODEL SALES AND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST); WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20 END DEFINE FUNCTION MKMARGIN CLEAR DEFINE FUNCTION MKMARGIN (RC/D7, DC/D7) NETPROFIT/D7=RC-DC; MKMARGIN/D5.2=(NETPROFIT*100)/DC; END TABLE FILE CAR PRINT COUNTRY CAR MODEL SALES AND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST); WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20 END

32 FILTERS and FUNCTIONS Functions MKMARGIN Function results PAGE 1 COUNTRY CAR MODEL SALES MARGIN ------- --- ----- ----- ------ ENGLAND JAGUAR XJ12L AUTO 12000 20.52 ITALY ALFA ROMEO 2000 GT VELOCE 12400 20.49 ITALY ALFA ROMEO 2000 SPIDER VELOCE 13000 20.49 ITALY ALFA ROMEO 2000 4 DOOR BERLINA 4800 20.55 ITALY MASERATI DORA 2 DOOR 0 26.00 W GERMANY BMW 3.0 SI 4 DOOR 14000 37.52 W GERMANY BMW 3.0 SI 4 DOOR AUTO 18940 28.39 FRANCE PEUGEOT 504 4 DOOR 0 21.14 END OF REPORT PAGE 1 COUNTRY CAR MODEL SALES MARGIN ------- --- ----- ----- ------ ENGLAND JAGUAR XJ12L AUTO 12000 20.52 ITALY ALFA ROMEO 2000 GT VELOCE 12400 20.49 ITALY ALFA ROMEO 2000 SPIDER VELOCE 13000 20.49 ITALY ALFA ROMEO 2000 4 DOOR BERLINA 4800 20.55 ITALY MASERATI DORA 2 DOOR 0 26.00 W GERMANY BMW 3.0 SI 4 DOOR 14000 37.52 W GERMANY BMW 3.0 SI 4 DOOR AUTO 18940 28.39 FRANCE PEUGEOT 504 4 DOOR 0 21.14 END OF REPORT

33 FILTERS and FUNCTIONS Functions Displaying Active FUNCTIONS > ? FUNCTION > ? FUNCTION > ? FUNCTION FUNCTIONS CURRENTLY ACTIVE Name Format Parameter Format -------- -------- ------------ -------- MKMARGIN D5.2 RC D7 DC D7 SUBTRACT D8.2 VAL1 D7 VAL2 D7 > ? FUNCTION FUNCTIONS CURRENTLY ACTIVE Name Format Parameter Format -------- -------- ------------ -------- MKMARGIN D5.2 RC D7 DC D7 SUBTRACT D8.2 VAL1 D7 VAL2 D7

34 FILTERS and FUNCTIONS Functions Clearing FUNCTIONS DEFINE FUNCTION MKMARGIN CLEAR DEFINE FUNCTION MKMARGIN (RC/D7, DC/D7) NETPROFIT/D7=RC-DC; MKMARGIN/D5.2=(NETPROFIT*100)/DC; END TABLE FILE CAR PRINT COUNTRY CAR MODEL SALES AND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST); WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20 END DEFINE FUNCTION * CLEAR DEFINE FUNCTION MKMARGIN CLEAR DEFINE FUNCTION MKMARGIN (RC/D7, DC/D7) NETPROFIT/D7=RC-DC; MKMARGIN/D5.2=(NETPROFIT*100)/DC; END TABLE FILE CAR PRINT COUNTRY CAR MODEL SALES AND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST); WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20 END DEFINE FUNCTION * CLEAR  Clear one specific function  Prevent collision of multiple functions  Allow dynamic function creation and use  Clear one specific function  Prevent collision of multiple functions  Allow dynamic function creation and use  Clear all active functions  Provides quick and easy cleanup  Clear all active functions  Provides quick and easy cleanup

35 FILTERS and FUNCTIONS Functions STDNAME Function – alpha formatting DEFINE FUNCTION STDNAME (FN/A30, MI/A1, LN/A30) LNLOC/A30 = LCWORD( 30, LN, LNLOC ); FNLOC/A30 = LCWORD( 30, FN, FNLOC ); MIPER/A1=UPCASE( 1, MI, MIPER ) ; STDNAME/A65=LNLOC || (', ' | FNLOC) || ( ' ' | MIPER) || '.'; END DEFINE FUNCTION STDNAME (FN/A30, MI/A1, LN/A30) LNLOC/A30 = LCWORD( 30, LN, LNLOC ); FNLOC/A30 = LCWORD( 30, FN, FNLOC ); MIPER/A1=UPCASE( 1, MI, MIPER ) ; STDNAME/A65=LNLOC || (', ' | FNLOC) || ( ' ' | MIPER) || '.'; END  Produces “Lastname, Firstname Middleinitial. “  Oversized alpha parameters accommodate multiple field sizes  Parentheses to control spacing in final expression  Produces “Lastname, Firstname Middleinitial. “  Oversized alpha parameters accommodate multiple field sizes  Parentheses to control spacing in final expression DEFINE FUNCTION STDNAME (FN/A30, MI/A1, LN/A30) LNLOC/A30 = LCWORD( 30, LN, LNLOC ); FNLOC/A30 = LCWORD( 30, FN, FNLOC ); MIPER/A1=UPCASE( 1, MI, MIPER ) ; STDNAME/A65=LNLOC || (', ' | FNLOC) || ( ' ' | MIPER) || '.'; END TABLE FILE EMPDATA PRINT PIN AS EMPID AND COMPUTE NAME/A65 = STDNAME( FIRSTNAME, MIDINITIAL, LASTNAME ); END DEFINE FUNCTION STDNAME (FN/A30, MI/A1, LN/A30) LNLOC/A30 = LCWORD( 30, LN, LNLOC ); FNLOC/A30 = LCWORD( 30, FN, FNLOC ); MIPER/A1=UPCASE( 1, MI, MIPER ) ; STDNAME/A65=LNLOC || (', ' | FNLOC) || ( ' ' | MIPER) || '.'; END TABLE FILE EMPDATA PRINT PIN AS EMPID AND COMPUTE NAME/A65 = STDNAME( FIRSTNAME, MIDINITIAL, LASTNAME ); END

36 FILTERS and FUNCTIONS Functions STDNAME Function results PAGE 1 EMPID NAME ----- ---- 000000010 Valino, Daniel A. 000000020 Bella, Michael D. 000000030 Cassanova, Lois E. 000000040 Adams, Ruth B. 000000050 Addams, Peter C. 000000060 Patel, Dorina K. 000000070 Sanchez, Evelyn P. 000000080 So, Pamela L. 000000090 Pulaski, Marianne D. 000000100 Anderson, Tim A. PAGE 1 EMPID NAME ----- ---- 000000010 Valino, Daniel A. 000000020 Bella, Michael D. 000000030 Cassanova, Lois E. 000000040 Adams, Ruth B. 000000050 Addams, Peter C. 000000060 Patel, Dorina K. 000000070 Sanchez, Evelyn P. 000000080 So, Pamela L. 000000090 Pulaski, Marianne D. 000000100 Anderson, Tim A.

37 FILTERS and FUNCTIONS Functions Other Candidates for Reformatting  Any standardized alpha format  ID Numbers or SSNs  Telephone Numbers  Product codes or SKUs  Address lines  Irregular line indentation

38 FILTERS and FUNCTIONS Functions EXPDATE Function – Time Value calculation DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME ); DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME );  Generates date-time field &NUM hours from current time  Combines multiple Datetime calls into single function  Parentheses to control spacing in final expression.  Generates date-time field &NUM hours from current time  Combines multiple Datetime calls into single function  Parentheses to control spacing in final expression. DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME ); EXPDATE/HYYMDm = IF ( EDIT(LNAME, '9‘ )) EQ 'A' OR 'B' OR 'C' OR 'D' OR 'E' THEN HADD( CURTIM, 'HOUR', &NUM, 10, 'HYYMDm') DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME ); EXPDATE/HYYMDm = IF ( EDIT(LNAME, '9‘ )) EQ 'A' OR 'B' OR 'C' OR 'D' OR 'E' THEN HADD( CURTIM, 'HOUR', &NUM, 10, 'HYYMDm') DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME ); EXPDATE/HYYMDm = IF ( EDIT(LNAME, '9‘ )) EQ 'A' OR 'B' OR 'C' OR 'D' OR 'E' THEN HADD( CURTIM, 'HOUR', &NUM, 10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'F' OR 'G' OR 'H' OR 'I' OR 'J' THEN HADD( CURTIM, 'HOUR', &NUM+24,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'K' OR 'L' OR 'M' OR 'N' OR 'O' THEN HADD( CURTIM, 'HOUR', &NUM+48,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'P' OR 'Q' OR 'R' OR 'S' OR 'T' THEN HADD( CURTIM, 'HOUR', &NUM+72,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'U' OR 'V' OR 'W' OR 'X' OR 'Y' OR 'Z' THEN HADD( CURTIM, 'HOUR', &NUM+96,10, 'HYYMDm') ; END DEFINE FUNCTION EXPDATE (LASTNAME/A15) CURTIM/HYYMDm = HGETC( 10, 'HYYMDm‘ ); LNAME/A15 = UPCASE( 15, LASTNAME, LNAME ); EXPDATE/HYYMDm = IF ( EDIT(LNAME, '9‘ )) EQ 'A' OR 'B' OR 'C' OR 'D' OR 'E' THEN HADD( CURTIM, 'HOUR', &NUM, 10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'F' OR 'G' OR 'H' OR 'I' OR 'J' THEN HADD( CURTIM, 'HOUR', &NUM+24,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'K' OR 'L' OR 'M' OR 'N' OR 'O' THEN HADD( CURTIM, 'HOUR', &NUM+48,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'P' OR 'Q' OR 'R' OR 'S' OR 'T' THEN HADD( CURTIM, 'HOUR', &NUM+72,10, 'HYYMDm') ELSE IF (EDIT( LNAME,'9‘ )) EQ 'U' OR 'V' OR 'W' OR 'X' OR 'Y' OR 'Z' THEN HADD( CURTIM, 'HOUR', &NUM+96,10, 'HYYMDm') ; END

39 FILTERS and FUNCTIONS Functions EXPDATE Function DEFINE FILE EMPDATA CALLBACK/HYYMDm = EXPDATE (LASTNAME); END TABLE FILE EMPDATA PRINT LASTNAME BY CALLBACK END DEFINE FILE EMPDATA CALLBACK/HYYMDm = EXPDATE (LASTNAME); END TABLE FILE EMPDATA PRINT LASTNAME BY CALLBACK END  Create BY field in DEFINE  Prompt for &NUM as runtime or include on EX line  Create BY field in DEFINE  Prompt for &NUM as runtime or include on EX line

40 FILTERS and FUNCTIONS Functions EXPDATE Function results PAGE 1 CALLBACK LASTNAME -------- 2008/04/21 22:59:25.423078 BELLA 2008/04/21 22:59:25.423090 CASSANOVA 2008/04/21 22:59:25.423135 ADAMS 2008/04/21 22:59:25.423147 ADDAMS 2008/04/21 22:59:25.423343 ANDERSON 2008/04/21 22:59:25.423507 CVEK 2008/04/21 22:59:25.423828 DUBOIS 2008/04/21 22:59:25.423964 CONRAD 2008/04/21 22:59:25.424031 CASTALANETTA 2008/04/21 22:59:25.424262 DONATELLO PAGE 1 CALLBACK LASTNAME -------- 2008/04/21 22:59:25.423078 BELLA 2008/04/21 22:59:25.423090 CASSANOVA 2008/04/21 22:59:25.423135 ADAMS 2008/04/21 22:59:25.423147 ADDAMS 2008/04/21 22:59:25.423343 ANDERSON 2008/04/21 22:59:25.423507 CVEK 2008/04/21 22:59:25.423828 DUBOIS 2008/04/21 22:59:25.423964 CONRAD 2008/04/21 22:59:25.424031 CASTALANETTA 2008/04/21 22:59:25.424262 DONATELLO

41 FILTERS and FUNCTIONS Functions Other Candidates for Selection  Any field that could be used as a dimension  Location fields  UserID – additional DBA  Brand or Product fields  Product characteristic - color  Cost range or budget amount

42 FILTERS and FUNCTIONS Functions ROLL4AVG Function – Rolling Average DEFINE FUNCTION ROLL4AVG (COND/A10, VAL/D12.2) CURR/D12.2 = VAL; L1CURR/D12.2 = IF COND EQ LAST COND THEN LAST CURR ELSE 0; L2CURR/D12.2 = IF COND EQ LAST COND THEN LAST L1CURR ELSE 0; L3CURR/D12.2 = IF COND EQ LAST COND THEN LAST L2CURR ELSE 0; L4/D12.2 = CURR + L1CURR + L2CURR + L3CURR; DEFINE FUNCTION ROLL4AVG (COND/A10, VAL/D12.2) CURR/D12.2 = VAL; L1CURR/D12.2 = IF COND EQ LAST COND THEN LAST CURR ELSE 0; L2CURR/D12.2 = IF COND EQ LAST COND THEN LAST L1CURR ELSE 0; L3CURR/D12.2 = IF COND EQ LAST COND THEN LAST L2CURR ELSE 0; L4/D12.2 = CURR + L1CURR + L2CURR + L3CURR;  Produces rolling average of last 4 values excluding zeroes  Single condition field used but could easily use multiple  LAST is supported here  Produces rolling average of last 4 values excluding zeroes  Single condition field used but could easily use multiple  LAST is supported here DEFINE FUNCTION ROLL4AVG (COND/A10, VAL/D12.2) CURR/D12.2 = VAL; L1CURR/D12.2 = IF COND EQ LAST COND THEN LAST CURR ELSE 0; L2CURR/D12.2 = IF COND EQ LAST COND THEN LAST L1CURR ELSE 0; L3CURR/D12.2 = IF COND EQ LAST COND THEN LAST L2CURR ELSE 0; L4/D12.2 = CURR + L1CURR + L2CURR + L3CURR; L4NUM/I1 = IF L1CURR EQ 0 THEN 1 ELSE IF L2CURR EQ 0 THEN 2 ELSE IF L3CURR EQ 0 THEN 3 ELSE 4; ROLL4AVG/D12.2 = L4 / L4NUM; END DEFINE FUNCTION ROLL4AVG (COND/A10, VAL/D12.2) CURR/D12.2 = VAL; L1CURR/D12.2 = IF COND EQ LAST COND THEN LAST CURR ELSE 0; L2CURR/D12.2 = IF COND EQ LAST COND THEN LAST L1CURR ELSE 0; L3CURR/D12.2 = IF COND EQ LAST COND THEN LAST L2CURR ELSE 0; L4/D12.2 = CURR + L1CURR + L2CURR + L3CURR; L4NUM/I1 = IF L1CURR EQ 0 THEN 1 ELSE IF L2CURR EQ 0 THEN 2 ELSE IF L3CURR EQ 0 THEN 3 ELSE 4; ROLL4AVG/D12.2 = L4 / L4NUM; END

43 FILTERS and FUNCTIONS Functions ROLL4AVG Function – Rolling Average TABLE FILE HEMPLOYEE PRINT GROSS AND COMPUTE ROLLAVG/D12.2=ROLL4AVG(EMP_ID,GROSS); BY EMP_ID BY PAY_DATE WHERE EMP_ID EQ ‘818692173’ END TABLE FILE HEMPLOYEE PRINT GROSS AND COMPUTE ROLLAVG/D12.2=ROLL4AVG(EMP_ID,GROSS); BY EMP_ID BY PAY_DATE WHERE EMP_ID EQ ‘818692173’ END PAGE 1 EMP_ID PAY_DATE GROSS ROLLAVG ------ -------- ----- ------- 818692173 81/11/30 $2,147.75 2,147.75 81/12/31 $2,147.75 2,147.75 82/01/29 $2,147.75 2,147.75 82/02/26 $2,147.75 2,147.75 82/03/31 $2,147.75 2,147.75 82/04/30 $2,255.00 2,174.56 82/05/28 $2,255.00 2,201.38 82/06/30 $2,255.00 2,228.19 82/07/30 $2,255.00 2,255.00 82/08/31 $2,255.00 2,255.00 END OF REPORT PAGE 1 EMP_ID PAY_DATE GROSS ROLLAVG ------ -------- ----- ------- 818692173 81/11/30 $2,147.75 2,147.75 81/12/31 $2,147.75 2,147.75 82/01/29 $2,147.75 2,147.75 82/02/26 $2,147.75 2,147.75 82/03/31 $2,147.75 2,147.75 82/04/30 $2,255.00 2,174.56 82/05/28 $2,255.00 2,201.38 82/06/30 $2,255.00 2,228.19 82/07/30 $2,255.00 2,255.00 82/08/31 $2,255.00 2,255.00 END OF REPORT

44 FILTERS and FUNCTIONS Functions Other Candidates for Creativity  Your in-house “business logic”  Trigonometric functions  Different Rounding  Financial analysis  Accounting functions  Mathematical functions

45 FILTERS and FUNCTIONS Functions


Download ppt "FILTERS and FUNCTIONS: Hidden Gems Walter F. Blood Technical Director, FOCUS Division June, 2008."

Similar presentations


Ads by Google