Focal Point
Decode Function in Webfocus...

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2411023952

November 29, 2007, 04:18 AM
focuzsambit
Decode Function in Webfocus...
Anybody having any clue on how to decode some values and not others.

Suppose in master file CAR, i only want to decode 'JAGUAR' VALUES TO 'HONDA' AND want to keep other values as same as in master file, wats the syntax ??

Below syntax not working.
Plz note : CAR is Hold file name as well as field name.

DEFINE FILE CAR
INDIACAR/A20=DECODE CAR( 'JAGUAR' 'HONDA' ELSE CAR );
END


WF Server: 7.1.4 on Z/OS and Linux, ReportCaster
Data: DB2, DB2/UDB, Adabas, SQL Server, Oracle Output: HTML,PDF,Excel2K
WF Client: Servlet, CGI
November 29, 2007, 04:24 AM
FrankDutch
The syntax looks ok, it works with me.

What is your error message?




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

November 29, 2007, 04:26 AM
GamP
How about:
DEFINE FILE CAR
INDIACAR/A20 = IF CAR EQ 'JAGUAR' THEN 'HONDA' ELSE CAR;
END

Hope this helps.


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
November 29, 2007, 04:29 AM
focuzsambit
oh..kewl..it works...
Thanks a bunch gamp


WF Server: 7.1.4 on Z/OS and Linux, ReportCaster
Data: DB2, DB2/UDB, Adabas, SQL Server, Oracle Output: HTML,PDF,Excel2K
WF Client: Servlet, CGI
November 29, 2007, 04:58 AM
FrankDutch
But your solution should work too.
The solution from G is in this case OK, but what if you decide to use this with 4 or 5 or 10 different fields??




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

November 29, 2007, 06:12 AM
GamP
Let's just say: We'll cross that bridge when we get to it....


GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
November 29, 2007, 06:45 AM
Tony A
That'll be the Arnhem Bridge then - lol

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
November 29, 2007, 08:27 AM
FrankDutch
Well, that should be a bridge to far...




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

November 29, 2007, 10:01 AM
TexasStingray
Lets not forget what the decode function is really for. To take some kind of code/value and translate it into an easy to understand meaningful description. If you only want to decode certain code then you have to use some kind of if then else logic.




Scott

So it's not allowed to use it as I (we) do?

..... Music




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

In WebFOCUS with DECODE the ELSE value can not be a field name, it must be a literal. That can be confusing since, for instance, Oracle has a Decode function where the ELSE value can be a field name. Essentially you have to do it like GamP did it.


(Prod: WebFOCUS 7.7.03: Win 2008 & AIX hub/Servlet Mode; sub: AS/400 JDE; mostly Self Serve; DBs: Oracle, JDE, SQLServer; various output formats)
N.

my solution is working with the ELSE fieldname...




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

quote:
DEFINE FILE CAR
INDIACAR/A20=DECODE CAR( 'JAGUAR' 'HONDA' ELSE CAR );
END

The DECODE function is putting the character string 'CAR' into the field INDIACAR.
so the way to use decode would be something like:
INDIACAR/A20=DECODE CAR('JAGUAR' 'ALL MINE' ELSE ' ');
or
INDIACAR/A20=DECODE CAR (filename ELSE ' ');
then
INDIACAR/A20=IF INDIACAR IS ' ' THEN CAR ELSE INDIACAR;
in this case the word CAR references a field, not a character string.
remembering that with DEFINEs, the last referenced define is the value pulled in a TABLE request, which is one of those blessedly *gifted* features of wf we take for granted and can't live without. Wink




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
In sql the Decode function is used often to flip the axis of data. (denormalize data)
I'm sure there's a better term, but I don't know what it is.

Such as, if you have data of
Product Line
Sales $

To get the Sum of Sales for a Product Line you would have to do a
Select ProductLine, Sum(sales) from table group by ProductLine

but, what if you wanted to group those productlines together? As in you wanted to combine something like Soap and Shampoo

Select
sum(Case when productline in ('Soap','Shampoo') then Sales else 0 end) as "ShowerSupplies',
Sum(case when productline NOT in
('Soap','Shampoo') then Sales else 0 end) as "Everything_But_ShowerSupplies'
from sometable

Comes in handy more than one might think. Thought I'd bring it up.


Prod: Single Windows 2008 Server running Webfocus 7.7.03 Reporting server Web server IIS6/Tomcat, AS400 DB2 database.