Rounding
Maloney, Charlie
Charlie.Maloney@Cognos.com
Fri, 29 Oct 1999 12:39:43 -0400
Sorry, I was thinking QUICK, not QTP.
I suppose you could write a QUICK batch routine, but...
First, some performance suggestions:
Be careful with DEFINEs in QTP. They're more like functions
than buckets. Since they're evaluated EVERY time they're
referenced, they can slow a program considerably when overused.
No guarantees, but try replacing some of your DEFINEs with
TEMPs like this:
TEMP AMT-REMAIN INT*8
ITEM AMT-REMAIN &
RESET AT PO-LINE TO AMT-ORDER - AMT-RCVD
Also, not sure how IMAGE keys work, but you may be able to use a
sorted key and change your "SORT ON" statement to a "SORTED ON".
Back to your question. In QTP, you could:
Accumulate the DIFFERENCES your adding to the records, or
Accumulate the TOTALS your write out to the records.
Here's some pseudo-code that accumulates DIFFERENCES.
Might need tuning.
ACCESS...
SORT...
;Declare the accumulator
TEMP T-ALREADY-DISTRIB INTEGER SIZE 4
;At detail time:
;Accumulate the differentials in a temp.
;Reset the TEMP to zero at the break.
ITEM T-ALREADY-DISTRIB &
= T-ALREADY-DISTRIB &
+ AMT-REMAIN-DISTRIB &
RESET AT PO-LINE
;Or you could do this instead:
;ITEM T-ALREADY-DISTRIB &
; SUBTOTAL AMT-REMAIN-DISTRIB &
; RESET AT PO-LINE
;Write out the updated record.
OUTPUT PO-DISTRIB UPDATE
ITEM X of PO-DISTRIB &
= X of PO-DISTRIB &
+ AMT-REMAIN-DISTRIB
;At end-of-sort-break-time:
;Use an alias to get the last detail record (or any detail record).
;Then, add to it the difference between the accumulator and the
;total to distribute.
OUTPUT PO-DISTRIB &
ALIAS DISTRIB-ALIAS &
UPDATE &
AT PO-LINE &
VIA ... USING...
ITEM X of DISTRIB-ALIAS &
= X of DISTRIB-ALIAS &
+ (AMT-REMAIN - T-ALREADY-DISTRIB)
You'll get the "record has been changed" message if you try to
re-update the detail record at end-of-sort-break-time without using
an ALIAS. Or you could add NOCHECK to the statement if you
really know what you're doing.
You can also skip the second UPDATE if you know the number of records
ahead of time. Just use a conditional ITEM statement and a counter.
-----Original Message-----
From: Maloney, Charlie
Sent: Friday, October 29, 1999 10:20 AM
To: 'Terry A. Pickering'
Cc: 'powerh-l@lists.swau.edu'
Subject: RE: Rounding
This is pretty standard. We've done this on a bunch of consults.
You need TEMPs as in:
T_NUMBER_OF_RECORDS ;number of records to write, if it varies
T_ALLOCATED_AMT INTEGER SIZE 4 ;amount written out
As you write out your allocated amount, also add the amount to
T_ALLOCATED_AMT,
which is an INTEGER and will round down.
On you last loop, subtract T_ALLOCATED_AMT from your original amount, and
write that result to your last record.
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Subscribe: "subscribe powerh-l" in message body to majordomo@lists.swau.edu
Unsubscribe: "unsubscribe powerh-l" in message to majordomo@lists.swau.edu
This list is closed, thus to post to the list, you must be a subscriber.