cancel
Showing results for 
Search instead for 
Did you mean: 

Assign Subreport parameters

Former Member
0 Kudos

Hi all,

I have a java program which fill in the table and parameter fields in the crystal report :

private static void setDatabaseControllerResultSet(Database db, DatabaseController databaseController, String pdfid, ReportClientDocument reportDocument)

throws Exception {

int n = databaseController.getDatabase().getTables().size();

if (n>2)

{

mLogger.error("Crystal Report with " + n + " tables is not supported.");

throw new Exception("Not supported");

}

// Set main table

String query = "Select * from " + (pdfid);

PreparedStatement statement = db.getConnection().prepareStatement(query,

ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

String tableAlias = databaseController.getDatabase().getTables().getTable(0).getAlias();

ResultSet resultSet = statement .executeQuery();

databaseController.setDataSource(resultSet , tableAlias , "resultsetTable ");

}

private static void setParameterFields(Database db, ParameterFieldController ctrl, String pdfid)

throws Exception

{

String query = "SELECT * from " + (pdfid) + "_param";

PreparedStatement stmt = null;

try {

stmt = db.getConnection().prepareStatement(query, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

} catch (SQLException e) {

if (e.getErrorCode() == 2117)

{

mLogger.info("Table (" + pdfid + "_param) does not exist, no parameter field is set.");

return;

}

mLogger.error("SQL err: (" + e.getErrorCode() + ") " + e.toString());

throw e;

}

ResultSet rs = stmt.executeQuery();

for (boolean rv=rs.first(); rv; rv=rs.next())

{

String param = rs.getString(1);

String type = rs.getString(2);

/* Set parameter fields by type, default is String */

if (type.equalsIgnoreCase("Integer"))

ctrl.setCurrentValue("", param, rs.getInt(3));

else if (type.equalsIgnoreCase("Short"))

ctrl.setCurrentValue("", param, rs.getShort(3));

else if (type.equalsIgnoreCase("Float"))

ctrl.setCurrentValue("", param, rs.getDouble(3));

else if (type.equalsIgnoreCase("Date"))

ctrl.setCurrentValue("", param, rs.getDate(3));

else

ctrl.setCurrentValue("", param, rs.getString(3));

}

}

The program work fine but now i need to add the sub-report in my .rpt file, could anyone guide me hwo to modify the function so that it can assign the parameters into the sub-report? thx!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you could add sub report through RAS SDK, here is the code snippet:

ReportClientDocument oReportClientDocument;
    IReportAppFactory oReportAppFactory;
    IInfoObjects oInfoObjects=null;
	IInfoObject oInfoObject=null;
	String reportName = "SimpleRCAPIReport.rpt";
    
    // Retrieve report to be modified
    oInfoObjects = iStore.query("Select * from CI_INFOOBJECTS where SI_PROGID = 'CrystalEnterprise.Report' and SI_INSTANCE = 0 and SI_NAME = '" + reportName + "'");
	oReportAppFactory = (IReportAppFactory)es.getService("", "RASReportService");
	oReportClientDocument = oReportAppFactory.openDocument((IInfoObject)oInfoObjects.get(0), 0, java.util.Locale.ENGLISH);
	
	// First determine the section to add the subreport to - in this case the report header section
	ISection sectionToAddTo = oReportClientDocument.getReportDefController().getReportDefinition().getReportHeaderArea().getSections().getSection(0);

	// When adding a new subreport (as opposed to importing), you need to leave the ReportURL property blank
	
	// Set the name of the new sub-report
	String subRptName = "testSub";
    ISubreportClientDocument subRpt = oReportClientDocument.getSubreportController().importSubreport(subRptName, "", sectionToAddTo, 0,0,8640,720);

    // If you try to add a sub-report to a section that is smaller than the dimensions you give the sub-report, you will get an error of 
    // "Invalid section height" error when you try to add sub-report links to the sub-report database tables.
    	
	// Now display the report
   session.setAttribute("reportSource", oReportClientDocument.getReportSource());
  

you could find the sample codes here:- [http://www.sdn.sap.com/irj/boc/samples?rid=/webcontent/uuid/f0aea666-5384-2b10-ffb0-a6facef1d5e5|http://www.sdn.sap.com/irj/boc/samples?rid=/webcontent/uuid/f0aea666-5384-2b10-ffb0-a6facef1d5e5]

let me know if this helps,

Regards,

Rameez.

Answers (1)

Answers (1)

Former Member
0 Kudos

Thanks for yr help... when i look into the report detail, i found that :

1. in the subreport, i have some "link parameters" which link up with the main report.

2. in the subreport, it was included another data table , which didn't use in the main report.

And i want to ask, for 1), is that i need to assign the parameters into subreport or it can auto grep the value from main report?

for 2), how I can assign the data table to subreport only?, i tried the following code and not sure it correct or not... thx

String subReportName = "sub-report";

SubreportController boSubreportController = reportDocument.getSubreportController();

ISubreportClientDocument boSubReportClientDocument = new ISubreportClientDocument();

boSubReportClientDocument = boSubreportController.getSubreport(subReportName);

...

Former Member
0 Kudos

Hi,

It depends whether you are using Linked or Unlinked Subreport,that the parameters from main report are passed.

You can have a different datasource for your sub reports when you are using an Unlinked subreport.

While using linked subreport ,the main report and the subreport should have a link field.

Let me know if you need more info on this.

Regards,

Prithvi