adding values based on conditions

anu123

New Member
Hi

I am new in progress programming. I need help with one problem, I am getting stuck at.
I have few records that are coming from various tables after joining.
Example is:
Bld year period amt
1 2006 1 100
1 2006 2 50
2 2006 1 200
2 2006 1 140
2 2007 2 300
3 2007 2 190

I need output as
Bld year amt1 amt2
1 2006 100 50
1 2007 0 0
2 2006 340 0
2 2007 0 300
3 2006 0 0
3 2007 0 190

where amt1 is sum for period 1 and amt2 is sum for period 2 for particular year for particular building.

I have been trying different options using break by,accum etc, but did not succceed. Can any one give me some hint to move ahead.

Thanks.
 

sphipp

Member
Define a Temp-Table with fields Bld year amt1 amt2.
Build it up, increment the counts and then display it in a different loop.
 

suny

ProgressTalk.com Sponsor
if you don't need empty lines:

define variable amt1 like amt no-undo.
define variable amt2 like amt no-undo.

for each table1 ...
,each table2 ...
break by Bld by year:
if first-of(year) then
assign
amt1 = 0
amt2 = 0.

if period = 1 then
amt1 = amt1 + amt.

if period = 2 then
amt2 = amt2 + amt.

if last-of(year) then
display Bld year amt1 amt2.
end.


if you need empty lines, ask me again.
 
Top