News, Events, Conferences, What's New About, Partners, Jobs Phone, E-mail, Address, Location Free Evaluation


home
products
product videos
customer support


Resources
Frequently Asked Questions

Subreport Management: includes logon, changing data sources and parameters

Download PDF version of this faq: Subreports.pdf
FAQ# 26-05310203

Every sub report conceptually is a report within the original main report and once you have a sub report, you need to work with it or any of its aspects just as if it were a standard Report object. You can manipulate sub reports in the exact same ways that you can manipulate reports.

There are two ways of accessing a sub report. You can either access it:
Directly by sub report name

or

Through the GetNSubreportsInSection () and GetNthSubreportInSection () methods in the PCREJob class.

PCREJob.GetNthSubreportInSection() does not actually retrieve the Nth sub report but rather the Nth subreport’s information, including the subreport's name, which you can then use to open the subreport using PCREEngine.OpenSubreport () method.

Once you are done configuring the sub report, call CloseSubReport() on the sub report PCREJob. This method has no effect on PCREJobs that do not represent sub reports. Also, sub reports cannot be run as separate reports from their parent.

Changing the data sources at run-time in a main report and in sub reports.
How to generate a parameter report that also has linked sub reports.

The following code sample demonstrates how to:

  1. Identify the sub reports in a main report
  2. Set the logon info for tables in main report and sub reports at run-time (in a single loop)
  3. Set the parameters in report.

Download the Java Code Sample and report (.rpt) files.
Download the ASP Code Sample and report (.rpt) files.

The main report used for this code sample namely Dyna_mainReport.rpt uses data from a single table - "Customers" and has a sub report linked by a parameter "city". The sub report uses data from a table called "Orders" from the same database as Customers table.

Please note that in the code sample by setting propagate to True in PCREJob.SetNthTableLogOnInfo() method, the logon info will be applied to all other tables in the same Database in the main report but not for tables in the sub report. Sub reports need to be processed separately from the main report.

Java Code Sample:
import com.mobileapps.pcre.*;
class subReportTest
{
public static void main(String [] args)
{
try
{
PCREApplicationClient client=null;
client=new PCREApplicationClient("lakshmi");
client.Connect();
PCREEngine engine=client.OpenEngine();
PCREJob job=engine.OpenJob("C:\\subreporttest\\Dyna_MainReport.rpt");

//Create new logon info
PCRELogOnInfo logonInfo;
logonInfo = job.GetNthTableLogOnInfo(0);
logonInfo.ServerName = "MSSQLTEST";
logonInfo.DatabaseName = "DevNorthwind";
logonInfo.UserID = "TestDev";
logonInfo.Password = "TestDev";

//logon to the server here
boolean logOnStatus = engine.LogOnServer ("p2ssql.dll", logonInfo);
if (logOnStatus)
System.out.println("Log on succeeded");
Else
System.out.println("Log on failed");

//Propagate is set to true to tell the server to try to use this logon
//information for the other tables in the main report that use the same
//database but not tables in subreports
job.SetNthTableLogOnInfo(0,logonInfo,true);

//Logon for subreports
int numSections = job.GetNSections();
for(int i=0;i<numSections;i++){
int sectionCode = job.GetSectionCode(i);
int numSubReports = job.GetNSubreportsInSection(sectionCode);
for(int j=0;j<numSubReports;j++) {
PCRESubreportInfo subInfo = job.GetNthSubreportInSection(sectionCode,j);
PCREJob subReport = engine.OpenSubreport(job,subInfo.name);
PCRELogOnInfo sLogonInfo=new PCRELogOnInfo();
sLogonInfo.ServerName = "MSSQLTEST";
sLogonInfo.DatabaseName = "ProdNorthwind";
sLogonInfo.UserID = "ProdTest";
sLogonInfo.Password = "ProdTest";
subReport.SetNthTableLogOnInfo (0,logonInfo,true);
subReport.CloseSubreport(subReport);
}
}
//set parameter in main report
PCREValueInfo valueInfo = new PCREValueInfo();
valueInfo.viString("Berlin");
job.AddParameterCurrentValue("City","",valueInfo);
job.OutputToPDF("C:\\subreporttest\\ReportOutput.pdf",null);
job.Start();
job.Close();
engine.Close();
client.Quit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

ASP Code Sample:
<%
Set objClient = Server.CreateObject("PCRE.PCREApplicationClient")
Set objGateway = objClient.getGateway
objGateway.SetHost "lakshmi"
objClient.Connect
Set objEngine = objClient.OpenEngine
Set job =objEngine.OpenJob("C:\Inetpub\wwwroot\Subreportwithparamtest\Dyna_MainReport.rpt")

'Create new logon info
set logOnInfo = Server.CreateObject("PCRE.PCRELogOnInfo")
logOnInfo.ServerName = "MSSQLTEST"
logOnInfo.DatabaseName = "ProdNorthwind"
logOnInfo.UserID = "ProdTest"
logOnInfo.Password = "ProdTest"

'logon to the server here
logOnStatus = objEngine.LogOnServer ("p2ssql.dll", logOnInfo)

If (logOnStatus)Then
Response.write("Log on succeeded")
Else
Response.write("Log on failed")
End If

'Propagate is set to true to tell the server to try to use this logon information
'for other tables in the main report that are in the same database but not for
'tables in subreports

call job.SetNthTableLogOnInfo (0,logonInfo,true)

'Logon for suberports
numSections = job.GetNSections()
for i = 0 to numSections-1
section = job.GetSectionCode(i)
numSubReports = job.GetNSubreportsInSection(section)
for j = 0 to numSubReports-1
Dim subInfo
set subInfo = job.GetNthSubreportInSection(section, j)
Dim subReport
set subReport = objEngine.OpenSubreport(job, subInfo.name)
set info = Server.CreateObject("PCRE.PCRELogOnInfo")
info.ServerName = "MSSQLTEST"
info.DatabaseName = "ProdNorthwind"
info.UserID = "ProdTest"
info.Password = "ProdTest"
call subReport.SetNthTableLogOnInfo (0,info,true)
subReport.CloseSubreport(subReport)
Next
Next

' set parameter in main report
set ValueInfo = Server.CreateObject("PCRE.PCREValueInfo")
ValueInfo.viString "Berlin"
job.AddParameterCurrentValue "City","",ValueInfo
job.OutputToPdf "C:\Inetpub\wwwroot\Subreportwithparamtest\subreporttest.pdf", null
job.Start
job.Close
objengine.Close
objclient.Quit
Set job = Nothing
Set objengine = Nothing
Set objclient = Nothing

%>

BACK TO TOP
BACK TO START

© 2000-2005 Dynalivery Corporation
formerly Mobile Application Servers, Inc.