Ab initio scan component

2.6k Views Asked by At

Suppose I have the following records:

code  sequence_no   group_no
4          1            1
2          2            1
3          3            1
4          4            1
1          1            2
3          1            3
4          2            3

the output should be: within the same group(by group_no) the code column is updated with the first(by sequence_no) code that is not 4.

so the output should look like this:

code  sequence_no   group_no
2          1            1
2          2            1
2          3            1
2          4            1
1          1            2
3          1            3
3          2            3

Here's my code, and my logic is that if the input.code == 4, then assign the next code to the temp variable. This doesn't work if the first record code == 4 for some reason. And I don't think this logic covers the last record of the group if it == 4.

type temporary_type=
record
  decimal("\x01") l_code;
end;

temp :: scan(temp, in) =
begin


temp.l_code:: 
if (temp.l_code == 4) in.code 
else temp.l_code;

end;


temp :: initialize(in) =
begin
  temp.code :: in.code;
end;

out :: finalize(temp, in) =
begin
  out.* :: in.*;
  out.code :: temp.l_code;
end;
0

There are 0 best solutions below