Home Subreports

Looping Subreport

edited February 2010 in Subreports
I'm trying to figure out how to write a subreport to calculate and print the
direct deposit amounts for each bank account on employee paystubs. Each
employee can specify multiple accounts, so I know I need some kind of loop
to run through each account, calculate the dollar amount going to that
account and the remaining amount to be distributed, and print the amount
going to that account on a line of the subreport.

I have NetPayAmount coming from the main report, and that serves as my
beginning balance.
RemainingBalance as double which calculates how much remains to be
allocated.
The subreport links to the main report on Employee_ID.

For each line of bank account data I have:

Employee_ID
Order_Number (integer) (the order accounts are processed in)
Account_Number (string)
Amount (double) (either a percent or fixed dollar amount to transfer)
Type (string) (either P if Amount is a percent or A if Amount is in dollars)

I'm stumped as to how to structure my loop. I suppose I could make it loop
until RemainingBalance = 0, but I would prefer to have it loop through all
of the bank accounts by order number. I just don't see any way to specify at
the beginning of the loop a value for MAX(Order_Number) or something similar
so that it knows how many times to cycle.

I am a complete novice with Pascal (this is the first program I've used it
in), but I'm not completely new to programming in general. Still, it's been
a whole lot of years since I've written a loop of any kind.

Comments

  • edited February 2010
    Hi Steve,

    I believe you are going to want to use a TppVariable component in the detail
    band of the subreport. There should be no need for a "loop" per se, you can
    utilize the fact that ReportBuilder will be iterating through all data
    records to make your calculation.

    1. Place a TppVariable inside the subreport's detail band. Set it's type
    to Double and be sure it is set to calculate on Traversal.
    2. Implement the OnCalc event of the variable and set the Value parameter
    equal to the value you would like displayed for that line. (Percentage *
    Total or dollar amount).

    3. Then if needed, update a different variable's value in the subreport's
    summary to reflect the remaining amount left to be distributed.

    The following article gives more information on how calculations should be
    made with ReportBuilder.

    http://www.digital-metaphors.com/rbWiki/Delphi_Code/Calculations/Overview

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited February 2010
    Hi Nico,

    I'm still having problems. I have created a variable to calculate the amount
    to be displayed for the line and put it in the detail band as you
    recommended. I have created a second variable to hold my declining balance.
    I cannot figure out how to use the result of one variable in the calculation
    of the second.

    Steve


  • edited February 2010
    Hi Steve,

    You can use the result of one variable in the calculation of another by
    accessing the TppVariable.Value property. You just need to be sure the
    variable has indeed been calculated before trying to use it. See the
    CalcOrder property.

    To make things easier, you should create a field to hold the declining total
    and initialize its value to the total amount.
    Assume the variable to hold the amount displayed is named Variable1, and the
    variable to keep track of the declining balance is named Variable2.

    Inside the OnCalc event of Variable1 you will want to do something like the
    following...

    begin

    //First calculate the value of the variable
    Value := Report.DataPipeline['PercentageField'] * TotalAmount;

    //Keep track of the declining value (this value was initially set to the
    TotalAmount)
    FDecliningValue := FDecliningValue - Value;

    //Next update the declining variable value
    Variable2.Value := FDecliningValue;

    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.