Focal Point
[Solved] Error using DECODE in IF statement

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

July 23, 2012, 11:10 AM
Jeff_f
[Solved] Error using DECODE in IF statement
I'm getting a FOC272 FORMAT ERROR IN DECODE OR FILE ELEMENT error when using a DECODE within an IF statement. The IF statement functions correctly if I replace the DECODE with a value.

 
DEFINE FILE CAR
CURNT_DT/YYMD = &YYMD;
CURNT_YR/YY=CURNT_DT;
CURNT_MT/M =CURNT_DT;
MTH_ID/A4 = 
IF (CURNT_YR LE '2006') THEN 
DECODE CURNT_MT(4 '0604' 10 '0610' ELSE '????') ELSE 
DECODE CURNT_MT(3 '0703' 11 '0711' ELSE '????');
END
TABLE FILE CAR
PRINT
CAR
CURNT_DT
CURNT_YR
CURNT_MT
MTH_ID
END



Using the DECODE alone works fine.
MTH_ID/A4 = 
DECODE CURNT_MT(3 '0703' 11 '0711' ELSE '????');


Does anyone have any ideas as to why?

Thanks,
Jeff

This message has been edited. Last edited by: Jeff_f,
July 23, 2012, 12:09 PM
Doug
Sorry, I don't get it. What exactly are you trying to accomplish here?




   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206
July 23, 2012, 12:51 PM
Jeff_f
I was trying to use Mickey's code to determine if it is currently EST or EDT.
July 23, 2012, 02:18 PM
Danny-SRL
If my memory does not fail me, I think that DECODE cannot be used in an IF-THEN-ELSE statement. So break it up:
  
DEFINE FILE CAR
CURNT_DT/YYMD = &YYMD;
CURNT_YR/YY=CURNT_DT;
CURNT_MT/M =CURNT_DT;
MTH_ID1/A4=DECODE CURNT_MT(4 '0604' 10 '0610' ELSE '????');
MTH_ID2/A4=DECODE CURNT_MT(3 '0703' 11 '0711' ELSE '????');
MTH_ID/A4 = IF (CURNT_YR LE '2006') THEN MTH_ID1 ELSE MTH_ID2 ;
END
-RUN
TABLE FILE CAR
PRINT
CAR
CURNT_DT
CURNT_YR
CURNT_MT
MTH_ID
END



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

July 23, 2012, 02:35 PM
Jeff_f
That will work. Thanks Danny.
July 24, 2012, 10:31 AM
j.gross
Jeff --

What release are you on? The code you posted works in 7.6.9.


I suspect the restriction (in your release) relates to using a date variable as argument of DECODE (within an IF clause).

If you take the error message, "FORMAT ERROR IN DECODE OR FILE ELEMENT", literally, it is a complaint about a format mismatch within the DECODE (comparing "4" to the format of CURNT_MT/M) -- rather than a complaint about the presence of a DECODE within the IF clause, or mismatch between its resultant value and the LHS, MTH_ID/A4. The primary form for a literal value to be assigned to a date variable is a character literal (to be converted to the corresponding integer date-offset value), not the offset integer value.


What happens if you substitute a proper numeric variable:
. . .
CURNT_MT/M =CURNT_DT;  iMth/I2=CURNT_MT;
MTH_ID/A4 = IF (CURNT_YR LE '2006') 
 THEN DECODE iMth(4 '0604' 10 '0610' ELSE '????')
 ELSE DECODE iMth(3 '0703' 11 '0711' ELSE '????');
. . .
?

This message has been edited. Last edited by: j.gross,
July 25, 2012, 07:38 AM
Jeff_f
We are on 7.7.03.

Using the integer variable worked. thanks