Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Subreport calculations for Master - Detail with visibilty of subreport set to false

edited March 2012 in RAP
I have a Master-Detail setup in Dade, and I am using a subreport to do
calculations based upon the detail data. I then transfer over the
calculated statistics over to the main report through the setting of
global variables. I always had in mind to set the subreport visibility
to false once I worked out the calculations. However, now I find that
when I set the visibility to false, the calculations do not work. I
guess the OnCalc events for the variables in the detail subreport never
fire when visibility is false.

How can I achieve what I am trying to do? I basically want to show
some summary information on the main report which is based upon
processing through transaction records for every record in the main
report, but I do not want to show all the detail records.

--

Comments

  • edited March 2012
    Some more information:

    I also do not want to show the main detail band, yet I am trying to do
    calculations in the summary band based upon the data in the detail
    band. If I set the main detail band visibility to false, the number
    being calculated in the summary band goes to zero. How do I do
    calculations based upon data traversal without showing all the records?
    Is there an event perhaps that I could be using instead of using a calc
    variable to do the calculations?

    --
  • edited March 2012
    More Information:

    What I am trying to do is calculate the number of customers who failed
    to make a monthly payment for at least 60 days.

    The main report processes the loan records, and the subreport processes
    transactions, filtering to include only payment transactions.

    On the main report is a calc variable called NrFailedPmts. The basic
    code in this variable looks like this:

    {Handle Loans That Never Made Any Payment}
    if Transactions.FieldObjects['TransNo'].IsNull then
    begin
    if ((Trunc(CurrentDate) - Trunc(Loans['DateT'])) >= MaxDaysLate)
    and not CustCounted then
    begin
    Value:=Value+1;
    CustCounted:=true;
    end;
    end
    else {The Subreport takes care of calculating gTimesVeryLate}
    begin
    if (gTimesVeryLate>0) and Not CustCounted then
    begin
    Value:=Value + 1;
    CustCounted:=true;
    end;
    end;
    gTimesVeryLate:=0; {Needs To Be Reset Before Each Record Is Processed}

    If the main detail band is visible, it seems to work. However, if I
    set the Main Detail band visibility to false, this calc field shows
    zero. I suspect this probably happens because setting the main report
    detail band visibility to false causes the subreport detail band not to
    process, which is responsible for setting the global variable
    gTimesVeryLate.

    How can I hide the main detail band, yet still process the transactions
    for each loan record so that I can do the calculations that I need and
    show them in the summary band?
  • edited March 2012
    Hi David,

    When setting the subreport's visibility to False, in addition to not
    printing the subreport and firing events the dataset is also not
    traversed. This makes it impossible to make running calculations on
    non-visible (non-generating) reports.

    I can think of two ways of working around this. First you could
    pre-calculate the values needed manually in Delphi code before printing
    the report(s). Second, you could run the report twice, first with the
    subreport visible to make the proper caluclation, save these calculated
    values, then run the report again with the subreport visible set to false.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2012
    Nico Cizik (Digital Metaphors) wrote:

    Do you think this could be done with a two pass report, where I turn do
    something like:

    if Report.SecondPass then Report.Detail.Visibility:=false;

    What event do you suggest to do this so that I get the timing right?

    --
  • edited March 2012
    Hi Nico.

    I have been able to suppress the subreport simply by setting the header
    and detail band visible property to false on the subreport page. The
    calculations seem to be going through just fine.

    However, I still need to suppress the main report detail band. If I
    set its visibility to false, then the subreport never processes. I
    have tried making it a 2 pass report, and then setting
    Report.Detail.Visible:=false in OnEndFirstPass and also
    OnStartSecondPass events, but the detail records still are displayed.

    Any ideas on how I can manage this in RAP? This is a special report
    for one customer using an interface like the End User demo. Using
    Delphi Code is not much of an option for this report. I want to do it
    all in RAP.

    David.


  • edited March 2012
    Perhaps instead of hiding the entire detail band, place each component
    in the detail band inside a region and hide the region. Be sure
    DetailBand.PrintHeight is phDynamic.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2012
    Hi Nico.

    Nice idea. This is getting me very close.

    I put the following in the OnStartSecondPass event:

    Report.Detail(Region1).Visible:=false;

    The detail of the report flashes on the screen, then disappears.

    However, I am experiencing some weird behavior now. The report runs the
    first time, but if I try to run the report again, it does not run. I
    get the search parameters where I can enter a date range, but when I
    select ok, the search box disappears and nothing happens. If I exit my
    application and restart it, the report will run the first time, but
    trying to run the report again does not work.

    If I go back and comment out this single line that I have placed in the
    OnStartSecondPass event, exit the application, restart app, then run
    report, it runs as expected as many times as I need.

    Customer will not like running report only once. Any ideas on how to
    fix this?


  • edited March 2012
    Hi David,

    Sorry for the delay in this response. Before running the report again,
    you need to be sure to set the Region.Visible back to True so the
    calculations can be made again. This is my guess to what is causing the
    problem. Perhaps in an early event such as OnInitializeParameters.

    Best Regards,

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