crystal report problem - crystal-reports

what is the equivalant command like in vb for EOF(), MoveNext, Moveprevious commands in crystal reports

There are no equivalent answers in Crystal Reports, at least not in the versions I have used. Crystal Reports more or less simply dumps the data out into the report.
That said, if you are in a detail row, and you want to find out what the next value of a field will be, you can use:
next({YourColumn})
You can also find out the previous column value by using this:
previous({YourColumn})
Keep in mind that Next() won't work on the last record, and Previous() won't work on the first record.
I'll have to double-check, but I believe there is an OnLastRecord function that returns TRUE if you are on the last record.

First, welcome to SO!
Second, you sound new to Crystal Report's purpose is to display data, not perform the kind of calculations you're talking about. CR usually goes record-by-record through the data, displaying (or suppressing) each record, and adding group headers & footers.
To answer your question, LittleBobbyTables does give a few good pointers. To see the entire list of functions available to you, there is a list in the Formula Editor (see pic below). Press F1 for detailed descriptions of each command.
You can also:
Create a "Running Total Formula" that will evaluate each record and give a calculation in the group footer.
Do the calculations outside of Crystal Reports and only feed the end result in (perhaps with an unlinked join to your primary table).
The most complex option is to make a subreport that does the calculation and feeds the result back to the main report
Can you give us some more details about what you're trying to do?

Related

How to use Details band to display multiple data sets

I have a JasperReports's report with 10 rows fetched from the main query..
When i run the report it will show 10 rows without a problem.
Now when i add another band with fields of a data set in a list item. It is repeated for every record in the main report!. :(
How can i avoid this situation and change the second details band to print when the main report data has finished printing on the first band?
I would want to achieve this without going for sub-reports as it's difficult to maintain many files for a single report.
I have learned a lot on jasper reports over time and I'm posting the answer for my very own question to help someone in future.
What you need to do is for complex, Multi-query reports you create the main report with a simple query like this.
SELECT SYSDATE FROM DUAL
What this means is that when it's run main report details band will have a single iteration. That means if we have used the SYSDATE field in the details band it will print once.
OK, now if you follow the following steps you should be able to achieve the above task successfully.
Add two details band to the report (you must be having one details band by default, to add another right click --> add another detail band)
Add two data-sets to the main report (right click on the report and select Add Dataset)
Now all you need to do is use those two data sets in the previously created details bands by using either a list item or table item (personally I would recommend table as you can do lot of advanced stuff in that)
Hope this will help someone in the future. let me know if you need more help!. Cheers!!

Including a subreport into a GROUPING section

Crystal Reports: including a subreport into a grouping section?
asked the same question, but I am hoping a comment on the accepted answer is wrong: that it can't be done because the subreport must be in the details section. Also, what the selected answer says to do isn't working (perhaps because of the other detail, no pun intended).
So this looks like a duplicate question, yet the original question does not appear to be answered, and certainly the accepted "answer" is not usable by me.
(see also How to handle a duplicate question when the original has an accepted answer that is not really acceptable?)
My subreport can list one to many items, each of which can join to one or more items in the main report details. The common field they join on is the grouping item. So, for example, the subreport might have three items and the details five, but if I put it all in the details, I would have fifteen rows, with the first part repeated five times and the second part three times.
The common item appears as a "command field", a "report field". and the Group item. But no matter which of those I link as a subreport parameter, the subreport gets nothing and asks me to enter a value when I try to view the report.
In a more recent version of Crystal Reports you have two options: You can either connect the subreport to a value on the main report via the subreport parameter dialog. or you can pass a Shared Variable between the reports. If you are using the subreport parameter dialog, then the value passed in will be whatever that value is at the time the group is displayed. If the value comes from a detail in that group or from a variable on the main report it shoud pass fine. If the value is something that would be displayed after the group is displayed on the report (going top to bottom) then the value won't be written yet and will be passed to the report as null or blank.
Shared Variables are shared between a report and all of its subreports. If you need to get data from a subreport or pass a single value to multiple subreports, it might be the better option. If the shared variable is changed in the report or a subreport, it'll use the new value in everything after that.
SAP has a good guide on both techniques here:
http://scn.sap.com/people/ashish.bamzai/blog/2011/11/23/passing-values-between-reports-crystal-reports-2008
Bear in mind that Crystal Variables are always populated based on their position in the report and the order they are printed in. If something needs to happen after another group or subreport prints, you'll need to use the WhilePrintingRecords keyword.

Is there a way to get field names in a crystal report programmatically?

I have some big reports. What I need is the list of 'displayed' column names - not the actual fields(that I know how to get). Is there a way to get that info programmatically? I need to get them so end user can decide what columns can be deleted. I am using crystal report 8.5.
Thanks
This might be worth a shot. First, export the report's definition ('File' -> 'Export' -> 'Export Report' -> 'Format': Report Definition). That should kick out a text file with quite a bit of information about the report, including all the data fields referenced. You could write a simple script to parse the file and spit out all of these fields.
I've never tried this before, so your mileage may vary. One thing to think about is what you mean by "displayed" fields. Fields could not be directly displayed on the report, but be used to calculate formulas or summaries which are displayed. You'll need to think about this along with how your specific reports are written when writing your script.

How do I do a CR-type formula in SQL Server Reporting services?

In Crystal Reports, I could define a formula that would evaluate for each detail line. For example, if I had a query that would return a PatientId, an ObsTerm name, and an ObsTerm value, I could define a formula called {#Hispanic} that had the value:
If {Command.OBSNAME} = "HISPANIC" Then
{Command.OBSVALUE}
Else
" "
Then, in the group footer, I could take Maximum({#Hispanic}, {Command.PATIENTID}) to see if I had gotten a value returned for the patient's ethnicity - either I'd get the value (assume only one, since that's how I built the query) or a blank.
I'm trying to convert a CR report over to SSRS 2008R2: how would I do the above? Thanks.
Add a calculated field to your data source (called 'Hispanic' or whatever) with a formula of:
=IIF(Fields!OBSNAME.Value="Hispanic",Fields!OBSVALUE.Value,"")
In your report, add a parent group to your detail row and type [Max(Hispanic)] into a field in the group row. You may then want to hide the detail row and show only the aggregate data. I think there's probably a much easier way to do what you want but it's not clear from your question.
I made the transition from Crystal to SSRS and it is a hard road. You need to unlearn all your Crystal (especially formatting).

How can I hide an empty second in crystal reports?

I have several groupings in my report, and based on a formula, sometimes there are no rows displayed for the parent grouping. How can I hide the parent grouping if there are no rows displayed? I have SupressIfBlank set to true but that doesn't seem to do anything.
I'm a little rusty, so bear with me....
In the section properties for the group totals, there's a setting for "Suppress", and one of the options is a button that lets you write a formula (in the most recent version I used, this was blue if blank & red if there's a formula written). Click this, it'll take you to the Formula Editor. Write something that counts the rows and returns a Boolean: True for zero rows, False for non-zero.
According to this similar question I found on the Internet, it doesn't seem like CR has this functionality built in. The options presented there are as follows:
Restructure the report's queries so that group headers aren't returned if the detail records are missing. As in you push the formulas down into the queries themselves so that the headers are never returned.
Count the number of detail records on a per-header basis. So you make a formula for the header's suppress field, and suppress it if the detail count is 0.
Either of those should work with the majority of reports. Don't know the specifics of how to implement them, though.