Hi Tracie,
I may not understand what you need, but here's an example using test data that displays the last five gifts sorted by date for the four accounts in the test file.
-*
-*** THIS CREATES A TEST FILE AND TEST DATA
-*
FILEDEF T_MAS DISK T_TAB.MAS
FILEDEF T_TAB DISK T_TAB.TXT
-RUN
-*
-WRITE T_MAS FILE=TESTTAB,SUFFIX=FIX
-WRITE T_MAS SEGNAME=SEG1
-WRITE T_MAS FIELD=T_ACCT,,A04,A04,$
-WRITE T_MAS FIELD=T_FIL1,,A01,A01,$
-WRITE T_MAS FIELD=T_DATE,,YYMD,A08,$
-WRITE T_MAS FIELD=T_FIL2,,A01,A01,$
-WRITE T_MAS FIELD=T_GIFT,,D12.2,A12,$
-*
-WRITE T_TAB 0001 20070701 000000500.00
-WRITE T_TAB 0001 20070601 000005500.00
-WRITE T_TAB 0001 20060801 000000530.00
-WRITE T_TAB 0001 20070201 000000130.00
-WRITE T_TAB 0001 20070801 000000100.00
-WRITE T_TAB 0001 20070811 000000050.00
-WRITE T_TAB 0001 20070101 000000025.00
-WRITE T_TAB 0001 20070215 000010500.00
-*
-WRITE T_TAB 0002 20070521 000000150.05
-WRITE T_TAB 0002 20070501 000000123.12
-WRITE T_TAB 0002 20070515 000000160.00
-WRITE T_TAB 0002 20070301 000000550.00
-WRITE T_TAB 0002 20070401 000000200.00
-WRITE T_TAB 0002 20070810 000004200.00
-WRITE T_TAB 0002 20070801 000000210.00
-*
-WRITE T_TAB 0101 20070701 000010500.00
-WRITE T_TAB 0101 20070219 000025500.00
-WRITE T_TAB 0101 20070301 000000501.01
-WRITE T_TAB 0101 20070401 000060130.00
-WRITE T_TAB 0101 20070601 000000700.70
-WRITE T_TAB 0101 20070611 000003050.30
-WRITE T_TAB 0101 20070101 000009025.99
-WRITE T_TAB 0101 20070215 000025500.25
-WRITE T_TAB 0101 20070105 000032100.05
-*
-WRITE T_TAB 0901 20070805 000000020.00
-WRITE T_TAB 0901 20070801 000000015.00
-*
-*** THIS SORTS TEST DATA BY ACCOUNT BY DATE OF GIFT
-*
DEFINE FILE T_TAB
A_GIFT/A15 = FTOA(T_GIFT,'(D12.2)',A_GIFT);
CNT/I3 = 1;
END
-*
TABLE FILE T_TAB
SUM CNT
BY T_ACCT
PRINT
COMPUTE CNTR/I3 = IF T_ACCT EQ LAST T_ACCT THEN CNTR + 1 ELSE 1;
T_GIFT
A_GIFT
BY T_ACCT
BY T_DATE
ON TABLE HOLD AS HOLD1
END
-*
-*** THIS CREATES A FILE OF THE LAST 5 GIFTS
-*
TABLE FILE HOLD1
PRINT *
WHERE ( CNTR GE (CNT - 4) )
ON TABLE HOLD AS HOLD2
END
-*
-*** THIS CREATES ONE RECORD PER ACCOUNT AND THE LAST 5 GIFTS(L5_GIFTS)
-*
DEFINE FILE HOLD2
L5_GIFTS/A91 = IF T_ACCT EQ LAST T_ACCT
THEN SUBSTR(91, L5_GIFTS, 1, 72, 72, 'A72') || ' <> ' || A_GIFT
ELSE A_GIFT;
END
-*
TABLE FILE HOLD2
SUM
L5_GIFTS
BY T_ACCT
END
This is a multiple pass solution and may not be of any use, but it is one idea.
Jim
WF DevStu 5.2.6/WF Srv 5.2.4/Win NT 5.2