Running Crystal Report from xml file

andrewt30

New Member
I am trying to use the activex Crystal Reports Viewer (Crystal Reports version 10) to display a report in our application. To do this I am producing an xml file containing the report data (created from a dataset), saving this to disk, and then running the report using this xml file as the datasource. When I first run the report in my application the report works and display the correct data, but if I then change any of the report criteria to change the data that should be displayed in the report the report that gets displayed to screen has not refreshed the data, and is just identical to the first report I displayed. If I close the application and restart it the report again works the first time I run it - though this could be a bit of a red herring as the filename of the xml data file will be different. Any ideas what I am missing. The code I use is below, and this is in a screen that has the Crystal Report activex Viewer for version 10 Crystal Reports attached to it.
gch-CrystalViewer = chcf-crystal:CrystalActiveXReportViewer.
DO ON ERROR UNDO, RETURN ERROR:
IF v-ConstructCrystalDone THEN
RETURN.
CREATE "CrystalRuntime.Application" gchApplication NO-ERROR.
IF ERROR-STATUS:ERROR THEN
do:
run sm-message in this-procedure ("ERROR":u,0,
"Crystal Reports Configuration/Installation error",
"").
run close-down in this-procedure.
end.
v-ConstructCrystalDone = YES.
END.
ch-Report = gchApplication:OpenReport(p-template,1).
do v-count = 1 to ch-Report:database:Tables:count:
ch-Report:Database:Tables:item(v-count):setTableLocation(p-xmlfilename, '', '').
end.
ch-Report:DiscardSavedData().
gch-CrystalViewer:ReportSource = ch-Report.
gch-CrystalViewer:refresh.
gch-CrystalViewer:ViewReport.

Thanks,
Andrew.
 

xxxcapxxx

New Member
I am having the same trouble here.
I tried to acces via ado or generique xml. but the data won't refresh . Used to check all around on peg, and forums but can't found any information.

Using CR XI with OE 10.1b.

I am wondering where the report does store the data (doing it even if you uncheck "save data with report").

Any help would be much appreciated.
 

andrewt30

New Member
Hi, This takes me back a long time. I can't remember, or find the exact solution we came up with, but we did get it working in the end. The code we have is very similar to the example code I gave in my post. What I think must have been the issue is we do now remove and set to null the com handle for the report, where as before we just assumed that closing the screen would do this for us:-
release object chReport no-error.
chReport = ?.
If you try using an xml file as a datasource within Crystal Reports, and change the xml file whilst Crystal is still open, refreshing the data in Crystal doesn't pull through the changes you made to the xml file - the only way of getting Crystal to recognise the changes to the data is to shut it down and open it again (or change the filename), so I think this was the issue we were having with using the Activex Crystal Report viewer control.
Hope that helps. If not let m know and I'll have another look.
Andrew.
 

xxxcapxxx

New Member
If you try using an xml file as a datasource within Crystal Reports, and change the xml file whilst Crystal is still open, refreshing the data in Crystal doesn't pull through the changes you made to the xml file - the only way of getting Crystal to recognise the changes to the data is to shut it down and open it again (or change the filename), so I think this was the issue we were having with using the Activex Crystal Report viewer control.
Hope that helps. If not let m know and I'll have another look.
Andrew.

Thank you for the answer ;)

I kept investigating onto it and finally found out this too myself, in fact you don't need to shut down the CR instance, but need to log off the xml sheet (handled like a DB by CR). After that when trying to refresh CR will reconnect on the xml and see the data changed and make them effective in the report.

The weird thing is that i didn't found any valuable information about it. However it seems to me really important to know if you want to handle Xml and CR reports together.
 

Prajan

New Member
Hi
I was going all the discussions when i find this post. I have something that might help you.
Its a small part in the crystal report you are using.
Can you please open your crystal report manually and go to file. In file tab you will see "Save Data With Report". I think in your case its on. Please check off this button then you will get your report automatically refreshed.
May be it can help you

Prajan Shrestha
Nepal
 

xxxcapxxx

New Member
Alas, i already know that option, and it isn't about data being saved with the report but purely the db that won't be refreshed as long as you don't reopen a new viewer.

If you want to work with xml sheets you have to be sure that you don't keep the same viewer.

Thanks anyway for the help
 

adisney

New Member
Or do this (which works even if data is saved with the report):

define variable i as integer no-undo.
define variable sItem as character no-undo.
define variable sLoc as character no-undo.

...

chReport = chApplication:OpenReport("sample.rpt",1).
chReport:discardSavedData.

/* set tables */
do i = 1 to chReport:Database:Tables:Count:
sLoc = chReport:Database:Tables:Item(i):Location.
sItem = 'Local XML File=' + "sample.xml" +
';Local Schema File=' + "sample.xsd".
chReport:Database:Tables:Item(i):SetTableLocation(
sLoc,"",sItem).
end. /* loop through tables */

chViewer:ReportSource = chReport.
chViewer:Refresh.
chViewer:ViewReport.

Of course, "sample.rpt", "sample.xml", and "sample.xsd" can be replaced by variable names.
 
Top