ltannous
21st March 2003, 20:32
I am trying to get the cummulative values of a purchase schedule.
This will be based upon the user entering the first requirement week to be displayed. How can I get the cummulative requirements to show in this format:
If the requirements were 50 pcs per week.

WK1 WK2 WK3 WK4 WK5 WK6
50 50 50 50 50 (net req.)
100 150 200 250 300 350 (cum req.)

I tried to sum up the values, but no luck. This is what I have so far.


after.tdpsc006.seqn.2:
before.layout:

week1 = week.f
week2 = week1 + 1
week3 = week2 + 1
week4 = week3 + 1
week5 = week4 + 1
week6 = week5 + 1
week7 = week6 + 1
week8 = week7 + 1
week9 = week8 + 1
week10 = week9 + 1
week11 = week10 + 1
week12 = week11 +1
week13 = week12 + 1
week14 = week13 + 1


select tdpsc006.*, tdpsc005.*
from tdpsc006, tdpsc005
where tdpsc006.item = :tdpsc006.item
and tdpsc006.cont = :tdpsc006.cont
and tdpsc006.pono = :tdpsc006.pono
and tdpsc006.suno = :tdpsc006.suno
and tdpsc006.seqn = :tdpsc006.seqn
and tdpsc005.item = :tdpsc006.item
and tdpsc005.suno = :tdpsc006.suno
and tdpsc005.seqn = :tdpsc006.seqn
and tdpsc005.pono = :tdpsc006.pono
and tdpsc005.cont = :tdpsc006.cont
selectdo
if tdpsc006.week < week1 then
select sum(tdpsc006.totq)
from tdpsc006
where tdpsc006.item = tdpsc006.item
and tdpsc006.seqn = :tdpsc006.seqn
and tdpsc006.cont = :tdpsc006.cont
and tdpsc006.pono = :tdpsc006.pono
and tdpsc006.suno = :tdpsc006.suno
selectdo
begcum = tdpsc006.totq
endselect
endif
if tdpsc006.week = week1 then
qnty1 =tdpsc006.totq+ begcum
endif
if tdpsc006.week = week2 then
qnty2 = tdpsc006.totq+qnty1
endif

tools123
22nd March 2003, 02:12
did you debug your program yet?

what is the value found in week1?

is week.f returning any values?

I am assuming that you are wanting to do this in a report script as this is a standard session for which you have no source code.

The script can be made efficient by using indices where available and minimizing the condition fields in the where statement.

If you could explain your requirement in terms output currently
in report,variables and indices available, it may be easier to get
to the solution.

Good Luck

ltannous
22nd March 2003, 05:02
What I need is in the sesison(I created)
the user can select what week range they would like to view for past purchase schedules. They can select for example week 10 (week.f)
The report will gather data for all historical purchase schedules and will display all requirements for each schedule starting from week 10 forward.(up to 14 weeeks)
The issue is that I need to get the sum of the requirements up to the week.f and then create the cummulative requirements.

Not sure if this is clear yet.

another example

on the session for the user enters week 10 for the field week.f and a date range to gather all histiorical schedules within the date range.

Each schedule may have data prior to week 10, This needs to be included in the cummulative count.

Ex
week1 100 pcs
week2 300 pcs
week3 200 pcs
week 4 150 pcs
week5 150 pcs qnty1 (on rpt)
week6 100 pcs qnty2 (on rpt)

When the user selects in the session to print starting on week 5, the values above need to be included in the cummulative count.
The begining cum here would be 750, then week5 would be 900 pcs and week 6 would be 1000 pcs.

How can I sum a field and then add the field to the sum
select sum(tdpsc006.totq)
where week > week.f
.....
begcum = tdpsc006.totq
...............
if tdpsc006.week = week.f
qnty1 = tdpsc006.totq + begcum

tools123
22nd March 2003, 14:12
My understanding is your table lists weeknumber and total
quantity as 2 fields.

Most simple solution would be :
====================

Select sum(tdpsc006.totq) :begcum
from tdpsc006
where tdpsc006.week < week.f
selectdo
endselect

select sum(tdpsc.totq) :curtotal
from tdpsc006
where tdpsc006.week >= week.f
selectdo
endselect

qnty1 = begcum+curtotal

=================================

As I said before, use Indices where available,take care of
variable declarations and initializing them when required.

The code can be made more concise but this is the most simple form.
Good Luck