cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Parameters to Procedure based sub report thru JRC

Former Member
0 Kudos

Hi

I am using storedprocedure based main report with a subreport and i am trying to invoke these reports with JRC.

I am passing parameters to main report then it is asking parameters for subreport then i placed following statement by placing subreport name

param2.setReportName("detailed_aging_report_wk.rpt");

but after using this statement it is prompting for main report parameters.

How i can pass the same parameter values to both main and sub reports?

Thankyou.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Here is a snippet code that demonstrates how to pass a parameter to a subreport, you can accommodate it and test it and see if you still have the same behaviour. What you need to do is to add the code to set the parameter of the main report.

<%

/* Applies to: XI
* Date Created: April 4, 2005
* Description:	This sample demonstrates how to pass parameters to a report that 
*				contains a subreport using the Crystal Reports Java 
*				Reporting Component (JRC) SDK.         
* Author: HP, CW
*/


try {

	//check to see if the report source already exists
	Object reportSource = session.getAttribute("reportSource");
  
 	//if the report source has not been opened
	if (reportSource == null)
	{
		//---------- Create a ReportClientDocument -------------
		ReportClientDocument oReportClientDocument = new ReportClientDocument();

		//---------- Set the path to the location of the report soruce -------------

		//Open report.
		oReportClientDocument.open("jrc_set_subreport_parameters/jrc_set_subreport_parameters.rpt", 0);

		//Get the report source
		reportSource = oReportClientDocument.getReportSource();

		//Cache report source.  
		//This will be used by the viewer to display the desired report.
		session.setAttribute("reportSource", reportSource);
	}

	//---------- Create the Parameter Field Objects -------------

    //Create a Fields collection object to store the parameter fields in.
    Fields oFields = new Fields();
 
    //----------- Initialize the parameter fields ----------

    //Set the name and value for each parameter field that is added.
    //Values for parameter fields are represented by a ParameterFieldDiscreteValue 
    //or ParameterFieldRangeValue object.

    //NOTE: Be sure to map the names of the parameters and their 
    //respective types against the correct type that the parameter 
    //field values was defined to accept in Crystal Reports.

    //NUMBER VALUE PARAMETER.  
    Integer numberValue = new Integer("55");
    
    //STRING VALUE PARAMETER.
    String stringValue = "String parameter value.";
    
    //BOOLEAN VALUE PARAMETER.
    Boolean booleanValue = new Boolean("true");
    
    //DATE VALUE PARAMETER.
    Calendar calendar = Calendar.getInstance();
    calendar.set(2004, 1, 17);
    Date dateParamVal = calendar.getTime();
    
    //DATE-TIME VALUE PARAMETER.
    Calendar calendar2 = Calendar.getInstance();
    calendar2.set(2002, 5, 12, 8, 23, 15);
    Date dateTimeParamVal = calendar2.getTime();
    
    //CURRENCY VALUE PARAMETER.
    Double currParamVal = new Double(555.99);
    
    //TIME VALUE PARAMETER.
    Calendar calendar3 = Calendar.getInstance();
    calendar3.set(2002, 5, 12, 13, 44, 59);
    Date timeParamVal = calendar3.getTime();
    
    //Set all of the parameter values using the utility function. 

	//Since we are passing parameters to the subreport, it is here that we set the
	//subreport name; if you are not passing a parameters to a subreport, the 
	//report name will be an empty string
	setDiscreteParameterValue(oFields, "NumberParam", "SubreportA", numberValue);
    setDiscreteParameterValue(oFields, "StringParam", "SubreportA", stringValue);
    setDiscreteParameterValue(oFields, "BooleanParam", "SubreportA", booleanValue);
    setDiscreteParameterValue(oFields, "DateParam", "SubreportA", dateParamVal);
    setDiscreteParameterValue(oFields, "DateTimeParam", "SubreportA", dateTimeParamVal);
    setDiscreteParameterValue(oFields, "CurrencyParam", "SubreportA", currParamVal);
    setDiscreteParameterValue(oFields, "TimeParam", "SubreportA", timeParamVal);
    
    //Push Fields collection into session so it can be retrieved by the viewer and set
    //at view time.
    session.setAttribute("parameterFields", oFields);  
        
	//Redirect to the viewer page to render the report
	response.sendRedirect("CrystalReportViewer.jsp");
	
}
catch(ReportSDKException sdkEx) {
	out.println(sdkEx);
}
%>

<%!
/*
 * Utility function to set values for the discrete parameters in the report.  The report parameter value is set
 * and added to the Fields collection, which can then be passed to the viewer so that the user is not prompted
 * for parameter values.  
 */
private void setDiscreteParameterValue(Fields oFields, String paramName, String reportName, Object value) {
	
	//Create a ParameterField object for each field that you wish to set.  
    ParameterField oParameterField = new ParameterField();

    //You must set the report name. 
    //Set the report name to an empty string if your report does not contain a
    //subreport; otherwise, the report name will be the name of the subreport
    oParameterField.setReportName(reportName);

    //Create a Values object and a ParameterFieldDiscreteValue object for each 
    //object for each parameter field you wish to set.
    //If a ranged value is being set, a ParameterFieldRangeValue object should 
    //be used instead of the discrete value object.
    Values oValues = new Values();
    ParameterFieldDiscreteValue oParameterFieldDiscreteValue = new ParameterFieldDiscreteValue();
    
    //Set the name of the parameter.  This must match the name of the parameter as defined in the
    //report.
    oParameterField.setName(paramName);
    oParameterFieldDiscreteValue.setValue(value);

    //Add the parameter field values to the Values collection object.
    oValues.add(oParameterFieldDiscreteValue);

    //Set the current Values collection for each parameter field.
    oParameterField.setCurrentValues(oValues);

    //Add parameter field to the Fields collection.  This object is then passed to the
    //viewer as the collection of parameter fields values set. 
    oFields.add(oParameterField);
        
}
%>

Cheers

ted_ueda
Employee
Employee
0 Kudos

So are you passing parameters to both the main and subreport?

Sincerely,

Ted Ueda