×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Calculating summary totals before detail lines

 Forum Search FAQs Links MVPs

Calculating summary totals before detail lines

(OP)
I have a order report that prints the summary lines first before it prints the detail lines. The report works fine so long as there is only one line per order.

The problem comes up when there are multiple lines for one order. Since the summary is written first before the detail only the first line in the order is included in the summary calculation. The report looks like this:

--------------------------------------------------
Order 1 total: n
--------------------------------------------------
Order 1 line 1 details: amount n

--------------------------------------------------
Order 2 total: x(this should be the sum of x+y+z)
--------------------------------------------------
Order 2 line 1 details: amount x
Order 2 line 2 details: amount y
Order 2 line 3 details: amount z

The logic of the program is such that after the initial CHAIN to find the order the summary line print is immediately called before the detail lines have a chance to get processed.

Any help would be appreciated. Thanks in advance.

RE: Calculating summary totals before detail lines

Well,, at this point,, you have some choices, none of them pretty. After the chain to get the order number,, you have to process all the detail, to get the summary total. Or you could pre-process the file, and build summary by order totals, put them in a temp. file,, and chain to that file,, for your totals. You could do somthing more traditional, and move the totals to "after", the detail. Are you using the rpg cycle, or controlling everything?

RE: Calculating summary totals before detail lines

This is backward from the way it's normally done. You could pass through the data twice. Once for order total and once for the detail.

RE: Calculating summary totals before detail lines

Well,, if you have seen crystal reports, as a reporting tool.. you can drag and drop the "group", totals, at the group header line. Not a traditional way of repsenting the natual flow of the data, but each to their own, so this could be why the question.

RE: Calculating summary totals before detail lines

The easiest way is to create a subroutine every time there is a change of order# or for the first order#. This subroutine is in fact a set of SQL statement to summarize the amount by order. Other suggestion above are valid too.

RE: Calculating summary totals before detail lines

(OP)
i FINALLY GOT IT!

Below is the pseudo code for the program I'm working on.

FILE12 - a LF containing Orders
SUMFILE - the summary file contains the Gross weight of the orders

Below is the structure of the orders as soted in FILE12

Order1 Line 1 Inc#1 quantity

Order1 Line 2 Inc#1 quantity
Order1 Line 2 Inc#2 quantity

Key KLIST
KFLD Order
KFLD Inc#

Execute $Init(this subroutine initializes variables, moves Inc# to TmpInc# and executes$Comput)
DOU EOF
Inc# casne TmpInc# $Comput Print detail line Read File12 Enddo$Comput
Chain to SUMFILE using Key to get the Gross Weight
Use Gross Weight to compute the other fields used for the Summary
Print Summary
z-add 0 to total
ENDSR

What I did:
Added FILE13 adding Prefix SV to differentite from FILE12

RE: Calculating summary totals before detail lines

An easier way is summarize by detail line
reset after group.
then drag summary group total and place it in the header,
it works like a charm.
d

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!