We help IT Professionals succeed at work.

Question on NumberVar Variables

Carla Romere
Carla Romere asked
on
Medium Priority
443 Views
Last Modified: 2012-05-12
I have a numbervar variable that is keeping a running total of a previously calculated field. The "accumulation" formula is:

whileprintingrecords;
numbervar sumFillerAll := sumFillerAll + {@RawMatFiller};

That does exactly what I need it to do. Now I have to do the same thing but for only certain records in the same column. Is it possible to do something like this:

whileprintingrecords;
if {VW_BATCH_DETAILS_PLANT_AUDIT.LOADTYPE} IN['LD']
THEN numbervar sumFillerPlastic := sumFillerPlastic + {@RawMatFiller};

I created this set of the three variable formulas (reset, accumulate and display). I then put the reset formula in the header, the accumulate formula in the details section and then put the display formula in GF2. I can follow the calculating and it's resetting itself to zero when the LOADTYPE isn't LD. LD normally occurs relatively early in the list and it grabs that value. But when it goes to the next row in the details section it resets to zero. Just for grins, I added a second LOADTYPE in the if statement and it works.  But I only need the LD section. What piece am I missing?
Comment
Watch Question

Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Try the accumulation this way

whileprintingrecords;
numbervar sumFillerPlastic;
if {VW_BATCH_DETAILS_PLANT_AUDIT.LOADTYPE} IN  ['LD']  THEN
      sumFillerPlastic := sumFillerPlastic + {@RawMatFiller};

mlmcc



Carla RomereDirector of Information Technology

Author

Commented:
Nope, still end with a 0. Here is a screenshot since I can't get the report to upload with data. The red column is the "accumulation" column and the column immediately to the right of that is the column for which it is grabbing the running total. The red bold number underneath is the "display" of the running total. It should be showing 0 on the first line which is correct and 18.06 on the second line, which is also correct. It should show 18.06 all the way down as well as the grand total because there is only one occurence of a LOADTYPE of "LD".
screenshot.png
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Can you upload the report?
With data if possible but without is fine.

mlmcc
Carla RomereDirector of Information Technology

Author

Commented:
Here you go - saved with data. I sent it also to myself at home and it looks like it saved the data with it this time. PLANT-AUDIT.rpt
Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
Your display formula should be

whileprintingrecords;
numbervar sumFillerAll;
sumFillerAll

By calling the formula again you were simply testing the last loadtype so it wasn't doing the add

Also you should declare the variable in the report header.

Attached an updated report

mlmcc
PLANT-AUDIT.rpt
Carla RomereDirector of Information Technology

Author

Commented:
As usual you are dead-on correct. I swear you need to write a book!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.