Focal Point
Fixing an IF statement

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

March 23, 2010, 04:15 PM
Max Nevill
Fixing an IF statement
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
March 23, 2010, 06:48 PM
Waz
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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 23, 2010, 07:28 PM
Max Nevill
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
March 23, 2010, 07:38 PM
Waz
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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

March 23, 2010, 10:14 PM
Dan Satchell
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
March 24, 2010, 03:55 PM
Max Nevill
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
March 24, 2010, 04:42 PM
Dan Satchell
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
March 24, 2010, 05:22 PM
Waz
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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!