FILTERS and FUNCTIONS: Hidden Gems
Walter F. Blood
Technical Director, FOCUS Division
June, 2008
FILTERS and FUNCTIONS FILTERs
TWO Types of FiltersVisible
Stored in Master FileActivated by reference in a request
InvisibleIndependent command Executable in PROFILEs, or FOCEXECsActive for the entire sessionAdded to every request using the Master
FILTERS and FUNCTIONSVisible 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 FILETABLE/TABLEF FILEMATCH FILEMORE SQL
FILTERS and FUNCTIONSVisible FILTER
Visible FILTER syntax
FILTER <filtername> = expression;$
Positioned anywhere in Master.Use any expression legal for WHEREUsable with Business View or Join.Shortest unique truncation will access it.FILTER TOPSELLERS = SALES GT 20000;$
FILTERS and FUNCTIONSVisible FILTER
ExpressionsWHERE (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.
FILTERS and FUNCTIONSVisible FILTER
Referencing Visible FILTERs
WHERE <filtername>
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.
FILTERS and FUNCTIONSVisible FILTER
Filter NamingThink of your endusers and how they see the data!Combine complex selection criteria into one filter!Give the filter a meaningful name!
FILTER1 – probably uselessFROMLASTWEEK - better
FILTERS and FUNCTIONSVisible 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);$
FILTERS and FUNCTIONSInvisible 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 JOINsStatus of FILTER can be queried -? FILTER.
Supports Defines available only to FILTERs.Allows both WHERE and IF syntax.
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTERS and FUNCTIONSInvisible FILTERs
FILTER FILE command
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTERS and FUNCTIONSInvisible FILTERs
FILTER FILE command
Deletes existing FILTER phrases and defines for this
file.
Deletes existing FILTER phrases and defines for this
file.
Adds new filter phrases to 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
Describes the filter and can be issued in profile,
focexec, or command line
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTERS and FUNCTIONSInvisible FILTERs
FILTER FILE command
Virtual fields used in Filters.Virtual fields used in Filters.
Only referenceable in Filters!Only referenceable in Filters!
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTER FILE <filename> [ CLEAR | ADD ][filter-defines;]NAME=filtername1 [ ,DESC=text] where-if phrases . .NAME=filternamen [ ,DESC=text] where-if phrases
END
FILTERS and FUNCTIONSInvisible FILTERs
FILTER FILE command
Any valid WHERE or IF screening conditions. Must reference filter defines, or
real or virtual fields in Master only.
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 allowedOnly one line of text allowed
FILTERS and FUNCTIONSInvisible FILTER
Filter Define LimitationsLocal to specific filter declarationCannot be used in DEFINE or TABLE Supports standard DEFINE functionalityUnlike DEFINE, do not count toward display field
limitMust all be declared before first named filterCannot reuse another virtual field from the same
file.
FILTERS and FUNCTIONSInvisible FILTER
Activating and Deactivating FILTERs
SET FILTER = * IN <filename> ON/OFFSET FILTER = * IN <filename> ON/OFF
ALL declared filters. Be careful using this setting.ALL declared filters. Be careful using this setting.
SET FILTER = name1 name2 …namen IN <filename ON/OFFSET FILTER = name1 name2 …namen IN <filename ON/OFF
Only named declared filters will be affected.Only named declared filters will be affected.
FILTERS and FUNCTIONSInvisible FILTER
Filter Declaration Example
FILTER FILE CAR ADDPROFIT/D7=(RCOST-DCOST);MARGINPCT/D7.2=(PROFIT/DCOST)*100 ;
NAME=HIMARGINWHERE MARGINPCT GT 20.0
NAME=MDMARGINWHERE MARGINPCT FROM 10.0 to 20.0
NAME=LOMARGINWHERE MARGINPCT LT 10.0END
FILTER FILE CAR ADDPROFIT/D7=(RCOST-DCOST);MARGINPCT/D7.2=(PROFIT/DCOST)*100 ;
NAME=HIMARGINWHERE MARGINPCT GT 20.0
NAME=MDMARGINWHERE MARGINPCT FROM 10.0 to 20.0
NAME=LOMARGINWHERE MARGINPCT LT 10.0END
FILTERS and FUNCTIONSInvisible 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 12000FRANCE PEUGEOT 504 4 DOOR 0ITALY ALFA ROMEO 2000 GT VELOCE 12400 2000 SPIDER VELOCE 13000 2000 4 DOOR BERLINA 4800 MASERATI DORA 2 DOOR 0W 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 12000FRANCE PEUGEOT 504 4 DOOR 0ITALY ALFA ROMEO 2000 GT VELOCE 12400 2000 SPIDER VELOCE 13000 2000 4 DOOR BERLINA 4800 MASERATI DORA 2 DOOR 0W GERMANY BMW 3.0 SI 4 DOOR 14000 3.0 SI 4 DOOR AUTO 18940
END OF REPORT
FILTERS and FUNCTIONSInvisible 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
FILTERS and FUNCTIONSInvisible FILTER
? FILTER [ {file | * } [ SET ] [ ALL ] ]? 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
Specify a single file or * for all files
Show status of each declared filter
Show status of each declared filter
Show description and WHERE/IF definition for each declared filter
Show description and WHERE/IF definition for each declared filter
> > ? FILTER CAR SET
> > ? FILTER CAR SETSET FILE FILTER NAME DESCRIPTION--- -------- ----------- --------------------------------- CAR HIMARGIN MARGIN GREATER THAN 10% CAR MDMARGIN MARGIN BETWEEN 10 AND 20% * CAR LOMARGIN MARGIN BELOW 10%>
> > ? FILTER CAR SETSET FILE FILTER NAME DESCRIPTION--- -------- ----------- --------------------------------- CAR HIMARGIN MARGIN GREATER THAN 10% CAR MDMARGIN MARGIN BETWEEN 10 AND 20% * CAR LOMARGIN MARGIN BELOW 10%>
FILTERS and FUNCTIONSInvisible FILTER
Checking FILTER status
Active Filters indicated with *Active Filters indicated with *
Use DESC to differentiate FILTERs since Filter Name only 8 characters
Use DESC to differentiate FILTERs since Filter Name only 8 characters
> > ? filter car all
> > ? filter car allFILTER FILE CAR ADDPROFIT/D7=(RCOST-DCOST);MARGINPCT/D7.2=(PROFIT/DCOST)*100 ;NAME=HIMARGIN, DESC=MARGIN GREATER THAN 10%WHERE MARGINPCT GT 20.0NAME=MDMARGIN, DESC=MARGIN BETWEEN 10 AND 20%WHERE MARGINPCT FROM 10.0 TO 20.0NAME=LOMARGIN, DESC=MARGIN BELOW 10%WHERE MARGINPCT LT 10.0END> >
> > ? filter car allFILTER FILE CAR ADDPROFIT/D7=(RCOST-DCOST);MARGINPCT/D7.2=(PROFIT/DCOST)*100 ;NAME=HIMARGIN, DESC=MARGIN GREATER THAN 10%WHERE MARGINPCT GT 20.0NAME=MDMARGIN, DESC=MARGIN BETWEEN 10 AND 20%WHERE MARGINPCT FROM 10.0 TO 20.0NAME=LOMARGIN, DESC=MARGIN BELOW 10%WHERE MARGINPCT LT 10.0END> >
FILTERS and FUNCTIONSInvisible FILTER
Checking FILTER status
Displays FILTER declarations.
Decrypts declarations for use and display. Be careful!
FILTERS and FUNCTIONSInvisible 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 1Context 1
Context 2Context 2
DEFINES and FILTERSFrom Context 1
cleared by JOIN
DEFINES and FILTERSadded in Context 2
cleared by JOIN CLEAR
FILTERS and FUNCTIONSInvisible 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=ONJOIN COUNTRY IN CAR TO ALL COUNTRY IN SALES AS J1
Context 1Context 1
Context 2Context 2
DEFINES and FILTERSfrom Context 1
retained!
DEFINES and FILTERSadded in Context 2
cleared by JOIN CLEAR
FILTERS and FUNCTIONSInvisible FILTER
FILTERS and FUNCTIONSFunctions
The Path to FUNCTIONSVirtual 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
FILTERS and FUNCTIONSFunctions
The Uses of FUNCTIONSStandardizing
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
FILTERS and FUNCTIONSFunctions
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 spacesToo 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 spacesToo long – truncated
FILTERS and FUNCTIONSFunctions
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 numberUse argments, constants and other temporary fields declared in the function.
Intermediate fields use in calculation of final result. Unlimited numberUse argments, constants and other temporary fields declared in the function.
FILTERS and FUNCTIONSFunctions
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.
FILTERS and FUNCTIONSFunctions
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.
FILTERS and FUNCTIONSFunctions
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 CARPRINT COUNTRY CAR MODEL SALESAND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST);WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20END
DEFINE FUNCTION MKMARGIN CLEAR
DEFINE FUNCTION MKMARGIN (RC/D7, DC/D7)NETPROFIT/D7=RC-DC;MKMARGIN/D5.2=(NETPROFIT*100)/DC;END
TABLE FILE CARPRINT COUNTRY CAR MODEL SALESAND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST);WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20END
FILTERS and FUNCTIONSFunctions
MKMARGIN Function results
PAGE 1
COUNTRY CAR MODEL SALES MARGIN------- --- ----- ----- ------ENGLAND JAGUAR XJ12L AUTO 12000 20.52ITALY ALFA ROMEO 2000 GT VELOCE 12400 20.49ITALY ALFA ROMEO 2000 SPIDER VELOCE 13000 20.49ITALY ALFA ROMEO 2000 4 DOOR BERLINA 4800 20.55ITALY MASERATI DORA 2 DOOR 0 26.00W GERMANY BMW 3.0 SI 4 DOOR 14000 37.52W GERMANY BMW 3.0 SI 4 DOOR AUTO 18940 28.39FRANCE PEUGEOT 504 4 DOOR 0 21.14
END OF REPORT
PAGE 1
COUNTRY CAR MODEL SALES MARGIN------- --- ----- ----- ------ENGLAND JAGUAR XJ12L AUTO 12000 20.52ITALY ALFA ROMEO 2000 GT VELOCE 12400 20.49ITALY ALFA ROMEO 2000 SPIDER VELOCE 13000 20.49ITALY ALFA ROMEO 2000 4 DOOR BERLINA 4800 20.55ITALY MASERATI DORA 2 DOOR 0 26.00W GERMANY BMW 3.0 SI 4 DOOR 14000 37.52W GERMANY BMW 3.0 SI 4 DOOR AUTO 18940 28.39FRANCE PEUGEOT 504 4 DOOR 0 21.14
END OF REPORT
FILTERS and FUNCTIONSFunctions
Displaying Active FUNCTIONS
> ? FUNCTION
> ? FUNCTION
> ? FUNCTIONFUNCTIONS CURRENTLY ACTIVE
Name Format Parameter Format-------- -------- ------------ --------MKMARGIN D5.2 RC D7 DC D7
SUBTRACT D8.2 VAL1 D7 VAL2 D7
> ? FUNCTIONFUNCTIONS CURRENTLY ACTIVE
Name Format Parameter Format-------- -------- ------------ --------MKMARGIN D5.2 RC D7 DC D7
SUBTRACT D8.2 VAL1 D7 VAL2 D7
FILTERS and FUNCTIONSFunctions
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 CARPRINT COUNTRY CAR MODEL SALESAND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST);WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20END
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 CARPRINT COUNTRY CAR MODEL SALESAND COMPUTE MARGIN/D5.2 = MKMARGIN(RETAIL_COST,DEALER_COST);WHERE MKMARGIN(RETAIL_COST, DEALER_COST) GT 20END
DEFINE FUNCTION * CLEAR
Clear one specific functionPrevent collision of multiple functionsAllow dynamic function creation and use
Clear one specific functionPrevent collision of multiple functionsAllow dynamic function creation and use
Clear all active functionsProvides quick and easy cleanup
Clear all active functionsProvides quick and easy cleanup
FILTERS and FUNCTIONSFunctions
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) || '.';ENDTABLE FILE EMPDATAPRINT PIN AS EMPIDAND 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) || '.';ENDTABLE FILE EMPDATAPRINT PIN AS EMPIDAND COMPUTE NAME/A65 = STDNAME( FIRSTNAME, MIDINITIAL, LASTNAME );END
FILTERS and FUNCTIONSFunctions
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.
FILTERS and FUNCTIONSFunctions
Other Candidates for Reformatting
Any standardized alpha format
ID Numbers or SSNs
Telephone Numbers
Product codes or SKUs
Address lines
Irregular line indentation
FILTERS and FUNCTIONSFunctions
EXPDATE Function – Time Value calculationDEFINE 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 timeCombines multiple Datetime calls into single function Parentheses to control spacing in final expression.
Generates date-time field &NUM hours from current timeCombines 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
FILTERS and FUNCTIONSFunctions
EXPDATE Function DEFINE FILE EMPDATACALLBACK/HYYMDm = EXPDATE (LASTNAME);END
TABLE FILE EMPDATAPRINT LASTNAMEBY CALLBACKEND
DEFINE FILE EMPDATACALLBACK/HYYMDm = EXPDATE (LASTNAME);END
TABLE FILE EMPDATAPRINT LASTNAMEBY CALLBACKEND
Create BY field in DEFINEPrompt for &NUM as runtime or include on EX line
Create BY field in DEFINEPrompt for &NUM as runtime or include on EX line
FILTERS and FUNCTIONSFunctions
EXPDATE Function results
PAGE 1
CALLBACK LASTNAME-------- --------2008/04/21 22:59:25.423078 BELLA2008/04/21 22:59:25.423090 CASSANOVA2008/04/21 22:59:25.423135 ADAMS2008/04/21 22:59:25.423147 ADDAMS2008/04/21 22:59:25.423343 ANDERSON2008/04/21 22:59:25.423507 CVEK2008/04/21 22:59:25.423828 DUBOIS2008/04/21 22:59:25.423964 CONRAD2008/04/21 22:59:25.424031 CASTALANETTA2008/04/21 22:59:25.424262 DONATELLO
PAGE 1
CALLBACK LASTNAME-------- --------2008/04/21 22:59:25.423078 BELLA2008/04/21 22:59:25.423090 CASSANOVA2008/04/21 22:59:25.423135 ADAMS2008/04/21 22:59:25.423147 ADDAMS2008/04/21 22:59:25.423343 ANDERSON2008/04/21 22:59:25.423507 CVEK2008/04/21 22:59:25.423828 DUBOIS2008/04/21 22:59:25.423964 CONRAD2008/04/21 22:59:25.424031 CASTALANETTA2008/04/21 22:59:25.424262 DONATELLO
FILTERS and FUNCTIONSFunctions
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
FILTERS and FUNCTIONSFunctions
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 zeroesSingle condition field used but could easily use multiple LAST is supported here
Produces rolling average of last 4 values excluding zeroesSingle 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
FILTERS and FUNCTIONSFunctions
ROLL4AVG Function – Rolling Average
TABLE FILE HEMPLOYEEPRINT GROSSAND COMPUTE ROLLAVG/D12.2=ROLL4AVG(EMP_ID,GROSS);BY EMP_IDBY PAY_DATEWHERE EMP_ID EQ ‘818692173’END
TABLE FILE HEMPLOYEEPRINT GROSSAND COMPUTE ROLLAVG/D12.2=ROLL4AVG(EMP_ID,GROSS);BY EMP_IDBY PAY_DATEWHERE EMP_ID EQ ‘818692173’END
PAGE 1EMP_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 1EMP_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
FILTERS and FUNCTIONSFunctions
Other Candidates for Creativity
Your in-house “business logic”
Trigonometric functions
Different Rounding
Financial analysis
Accounting functions
Mathematical functions
FILTERS and FUNCTIONSFunctions