Pages

Tuesday, October 12, 2010

creating jasper sub-report using iReport

creating a sub-report example with Jasper

Pre-requisite: I assume that you know how to create normal reports using iReport GUI tool also basic knowledge of database, sql with MySql.

before we start with actual creating of report lets understand the database that we require.
following is the table structure that we require.

I have taken the sample database that comes with iReport hsqldb, you can use that directly also.










following is that data within each table.

I have restricted data to minimum to show here if you fire the same query in iReport you can see all data.














so basically it shows the billing information for each transaction taken place, master table is document and its detail table is positions.

lets now create a sub report first which we need to include in the main report for every transaction.
so open iReport tool
1. file>> new... click on "Launch Report Wizard"

2. enter report name and its location where it will save report on local machine
name: sub-rpt-det
location: C:\data\mytest
file: C:\data\mytest\sub-rpt-det.jrxml

click on next,

3. if you are using hsqldb / mysql databse as a datasouce choose appropriately.
paste following query in the tab
select * from positions
where documentid=0
order by positionno
later, we will be replacing the documentid value with the actual parameter passed from the master report.
click next>>

4. select all fields shown in the left side of fields combo
click next>> next >> finish

5. set title, page header, summery band height as 0 (zero)

6. add the fields to report detail section

7. add fields column labels in the column header

8 now goto report inspector >> expand variables >> right click on variables>> select "Add Variable"
9. check the following variable1 properties for the variable that just created. modify them appropriately














10. similarly create another variable named tot check out its properties as below














11. Place the field "cost" in detail section at end and "tot" field in column footer along with label (see below)

12. add a "Rectangle" box in the column header and move it to back, add a background color as gray

13. add a "line" the column footer.

your report will look like as below





14. try to click on preview button and check if its generating output

15. go to report inspector>> expand parameters>> right click >> "Add Parameter"
add a parameter named "m_docid" change its parameter class as "Integer"

16. click on db tool button is next to preview button
replace the query parameter from (zero) 0 to $P{m_docid} so your query will look like as below

select * from positions
where documentid=$P{m_docid}
order by positionno
with this your sub report is complete now lets create a master report.

1. file>> new...

2. click on button "Launch Report Wizard"

3. enter report name as "mst_rpt"
name: mst_rpt
location: C:\data\mytest
file: C:\data\mytest\mst_rpt.jrxml

click on next,

4. if you are using hsqldb / mysql databse as a datasouce choose appropriately.
paste following query in the tab
select d.*, a.* from document d
left join address a on a.id= d.addressid
order by task
click next>>

5. select all fields shown in the left side of fields combo
click next>> next >> finish

6. select Palette>> report element>> sub report
drag it to the detail section. subreport wizard will appear on screen

a. select option use existing report and browse and select the sub report that we had created.
C:\data\mytest\sub-rpt-det.jrxml
click next>>

b. select first option "use the same connection used to fill the master report"
click next>>

c. it will show paramters created in sub report "m_docid" which we need to map with the master report field so we will be passing our document table's id filed here, click on expression drop down combo you will find all parameters, fields and variables that are defined in master report. choose "id" field from it.
click next>>

d. select the first option of subreport expression as "store the directory name in a parameter"
click FINISH

so your master report created with its sub report and other fields added in the details band will be seen as below










click on subreport and check its properties as below












note the parameters says that one parameter defined click on its button and see that it should show the m_docid as the parameter that we are passing to sub report.

here is the way to pass parameters to sub-report and to get value from sub-report
note that when you pass any value to sub report, that value may be parameter/field/variable defined in main report. you have to take special care for variable field of main report that it should have defined and has some value. please see below image how to pass
define one parameter in sub-report that will accept value from main report.
make sure that data type of sub-report parameter and main report parameter/field/variable should be same/compatible. here I have defined m_docid which will take value from main report.


