I am trying to create a column of data that has the difference between numeric format field value on the current record to the one on the previous record with the code below.
The PRVDELTA define correcly returns the previous record's value. However, the PRVDELTA2 define does not return previous record's value that corresponds with PRVDELTA.
Am I using the LAST Function correctly?
TABLE FILE BASELINE2
SUM
CT_DAYS AS 'CT_DAYS'
BY SRT_MONTH AS 'SRT_MONTH'
ON TABLE HOLD AS 'BASELINE3'
END
DEFINE FILE BASELINE3
PRVDELTA/YYMD= IF SRT_MONTH EQ LAST SRT_MONTH THEN SRT_MONTH ELSE LAST SRT_MONTH;
PRVDELTA2/I8= IF SRT_MONTH EQ LAST SRT_MONTH THEN CT_DAYS ELSE LAST CT_DAYS;
END
TABLE FILE BASELINE3
PRINT
SRT_MONTH AS 'Month'
CT_DAYS AS 'Cycle Days'
PRVDELTA AS 'Previous Month'
PRVDELTA2 AS 'Previous Month Cycle Days'
BY SRT_MONTH NOPRINT
ON TABLE SET STYLE *
TYPE=DATA, COLUMN=N2, BACKCOLOR=BLUE, WHEN=CT_DAYS LT 14,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=LIME, WHEN=CT_DAYS LT 19,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=YELLOW, WHEN=CT_DAYS LT 24,$
TYPE=DATA, COLUMN=N2, BACKCOLOR=RED, WHEN=CT_DAYS GT 25,$
ENDSTYLE
ON TABLE SET HTMLCSS ON
ON TABLE SET PAGE-NUM OFF
ON TABLE NOTOTAL
END
-EXIT
This message has been edited. Last edited by: Kerry,
Production - 7.6.4 Sandbox - 7.6.4
January 07, 2010, 04:05 PM
GinnyJakes
DEFINE FILE BASELINE3
PRVDELTA/YYMD= IF SRT_MONTH EQ LAST SRT_MONTH THEN PRVDELTA ELSE LAST SRT_MONTH;
PRVDELTA2/I8= IF SRT_MONTH EQ LAST SRT_MONTH THEN PRVDELTA2 ELSE LAST CT_DAYS;
END
PRVDELTA/YYMD= IF SRT_MONTH NE LAST SRT_MONTH THEN LAST SRT_MONTH ELSE PRVDELTA;
PRVDELTA2/I8= IF SRT_MONTH NE LAST SRT_MONTH THEN LAST CT_DAYS ELSE PRVDELTA2;
Try this. I always do my NE logic first as it makes more sense to me to figure out what I want to do on the sort break.
The LAST function seems to pickup the previous cycle days, except sometime gives (previous-days - 1)???
Developer Studio 7.6.11 AS400 - V5R4 HTML,PDF,XLS
January 08, 2010, 04:47 AM
Alan B
I suspect that the data in BASELINE3 is not as you are expecting, reason unknown. Your use of LAST is fine if the data coming in is correct. Try
TABLE FILE BASELINE3
SUM
SRT_MONTH AS 'Month'
CT_DAYS AS 'Cycle Days'
COMPUTE
PRVDELTA/YYMD = IF SRT_MONTH EQ LAST SRT_MONTH THEN SRT_MONTH ELSE LAST SRT_MONTH;
AS 'Previous Month'
COMPUTE
PRVDELTA2/I8 = IF SRT_MONTH EQ LAST SRT_MONTH THEN CT_DAYS ELSE LAST CT_DAYS;
AS 'Previous Month Cycle Days'
BY SRT_MONTH NOPRINT
END
and see what happens.
Alan. WF 7.705/8.007
January 08, 2010, 09:41 AM
ColdWhiteMilk
This gives me the same results. Does that mean that it is something wrong with the code that creates the BASELINE3 hold file?
Production - 7.6.4 Sandbox - 7.6.4
January 08, 2010, 09:49 AM
GinnyJakes
Did you use the defines in my last post. I tested those with your data and got the right answers.
It appears to me that your data is correct. It must be sorted by SRT_MONTH and there is only one row per month. That is what I determine from your code.
PRVDELTA/YYMD= LAST SRT_MONTH ;
PRVDELTA2/I8= LAST CT_DAYS;
Hua
Developer Studio 7.6.11 AS400 - V5R4 HTML,PDF,XLS
January 08, 2010, 11:09 AM
ColdWhiteMilk
Ginny -
I greatly appreciate your help. I used your defines. It appears to be working correctly for the previous month column, but not the cycle days column.
For example, on the results I got above, the February record correctly shows that the previous month is January, but on the February row, the Previous Month (January) cycle days do not match the january record from above.
What would cause LAST to work for one field, but not the other? Field format? Sorting?
Production - 7.6.4 Sandbox - 7.6.4
January 08, 2010, 11:41 AM
Tony A
CWM,
To be sure that you are using the correct LAST operation that matches your sort requirement, use COMPUTE within the TABLE request as per Alan above.
T
In FOCUS since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2
WebFOCUS App Studio 8.2.06 standalone on Windows 10
The problem was not with the DEFINE itself, or the compute.
The problem was being caused by the PRVDELTA2 field formatting being I8, but the CT_DAYS was formatted as D8S. Once I made PRVDELTA2 to a D8S format, it fixed the problem.