Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Add date shared variable as parameter Post Reply Post New Topic
Page  of 4 Next >>
Author Message
pto160
Newbie
Newbie


Joined: 13 May 2009
Location: United States
Online Status: Offline
Posts: 16
Quote pto160 Replybullet Topic: Add date shared variable as parameter
    Posted: 13 May 2009 at 11:54am
I have a date value shared variable. I have an inventory forecasting report that calculates an out of stock date in Crystal Reports X1. The parameter would ask you the date. I would put in 6/1/09. The report would show only dates equal to or less than this date on the report. Is there a way to do this?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 13 May 2009 at 8:07pm
If you are asking how to create a user entered parameter that can be used in a select statement...
Right Click on Parameters and select New.
Enter a parameter name, we'll call it "Date" here.
Choose the field data type of Date.
Save and close it.
In the Select Expert enter your formula using your new parameter:
{table.datefield}<={?Date}


Edited by DBlank - 13 May 2009 at 8:09pm
IP IP Logged
pto160
Newbie
Newbie


Joined: 13 May 2009
Location: United States
Online Status: Offline
Posts: 16
Quote pto160 Replybullet Posted: 14 May 2009 at 8:24am
Thanks. The out of stock date shared variable is not a field in the database. It is a calculated formula.
Will this method still work or do I have to somehow share it with the main report?

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 May 2009 at 8:43am
Depends on how and where it is calculated.
What is the formula?
IP IP Logged
pto160
Newbie
Newbie


Joined: 13 May 2009
Location: United States
Online Status: Offline
Posts: 16
Quote pto160 Replybullet Posted: 14 May 2009 at 8:54am
The formula is in a sub report called Shipped Qty. The formula is as follows:

DateVar ReturnDate;
if {@Monthly Forecast}=-1 then ReturnDate:= Date (2099,12 ,31 );
if {@Monthly Forecast} <> -1 then
(Shared dateTimeVar Shared_Out_of_Stock_Date :=CurrentDateTime + {@Monthly Forecast} ;
ReturnDate:=Date( CurrentDateTime + {@Monthly Forecast}));
ReturnDate

The Shared_Out_of_Stock_Date is the variable. I need to get this as the parameter. 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 14 May 2009 at 9:07am
Variables are not my forte but lockwelle will correct me if I am wrong here...
It appears you are not using this parameter date in the main report, only the sub report.
You can create the parameter in the main report without placing it in your select statement.
When you create your "Shared_Out_of_Stock_Date variable" jsut set it to  = {?date} parameter.
 
If this does not set it to ask for the parameter at run time just drop the {?Date} parameter field in your main report report header and suppress it.
 


Edited by DBlank - 14 May 2009 at 9:20am
IP IP Logged
pto160
Newbie
Newbie


Joined: 13 May 2009
Location: United States
Online Status: Offline
Posts: 16
Quote pto160 Replybullet Posted: 14 May 2009 at 11:39am
I will try that and see what happens. 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 15 May 2009 at 11:06am
Sorry, I don't usually look at items that DBlank has answered as they correct and there is nothing for me to add...had some time and the title intrigued me.
 
I am a bit confused by how things are being used.  I understand that you are entering a date and you want all the items that will be projected to be out of stock on or before that date.  I think I have that right.
 
You have a formula in a subreport that does a calculation, but that is not real clear.  Is this what you were getting at:
local DateVar ReturnDate := Date (2099,12 ,31 );
Shared dateTimeVar Shared_Out_of_Stock_Date := ReturnDate;
if {@Monthly Forecast} <> -1 then(
 Shared_Out_of_Stock_Date := CurrentDateTime + {@Monthly Forecast} ;
 ReturnDate:=Date( CurrentDateTime + {@Monthly Forecast}));
);
ReturnDate
Either way, you have this shared variable Shared_Out_of_Stock_Date being set in the subreport.  Here comes the big question...can you see this subreport?  Does the subreport do more than this, and if this item is to be 'in stock' should it be displayed?
 
why do I ask?  You are going to want to suppress something (and possibly this subreport) in the main report based on the variable Shared_Out_of_Stock_Date, and if you need to run the subreport before you can suppress the subreport, you are in a catch-22.  If the subreport is already suppressed, then life might be easier, depending on how the report is displayed, but as DBlank said, it doesn't appear that you are looking at the variable, you created it and set a value, but now what...
 
In the main report, create another formula:
shared datevar Shared_Out_of_Stock_Date;
 
this will display the results of the shared variable.  you can use it in suppression formula for a row, a field, or whatever you want to do with it.  Just remember that Crystal basically reads a report from top to bottom stopping to read subreports, so if the subreport is after the line you want to hide, you will have problems.
 
As always, if you got the data via a stored proc, you wouldn't need this as you could suppress the records from every making it to your report and the need of a subreport would go away...they are impose a lot more data reads to the database...1 is enough in the vast majority of instances...but the number of rows + 1 can really the impede the performance of your report.
 
Hope this made sense.
IP IP Logged
pto160
Newbie
Newbie


Joined: 13 May 2009
Location: United States
Online Status: Offline
Posts: 16
Quote pto160 Replybullet Posted: 15 May 2009 at 11:53am
Thanks. So if I add the shared variable to the main report, I can then create s user input parameter? The shared variable is displayed on the subreport.
I will try this and see if that works.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 15 May 2009 at 1:09pm
you would have already wanted to have a user parameter.  The parameter is available through the report.  Yes, the shared variables are available in both the main report and the subreport...global variables do not cross the boundary between shared and main.
IP IP Logged
Page  of 4 Next >>
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.