Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Using DECODE vs. IF THEN ELSE

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Using DECODE vs. IF THEN ELSE
 Login/Join
 
Silver Member
posted
We have a user in HR that is trying to write their own report (using the same setup listed in my signature) regarding employees and education levels.

The problem they are having is that if a person has two levels of education on record (High School, Bachelors, Masters, or Doctorate) there are two records returned for that user in the report showing identical information for all fields except Education Level.

The desired result is to have only one record per person returned, and to have that record reflect their highest level of education.


I don't have access to the actual tables used in their report due to their sensitive nature, so I tried working the scenario with manufacturing data. My first inclination was to use a DECODE function to assign a value to each education level, and then subject those values to a MAX function to only return the maximum value for each record.

Unfortunately, this approach applies the MAX function to the entire report, not on a by-record basis, and thus only returns those records that reflect the maximum DECODE value...or in the case of Education level, would only return those employees with their Doctorate degree.


Are the DECODE and MAX functions the best way to go about this? If so, how do I apply them to this report on a record-by-record basis? If they are not the best approach, what is...an IF THEN ELSE statement?

For reference, here is the relevant part of the code I used to apply my DECODE and MAX functions:

 -* File Define_Test.fex
DEFINE FILE IFS_PART_CATALOG ADD
DESCRIPTION_NUMBERS/I5=DECODE IFS_PART_CATALOG.IFS_PART_CATALOG.DESCRIPTION( 'TRANSDUCER, PRESS' 1 'CIRCUIT BREAKER, SINGLE' 2 'CONNECTOR, RCPT' 3 );
END
TABLE FILE IFS_PART_CATALOG
PRINT
     'IFS_PART_CATALOG.IFS_PART_CATALOG.STD_NAME_ID'
     'IFS_PART_CATALOG.IFS_PART_CATALOG.DESCRIPTION_NUMBERS' NOPRINT
     'IFS_PART_CATALOG.IFS_PART_CATALOG.UNIT_CODE'
     'IFS_PART_CATALOG.IFS_PART_CATALOG.CELL_STOCK'
BY 'IFS_PART_CATALOG.IFS_PART_CATALOG.PART_NO'
BY 'IFS_PART_CATALOG.IFS_PART_CATALOG.DESCRIPTION'
HEADING
""
FOOTING
""
WHERE IFS_PART_CATALOG.IFS_PART_CATALOG.DESCRIPTION_NUMBERS EQ MAX(0, 3);
WHERE RECORDLIMIT EQ 50
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
ON TABLE PCHOLD FORMAT HTML
ON TABLE SET HTMLCSS ON
ON TABLE SET STYLE *
     UNITS=IN,
     SQUEEZE=ON,
     ORIENTATION=PORTRAIT,


My apologies for the long post, and I thank you in advance for any assistance you may provide.


Evan




WebFOCUS (DEV and PROD): DevStudio 7.6.10 HF2 Servlet - MRE/Dashboard/Self Service/Report Caster - MS Windows XP SP2 - IIS & Apache - MS SQL 2005
Output: HTML (Internet Explorer 7), Excel 2003, PDF, Active Reports and FLEX
 
Posts: 38 | Location: Detroit, MI | Registered: September 23, 2008Report This Post
Expert
posted Hide Post
The DECODE is fine, but I would use
BY HIGHEST 1 level_of_education
This returns all the levels of education from SQL Server, then WebFOCUS takes over to output the highest level.

This message has been edited. Last edited by: Francis Mariani,


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
Bear in mind that in case of ties (i.e., someone who has two Degree records with the same decode score), HIGHEST 1 will yield two rows.


- Jack Gross
WF through 8.1.05
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Expert
posted Hide Post
Oops, overlooked that scenario.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Virtuoso
posted Hide Post
And (to state the obvious) make sure that you use

BY employee_id
BY HIGHEST 1 level_of_education

to get the highest level for each employee. Otherwise you get the highest level of education available with all employees that have that level.

Also, as Jack states, you would still get two records for someone that has two BA's, two MA's or (eek!) two PhD's (assuming that a Master's of Accounting is the same decode value as an MBA and the like.)


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
 
Posts: 2298 | Location: Salt Lake City, Utah | Registered: February 02, 2007Report This Post
Silver Member
posted Hide Post
Thank you all for the prompt replies!

quote:
Originally posted by Francis Mariani:
The DECODE is fine, but I would use
BY HIGHEST 1 level_of_education
This returns all the levels of education from SQL Server, then WebFOCUS takes over to output the highest level.


My apologies, but I am very new to WebFOCUS, as I'm sure you're aware by this post and my ignorance of the BY HIGHEST 1 command. At risk of sounding like I want you to 'hold my hand', could I ask where in the fex file the 'BY HIGHEST 1' code should appear? Your post makes me think it belongs at the top of the file before the DECODE appears...is this correct?

Something like this for my manufacturing example, perhaps?

-* File Define_Test.fex
BY HIGHEST 1 DESCRIPTION_NUMBERS
DEFINE FILE IFS_PART_CATALOG ADD
DESCRIPTION_NUMBERS/I5=DECODE IFS_PART_CATALOG.IFS_PART_CATALOG.DESCRIPTION( 'TRANSDUCER, PRESS' 1 'CIRCUIT BREAKER, SINGLE' 2 'CONNECTOR, RCPT' 3 );
END
TABLE FILE IFS_PART_CATALOG
PRINT
.
.
.


sleepy

This message has been edited. Last edited by: sleepyEDB,




WebFOCUS (DEV and PROD): DevStudio 7.6.10 HF2 Servlet - MRE/Dashboard/Self Service/Report Caster - MS Windows XP SP2 - IIS & Apache - MS SQL 2005
Output: HTML (Internet Explorer 7), Excel 2003, PDF, Active Reports and FLEX
 
Posts: 38 | Location: Detroit, MI | Registered: September 23, 2008Report This Post
Expert
posted Hide Post
We're all sleepy on Friday afternoon. The BY HIGHEST is an alternate form of the BY command and belongs with the other BYs in your TABLE part. The normal sort order is low to high. BY HIGHEST sorts high to low.

You might want to check the syntax for BY in the language manual, wfcrlang.pdf.


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
 
Posts: 2723 | Location: Ann Arbor, MI | Registered: April 05, 2006Report This Post
Silver Member
posted Hide Post
Wow, I guess it's time for me to sign off for the week, eh? It's a BY statement so you think I'd have at least figured out that it goes with the other BY statements.

I have a copy of the wfcrlang, but didn't even think to check it before asking here for help...sorry! :-\

Thanks Ginny, I'll see what I can find and post back if I can't figure it out AFTER reading and experimenting.


sleepy




WebFOCUS (DEV and PROD): DevStudio 7.6.10 HF2 Servlet - MRE/Dashboard/Self Service/Report Caster - MS Windows XP SP2 - IIS & Apache - MS SQL 2005
Output: HTML (Internet Explorer 7), Excel 2003, PDF, Active Reports and FLEX
 
Posts: 38 | Location: Detroit, MI | Registered: September 23, 2008Report This Post
Master
posted Hide Post
I think you are on the right track with assigning a numeric value to the level of education. It shouldn't matter if you use decode or if, then, else. The problem is coming up with one record per employee. Try running through your data two times. In the first pass define the level of education as a numeric value and sort:
BY EMPLOYEE
BY HIGHEST EDUCATION
etc.

In your second pass use:
WHERE EMPLOYEE NE LAST EMPLOYEE


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes
 
Posts: 755 | Location: TX | Registered: September 25, 2007Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Using DECODE vs. IF THEN ELSE

Copyright © 1996-2020 Information Builders