sureca
5th January 2015, 10:00
Good Noon All,
My requirement is to get sum of a array field.. Here bptmm111.hrea is the array field.. If my input cprj is s010001c and it is the index field of main table ltrpd300 and it has another index cact..
In table ltrpd300 In table bptmm111
For cprj:S010001C cprj:s0100001c
Cact is:01 cact :01
02 02
03 03
I want sum of all the records which matches with the main table ltrpd300.
i.e if for 01 hrea is 12 then for 02 hrea is 12 then for 03 hrea is 2 then on the whole normal should be 26
Here is my script:
function extern summary()
{ | normal = 0
| othrs = 0
select ltrpd300.*
from ltrpd300
where ltrpd300._index1 inrange {:cprj.f} and {:cprj.t} and
ltrpd300.loca inrange {:loca.f} and {:loca.t}
selectdo
normal = 0
othrs = 0
select sum(ltrpd300.rhrs):rccp , sum(ltrpd300.bhrs):book
from ltrpd300
where ltrpd300._index1 inrange {:cprj.f} and {:cprj.t} and
ltrpd300.wtyp = ltrpd.wctype.labour
selectdo
ltrpd300.rhrs = rccp
ltrpd300.bhrs = book
varhrs = book - rccp
varper = varhrs/rccp*100
select bptmm111.hrea,bptmm111.cact,bptmm111.cprj,bptmm111.chlt
from bptmm111
where bptmm111.cprj = :ltrpd300.cprj and
bptmm111.cact = :ltrpd300.cact
selectdo
if bptmm111.chlt = "REG" then
normal1 = bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8)
message(str$(normal1))
normal = normal1 + (bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8))
message(str$(normal))
else
if trim$(bptmm111.chlt) = "OT" then
othrs = bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8)
othrs = othrs + (bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8))
endif
endif
endselect
endselect
endselect
brp.ready(brp_id1)
}
But its giving the last record value i.e 12+12 =24
Am not getting the whole sum value...
please help...
My requirement is to get sum of a array field.. Here bptmm111.hrea is the array field.. If my input cprj is s010001c and it is the index field of main table ltrpd300 and it has another index cact..
In table ltrpd300 In table bptmm111
For cprj:S010001C cprj:s0100001c
Cact is:01 cact :01
02 02
03 03
I want sum of all the records which matches with the main table ltrpd300.
i.e if for 01 hrea is 12 then for 02 hrea is 12 then for 03 hrea is 2 then on the whole normal should be 26
Here is my script:
function extern summary()
{ | normal = 0
| othrs = 0
select ltrpd300.*
from ltrpd300
where ltrpd300._index1 inrange {:cprj.f} and {:cprj.t} and
ltrpd300.loca inrange {:loca.f} and {:loca.t}
selectdo
normal = 0
othrs = 0
select sum(ltrpd300.rhrs):rccp , sum(ltrpd300.bhrs):book
from ltrpd300
where ltrpd300._index1 inrange {:cprj.f} and {:cprj.t} and
ltrpd300.wtyp = ltrpd.wctype.labour
selectdo
ltrpd300.rhrs = rccp
ltrpd300.bhrs = book
varhrs = book - rccp
varper = varhrs/rccp*100
select bptmm111.hrea,bptmm111.cact,bptmm111.cprj,bptmm111.chlt
from bptmm111
where bptmm111.cprj = :ltrpd300.cprj and
bptmm111.cact = :ltrpd300.cact
selectdo
if bptmm111.chlt = "REG" then
normal1 = bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8)
message(str$(normal1))
normal = normal1 + (bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8))
message(str$(normal))
else
if trim$(bptmm111.chlt) = "OT" then
othrs = bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8)
othrs = othrs + (bptmm111.hrea(1)+bptmm111.hrea(2)+
bptmm111.hrea(3)+bptmm111.hrea(4)+
bptmm111.hrea(5)+bptmm111.hrea(6)+
bptmm111.hrea(7)+bptmm111.hrea(8))
endif
endif
endselect
endselect
endselect
brp.ready(brp_id1)
}
But its giving the last record value i.e 12+12 =24
Am not getting the whole sum value...
please help...