loops

tjsingh

Member
Hi

I have a loop in my code which goes through each job and extracts the relevant information for labour. there is a temp table which gets populated so that data can be outputted called ptjobs.

But the problem i have is that when adding the labour quantity together it loop sthrough 9 times for the same value and then moves onto the next.

example i have a job number 1234e this has 9 labour quantities against it. these have to be accumulated for each job number. but it finds the first value and adds that 9 times and then gets the next value and adds that 9 times why would this be???

Heres my code:


FOR EACH job WHERE
job.kco = 1 AND
job.comp-date ge jp-start AND
job.comp-date le jp-end NO-LOCK,
EACH labour WHERE
labour.kco = 1 AND
labour.kjobcode = job.kjobcode AND
labour.kdeptsn begins "24" AND
(labour.koper = "14") NO-LOCK, /* removed 9 as run on has metr~
es */
EACH blab where bLab.kco = labour.kco and
bLab.kjobcode begins labour.kjobcode and
(bLab.koper = "14" or
bLab.koper = "9") and
bLab.kdeptsn begins "21" no-lock,
EACH ptjobs WHERE
ptjobs.pt-docket = job.kjobcode :

find jpwid where jpwid.kco = 1 and jpwid.kjobcode = job.kjobcode ~
no-lock no-error.
IF labour.ktt lt 501 OR labour.ktt gt 510 THEN NEXT .
ASSIGN
ptjobs.pt-labquantity = ptjobs.pt-labquantity + labour.qty.
 

sphipp

Member
In circumstances like this, the easiest way to understand what is happening is to display some of the fields of the records you are looping through. That way you can see which records it is trying to access.

My guess is that you are accessing the same records more than once because you are accessing a crossreference table more than once. Try a display like the one below inside your loop. You'll probably look at the output and see exactly what is happening.

DISPLAY
job.kco job.comp-date
labour.kjobcode labour.kdeptsn labour.koper

bLab.kco bLab.kjobcode bLab.koper bLab.kdeptsn
ptjobs.pt-docket
WITH FRAME ftest DOWN.
DOWN WITH FRAME ftest.
 
Top