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

Facebook Twitter LinkedIn YouTube
Go
New
Search
Notify
Tools
Reply
  
Fixing an IF statement
 Login/Join
 
Gold member
posted
I'm trying to build a quick and simple function that takes a "session code" which is a semester in a year and convert it into a fiscal year value:

IF( SUBSTR(6, SSR_SES_CODE,5, 6, 2,'I2') in (04,05,08,09) )

THEN SUBSTR(6, SSR_SES_CODE,1, 4, 4,'I4')

ELSE SUBSTR(6, SSR_SES_CODE,1,4, 4,'I4') -1

gives me the error:

(FOC36355) INVALID TYPE OF ARGUMENT #6 FOR USER FUNCTION SUBSTR
IF( SUBSTR(6, SSR_SES_CODE,5, 6, 2,'I2') in (04,05,08,09) )

Any help would be great, my SQL is lousy and quite rusty.

Edited to add:

So I got the bright idea to check the data type of my SSR_SES_CODE. It's stored as A6V, which causes one problem. The other problem is that the function SUBSTR only wants to output Alphanumeric values, not integers. Any suggestions would be great!

This message has been edited. Last edited by: Max Nevill,


WebFocus 8.104
Windows 7 Entreprise, SP1
 
Posts: 82 | Location: Abbotsford BC | Registered: March 15, 2010Reply With QuoteReport This Post
Expert
posted Hide Post
SUBSTR works on strings.

Change 'I2' to 'A2' and put quotes around the values in your list.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6054 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Gold member
posted Hide Post
I've tried that before and it won't let me do a subtraction on an alpha numeric...

So how do I do the -1 at the end? The problem is that I'm working with university data, and the "spring" semester is technically part of the last year.


WebFocus 8.104
Windows 7 Entreprise, SP1
 
Posts: 82 | Location: Abbotsford BC | Registered: March 15, 2010Reply With QuoteReport This Post
Expert
posted Hide Post
I assume that the field you are populating is a numeric, if so, then you could wrap an EDIT() arround the SUBSTR functions.

EDIT(SUBSTR(6, SSR_SES_CODE,1, 4, 4,'A4')) - 1

It may be easier to prep some fields prior to the IF THEN ELSE.

What does the actual code look like ?, Is this in a DEFINE or COMPUTE ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6054 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You could use the EDIT function instead of SUBSTR. EDIT can be used to extract portions of a string, or to convert alpha-numeric strings to integer and vice-versa.

SES_YEAR/A4    = EDIT(SSR_SES_CODE,'9999$$');
YEAR_ADJUST/I1 = IF EDIT(SSR_SES_CODE,'$$$$99') IN (04,05,08,09) THEN 0 ELSE (-1);
FISCAL_YEAR/I4 = EDIT(SES_YEAR) - YEAR_ADJUST ;


EDIT: Obviously made an error in YEAR_ADJUST calculation ... should be:

YEAR_ADJUST/I1 = IF EDIT(SSR_SES_CODE,'$$$$99') IN (04,05,08,09) THEN 0 ELSE 1 ;

This message has been edited. Last edited by: Dan Satchell,


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Reply With QuoteReport This Post
Gold member
posted Hide Post
Thanks for the suggestions guys, unfortunately my implementation of them didn't seem to work.

IF( SUBSTR(6, SSR_SES_CODE,5, 6, 2,'A2') in (04,05,08,09) )

THEN SUBSTR(6, SSR_SES_CODE,1, 4, 4,'A4')

ELSE EDIT(SUBSTR(6, SSR_SES_CODE,1,4, 4,'A4')) -1

and

IF( SUBSTR(6, SSR_SES_CODE,5, 6, 2,'A2') in ('04','05','08','09') )

THEN SUBSTR(6, SSR_SES_CODE,1, 4, 4,'A4')

ELSE EDIT(SUBSTR(6, SSR_SES_CODE,1,4, 4,'A4')) -1

Both give the error: (FOC266) IF .. THEN .. ELSE .. SYNTAX ERROR

Waz, yes, I am trying to output as an integer 'I4' field type.

Dan, your code looks great, I just have no idea how to put it into the source transforms calculator without it going crazy.

(FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: S_YEAR
S_YEAR/A4 = EDIT(SSR_SES_CODE,'9999$$');

Is the most popular error message.

Any further help would be fantastic, thanks!


WebFocus 8.104
Windows 7 Entreprise, SP1
 
Posts: 82 | Location: Abbotsford BC | Registered: March 15, 2010Reply With QuoteReport This Post
Virtuoso
posted Hide Post
You could try this. The result is a numeric year.

IF EDIT(SSR_SES_CODE,'$$$$99') IN (04,05,08,09)
 THEN (EDIT(EDIT(SSR_SES_CODE,'9999$$')) - 1 ) 
 ELSE EDIT(EDIT(SSR_SES_CODE,'9999$$')); 


If you need an alpha-numeric result, then:

IF EDIT(SSR_SES_CODE,'$$$$99') IN (04,05,08,09)
 THEN EDIT(EDIT(EDIT(SSR_SES_CODE,'9999$$')) - 1 ) 
 ELSE EDIT(SSR_SES_CODE,'9999$$'); 


WebFOCUS 7.7.05
 
Posts: 1213 | Location: Seattle, Washington - USA | Registered: October 22, 2007Reply With QuoteReport This Post
Expert
posted Hide Post
My suggestion is to break this up a little bit. Make it a bit less confusing.

SEMESTER/A2 = EDIT(SSR_SES_CODE,'$$$$99') ;
YEAR    /A4 = EDIT(SSR_SES_CODE,'9999') ;

NEW_YEAR/I4 = IF SEMESTER IN ('04','05','08','09')
              THEN EDIT(YEAR)
              ELSE EDIT(YEAR) - 1 ;


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.05OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Know The Code

 
Posts: 6054 | Location: Land of the Darug people, Terra Australis Incognita | Registered: October 31, 2006Reply With QuoteReport This Post
  Powered by Social Strata  
 


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