cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report 2008. Attempted to divide by zero. -

Former Member
0 Kudos

*

We are using .NET SDK for Crystal Reports 2008 and Report Document Object Model \ API.

Printing throws error but preview works fine launching an empty report viewer.

*

Message = Attempted to divide by zero.

StackTrace =

at CrystalDecisions.Shared.PrintingHelper.PrintPage(PrintPageEventArgs e, PageObject page,

PrintLayoutSettings layoutSettings, Int32& currentPageNumber, Int32& currentHorizontalPageNumber)

at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintPageEventHandler(Object sender, PrintPageEventArgs e)

at System.Drawing.Printing.PrintDocument.OnPrintPage(PrintPageEventArgs e)

at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)

at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument document)

at System.Drawing.Printing.PrintController.Print(PrintDocument document)

at System.Drawing.Printing.PrintDocument.Print()

at CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)

at CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)

at CREngine_2008.CCRPEngine_2008.Print()

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

This error is only faced when there are no records returned from the binded stored procedure.

The report has sub-reports present.

Main Report has "Suppress Printing if No Records" checked, but the sub reports do not have this checked ?

Could this be the problem

Any thoughts are appreciated.

former_member188030
Active Contributor
0 Kudos

Hi,

Check if the report has a fromula against the data returned by the stored proc.

the formula is more likely to fail when no data is returned by the stored proc.

See if below kbase helps,

[1214596 - Err Msg: "Division by zero" with formula containing IIF function |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313334333533393336%7D.do]

Thanks,

Bhushan.

Former Member
0 Kudos

Hi ,

Many thanks for your response.

There are no division operator used in my formulas.

I have also handled all possible exception catches , but the exception is captured in .NET standard Exception (Exception handler)

catch (LogOnException e)

catch (DataSourceException e)

catch (SubreportException e)

catch (ParameterFieldException e)

catch (FormulaException e)

catch (FormattingException e)

catch (EngineException e)

former_member188030
Active Contributor
0 Kudos

Try following test.

- Remove the subreport from the report, see if it reproduces the issue.

- Supress all the sections. print the report.

- Now unsupress one section at a time, and print report, observe the behaviour.

- follow the procedure untill all the sections are unsupressed.

At the end of this test, we will know which section is causing the error, then reevaluate that particluar section.

- Bhushan.

former_member183750
Active Contributor
0 Kudos

Crystal Reports 2008 and Report Document Object Model \ API.

- Are you referencing the craxDDrt.dll and crviewer.dll in your project? If not, what CR files are you referencing?

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Former Member
0 Kudos

- Are you referencing the craxDDrt.dll and crviewer.dll in your project? If not, what CR files are you referencing?

NO

<Reference Include="CrystalDecisions.CrystalReports.Engine, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

<Reference Include="CrystalDecisions.Enterprise.Framework, Version=12.0.1100.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />

<Reference Include="CrystalDecisions.Enterprise.InfoStore, Version=12.0.1100.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />

<Reference Include="CrystalDecisions.ReportSource, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

<Reference Include="CrystalDecisions.Shared, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

<Reference Include="CrystalDecisions.Windows.Forms, Version=12.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" />

Former Member
0 Kudos

Hi LUDEK UHER,

SAP Crystal Reports 2011 Release Notes -- 07/12/2010

SAP Crystal Reports General Issues

Functional Correctness

ADAPT00264642

Blank pages are printed when the "Suppress printing if no records" option is enabled

If a user attempts to print from an empty report, or attempts to print an empty selection from a report, a blank

page is printed, even when the "Suppress printing if no records" option is enabled.

Does this problem exiist in Crystal Report 2008 ?

former_member183750
Active Contributor
0 Kudos

Here is an extract from the ADAPT:

 

...the conclusion is to postpone to future as this requires some significant changes.


There is no word re. definition of "future", however the feeling I get from the rest of the notes in the ADAPT is that there is significant hesitation re. implementing the changes required due to the risk of adding significant instabilities along with the fix... E.g.; no ETA.

Suggested work-around in the ADAPT:

 

...check for number of records returned, the developer can check this value and simply not call the PrintToPrinter() api. 

Code that would let you check the record count is documented in KB [1471477 - Using the RAS SDK for VS .NET, how to determine number of data rows returned to a report?|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333433373331333433373337%7D.do]

Another KB that may help:

[1487765 - How to stop a report with no data from printing|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333433383337333733363335%7D.do]

- Ludek

Edited by: Ludek Uher on Dec 7, 2011 8:00 AM

Former Member
0 Kudos

Hi Ludek,

Thank for your reply much appreciated.

We are using .NET SDK We set formulas , parameters on the fly , hence we cannot use Refresh() as it would reset parameter and formula set.

1487765 - How to stop a report with no data from printing

Use the following code for CR for .NET SDK:

If crReportDocument.Rows.Count > 0 Then crReportDocument.PrintToPrinter(1, False, 0, 0)End if

At point in time the ROWS property of the reportdocument will be populated ?

Thanks

Ilan

former_member183750
Active Contributor
0 Kudos

Yes. The report should be all formatted at this point and only be waiting for the next "command"; view, print, export.

- Ludek

Former Member
0 Kudos

Hi Ludek,

Many thanks for the replies.

I mispelled my last reply.

Currently PrinttoPrinter method call results in firing the database query ( Stored Procedure call)

I cannot call REFRESH, as it resets the parameter i set after loading the report.

What method should i call , to fire the database query to get the database query fired, but not print it.

If i can fire database query before printing, i can access the count of ROWS attribute of the ReportDocument and

work around the problem ?

former_member183750
Active Contributor
0 Kudos

Use .Refresh before setting the parameters. At that point, .Refresh should only drop any "Saved Data" that may be with the report, but no query to the DB should be issued. Then set that parameters.

From the SAP Crystal Reports .NET API Guide:

Removes saved data. This causes fresh data to be loaded when the report is subsequently viewed.

- Ludek

Former Member
0 Kudos

Hi Ludek,

Many Thanks that worked.

1) Load Report

2) Refresh

3) Set Parameters

4) If we make an attempt to access the Rows Attribute ( m_RptDocument.Rows.Count )

on the Report Document, Crystal Report seeing data is not populated fires the query back to the database.

5) You check the count and decide to all PrintToPrinter.

Can i sneak another one please ?

Is there way we can know if a reportdoucment has "Suppress Printing if no records" is turned on / off

via .NET SDK of Crystal Report 2008.

I tried the property "ReportOptions" on the Report Document bt no luck?

Thanks

Ilan

Edited by: Ilanthendral on Dec 8, 2011 4:54 PM

former_member183750
Active Contributor
0 Kudos

I was pretty sure there was no way. But to make really, really sure, I asked a few people way smarter than me and they confirmed the lack of this option API. Many (if not most) of these options are not part of the SDK (CR or RAS) at this time.

- Ludek

Answers (0)