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
Thanks, JeffThis 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: