Focal Point Banner
Community Center Education Summit Technical Support User Groups
Let's Get Social!

Facebook Twitter LinkedIn YouTube
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] DECODE: Using a field value for default
Go
New
Search
Notify
Tools
Reply
  
[CLOSED] DECODE: Using a field value for default
 Login/Join
 
Gold member
posted
I am hoping this is a stupid question, but I am having trouble finding documentation for it. Maybe someone can easily answer for me:

Here is the scenario: I am using DECODE to reassign some field values. Pretty straight forward.

So,

DECODE FIELD1('The Fieldname Value A' 'A'
'The Field Value B' 'B' ...


That sort of thing. But instead of assigning a default literal value, like: ELSE 'Other', I want to use the incoming field value if that value has not been included in the DECODE.

So, instead of:

DECODE FIELD1('The Fieldname Value A' 'A'
                    'The Field Value B' 'B'
                    ELSE 'Other');



I want something like:

DECODE FIELD1('The Fieldname Value A' 'A'
                    'The Field Value B' 'B'
                    ELSE FIELD1);




Where the table value of FIELD1 is displayed, if a decoded value has not been supplied for that field value.

I am sure that I had some method of doing this at some point (and that it was simple), but I'm banging my head on the desk a bit trying to figure it out now. I am sure that I could do it with a couple of DEFINE fields, but I am trying to avoid getting into a large, convoluted IF THEN ELSE statement.

Any tips would be appreciated.

This message has been edited. Last edited by: Kerry,
 
Posts: 52 | Location: Merrimack, NH | Registered: August 17, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You could try something like this.

DEFINE FILE CAR
NEWCAR/A20 =   DECODE CAR ('JAGUAR' 'JAG' 'JENSEN' 'JEN' );
NEWCAR2/A20 = IF NEWCAR NE ' ' THEN NEWCAR ELSE CAR;
END
TABLE FILE CAR
PRINT CAR NEWCAR NEWCAR2
END
  


In Focus since 1993. WebFOCUS 7.7.03 Win 2003
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
@Prairie

Maybe it works as is, but I always make the default of a DECODE assignment explicit:

... = DECODE CAR ('JAGUAR' 'JAG', 'JENSEN' 'JEN', ELSE ' ');
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Reply With QuoteReport This Post
Virtuoso
posted Hide Post
Jack,

Do you always put commas in your DECODE?
I tested it and IT WORKS although never mentioned in the documentation!
Another WF wonder?


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

 
Posts: 1934 | Location: Tel Aviv, Israel | Registered: March 23, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
The bottom of the function definition in the documentation says:
quote:
You can use up to 40 lines to define the code and result pairs for any given DECODE function, or 39 lines if you also use an ELSE phrase. Use either a comma or blank to separate the code from the result, or one pair from another.


So in practice you can put those comma's wherever you like and it should work.

So apparently you could also write it as:
... = DECODE CAR ('JAGUAR','JAG' 'JENSEN','JEN' ELSE '');
... = DECODE CAR ('JAGUAR','JAG','JENSEN','JEN',ELSE '');


I am a bit surprised that a comma before the ELSE statement is accepted though!


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
 
Posts: 1644 | Location: Enschede, Netherlands | Registered: August 12, 2010Reply With QuoteReport This Post
<JG>
posted
is mentioned

quote:
You can use up to 40 lines to define the code and result pairs for any given DECODE function,
or 39 lines if you also use an ELSE phrase. Use either a comma or blank to separate the
code from the result, or one pair from another.


Wep5622 just beat me
 
Reply With QuoteReport This Post
Virtuoso
posted Hide Post
j.gross - yes the ELSE ' ' should be added.

Interesting about the comma...
 
Posts: 1903 | Location: San Antonio | Registered: February 28, 2005Reply With QuoteReport This Post
  Powered by Social Strata  
 

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [CLOSED] DECODE: Using a field value for default

Copyright © 1996-2018 Information Builders, leaders in enterprise business intelligence.