cancel
Showing results for 
Search instead for 
Did you mean: 

Shared Variable not working between subreport & main report

Former Member
0 Kudos

I'm having difficulty with a report I'm trying to write... I need to pass a value from the sub report to the main report. I've read elsewhere in the forum about the solution being a shared variable, and I've tried to implement it but it comes up as zero in the main report. Here's what I have:

In the subreport I have a formula called PassedEstTotal which looks like this:


WhilePrintingRecords;
Shared CurrencyVar EstTotal := Sum ({@TotalEstTime});

In the main report I have a formula called EstLab which looks like this:


WhilePrintingRecords;
shared CurrencyVar EstTotal;
CurrencyVar i;
i:=i+EstTotal;

PassedEstTotal does hold a value - I put it in the subreport and it properly shows a value of $283.99. But EstLab in the main report shows zero. What am I doing wrong here?

Former Member
0 Kudos

Hi Jon,

Is PassedEstTotal a variable? If so, how are you declaring it?

Regards,

Zack H.

Former Member
0 Kudos

PassedEstTotal is set up as a formula, and I have EstLab appearing directly below the subreport.

0 Kudos

Hi Former Member,

I got lost on this"

1. I had the subreport and the destination field in the same report footer section. I inserted a new section in the footer and moved the destination there. (This is the one which I think made the big difference.)

Please clarify as i also having this issue of shared numbervar not being passed to main report from subreport. I only get 0 output.

Thank you.

mynynachau
Community Advocate
Community Advocate
0 Kudos

Hi garyreal I recommend asking a new question in the community where you could receive helpful answers by other community members: https://answers.sap.com/questions/ask.html

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Are you sure your formula @TotalEstTime returns a currency value? I just want to make sure you are returning the correct data type. Can you try NumberVar instead. Also, as Vinay was suggesting, make sure that the subreport is placed in a section / group above the formula EstLab in your main report.

I hope this helps,

Regards,

Zack H.

Former Member
0 Kudos

TotalEstTime is defined in whole as this:


({track.process_qty}/{order_routing.run_speed}+{order_routing.setup_time}/60)*{process.dol_hour}

Former Member
0 Kudos

Okay... I've got it working now. I pulled down the sample in the library which showed how to do it and I was able to get it working right. I made two changes and it's cooking now:

1. I had the subreport and the destination field in the same report footer section. I inserted a new section in the footer and moved the destination there. (This is the one which I think made the big difference.)

2. I copied the existing code for passing the variable and it now works. PassedEstTotal now reads like this:


whileprintingrecords;
shared numbervar x;
x:=Sum ({@TotalEstTime});
x

and EstLab now looks like this:


whileprintingrecords;
shared numbervar x;
x

Answers (3)

Answers (3)

Former Member
0 Kudos

Subreports calculate last. Your main report will have already been processed by the time it gets to your subreport, so as far as the main report is concerned the variable value is zero.

I can't load a screen capture in here, but check the 'Report Processing Model' in your help menu.

I ran into something very similar a little while ago. I ended up getting around it by writing a SQL statement that got me the same result. I'm not sure how feasible that is for your situation.

Former Member
0 Kudos

I misread your post earlier,

In your main report, for your EstLab, try using this formula and see if you get a value:


WhilePrintingRecords;
shared CurrencyVar EstTotal;

EstTotal

Regards,

Zack H.

Former Member
0 Kudos

Nada.. no change from before.

Former Member
0 Kudos

Hi Jon,

Make sure that the shared variable which you are calling in the main report should be in the below section of the sub report. If you want to pass the sub report to the main report in the same section then insert section below the sub report

Regards,

Vinay