Focal Point
Help with IF within a THEN phrase

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

April 30, 2008, 01:51 PM
Dan Pinault
Help with IF within a THEN phrase
Hi,

I am trying to use the code below in a DEFINE and I am getting this error,
"(FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: BEGIN
(FOC844) UNCORRECTABLE SYNTAX ERROR: IF"

I'm trying to use the same syntax shown in the "Nesting IF Commands" section of the WebFOCUS Language Reference. Can anybody tell me how to structure this so it will work in a DEFINE?

THANKS!

YR_PRIOR_96/D12=
IF (ENG_SOP LT 1960) THEN BEGIN
	IF ((&POP_YR - ENG_LIF_YRS) GT 1960) THEN BEGIN
		IF ((1996 - (&POP_YR - ENG_LIF_YRS)) LT 1) THEN 1 ;
		IF ((1996 - (&POP_YR - ENG_LIF_YRS)) GE 1) THEN (1996 - (&POP_YR - ENG_LIF_YRS));
	ENDBEGIN
	ELSE IF ((&POP_YR - ENG_LIF_YRS) LE 1960) THEN (1996 - 1960)
ENDBEGIN
IF (ENG_SOP GE 1960) THEN BEGIN
	IF ((&POP_YR - ENG_LIF_YRS) GT ENG_SOP) THEN BEGIN
		IF ((1996 - (&POP_YR - ENG_LIF_YRS)) LT 1) THEN 1;
		IF ((1996 - (&POP_YR - ENG_LIF_YRS)) GE 1) THEN (1996 - (&POP_YR - ENG_LIF_YRS));
	ENDBEGIN
	ELSE IF ((&POP_YR - ENG_LIF_YRS) LE ENG_SOP) THEN BEGIN
		IF ((1996 - ENG_SOP) LT 1.0) THEN 1;
		IF ((1996 - ENG_SOP) GE 1.0) THEN (1996 - ENG_SOP);
	ENDBEGIN
ENDBEGIN
ELSE 1;



7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
April 30, 2008, 02:03 PM
Francis Mariani
I took a look at what looks like the latest "Creating Reports With WebFOCUS Language Version 7 Release 6" document (wf761crlang.pdf) and did not find
quote:
Nesting IF Commands
.

I think the documentation you're referring to is for Maintain.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
April 30, 2008, 02:11 PM
Dan Pinault
Well now... that would sure explain the "(FOC258) FIELDNAME OR COMPUTATIONAL ELEMENT NOT RECOGNIZED: BEGIN error now wouldn't it?

Bummer!

So, what do you think? Should I break each component down into a variable of its own and then do a simple IF THEN statement?

Thanks!

Dan


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
April 30, 2008, 02:18 PM
FrankDutch
The code BEGIN and ENDBEGIN are IMHO typical Visualbasic codes.
Change it to ( and ) also the ";" are not correct codes, change them to "ELSE" I think that would work.




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

April 30, 2008, 02:25 PM
Leah
quote:
BEGIN
IF ((1996 - (&POP_YR - ENG_LIF_YRS)) LT 1) THEN 1 ;
IF ((1996 - (&POP_YR - ENG_LIF_YRS)) GE 1) THEN (1996 - (&POP_YR - ENG_LIF_YRS));
ENDBEGIN


I don't think

BEGIN
ENDBEGIN

is a supported part of IF THEN structure.


Leah
April 30, 2008, 03:44 PM
Dan Pinault
FrankDutch,

Thanks for the replacement suggestions. That did the trick! I ended up with...

YR_PRIOR_96/D12=
IF (ENG_SOP LT 1960) THEN (
IF ((&POP_YR - ENG_LIF_YRS) GT 1960) THEN (
IF ((1996 - (&POP_YR - ENG_LIF_YRS)) LT 1) THEN 1
ELSE IF ((1996 - (&POP_YR - ENG_LIF_YRS)) GE 1) THEN (1996 - (&POP_YR - ENG_LIF_YRS))
)
ELSE IF ((&POP_YR - ENG_LIF_YRS) LE 1960) THEN (1996 - 1960)
)
ELSE IF (ENG_SOP GE 1960) THEN (
IF ((&POP_YR - ENG_LIF_YRS) GT ENG_SOP) THEN (
IF ((1996 - (&POP_YR - ENG_LIF_YRS)) LT 1) THEN 1
ELSE IF ((1996 - (&POP_YR - ENG_LIF_YRS)) GE 1) THEN (1996 - (&POP_YR - ENG_LIF_YRS))
)
ELSE IF ((&POP_YR - ENG_LIF_YRS) LE ENG_SOP) THEN (
IF ((1996 - ENG_SOP) LT 1.0) THEN 1
ELSE IF ((1996 - ENG_SOP) GE 1.0) THEN (1996 - ENG_SOP)
)
)
ELSE 1;


Regards,

Dan


7.7.05M/7.7.03 HF6 on Windows Server 2003 SP2 output to whatever is required.
April 30, 2008, 04:08 PM
Dave Ayers
quote:
The code BEGIN and ENDBEGIN are IMHO typical Visualbasic codes.


They are also legal, and useful Maintain commands !

I always remember IF-THEN-ELSE, IF-THEN-ELSE, IF-THEN-ELSE... to check my syntax in Defines. It's helped me write and fix complex Defines many times.


Regards,
Dave

http://www.daveayers.com

WebFocus/Maintain 7.6.4-8
on Win2000 and 2003 Server