Skip to Content

Passing Values Between Reports (Crystal Reports – 2008)

There are 2 ways in which a value or a pre-calculated field can be passed from a main report to the sub report.

1)      Creating a Parameter and linking the sub report to the main report (primary report)

2)      Creating Shared Variables.

 

Passing values using Parameters

 

Scenario: – In a Business requirement where we have the Main Report which displays the country data and the sub report which displays the sales data.

 

Following are the steps required to pass a value from a main report to a sub report using linked parameter

 

1)      Create a Parameter at the Main Report (Say Parameter name: – Country ID).

2)      Link the two reports using the Country ID.

3)      Run the Report. (Here when the report runs, it finds the first country data and passes the associated country id from that record to the sub report parameter field. Like wise the process is followed for all the associated country ids with the corresponding country data).

4)      All the parameter field manipulation takes place behind the scenes. We only have to pick up the fields that will link the main report (primary report) with the sub report.

 

(Note: – The values are passed from the main report to the sub report, with out the parameter field prompting you for a value)

 

In the above scenario we can even create a calculated formula field at the main report and then pass the same field to the sub report by following the below process

 

1)      Create Formula field at the main report from the field explorer menu.

2)      Link the sub report to the main report by the newly created formula.

3)      Run the report.

4)      The calculated formula field would be directly passed on to the sub report through the linked parameter. (An equivalent linked parameter will be created automatically at the sub report when both the reports are linked).

5)      At the sub report level the parameter field value can be further used for any customized calculation or for display at the sub report section level.

 

Passing values using shared variables.

 

Shared variables are those variables which can be shared with the sub report as well as with the current report.

Steps to pass values from a main report to the sub report using shared variables

1)      Create a formula say fr_shared_variable using the formula editor from the field explorer menu

 

2)      Paste the below code at the formula editor window

 

Shared NumberVar z: =10;

 

(Assigns a value to the shared variable z of type Number)

(Note: – we can also assign any calculated business logic or a database field as per the requirement to the shared variable)

 

3)      Now go to the sub report and create a new formula say fr_value_shared_variable  using the formula editor from the field explorer menu

 

4)      Paste the below code at the formula editor window

 

Shared NumberVar z;

(Declares the shared variable at sub report)

 

5)      The shared variable which is assigned a value at the Main report using formula fr_shared_variable and declared at the sub report using the formula fr_value_shared_variable is now ready to be used.

 

6)      At the sub report level the shared variable can be further used for any customized calculation or for display at the sub report section level by making use of the formula fr_value_shared_variable.

 

Note:-

 

1)      In order to use shared variables, the variable must be declared and assigned a value before it can be passed between the main report and the sub report.

2)      The values can also be passed from the sub report to a main report by using shared variable which is assigned a value at sub report and declared at main report. For doing so the sub report should be placed at a section in the main report level which is executed prior to the section at the main report which uses the shared variable.

3)      By using a parameter the values can only be passed from a main report to the sub report and not from the sub report to the main report.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Former Member
    Hi,
    I want to create a report which verifies an user before creating main report. I had tried to do so by generating a sub-report from user detail and than stored values as shared variable and tried to used in record selection, unfornately it does not worked.
    If you have any idea regarding this please suggest.
    Thanks,
    Sanjeev
    (0) 
    1. Former Member Post author
      Hi Sanjeev

      Couple of points I would suggest which may be of some help for your report requirement:-

      1) If you want to retrive any value from the sub report or pass a value from the sub report to the main report then the sub report should be placed at a section in the main report prior to the section where the value is retrived at main report.

      2) Also it is the main report which calls the sub report.The sub report does not require a different functional call.So if any thing is tested at sub report it would reqire the main report to get excuted first.

      3)I would suggest you to either use a alert (Based on user condition) at the main report which will trigger the user name when the report is executed.

      4)Verifying a user before creating a report can only be possible if we create a prompt(asking for user id) and then based on the user condition we can set the Report filter condition to check whether the entered user has a right to execute the report .If yes then set filter condition/Query condition as true or else set it as false.

      Hope this can be of some help to you

      Feel free to let me know in case you have any Questions

      Thanks & Regards

      Ashish Bamzai

      (0) 
      1. Former Member
        Hi Ashish,
        Thanyou for your prompt reply. Unfortunately this facility is not available in BOXI (Business Object XI) and would’t work.
        Scenario: User wants to see sales report of the agency which he belongs to.
        ** for this i can get user id in crystal report ‘CurrentCEUserName’, and can get user agency from user table.
        ** now when i get value of user agency, i have to use this value in records selection so that the main report will only show data of the agency which user is belongs to.
        hope this will give you more idea about what i am looking after.
        Thanks
        (0) 
        1. Former Member Post author
          For the above requirement I would suggest you to do below steps

          1) Create a balnk Main Report which will have a formula to get/store the User id (CurrentCEUserName) say formula 1.
          2)Create another formula say formula 2 to fetch the User agency from the usertable based on the userid (from formula 1)
          3)Create a sub report which will have the sales content.
          3) Create a parameter at the main report and link it to the sub report to pass the Formula value (Formula 2 – Agency name).
          4)Finally use this parameter value at the record selection for the sub report where you need to put the condition as User.useragency=@Parameter (Formula2 linked from the main report to the sub report).

          THE ABOVE APPROCH SHALL DEFINATELY WORK IN THE REQUIRMENT SPECIFIED BY YOU

          Regards

          ASHISH BAMZAI

          (0) 
  2. Former Member
    Dear Ashish,
    You are so kind, thank you again for prompt reply.
    I want to use values FROM sub-report into main report. As you know sub-report has some limitation to display, while many reports we creates are most complicated, so i have to use main report for display and for the user details i am looking a way which help me to identify user BEFORE GENERATING A MAIN REPORT in Business object.
    (0) 

Leave a Reply