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.



Read-Only Read-Only Topic
Go
Search
Notify
Tools
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, 2010Report 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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report 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, 2010Report 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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report 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, 2007Report 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, 2010Report 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, 2007Report 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.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic


Copyright © 1996-2020 Information Builders