Question on Looping

nate100

Member
Hello,
I have a table that has the following info:

Ln Part Date Field1
-- ---- ---- ------
1 part1 09/09/08
2 partxx 09/08/08
3 partyz 09/08/06
4 partki 08/07/06

What I need to do is while looping through the table, look for the next record down and depending on the date value update Feild1 of the next record.

So in case below (which is a far simplied version of what I need to do),
while I am on line 1, I need to check the date value of Ln 2. If the date value meets some conditions, then I need to update Ln 2's Field1 value. I tried to use a buffer but did not quite figure out how to proceed all the way through. Thank you in advance.
 
Code:
DEFINE BUFFER bttTable for ttTable.

FOR EACH ttTable NO-LOCK
  BY ttTable.Ln,
  FIRST bttTable EXCLUSIVE-LOCK
  WHERE bttTable.Ln = ttTable.Ln + 1:

  IF bttTable.Date EQ <condition> THEN
  DO:
    <whatever you want to do>
  END.
  
END.
I think that should get you started.
 
What is essential here is, that whenever you want to access more records of the same table ( database or temp ) simultaneously is that one buffer can only hold one record at a time. Therefore you need to use additional, defined buffers.

Regards, RealHeavyDude.
 
Back
Top