similarly now when you have to define a variable that returns a value from sub report note that
1. values should come from sub-report variables, and place holder in main report also should be a variable.
2. variable defined in main report will get populated only after sub-report is totally generated, so it has to be placed after sub report defined.
please have a look how to get value from sub report.
1. I have defined "AValueFromSubRep" variable in main report
2. then I am mapping this variable to the sub report variable "totcost"


see how its get written in jrxml as below.
<subreport>
    <reportelement height="34" width="555" x="0" y="43">
    <subreportparameter name="m_docid">
     <subreportparameterexpression></subreportparameterexpression>
    </subreportparameter>
    <connectionexpression></connectionexpression>
    <returnvalue subreportvariable="totcost" tovariable="AValueFromSubRep">
    <subreportexpression class="java.lang.String"></subreportexpression>
   </returnvalue></reportelement>
</subreport>

now save the report and click on preview it will show the report with its sub report details as below
























thats how you will do a subreport.


Lastly, If possible before closing, click on ad to support me.

90 comments:

  1. Hello ..
    thanks for this nice tutorial, really helped me.
    But I've two questions:

    1- When previewing my report, I see a large gap between details & column-footer, how to fix this?

    2- I created a subreport with charts, then included it in the master report (with tables in it's details band). The output is generating the chart repeatedly over 30 pages without full display of the original table (i.e. each row displayed per page), any idea how to display first page only of the subreport?

    Thanks

    ReplyDelete
  2. 1. there are 2 things to avoid this first don't leave any gaps in your bottom side of detail band and fields placed. secondly there is a report level property "Float column footer" checked it to have column footer come exactly below your detail band.

    2. you need to place your subreport in summery band to generate chart only once after your main report generate table. if you want your chart to appear first before table put it in page title band.

    ReplyDelete
  3. Thanks for your help.
    I've added the subreport in summary band, charts are no longer repeated,
    but the summary band appears in the next page.

    Can i configure it to be displayed in the main page?

    Thank you,

    ReplyDelete
  4. it depends on how much data it generated on that page. if it has no space then it will move chart on next page only.
    Also check if you have checked report property "summery on new page".

    ReplyDelete
  5. Thank you .. Appreciate your help

    ReplyDelete
  6. Could you please tell me how i can pass one subreport value to another subreport?
    Also i want to know how i can get value from subreport to main report?

    ReplyDelete
  7. Please find I have updated last section to show how to pass and get values from sub report.

    ReplyDelete
  8. hi,i have a report with five sub reports..how can i adjust them so that there wont be overlapping of reports? and iam getting main report balnk...i want to move the data up how can i do it?as u said to check the property of summery on new page it is not enabled..and what is difference b/w detail and summary?can we keep subreports in either of them?please do reply...thank you..

    ReplyDelete
    Replies
    1. Hi,
      1. how can i adjust them so that there wont be overlapping of reports?
      >> when you create sub reports and add it in main report, it depends on the order how you place them in main report. execution will take one after another as you have placed. Also it matters where have you placed in detail or footer or summery etc.

      2. iam getting main report balnk
      >> this could be
      a. probably you have left detail blank with some height.
      b. if you have no data in main report you should keep height of all other bands to 0 (ZERO) to avoid blank spaces.
      c. also when you place sub reports you make sure you are not leaving spaces in between two sub reports
      d. also inside of sub report there should be only detail section and no header and footer (check my example point 5, 13)

      what is difference b/w detail and summary?can we keep subreports in either of them?
      >> in general details band gets repeted no. of times the rows that you have in report and summery only once and end of report. with respect to report having sub report in it. It really depends on your design of report most of time sub report will have their own data (detail) and main report is just used as container to club all sub report so we keep sub report in end section.

      hope these points clear your doubts. if there is anything please feel free to ask

      Delete
  9. hi sir,thanks for the quick reply...
    1)as i said that iam having 4 subreports.i kept them in main report by creating 4 detail bands (each subreport in separate detail band)is it a correct way?and
    2)when we make an existing report as subreport of other , url should be till jrxml or .jasper?
    3)how many subreports can we have..and is it compulsary that we hav to make a subreport when it is very necessary or we can just take a subreport so as to decrease our main report query..?
    4) for all the above cases what would be the performance effect?

    hope these are not many questions..thanks in advance...reply for my previous query was really helpful..thankyou...

    ReplyDelete
    Replies
    1. Hey Hi,
      1. Well you need only one single band in your main report
      and in one detial band you can keep all your 4 sub report one below another.
      2. while including subreport in main you can use any of approach. but more useful is jasper because it works faster as report is already complied
      3. There is no limitation as such how many you can add... it depends on your report weight and generation time that it takes, thats barealble to you.
      4. as I said above it depends, I had example of main report having 8 sub reports and 3 subreports having another 3 sub report in it. and it works pretty fast. acceptable for my client.

      Delete
  10. hi,i changed it as u said...its working fine...thank u...
    i also wanted to ask u abt fonts,i changed pdf font to arial in xml & i am not getting pdf file...so when i gone through net i got to know abt .ttf files where do we get these..to set a classpath for font...and what r the fonts that support printing of reports...and in ireport text preview is not working...can we take print of pdf as well as text files? how to export our report as text file?
    thanks again for ur reply....

    ReplyDelete
    Replies
    1. Hi Again,
      Well Thanks,
      nice to hear that it worked fine.
      normally you find ttf fonts in your c:/windows/font directory. but assume if your reports are running from unix env. then its a diff case.
      I have not much checked about changing fonts other than what are normally available.

      is your reports are only text?
      people genearally use rich text to generate text report. I don't know if jasper provide only text output.
      but if your report is columner and you want only text output then you can choose CSV format. and you can open in excel or normal text file.

      hope you get things.

      Delete
  11. Thank ....super content...very much thanks

    ReplyDelete
  12. hi sir,i have a problem when i keep all my subreports one by one in detail band all the reports are overlapping..if i keep them in summary then i have to set it like givivg gaps between subreports...so if there will be more data for first subreport then it overlaps with second sub report how to remove it?
    and in crosstab if complete row or column is null that is no value i want it to show 0 but it doesnot give that row or column at all...what to do?
    thanks...plz reply

    ReplyDelete
    Replies
    1. Hi Sorry,
      I had already posted but it did not applied so writing again,
      As I had mentioned to keep subreports in footer or summery part based on your requirement. becase summery gets executed only once at report end. and if your main report has some data and sub report requires parameters and need to prind filter data for each row of main report then it make sence to keep sub report in detail section.
      well, the data length of subreport do not matter and it do not overlap with other sub report, unless you have given its position type "Fix relative to Top"
      if you keep "float" then it will cause you problem of overlapping.

      for your second question there are couple of things to check.

      check for your every field in the row or column
      . "remove line when blank " is not selected
      . "blank when null" is not selected
      . "print when expression " you must do a check if value is null then print 0 "

      Other alternate is from your query/dataset make sure that for null field you are passing default to 0 value.

      I hope this will help you.

      Delete
    2. i no need to display sub report fields in main report.i need only total value from sub report i want to display only total value of the sub report without other fields of the sub report how can i do it

      Delete
  13. hi sir,i'm waiting for ur reply on crosstab doubt!please help...

    ReplyDelete
  14. sir can we write single servlet program for 6 different reports as their parameters(3) are same...like i'l keep 4th parameter through java &jsp,if 4th parameter =to one of report i want to get from 6reports then i'l write its codein if loop ...is it correct then just show me a outline for this as i am very new to java coding..thanks and regards in advance...

    ReplyDelete
    Replies
    1. Dear,
      I hope you can get calling jasper report code in tutorials on net.
      here it is basic
      in your servlet
      doGet() method
      {
      String s = request.getParameter("fourth");
      if(s != null && s.equals("yourvalue"))
      ///c all report
      else
      // do something else...
      }

      if you have any further query please send me email on my id do not post on this thread.
      my email in one of above replies.
      Regards,
      Rajendra

      Delete
  15. hi..sorry for posting on this thread again but i have seen the replies but i dint fid ur mail id! i also saw ur profile but i dint find!!!

    ReplyDelete
    Replies
    1. i think its get removed automatically its my name dot my surname at gmail

      Delete
    2. so,its rajendra.tambat@gmail.com right...because i sent a mail 2 this id...if its not ur id then it will be a problem!!! i dont know who is gng to get it..

      Delete
  16. Hi,

    I am facing one issue in subreport is he records in the subreport gets distributed in two pages when there are more records in subreport to display and in my case I don't have fixed size of records included in subreport so there may be case where one report will have only 1 or 2 records in the sub reports and there second main record will have 20 records included in the subreport

    I want my report to display the record in the page if the whole record can be fit in the same page else it should be displayed in the next page.

    Please help me if there is any property need to be set.

    ReplyDelete
    Replies
    1. Hi Shraddha,
      If I understand you correctly you just want that report to print its details in page only if it fits otherwise move on to next page.
      Yes ? if so then yes Jasperreports provides such feature it is called "Split allowed" -> this one is now depricated and replaced by "Split Type" depending on the version that are you using it will be available
      this property is available for the band you need to apply/change this property for your master report detail band.
      you need to change
      split allowed -> unchecked
      Split type -> prevent
      and Jasper report will take care of rest.

      hope this helps. do comment back.
      good luck.

      Delete
    2. Thanks a lot sir, This just worked perfect for me. I was working on this since a week. Thanks again

      Delete
  17. {call pr_eip_certificate ($P{ORACLE_REF_CURSOR},$P{n_orgid},$P{n_langid},$P{v_f_date},$P{v_to_date})}

    HI
    this is kumar

    pr_eip_certificate is my procedure

    when ever call the procedure
    It given invalid column type


    can u please help me

    ReplyDelete
  18. Hrllo Sir,

    I Have one more issue that is when my record in the subreport is too big to fit in single page it carry forwards to another page and I get Total on both the pages where as I only need the Total at the last for all the items in that particular record.

    And another thing is when the subreport get overflow and the items are carry forwarded to the new page at this point my design i.e. border and squarebox does not show in the next page. In the Next page the subrport Items are shown without design

    ReplyDelete
  19. If I keep the sub report as it is to display in two pages as my records in subreport are more than 60. So I think it can't fit in one page but than I want to display the TOTAL only once in the end i.e. the second page where finally the subreport will complete. Currently its showing me on both the pages as I have added it in pageFooter band...Please help me its urgent as Project is going in production

    ReplyDelete
  20. hi sir i have report which is having 3 subreports ,but i need to call only one subreport and all 3 subreports have same parameters.so i have fixed a value for each report so that main report can differentiate to call particular report...can we do like this?
    please help...thanks in advance..

    ReplyDelete
    Replies
    1. normally every object has "print when expression". so for your subreport also has this you can place a specific condition which will be true for one report at a time to make only one sub report to run rest.
      2nd solution would be for each sub report make the query fail on condition so that only one sub report can fetch data and other 2 subreport query fails and for each sub report main properties you set "when no data" expression "no page/no detail" so it will not gernerate any row for same.

      i hope you get this...

      good luck... and feel free to ask

      Delete
  21. This comment has been removed by a blog administrator.

    ReplyDelete
  22. hi...i have a problem that is where to store jrxmls& jaspers in our running application...from browsing i came 2 know that only .jasper file is enough...so i created a package in src and kept .jasper files in it...but i got file not found exception.

    should we change default expression in jrxmls also?

    if we have to change how and where we have to change it?

    initially i stored my jrxmls&.jasper in jasperreports folder in /root/JasperReports.

    please do help...its really important and urgent....
    thanks in advance...


    instead of giving like this can we have dynamic saving..because if i want to store the folder some where else then i have to change this line in all files!!

    ReplyDelete
    Replies
    1. hello please let me know what kind of application it is ?
      if it is web based then it has to be in your web-inf/classes
      folder. or if its a stand alone application then you need to specify the classpath during application startup.
      additionally even if your web application if you have any path outside of your application then you can make it globally available by putting in server lib folder or either specify server startup parameters.

      i did not get what you mean by default expression means?

      if you are going to change jrxml during run time of program then it make sense to generate jasper files dynamically.


      Delete
  23. hi thanks a lot for the reply ...ours is an web based application ,how to store it now? should i directly keep .jaspers(only or jrxml's also) in classes or should i create any folder?
    thanks in advance...

    ReplyDelete
    Replies
    1. As I mentioned earlier you need to put it in your web-inf/classes so that it can be reachable to classloader. if you created additional folder or want to put in any path of your context root then make sure that you give the ref. of your path in program where you load jasper...

      Hope this help.

      Delete
  24. hi sir... i have application , i stored my jasperreports /root but the problem is if client wants to change the place where they are stored then i have to change all reports&subreports injrxmls as it is taking default address ...i.e; if we save them in root then /root is being taken and if it is xyz folder then /root/xyz ...what can i do to solve this problem...i have been trying to know this for so long....wish u could help me...thank u.

    ReplyDelete
    Replies
    1. you mean you use stand alone application?.
      a way could be to configure your path as a property in a file or store in database. load it at run time if it get changed then then it will not affect your code because you will change path in database or in file. but your calling machanism is intact. eg.
      assume you read it from property file as below
      property file (app.properties)
      -----------------
      report.path=/root/mno/xyz

      code
      ------
      properties.load(new FileInputStream("app.properties"));

      String path = properties.get("report.path");

      URL jasperResURL = this.getClass().getResource(path +"/myreport.jasper");
      JasperReport jasperReport = (JasperReport) JRLoader.loadObject(jasperResURL);
      ....

      something like this...
      hope this help... it just a sudo code not perfect...

      Delete
  25. hello.i have written a code in which i'm usingjasper viewer to view a report generated from ireports through jsp and controllers.

    but is jasper viewer enough to get a print or we have to write anything like jasper export(is it only to export a pdf to some location or anything more?)..

    please tell me the process of getting a print with an example...

    ReplyDelete
    Replies
    1. it basically depend on application style... I never used jasper viewer to integrate with application. but still i think that can be sufficient. or you can simply write a export servlet to export. both servlet and viewer support facility to export in different supported format. location would be on clients machine who invoke servlet or report.
      my humble request to just search on net for example to export report. as I don't have setup at moment to come up with example to show...sorry for that

      Delete
  26. Hai, i have a main report which is havimg 4 sub reports .now i want to get each subreport in new page.and i have kept my subreports in summary.there is situation that sometimes 2 repotrs get executed sometimes 3 get executed .in extreme condition ,when four execute i'm getting correct but when only one or two get executed i'm getting empty pages at last...what should i do?
    2)if i keep these sub reports in detail band then when i should get 3 reports it's showing 9 reports?
    please tell the solution in both cases as it will be useful...
    3)in the above posts you told to keep in webinf/classes what should we keep jrxml or jasper?
    4)if we store jasper or jrxmls in our application jrxml's contain the place where we store them so should we have that folder also in particular place?
    please let me know the answers ..thanks & regards

    ReplyDelete
    Replies
    1. I have answered this same to Shraddha Please check.

      Delete
    2. ok...then what about
      1)in the above posts you told to keep in webinf/classes what should we keep jrxml or jasper?
      2)if we store jasper or jrxmls in our application jrxml's contain the place where we store them so should we have that folder also in particular place?
      thanks & regards

      Delete
    3. it depends on your applcation or your need if you need to complie jrxml everytime then you need to keep jrxml or otherwise you can simply keep only jasper files for faster processing.

      normally jrxml forms the part of your web content so it should be under your context root so that classloader could able to find it.

      Delete
    4. hi...i'm using ireports 4.5.1 and i'm not able to find any split type! is there any other way?

      Delete
    5. Jasper has changed this property from older version
      The Split Allowed option is deprecated, and its use has been replaced by theSplit Type property so isSplitAllowed="false" is equvalent to splitType="Prevent"

      Delete
  27. wantetd to thanks...this blog is really helpful for me!!! as i am new to jasper reports , i'm able to know a lot about designing.. thanks for giving quick replies...

    ReplyDelete
  28. hi sir i have 3 rows ,and i want to get total of each row at end how to get that? crosstab is not applicable for my application..is there any option in the design?plz reply

    ReplyDelete
    Replies
    1. there is a way you define a variable.!
      and use expression to count on details band... unfortunatly i can not show it now. but if you explore you can get it.
      there are expression available to sum or count etc. so you need to put field whose value you want to sum and there is also a expression to reset the variable which you need to set at end of report or group etc.

      pls explore.

      Delete
  29. Hello Rajendra, very informative blog. Nice work.

    I am having the following issues see if you can answer:
    - in my sub report the column headers are appearing twice, I mean in two rows two times.
    - data in columns are not visible properly. I have given the width as 80 but a short word like NO started appearing vertically.

    Plz help, working o a escalated issue.

    ReplyDelete
  30. Hi to the article writer..
    this information is very helpful..I try it. it really works for me..

    Can I ask if I could also pass the total of 1 column a page to subreport?..


    Thanks...

    ReplyDelete
    Replies
    1. Hi Dondell,
      Thanks for appriciating, well it may be possible, provided you make sure that your total of column of 1 is process before calling sub report and is displayed earlier. it is possible to pass variables to sub report.

      hold value of column total in variable and pass to subreport as parameter

      regards,
      Rajendra

      Delete
  31. hi ,i am having value 37.006 ,to show on report like 37.00 i'm fixing the field pattern to two decimals and ireport is showing me as 37.01 but i want it to show 37.00 only is there a way...please reply

    ReplyDelete
    Replies
    1. There are many ways, you can fix, first and most do you want to round it off or not? if yes then what it is doing is correct if not then try to fix from database from where you are getting values else, try to use formatter, or also try math.slab. and if nothing works just get value in string and trim it to 2 places after dot. hope you get it.

      Regards,
      Rajendra

      Delete
    2. thank you so much...i used truncate for this and it worked!!!

      Delete
  32. HI SIR ,i have a field where i get 19807,7451 as its value
    but i'm getting following error what should i do to remove this..this really urgent hope u answer soon thank you..
    Setting up the file resolver...  net.sf.jasperreports.engine.JRException: Unable to get value for field 'NO OF WINNERS' of class 'java.math.BigDecimal'      at net.sf.jasperreports.engine.JRResultSetDataSource.getFieldValue(JRResultSetDataSource.java:309)      at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:922)      at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:887)      at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:864)      at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1435)      at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:130)      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:836)      at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:746)      at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:58)      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:417)      at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:247)      at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:879)      at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)      at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)  Caused by: java.sql.SQLException: Bad format for BigDecimal '19807,7451' in column 13.      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)      at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)      at com.mysql.jdbc.ResultSetImpl.getBigDecimal(ResultSetImpl.java:1256)      at net.sf.jasperreports.engine.JRResultSetDataSource.getFieldValue(JRResultSetDataSource.java:207)      ... 13 more 

    ReplyDelete
    Replies
    1. Hi, i could only think that try to check the parameter or field datatypes are set properly or not this may cause due to it. seems that it is reading like string but trying to read as bigdecimal. if both datatypes match (database and report filed) then it will work proper.

      Goodluck,
      Rajendra

      Delete
    2. hi sir,what you said is right ..i changed all types to integer its working.but i have a query(which contains sub queries) which returns 7-8 values(fields) for 5 rows.it is working fine.but in some cases a field in a row will give more than one value, how to get like that means 5 fields are normal with one value but 3 fields will give 2 values each.i used group_concat ,so its showing values but at ending i have to add complete column .so please tell me what to do...waiting for your reply..

      Delete
    3. forgot to mention as its subquery if it gives me more than one value it shows me sub query returning more than one value...hence i used groupconcat.

      Delete
    4. Hey Good to know that it worked for you, but I did not get your question, what you mean by add complete column at end? and where have you used gourpconcat? at database level? or in report?

      Delete
    5. i'm using it in ireport ...& adding complete column is from top to bottom i have 5 values for one column and i have to show their sum at ending ..down like addition

      Delete
  33. HI..will you please tell me how to send a value of one report to its sub report in step wise process? i am not getting it correctly,thank you...

    ReplyDelete
    Replies
    1. Hi, Thanks for visiting, have you gone through my post correctly I have shown it and also shown screenshot and generated xml part of jrxml with that you can match and check if its proper or not or if you have any further query then please feel free to ask

      Delete
  34. hi sir i am having 2 doubts
    1) how to send a field from sub report to main report so that i can add it to already existing another field in main report.
    2)i have written procedure and called it in reports,its running in tool but when i run it in eclipse i'm getting following error please tell me what to do as its really important and urgent,please give step wise as i don't have much time left to complete this work.i'm using mysql and ireports4.5.1,should i add any jars from where,i saw in your posts but its for oracle...
    as i cannot post complete error message i'm sending you one line of it
    Caused by: net.sf.jasperreports.engine.JRRuntimeException: No query executer factory registered for the 'plsql' language.
    many thanks in advance,waiting for your answer...

    ReplyDelete
  35. hi,i have solved my first problem regarding sending of filed but please tell me the second one

    ReplyDelete
    Replies
    1. Hi It is possible,
      follow below steps
      1. create a variable ret_value_xx in main report
      2. set evaluation time as band ( so su report should able to pass value correctly)
      3. define variable in sub report sub_rpt_xx
      4. in main report again go to subreprot properties
      5. you will find property return values
      6. add value there subreport variable= sub_rpt_xx and destinationvariable= ret_value_xx
      7 or (instead of step 6 directly modify from source insert below line in your subreport tag after connextionExpresison

      8. done

      I hope this will help you,
      unfortunately i dont have setup here so cant explain in more detail


      Delete
    2. this process is working fine but i have 10 columns in each subreport and there are 7 sub reports,so creating of these many variables is much time consuming and i dont know whether its effective,so is there any other way?
      thanks for the reply

      Delete
    3. ok...now this process would be big,i have to do it now...thanks for giving the information...i have been searching for this(to know whether there is a way or not) for 2 days now!!!

      Delete
  36. hi,i'm working on mysql,jasperreports and i want to do certification in it.do u have any idea about how many types certifications are there and any links for study material.i am fresher and have been working on these for past 4 months.any information regarding this would be help full.

    ReplyDelete
  37. तांबे साहेब,
    उत्तम लेख. आपल्या मातृ भाषेत मला जास्पर रिपोर्ट वर लिहिण्याची इच्छा आहे.
    मी आपली मदत गृहीत धरू का ?

    ReplyDelete
  38. Hi,
    I have a Constant value '12345' defined for variable "myvariable" in subreport when I try to map to mainreport variable "myvari" it is always returning null tried out various possibilities but nothing helped to solve the issue.Can you help out on this.

    ReplyDelete
    Replies
    1. Hi Please read end of my tutorial I have explained how to return value from sub report, but there is pre conditions I place it here --
      when you have to define a variable that returns a value from sub report note that
      1. values should come from sub-report variables, and place holder in main report also should be a variable.
      2. variable defined in main report will get populated only after sub-report is totally generated, so it has to be placed after sub report defined.

      I hope if you follow same it will work otherwise please expalin in detail.

      Delete
  39. Hi ,
    Thanks for the reply.Kindly find the below details
    Same as you explained I have a variable defined in my subreport- "myvariable" with value 12345 .I assigned the same to my main report variable named "Temp" using the return property .And I have placed my subreport element in detail band and Temp variable in page footer band of my main report.I have tried out the calculation types "System"/"Nothing and evaluation time to Band but nothing worked .Still My main report shows null value for the variable "Temp".

    ReplyDelete
    Replies
    1. Hi Kayal, your procedure looks ok.
      does it give any error on generation? if not means it is not yet defined as return value in your sub report, try to verify same by looking at source code in jrxml in subreport tag for following as shown in my example



      just once again verify following.
      -- sub report
      define variable (myvariable)
      variable class = string
      variable expression = 1234

      -- main report
      1. define variable temp
      variable class = string
      2. add subreport>>properties>return values
      subreport variable = myvariable
      destination variable = temp
      3. add variable to page footer
      texfield in page footer should also be of type string

      hope this works.

      Delete
  40. Hi, i would like to print filter data of the subreport for each row of main report. when i send a fileld parameter from the main report to the subreport , the main report does not execute at all. please help.

    ReplyDelete
  41. hi all, has u can see price value is in column wise , can we display price data in a row wise .kindly guide

    ReplyDelete
  42. hi
    Sir , I have Problem with subreport ---> My requirement is to show Two subreports in the Master Reports as for that i have taken three details band details-1 and details-2 ,detail-3. In detail-1 band ,

    i have some staitc text as a heading of subreport-1 ,in detail-2 i have some paragraph to print and in detail-3 band i have 2nd subreport-2 , But when i am compling it and getting pdf, i am getting the subreport-1 data in detail-3 band ...

    and the staitc text of detail-3 band repeting as a heading to subreport-1,and the paragraph of detail-2 band repeting multiple times ...

    i have used "position type"=float and everything that i could do .... but for some extent iam able to solve the detail-2 repeating part by unchecking the PRINT REPETED VALUE ...

    But the Subreport-1 data still displaying down the detail-3 static heading ...

    as i don't know much about it .... thank you

    ReplyDelete
  43. Hi,
    I have made a report for invoice printing.

    Problem 1: Detail band should extend or should have a fixed height even if it has only one row, it should end just before the group footer where the subreport is kept.

    Problem 2: Have kept subreport on the group footer and set it's footer position properties to Force at bottom and it's working fine when previewing in jasper but when i compile & run the report on live environment it shows the subreport on the middle of the page right after the detail part.

    Thank You

    ReplyDelete
  44. I want break a4 page into two exactly two part invoice bill one as original and one as duplicate plz help me out from this

    ReplyDelete
    Replies
    1. enven though you give page break it will not evenly cut your page, becauase it varies with your detail band number of rows it generates, unless you are sure you have fixed row format.
      well but solution would be define your invoice format in sub report and use sub report twice in main report with pagebreak.

      Delete
  45. Hi,
    I have print product sales report by different days
    product as row data, days as column.

    problem:
    some product name display two times (row data).
    How to avoid it? please guide me..

    ReplyDelete
    Replies
    1. Hi Siva,
      Are you sure your database query is not returning duplicate records?
      please make sure your query has proper results as expected.
      I don't think it would be possible anything from jasper side.

      Delete
  46. Hi Rajendra,

    How to create jasper report using two csv files.
    How to create subreport using csv file

    ReplyDelete
  47. Hi Sir,
    i have many fields in sub report but i want to display only one field total value only in main report how can i achieve it

    ReplyDelete
    Replies
    1. Hi Ram, it is possible to put condition on your remaining fields so that they are not displayed which alwayz evaluate false for eg. if(1==0) etc

      Delete
  48. Hello Sir,

    I have one question is it possible that main reports fetching data from one datasource but in different machine and the sub-reports fetching the data from other datasource but username and password are the different?
    Example:
    First machine:
    Database: Oracle
    Username and password: usr,usr
    Second machine:
    database Oracle
    Username and password:sys,sys.
    Please suggest me if it is possible.

    ReplyDelete
    Replies
    1. technically should be possible actually username password is the concern its managed in datasource connection properties and (well i don"t remember now) if jasper now supports multiple datasources then you can have two different datasources created for main report and sub report.
      my blog is quite old I am not uptodate on jasperreport currently, but you can check this.

      Delete