Jump to content
We've recently updated our Privacy Statement, available here ×

Problem adding a subreport to a report


stig

Recommended Posts

Hello,

I am a complete newbie not only with regard to iReport but with Java programming and databases in general.

I have successfully created some simple reports based on a JRDataSourceProvider connection.

At this point, i am trying to include a subreport in a simple report but without any luck.

 

Procedure:

I create the master report (report A) which extracts fields from a single model via the JRDataSourceProvider connection. The master report contains a startdate field, an employee field and a currentliftedweight field. The info is grouped by employee.

I create a report (report B) which extracts fields from another model via the same connection. The report contains an employee maxallowedweight field.

Separately, I can run the two reports successfully. But when I try to add the subreport (report B) to the master (report B) and feed info to/from the subreport my luck seems to run out.

 

What I would like to happen is this:

The employee field from the master report should be fed to the subreport and thus determine which employee's value the subreport should show.

So the finished report should have 4 fields and a variable and look something like this (grouped by employee):

Startdate - employee - currentliftedweight - maxallowedweight - [variable showing the difference btw current and max weights]

 

I hope someone can help me out with some pointers. Please feel free to ask if you need info - I know that I am probably not easy to understand since I have absolutely no experience in these programming areas...

 

Thanks,

stig



Post Edited by stig at 11/06/2009 10:37



Post Edited by stig at 11/06/2009 10:38
Link to comment
Share on other sites

  • Replies 22
  • Created
  • Last Reply

Top Posters In This Topic

stig
Wrote:
 

The employee field from the master report should be fed to the subreport and thus determine which employee's value the subreport should show.

Hi, i've a few problem with english... sorry but my english is too scholastic...

do you mean "the emloyee FIELD"  of the master report SHOULD BE FED by a sub report variable/parameter

OR " EACH emloyee FIELD" SHOULD FEED the subreport dataset?

I'm rather new with iReport but in this month i worked a lot on it and so i try to help you.

 



Post Edited by giobby at 11/06/2009 10:56
Link to comment
Share on other sites

Hi giobby,

 

Thanks for replying, it is much appreciated!

 

I mean that for each employee listed in the master report, I want the subreport to show the maxallowedweight for that employee. The maxallowedweight must be passed on to the master report from the subreport based on the employee field in master report. As mentioned the master report is grouped by employee.

 

Example with three employees:

 

11/06/2009 (startdate) - John Smith (employee) - 125kg (currentliftedweight) - 300kg (maxallowedweight) - 175kg (variable showing diff)

11/06/2009 - Dave Olson - 200kg - 300kg - 100kg

11/06/2009 - Laura Brees - 100kg - 250 - 150kg

Link to comment
Share on other sites

well,

THEORICALLY we have to proceed in this way:

1- put the sub rpt in detail band

2-declare a variable in sub rpt that read the current  "maxallowedweight"  field (called for example "varMaxAllowedWeight")

3-declare a variable in main rpt (called for example "varMaxAllowedWeightFromSub")

4-in the main rpt go in the "sub rpt properties"  => "return values" and try to match theese two vars (setting subreport var with "varMaxAllowedWeight"  and destination var with "varMaxAllowedWeightFromSub")

5- dont' forget to set evaluationTime="Band" for the text field that shows the var.

6- the only problem is that i don't know if you want to display or not the dataset of the sub.

PRATICALLY i don't  if this works...

 

Anyway try to have a look at theese two threads:

a-  http://www.jasperforge.com/plugins/espforum/view.php?group_id=83&forumid=101&topicid=11402

b-  http://jasperforge.com/plugins/espforum/view.php?group_id=83&forumid=101&topicid=28040

the first it may help you to make the "difference operation" with a sub var;

the second helps you to clarify what i've written...

 

P.S. sorry for my english

 

Giovanni

...La puissance est rien sans controle...

 



Post Edited by giobby at 11/06/2009 13:10
Link to comment
Share on other sites

I am off for the weekend now - but I will return Monday and test out your suggestion.

Out of curiosity - does this suggestion also take into consideration that the value from the subreport should depend on which employee is shown in the master report?

 

Again, thanks so much for your time.

 

Have a great weekend :)

Link to comment
Share on other sites

