Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2678
  • Last Modified:

Crystal Reports 8.5 issue with while do loop

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
printmedia
Asked:
printmedia
  • 6
  • 3
1 Solution
 
mlmccCommented:
What is your intent with those lines?
{GL_PeriodPostingHistory.FiscalPeriod} = "01"

They simply compare the fiscalperiod to '01'

mlmcc
0
 
printmediaAuthor Commented:
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
 
mlmccCommented:
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
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
printmediaAuthor Commented:
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
 
printmediaAuthor Commented:
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
 
mlmccCommented:
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
 
printmediaAuthor Commented:
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
 
printmediaAuthor Commented:
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
 
printmediaAuthor Commented:
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now