Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Include program variable in birt sql query
dome
Hi all,<br />
<br />
i want to include extern parameter for creating a different sql query.<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
public void executeReport(int typ , String[] parameter) throws EngineException
{
IReportEngine engine = null;
EngineConfig config = null;
try
{
String sProgrammpfad = new String();
sProgrammpfad = "c:/temp/test/";
String sDateiname = new String();
sDateiname = "test.pdf";
String sReportverzeichnis = new String();
sReportverzeichnis = "C:/Programme/eclipse/workspace/Birt_Converter/";
String sReportDatei = new String();
//Erstellen der Reports je nach typ
switch(typ)
{
case 0: sReportDatei = "rep_para.rptdesign";
break;
//typ > 0 sind die Standardreports
case 1: sReportDatei = "rep1.rptdesign";
break;
case 2: sReportDatei = "rep2.rptdesign";
break;
default: sReportDatei = "rep1.rptdesign";
break;
}//[...]
</pre>
<br />
How can i work with the parameter which i get from the porgam?<br />
I want to use this parameter in a special report rptdesign-document.<br />
<br />
Hope you understand my problem.<br />
<br />
<br />
greetings<br />
dome
Find more posts tagged with
Comments
CBR
Hi,<br />
<br />
you have different options:<br />
<br />
1) Add a report parameter to this report and set the parameter in from your program. Let's say the report parameter is called external and is of type integer:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
IRunAndRenderTask task = ...
HashMap<String, Object> myParams = new HashMap<String, Object>();
myParams.put("external", new Integer(1));
task.setParameterValues(myParams);
task.run(...)
...
</pre>
<br />
2) You don't want to use parameters. In that case you can use the application context object.<br />
The application context is a java.util.HashMap that is injected into each report before running it.<br />
inside your report you can get that HashMap by using this snippet of Rhino code:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
var map = reportContext.getAppContext();
var value = map.get("xy")
</pre>
<br />
You can add values to the appContext from your program using:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
IRunAndRenderTask task = ...
task.getAppContext().put("xy", new Integer(1));
task.run(...)
...
</pre>
the getAppContext method exists for all Tasks where you can only set parameters in Run pahse (therefore the setParameters method only exists for Run and RunAndRender Task)
CBR
also keep in mind that the creation of a IReportEngine object is a very time consuming thing. In addition the first report takes quite a while because it initializes all the components. If you plan to generate a bunch of reports better cache the IReportEngine object and keep reusing it (it is thread safe)