×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

Calculating summary totals before detail lines

Calculating summary totals before detail lines

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#     

read FILE12
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

in $Comput after the Chain to Sumfile
CHAIN to FILE13 using Key indicator 23
If *IN23 is '0'
Dow *in23 = '0'
if SV_Inc# = Inc#
add sv_qty to total
endif
Reade FILE13 *IN23 if eof
Enddo

The order line with multiple Inc# gets accumulated and all the lines with single orders also have the correct computation.

Couldn't have done it without the inspiration your suggestions. Thanks to everyone!

RE: Calculating summary totals before detail lines

Just a suggestion, Ju5. You don't need to execute $Init. Set up your $Init in *INZSR. It executes automically when the program starts; no need to call it. It's minor but just a thought.

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.

Reply To This Thread

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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close