You've got it, with a couple of suggestions. First, I'm thinking that you may want to use TTRSET3 rather than TTRSET1, since it's keys are (in this order) Company, Plan, EmployeeGroup, Employee, Position, Date, SeqNbr. Second, I think you should probably include a date limiter (Maybe within the previous month or 6 months or something?) In the samples below, wehre I have put "{LOGIC}, you'd need to take TTR-EMPLOYEE-GROUP and toss it against your WS array to find the matching EMPLOYEE-GROUP record, then check the TTR-DATE value against the stored WS DATE value to see if the current date is greater, and if so overwrite. The filter query probably would be best, though they can be tricky. Note that the "?" values are populated in order using the 890-SET statements that follow. I think it would need to be something like this (you'll need to test to be sure): STRING "(TTR-DATE >= ? AND ((TTR-TRAN-TYPE = ?) OR" "(TTR-TRAN-TYPE = ?))) " DELIMITED BY SIZE INTO FILTER-STRING. PERFORM 890-CREATE-FILTER. MOVE {your low-end date} TO DATETIME-FILTER-VALUE. PERFORM 890-SET-DATETIME-FILTER-VALUE. MOVE 21 TO NUMERIC-FILTER-VALUE. PERFORM 890-SET-ALPHANUM-FILTER-VALUE. MOVE 22 TO NUMERIC-FILTER-VALUE. PERFORM 890-SET-ALPHANUM-FILTER-VALUE. MOVE LPMST-TEM-COMPANY TO DB-COMPANY. MOVE LPMST-TEM-PLAN TO DB-PLAN. MOVE TTRSET3-PLAN TO WS-DB-BEG-RNG. PERFORM 850-FILTER-BEGRNG-TTRSET3. PERFORM UNTIL (TAEMPTRANS-NOTFOUND) OR (TTR-COMPANY NOT = LPMST-TEM-COMPANY) OR (TTR-PLAN NOT = LPMST-TEM-PLAN) {LOGIC} PERFORM 860-FIND-NXTRNG-TTRSET3 END-PERFORM. If you were going to use the second option, it would spin through all employees in COMPANY and PLAN, by employee group and look at every record in TAEMPTRANS. It would take time, but it's pretty bullet-proof. So I'd do something like this:
MOVE LPMST-TEM-COMPANY TO DB-COMPANY. MOVE LPMST-TEM-PLAN TO DB-PLAN. MOVE SPACES TO DB-EMPLOYEE-GROUP. MOVE ZEROES TO DB-EMPLOYEE. MOVE SPACES TO DB-POSITION. PERFORM 850-FIND-NLT-TTRSET3. PERFORM UNTIL (TAEMPTRANS-NOTFOUND) OR (TTR-COMPANY NOT = LPMST-TEM-COMPANY) OR (TTR-PLAN NOT = LPMST-TEM-PLAN) IF(TTR-TRAN-TYPE = '21') OR(TTR-TRAN-TYPE = '22') {LOGIC} END-IF PERFORM 860-FIND-NEXT-TTRSET3 END-PERFORM. I hope this helps. Good Luck.