when i said "PRATICALLY i don't know if this works" is properly for this reason...
i ever used this method with sub reports located in the summary band (that shows dataset only once)...
i'm really sorry but i'm a newbe too and i never dealt your situation...
I think we have to wait for another one's opinion.

have a great week-end you too.

 p.s. don't forget to post your results

 

Giovanni

...La puissance est rien sans controle...


 



Post Edited by giobby at 11/06/2009 13:40
Link to comment
Share on other sites

I just tried your suggestion, Giovanni, but without any luck - it won't show any data from the subreport in the master report. Thanks for your time and effort, though! :-)

 

Is there perhaps anyone else who can help me with my problem?

Link to comment
Share on other sites

hi stig, i've have only a curiosity:
have you already tried to make a simple example in wich you pass a var from subrpt to mainrpt and try to show it (naturally in the mainrpt)? it works?

ps:  for "simple example" i mean a rpt that contains a subrpt situated in the summary band.

 

Giovanni


 

...La puissance est rien sans controle...


 

 



Post Edited by giobby at 11/11/2009 12:15



Post Edited by giobby at 11/11/2009 12:17
Link to comment
Share on other sites

Hello again, Giovanni :-)

 

I have tried to make a very simple report with a subreport (actually I have tried to make several simple reports with subreports). But I could not get any of them to work.

