Solved

Crystal Reports 8.5 issue with while do loop

Posted on 2008-06-17
9
2,651 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
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.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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