How to generate a Crystal Report from a list of parameters - crystal-reports

My requirement is to generate a employee details report of multiple employees.Parameters for query will be employee number and a date range.
This is the record selection formula i'm using
{EMP_LEAVE_REPORT_VIEW.LEAVE_START_DATE} in {?sDate} to {?eDate}
and
(
Stringvar Array strings := Split({?empNoList}, "_");
Numbervar Array numbers;
Redim numbers[Ubound(strings)];
Numbervar i;
for i := 1 to Ubound(strings) do (
numbers[i] := ToNumber(strings[i]);
if {EMP_LEAVE_REPORT_VIEW.EMP_NO} = numbers[i] then
(true;)
else
(false;)
);
)
First i'm checking for the date.
Then i'm taking the employee list as a one string {?empNoList} eg: 5162_5468_5896_5236
and i'm splitting it to separate strings using "_" as the delimiter and assign those values again into a number array and using that value to filter the employee.
But this formula doesn't work.It gives the details of all the employees.
Is this a problem of the way i converted the string array or is there something wrong in the for loop of my code?
I used this code and tried assigning one employee number to the {?empNoList} and it worked.
if (ToNumber({?empNoList}) = {EMP_LEAVE_REPORT_VIEW.EMP_NO}) then true else false
Please help me out with this.Thanks in advance!

I found the solution!
Stringvar Array strings := Split({?empNoList}, "_"); //Spliting and saving the string in a string array
Numbervar Array numbers; //Creating a number array
Redim numbers[Ubound(strings)]; //Declaring number array size
Numbervar i;
//For loop to traverse through string and convert each into numbers and saving them in the numbers array
for i := 1 to Ubound(strings) do (
numbers[i] := ToNumber(strings[i]);
);
if({EMP_LEAVE_REPORT_VIEW.EMP_NO} in numbers) //If condition to check whether Employee number is in the numbers array
then
(true;)
else (false;)
It was a simple out of the box thinking ;)

1) Convert your EMP_LEAVE_REPORT_VIEW.EMP_NO to a string.
2) Then use the Like or In operator with {EMP_LEAVE_REPORT_VIEW.EMP_NO} and {?empNoList}
Simply, search the string version EMP_LEAVE_REPORT_VIEW.EMP_NO inside the bigger string {?empNoList}. You can avoid using the arrays.

Related

How to split data every n-th character and make it into array in crystal report

i want to split data to make it into array. so given for example: 12345678
i want to get string array like this => ["234","678"]
is it possible in crystal report?
Yes, it is possible. But the requirements are not clear.
Data type of input (string or Number?)
Logic: discard 1st character? Then, groups of 3 skipping the 4th character?
Here is formula code that takes "12345678" and returns "^234^678":
local stringvar myString := "12345678";
local stringvar myDelimitedString := "";
local numbervar StringLength := Len(myString);
local numbervar i;
For i := 1 to StringLength step 4 do
myDelimitedString := myDelimitedString + "^" + MID(myString, i+ 1, 3);
myDelimitedString;

How do I reset a string array variable

I have a report with 4 different arrays.
All are set up like this
shared stringvar array arr1 := split({client_relations.sales_value}, "&");
'';
I need them to reset for each group. How do I do that? I tried something like this
WhilePrintingRecords;
shared stringvar array arr1 := " ";
But I got an error saying the formula could not create an array.
Someone suggested to me I try:
WhilePrintingRecords;
shared stringvar array arr1 := "";
'';
And it worked
Create a new formula putting the below code in, calling it reset or something along those lines and place it in the group header.
StringVar Array arr1;
Redim arr1[0];
However, you will have to put any outputs in the group footer for this to work as it resets all data at the start of a new group.

A month number must be between 1 and 12, Error<Month>

Error in formula .
'Stringvar Array strings := Split({?#V2_month}, ",");'
A month number must be between 1 and 12.
Above is the error that i get, {?#V2_month} is my report parameter.
Month is my formula field
Below is the formula in the Month formula field
Stringvar Array strings := Split({?#V2_month}, ",");
Stringvar result := "" ;
//populate array
Numbervar i;
for i := 1 to Ubound(strings)
do (
result := result + MonthName(ToNumber(strings[i]) , true)+", " ;
);
MID(result , 1 , len(result) - 2);
Any idea why this formula prompt this kind of error?
I got the same error as yours. You forgot to add comma in your input values of the parameter ?#V2_month making it more than 12 or less than 1. Make sure the value you entered is comma separated and number between 1 and 12.

How to split a string and make an array of integers in crystal report

I have a string with set of employee IDs separated by an _(Underscore).
What i want to do is to split that into separate strings and convert them to integers and save them in an integer array.
Is this possible in Crystal Reports?
Is it possible to convert string into integer/number in Crystal Report?
I have tried using split function but still couldn't figure out how to use it to create an array.
I am very new to crystal report it would be a great help if you could help me out.
//create an array of strings by parsing a underscore-delimited string field
Stringvar Array strings := Split({table.string_field}, "_");
//empty numeric array; sized to match
Numbervar Array numbers;
Redim numbers[Ubound(strings)];
//populate array
Numbervar i;
for i := 1 to Ubound(strings) do (
numbers[i] := ToNumber(strings[i])
);
//return
numbers;
split is the correct function. i think it will probably be easiest to keep them as strings and then convert when you need to use them (otherwise you will simply have to loop through the string array and populate a new number array).
what trouble are you having with split? and what do you then intend to do with your array?

error at runtime setting the size of an array in crystal reports

I've got 2 arrays;
shared stringvar array dkrowarrray;
shared stringvar array newArray;
I know that the first array contains 10 elements.
When I try to set the value of newArray I get a runtime error (Error in formula deltakrow: 'shared stringvar array dkrowarray; ' An array's dimension must be an integer between 1 and 1000). I'm trying to set it like;
numbervar dkrowarraysize := count(dkrowarray);//I also tried ubound here.
redim newArray[dkrowarraysize];
When I prescribe the value like redim newArray[10]; then it runs OK, but the size of the array will need to change.
Why does crystal not like the int variable name between the square brackets?
You misspelled dkrowarrray/dkrowarray. This worked for me:
shared stringvar array dkrowarrray := ["1","2","3","4","5"];
shared stringvar array newArray;
//5
ubound(dkrowarrray);
//0
ubound(newArray);
//3 ('rrr') lower-case 'r' characters in the name
numbervar dkrowarraysize := ubound(dkrowarrray);
//5
redim newArray[dkrowarraysize];
//5
ubound(newArray);