As I mentioned, they work separately but as soon as I try to 'connect' them, the subreport shows no values in the main report :-(

Link to comment
Share on other sites

Hi Christina - thanks for helping!

 

I have tried to connect the main/sub reports by adding a parameter in the "Sub reports properties -> Parameters" field.

However, I am not sure that I have done this correctly, as I don't know the correct way to do it.

 

If we forget all the other fields in the report just to simplify my problem, what I want is basically this:

The main report should show a list of employees via the main report data source field "Employee".

The sub report should show the max allowed weight (via a MaxAllowedWeight field) for a given employee (if it is of any importance: in the subreport's datasource, the field that defines the employee is called "Id").

I would like the link between the two reports to be the Employee/Id, so that for each single employee in the main report, the subreport shows that employee's max weight.

 

Do you have any suggestion on how I can accomplish this?

Link to comment
Share on other sites

hi stig,

probably your problem is to link the subrpt because the intructions that i've post previously (in relationship with passing parameters from subrpts) work perfectly (at least in a simple context:-)).

try to follows theese steps:

Add the sub rpt in your mainrpt with drag'n drop option from the palette than follow the wizard intructions.

1 - don't forget to choose the option "use an existing report"

2 - check the option use the same conecction used by the mainrpt

3 - in the 3rd step you can see a parameters called (as default) "SUBREPORT_DIR"

4 - choose the relative(dynamic)/static subrpt dir path (for me the 1st one is better)

hope this help you bye

 

Giovanni

...La puissance est rien sans controle...

 

Link to comment
Share on other sites

Hi stig,

I don't know which version of iReport you are using. I use version 3.6.0. And if I left klick on a subreport in my main report, on the right side of my ireport window the properties of the subreport appear. In the properties there is an option 'parameters' (near the end of the list) if you open the window for that (use the 'three point button') you can see and set which subreport parameter should get which value (with button 'Add' you can add another parameter). In your case it would be 'Subreport parameter name' = id and 'Value Expression' $F{Employee}.

HTH

Christina.

Link to comment
Share on other sites

Hi again, Giovanni and Christina,

Sorry for the late response to your kind attempts to help.

 

Giovanni, I use the same method as you describe in #1-4, so I don't think these particular steps are where I mess things up. However, I think you are right that it is the link between the two reports that I am not establishing correctly.

 

Christina, when having setup the "Subreport parameter name/Value expression", should I set up anything the subreport so that it "connects" with the mainreport and only shows the max weight for the Employees listed in the mainreport?

 

Again, thanks for your time and effort!

Link to comment
Share on other sites

Hi stig,

how have you inserted the subreport into your main report? Have you drag and drop a subreport element out of the 'Report Elements' onto your report an followed the wizard? If not you have to set the connection type (in the subreport properties where you found the parameter settings) to 'Use a connection expression' and connection expression to '$P{REPORT_CONNECTION}' . So that the subreport knows which connection it should use to connect to the database.

HTH

Christina.

Link to comment
Share on other sites

Christina, I use the drag&drop wizard for subreports - and I also use connection expression $P{REPORT_CONNECTION}.

I have added the code for the two reports (reportmaster at the top and reportsub at the bottom). It's probably something very basic that I am missing due to my lack of java/report experience, so maybe you can deduce something from the code?

 

Code:
<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report4master" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">	<property name="ModelName" value="TimeHandlingWeightSpec"/>	<property name="ireport.scriptlethandling" value="0"/>	<property name="ireport.encoding" value="UTF-8"/>	<property name="FinderName" value="findAll"/>	<import value="net.sf.jasperreports.engine.*"/>	<import value="java.util.*"/>	<import value="net.sf.jasperreports.engine.data.*"/>	<parameter name="FieldLabelMap" class="java.util.Map" isForPrompting="false"/>	<parameter name="FinderDescription" class="java.lang.String" isForPrompting="false"/>	<parameter name="Title" class="java.lang.String" isForPrompting="false"/>	<parameter name="UserId" class="java.lang.String" isForPrompting="false"/>	<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">		<defaultValueExpression><![CDATA["C:\\Users\\stig.AXACONAD\\Desktop\\reports\\New Folder\\"]]></defaultValueExpression>	</parameter>	<queryString>		<![CDATA[]]>	</queryString>	<field name="Id" class="java.util.Date">		<fieldDescription><![CDATA[iD]]></fieldDescription>	</field>	<field name="WeightCoefficientId" class="java.lang.String">		<fieldDescription><![CDATA[Weight coefficient]]></fieldDescription>	</field>	<field name="WeightCoefficientTxt" class="java.lang.String">		<fieldDescription><![CDATA[Weight coefficient - text]]></fieldDescription>	</field>	<field name="WeightCoefficientValue" class="java.lang.String">		<fieldDescription><![CDATA[Weight coefficient - value]]></fieldDescription>	</field>	<field name="QtyAppliedTo" class="java.lang.Double">		<fieldDescription><![CDATA[Quantity the coefficient has been applied to]]></fieldDescription>	</field>	<field name="Contribution" class="java.lang.Double">		<fieldDescription><![CDATA[Contribution to weight]]></fieldDescription>	</field>	<field name="TimeHandlingId" class="java.lang.Integer">		<fieldDescription><![CDATA[Handling times ID]]></fieldDescription>	</field>	<field name="TimeStarted" class="java.util.Date">		<fieldDescription><![CDATA[start time]]></fieldDescription>	</field>	<field name="TimeFinished" class="java.util.Date">		<fieldDescription><![CDATA[End time]]></fieldDescription>	</field>	<field name="JobTypeId" class="java.lang.String">		<fieldDescription><![CDATA[Job type]]></fieldDescription>	</field>	<field name="JobGroupId" class="java.lang.String">		<fieldDescription><![CDATA[Job group]]></fieldDescription>	</field>	<field name="ProcessHistName" class="java.lang.String">		<fieldDescription><![CDATA[Pick round name]]></fieldDescription>	</field>	<field name="EmployeeId" class="java.lang.String">		<fieldDescription><![CDATA[Employee]]></fieldDescription>	</field>	<field name="ItemId" class="java.lang.String">		<fieldDescription><![CDATA[item]]></fieldDescription>	</field>	<field name="LocationId" class="java.lang.String">		<fieldDescription><![CDATA[Location]]></fieldDescription>	</field>	<field name="QtyAtLocationBeforeHandling" class="java.lang.Double">		<fieldDescription><![CDATA[Quantity on the location before handling]]></fieldDescription>	</field>	<background>		<band splitType="Stretch"/>	</background>	<pageHeader>		<band height="35" splitType="Stretch"/>	</pageHeader>	<columnHeader>		<band height="32" splitType="Stretch"/>	</columnHeader>	<detail>		<band height="80" splitType="Stretch">			<textField>				<reportElement x="0" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{EmployeeId}]]></textFieldExpression>			</textField>			<subreport>				<reportElement x="0" y="25" width="555" height="50"/>				<subreportParameter name="ID_PARAMETER">					<subreportParameterExpression><![CDATA[$F{EmployeeId}]]></subreportParameterExpression>				</subreportParameter>				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>				<subreportExpression class="java.lang.String"><![CDATA[$P{SUBREPORT_DIR} + "report4sub.jasper"]]></subreportExpression>			</subreport>		</band>	</detail>	<columnFooter>		<band height="36" splitType="Stretch"/>	</columnFooter>	<pageFooter>		<band height="34" splitType="Stretch"/>	</pageFooter>	<summary>		<band height="30" splitType="Stretch"/>	</summary></jasperReport>------------------------------------------------------------<?xml version="1.0" encoding="UTF-8"?><jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report4sub" pageWidth="400" pageHeight="842" columnWidth="400" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">	<property name="ModelName" value="Employee"/>	<property name="ireport.scriptlethandling" value="0"/>	<property name="ireport.encoding" value="UTF-8"/>	<property name="FinderName" value="findAll"/>	<import value="net.sf.jasperreports.engine.*"/>	<import value="java.util.*"/>	<import value="net.sf.jasperreports.engine.data.*"/>	<parameter name="FieldLabelMap" class="java.util.Map" isForPrompting="false"/>	<parameter name="FinderDescription" class="java.lang.String" isForPrompting="false"/>	<parameter name="Title" class="java.lang.String" isForPrompting="false"/>	<parameter name="UserId" class="java.lang.String" isForPrompting="false"/>	<parameter name="ID_PARAMETER" class="java.lang.String" isForPrompting="false"/>	<queryString>		<![CDATA[]]>	</queryString>	<field name="Id" class="java.lang.String">		<fieldDescription><![CDATA[iD]]></fieldDescription>	</field>	<field name="WeightPrDay" class="java.lang.Integer">		<fieldDescription><![CDATA[Max lift]]></fieldDescription>	</field>	<field name="BufferWeightPct" class="java.lang.Integer">		<fieldDescription><![CDATA[Light lifts at]]></fieldDescription>	</field>	<field name="Name" class="java.lang.String">		<fieldDescription><![CDATA[Name]]></fieldDescription>	</field>	<field name="Warehouse" class="java.lang.String">		<fieldDescription><![CDATA[Default warehouse]]></fieldDescription>	</field>	<field name="EmployeeType" class="java.lang.String">		<fieldDescription><![CDATA[Type]]></fieldDescription>	</field>	<field name="WeightGender" class="java.lang.String">		<fieldDescription><![CDATA[Gender]]></fieldDescription>	</field>	<field name="WeightAge" class="java.lang.String">		<fieldDescription><![CDATA[Age]]></fieldDescription>	</field>	<field name="WeightHeight" class="java.lang.String">		<fieldDescription><![CDATA[Height]]></fieldDescription>	</field>	<field name="HandlingTypes" class="java.util.HashSet">		<fieldDescription><![CDATA[Allowed handling types]]></fieldDescription>	</field>	<field name="DispatchCodes" class="java.util.HashSet">		<fieldDescription><![CDATA[Dispatch codes]]></fieldDescription>	</field>	<field name="PickGroups" class="java.util.HashSet">		<fieldDescription><![CDATA[Allowed job groups]]></fieldDescription>	</field>	<field name="HandlingUnit" class="java.lang.String">		<fieldDescription><![CDATA[Handling unit]]></fieldDescription>	</field>	<field name="Owner" class="java.lang.String">		<fieldDescription><![CDATA[Default owner]]></fieldDescription>	</field>	<field name="CurrentPickRound" class="java.lang.String">		<fieldDescription><![CDATA[Current pick round]]></fieldDescription>	</field>	<field name="ReserveSpaceLocationPrefix" class="java.lang.String">		<fieldDescription><![CDATA[Location prefix on space reservation]]></fieldDescription>	</field>	<field name="CompanyId" class="java.lang.Integer">		<fieldDescription><![CDATA[Company ID]]></fieldDescription>	</field>	<field name="UserId" class="java.lang.String">		<fieldDescription><![CDATA[user ID]]></fieldDescription>	</field>	<field name="CompanyName" class="java.lang.String">		<fieldDescription><![CDATA[Company name]]></fieldDescription>	</field>	<field name="RemainingDayWithinHorizon" class="java.lang.Boolean">		<fieldDescription><![CDATA[Rest of day within horizon]]></fieldDescription>	</field>	<field name="HoursWithinHorizon" class="java.lang.Integer">		<fieldDescription><![CDATA[Hours within horizon]]></fieldDescription>	</field>	<field name="CurrentDayInMemory" class="java.lang.Boolean">		<fieldDescription><![CDATA[Current day in memory]]></fieldDescription>	</field>	<field name="HoursInMemory" class="java.lang.Integer">		<fieldDescription><![CDATA[Hours in memory]]></fieldDescription>	</field>	<field name="HorizonEnabled" class="java.lang.Boolean">		<fieldDescription><![CDATA[Horizon activated]]></fieldDescription>	</field>	<field name="MemoryEnabled" class="java.lang.Boolean">		<fieldDescription><![CDATA[Memory activated]]></fieldDescription>	</field>	<field name="ViewName" class="java.lang.String">		<fieldDescription><![CDATA[View name - postfix]]></fieldDescription>	</field>	<field name="WeightCoefficientAge" class="java.lang.String">		<fieldDescription><![CDATA[Weight coefficient for age]]></fieldDescription>	</field>	<field name="WeightCoefficientHeight" class="java.lang.String">		<fieldDescription><![CDATA[Weight coefficient for height]]></fieldDescription>	</field>	<field name="Gender" class="java.lang.String">		<fieldDescription><![CDATA[Gender]]></fieldDescription>	</field>	<field name="MaxWeightInMemory" class="java.lang.Double">		<fieldDescription><![CDATA[Max weight in memory]]></fieldDescription>	</field>	<field name="InspectionRatio" class="java.lang.Double">		<fieldDescription><![CDATA[inspection ratio]]></fieldDescription>	</field>	<variable name="variable1" class="java.lang.String">		<variableExpression><![CDATA[$F{Id}]]></variableExpression>	</variable>	<background>		<band splitType="Stretch"/>	</background>	<columnHeader>		<band height="38" splitType="Stretch"/>	</columnHeader>	<detail>		<band height="53" splitType="Stretch">			<textField>				<reportElement x="0" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.String"><![CDATA[$F{Id}]]></textFieldExpression>			</textField>			<textField>				<reportElement x="140" y="0" width="100" height="20"/>				<textElement/>				<textFieldExpression class="java.lang.Double"><![CDATA[$F{MaxWeightInMemory}]]></textFieldExpression>			</textField>		</band>	</detail>	<pageFooter>		<band height="33" splitType="Stretch"/>	</pageFooter></jasperReport>
Link to comment
Share on other sites

hi Stig i've  tried to create the rpt by the xml code that you've posted and it works (two times to be sure)

the only 2 changes that i've done are

1-  to set, in the sub rpt, the property "when no datas prints..."  with the value: " all sections without details".

2- to put the sub rpt in the summary band

anyway i send you the 2 jrxml file and dont' forget to change the expression of subreport_dir  param with your path

(that was "C:\Users\stig.AXACONAD\Desktop\reports\New Folder\")

ps: in the sample.zip there is the report create by your xml code, in the other one the same thing but with the insertion of subrpt created from scratch 

 ps2: i've put the subrpt in the summary band because when there are no datas the details band doesn't show nothing..

hope this help you, bye :-)

 

 

 



 

Giovanni

...La puissance est rien sans controle...

 



Post Edited by giobby at 11/23/2009 07:16
Link to comment
Share on other sites

Hey Giovanni - thanks for not giving up on me :)

 

I've tried to implement your attachments (including changing the paths to fit my local computer folders). Other than that, I've used your exact versions.

The experiment was a partial success.

It was a success in that I can now, in the main report, see the "Sub rpt showed" headline from the subreport.

The not-so-successful part, however, is that, in the main report, I still cannot see any of the actual subreport data besides the mentioned headline (even though when running the subreport in itself, there is data in it).

Any idea what could cause this lack of data?

 

I have attached a couple of screenshots of the mainreport result (report1.PNG) and the data that the subreport shows in itself (report2.PNG).

Link to comment
Share on other sites

i didn't unterstand that you're working with JRDataSourceProvider... this is another thing!

i'm working in theese weeks on theese kind of data source but not on iReport (that i use only to read the fields from the dataSourceProvider and to pass the relative sub rpt already filled ) but with java app.

I can help you only in this case... sorry

 

Giovanni

...La puissance est rien sans controle...

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...