Solved

Crystal Reports 8.5 issue with while do loop

Posted on 2008-06-17
9
2,643 Views
Last Modified: 2008-06-18
Hi all.

I'm working on a Crystal Report (version 8.5) that uses a table with the following data:

Account (Text), FiscalYear(Text), FiscalPeriod(Text), DebitAmount(Number), CreditAmount(Number)

I have the following formula that basically adds up the debit amounts and subtracts the credit amounts based on the date range the user enters

As you can see I want it to calculate the total for the period (for example if I put january then the period = 01 that's why I put {GL_PeriodPostingHistory.FiscalPeriod} = "01" right before I calculate the total), but instead it simply calculates the entire total for the {GL_PeriodPostingHistory.FiscalYear} value.

I know my mistake is at the line where I do: {GL_PeriodPostingHistory.FiscalPeriod} = "01" , but I can't seem to get it to only pick the debitamount and creditamount of the period I'm currently searching.

Thank you in advance!


If {GL_Account.Account} Like "4*" then
(
NumberVar Per:= (ToNumber({@GetMinimumMonthPriorPeriod})); //user enters begin date range i.e. from 01/01/2005
NumberVar Per1:= (ToNumber({@GetMaximumMonthPriorPeriod})); //user enters end date of range i.e. to 03/01/2005
 
NumberVar PerAmount1 :=0;
NumberVar SumofPerAmount1:=0;
 
While (Per <= Per1) and {@GetPriorPeriodYear} = {GL_PeriodPostingHistory.FiscalYear}  Do 
( 
 
    
If(Per = 01) then  
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "01"
        PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 :=  SumofPerAmount1 + PerAmount1;
        Per := Per+1;
     
    )
 
    Else If (Per = 02) Then 
    (
    {GL_PeriodPostingHistory.FiscalPeriod} = "02"
    PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 03 ) Then 
    (
     {GL_PeriodPostingHistory.FiscalPeriod} = "03"
   PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 04 ) Then 
    (
	{GL_PeriodPostingHistory.FiscalPeriod} = "04"
        PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 05 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "05"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 06 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "06"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 07 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "07"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 08 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "08"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 09 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "09"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 10 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "10"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else If (Per = 11) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "11"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
    Else if (Per = 12 ) Then 
    (
        {GL_PeriodPostingHistory.FiscalPeriod} = "12"
	PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 := SumofPerAmount1 + PerAmount1;
        Per := Per+1;
    )
 
 
);
 
SumOfPerAmount1

Open in new window

0
Comment
Question by:printmedia
  • 6
  • 3
9 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 21808089
What is your intent with those lines?
{GL_PeriodPostingHistory.FiscalPeriod} = "01"

They simply compare the fiscalperiod to '01'

mlmcc
0
 

Author Comment

by:printmedia
ID: 21808219
That's where my problem is, the table looks like this:

Account----FIscalYear---FiscalPeriod---Debit---Credit
1000-------2006-----------01-------------$50.00--$20.00
1000-------2006-----------02-------------$20.00--$10.00
1000-------2006-----------03-------------$100.00--$50.00
1000-------2007-----------05-------------$30.00---$10.00

So the user enters the following:
BeginDate: 01/01/2006
EndDate: 02/01/2006

So the fields would be: {@GetMinimumMonthPriorPeriod} = 01
{@GetMaximumMonthPriorPeriod} = 02
{@GetPriorPeriodYear} = 2006
{GL_PeriodPostingHistory.FiscalYear} = 2006

So the result would be:

SumOfPerAmount1 = -40.00 (b/c: 50-20 = -30 and 20-10 = -10 which totals out to -40)

I want the script to to get the values that the fiscal year and the fiscal period have in the table, would I need an array for that?




0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 21808237
How about using a select folter to limit the records selected then simple summary fields would do the totaling.

{PerField} >= {@GetMinimumMonthPriorPeriod} AND {PerField} <= {@GetMaximumMonthPriorPeriod}

mlmcc
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:printmedia
ID: 21808285
The problem is getting the values in the debit and credit columns, how do I get it to retrieve those values for the year and period as it goes through the while loop?
0
 

Author Comment

by:printmedia
ID: 21808297
That's why I thought doing this: {GL_PeriodPostingHistory.FiscalPeriod} = "01"
 line 15 from the above code snippet, would tell it to go to the fiscalyear, and period combination and retrieve the debit and credit amounts.

Instead, what it does is simply add all of the debit and credit fields for every month in the fiscal year, regardless of what period (months) the end user puts in the range.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 21808367
I think you misunderstand how Crystal works.

Crystal works on 1 record at atime.  You can't write code to walk through the recordset.

Try this
Use the filter I provided
    Click REPORT --> SELECT EXPERT

Drag the debit and credit fields onto the report
Right click debit
Click INSERT --> SUMMARY
Choose sum
Set it in the group you want it in.

Similarly for Credit

mlmcc
SImilarly
0
 

Author Comment

by:printmedia
ID: 21813374
Let's say I have a blank report.

The user enters two set of date ranges:

Prior Date Range: 01/01/2005 - 03/31/2005
Current Date Range: 01/01/2006 - 03/31/2006

I want to add up the sale amounts for the Prior Date Range and the amounts for the Current Date Range

The table where the data is stored looks like this:

FiscalYear(String)--FIscalPeriod(String)--Sales(Number)
2005------------------01----------------------500
2005------------------03----------------------200
2006-----------------01----------------------100
2006-----------------02----------------------300
2006-----------------03----------------------200

The final totals would be: PriorDateRange: 700
                                         CurrentDateRange: 600

Can I have a field that stores that information so that I can use it in other formulas in my crystal report? If so, what kind of formula can I create?
0
 

Author Comment

by:printmedia
ID: 21813392
Also, there could be other period in the table for the same year:
FiscalYear(String)--FIscalPeriod(String)--Sales(Number)
2005------------------01----------------------500
2005------------------03----------------------200
2005-----------------05----------------------600
2005----------------12-----------------------700
2006-----------------01----------------------100
2006-----------------02----------------------300
2006-----------------03----------------------200
2006----------------07-----------------------150

But I just want the ones that fall in the date ranges the end user chooses.
0
 

Author Comment

by:printmedia
ID: 21816992
I got it to work by doing the following:


If ({@GetPriorPeriodYear} = {GL_PeriodPostingHistory.FiscalYear}) and ToNumber({GL_PeriodPostingHistory.FiscalPeriod}) in (ToNumber({@GetMinimumMonthPriorPeriod}) to ToNumber({@GetMaximumMonthPriorPeriod})) then 
      
     ( 
 
        PerAmount1 := ({GL_PeriodPostingHistory.DebitAmount} - {GL_PeriodPostingHistory.CreditAmount});
        SumofPerAmount1 :=  SumofPerAmount1 + PerAmount1;
 
 
      )

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now