Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Forcing to show output in next row 1

Status
Not open for further replies.

pmk16

Programmer
Nov 20, 2002
33
US
I have a formula which is displaying 'A' or 'B' based on some criteria. But, I noticed that the output is getting displayed by 1 row.

For example @form1,
1 A
2 B
3 A
4 B
5 B

Output should have been @form2:
1 B
2 A
3 B
4 B
5 A

Is there some way where I can force it to show in the next row. I did try next() function by creating a new formula, but it says that 'This field has no previous or next value'
 
Show what's in your formula, and the data being returned to the report, seeing what doesn't work (@form1) isn't useful.

The next function works against any fields that have values in the next row, so you might need:

if not(onlastrecord) then
next({@form1})
else
{@form1}

But as you can see, this won't show the last row properly.

Successful posts tend to include basic technical information:

Crystal version
Database/version/connectivity
Example data (not examples of something in the report that you DON'T want)
Expected output

Statements such as "based on some criteria" are also wasteful, state the criteria, it doesn't take much effort to convey real requirements.

-k
 
Sorry for not being clear in my earlier post.

Crystal version: Crystal 10
Database/version/connectivity: Oracle 9
Example data (not examples of something in the report that you DON'T want)

For eg, an employee set a benefit account = $10
So, every month, company would deduct $10 from employees pay check and keep it with them, until it becomes $25. So, on the 3rd paycheck, employee would have contributed $25 towards the benefit account and $5 would appear as balance.

Emp #, Amount(given), Balance(calc), Amount reached(calc),Paycheckdt
------------------------------------------------------------
1 10 10 0 01/01/2001
1 10 20 0 02/01/2001
1 10 5 25 03/01/2001
1 10 15 0 04/01/2001
1 10 0 25 05/01/2001
1 10 10 0 06/01/2001
1 10 20 0 07/01/2001


So the way I performed balance calc(@balvar) was:

numbervar balvar := 0;
balvar := balvar + amount;
if balvar >= 25 then
balvar := abs(25 - balvar)
else balvar;


but, how do i compute amount reached? Amount reached will show 25 only in line 3 and 5 when the amount equals or crosses 25.

What I tried is:
if next(amount)+ {@Balvar} >= 25 then
amntReached:= 25
else
amntReached:= 0;

The output is:
0
25
0
25
0
0
0
which is actually displaced by 1 row (in comparison to previous output)!

Thanks for offering help
 
It looks like you just need to change the formula to:

if amount + {@Balvar} >= 25 then
amntReached:= 25
else
amntReached:= 0;

-LB
 
Admittedly I'm no Crystal expert but here's my crack at this.

Looking at your example it makes sense that the 25's are being displayed a row early. Since this is the case you could try creating the amount reached as a global variable, display the current value of the variable first (this will be the amount calculated in the previous row), then follow this output with the code to calculate this variable for the next row. You will just need to account fo the first record but thats easily done.

So something like this:

global numbervar amntReached;
if onfirstrecord
then 0
else amntReached;
if next(amount)+ {@Balvar} >= 25 then
amntReached:= 25
else
amntReached:= 0;

Hope this works for ya.
 
Thank you Lbass and rob11nj for replying.

Lbass: I can't use current amount and current balance to perform calculation because if I implement your logic, then I would obtain 25 in line 2 and not line 3, as depicted in the example.

rob11nj: You are exactly right. This is exactly what I have been trying to do and that is some how force the output appear in the next line and I did try your formula, but it is showing the same results as my wrong output, unless I made some mistake in following your steps

The output I am getting is(wrong output):
0
25
0
25
0
0
0
 
Did you try my suggestion? Try removing next().

-LB
 
LB: I did try your suggestion namely:
if amount + {@Balvar} >= 25 then
amntReached:= 25
else
amntReached:= 0;

and here is the output:

1 10 10 0 01/01/2001
1 10 20 25 02/01/2001
1 10 5 0 03/01/2001
1 10 15 25 04/01/2001
1 10 0 0 05/01/2001
1 10 10 0 06/01/2001
1 10 20 0 07/01/2001

which is still showing the wrong result.

 
Is there a way that I can force the balance calculation to complete first, so that I could use previous(balance).

I did try :

EvaluateAfter({@Balance});
if {@amountreached}+previous({@Balance})>= 25 then
x:= 25
else x:= 0;
x;

but it throws an error that @balance: "This field has no previous or next value
 
Okay, now I see. I think your balamt formula should be:

whileprintingrecords;
numbervar balamt;

balamt := balamt + {table.amt};
if balamt >= 25 then
remainder(balamt,25) else
balamt

Then your {@AmtReached} should be:

whileprintingrecords;
numbervar amtx := amtx + {table.amt};

if remainder(amtx,25) in [0,5] then
25 else 0

-LB
 
Thank you LB for all your help.

It seems to be there, but still not there yet!

We will have to refine the logic further since i am using the same logic as u suggested to build 3 cases:

whileprintingrecords;
numbervar amtx := amtx + {PAYDEDUCTN.DED_AMT};
Select {pay_type}
Case "25" : if remainder(amtx,25) in [0,5] then
25
else 0
Case "50" : if remainder(amtx,50) in [0,10] then
100
else 0
Case "100" : if remainder(amtx,100) in [0,10] then
100
else 0

Default : 0;

This works well for most of the cases. But I noticed an exception case when type = 50 where the logic turned out to be faulty.
Type= 50 worked for:

20 20 0
20 40 0
20 10 50 (** correct **)
20 30 0
20 0 50

Type=50 did not work for:
-----------------------------

5 5 0
5 10 50 (** wrong ***)
5 15 0
5 20 0

any suggestions?

thank you so much for all your time and help.


 
Please note that you have changed the problem. You need to test what the remainder is in each case. Change it to:

whileprintingrecords;
numbervar amtx := amtx + {PAYDEDUCTN.DED_AMT};
Select {pay_type}
Case "25" : if remainder(amtx,25) in [0,5] then
25
else 0
Case "50" : if remainder(amtx,50) = 0 then
50
else 0
Case "100" : if remainder(amtx,100) = 0 then
100
else 0

Default : 0;

-LB
 
You are absolutely correct. I got the picture.

Basically, remainder = balance and we need to determine the possible values.

This will not work:
Case "50" : if remainder(amtx,50) = 0 then
50
else 0
since if you notice my example above,

Type= 50 worked for:
amnt rem amntreached
=------------------------
20 20 0
20 40 0
20 10 50 (** correct **)
20 30 0
20 0 50
I need to see 50 in line 3 (***correct ***) and if I apply remainder = 0 , then that particular row is ignored.


Type=50 did not work for:
-----------------------------

5 5 0
5 10 50 (** wrong ***)
5 15 0
5 20 0
20 0 50 (***correct ***)
although, remainder = 0 will work here.




 
I only now noticed that you also changed the amount column. You would have to test the remainder values for each different value of the amount column. You could do a formula like this:

whileprintingrecords;
numbervar amtx := amtx + {PAYDEDUCTN.DED_AMT};

if {PAYDEDUCTN.DED_AMT} = 10 then (
Select {pay_type}
Case "25" : if remainder(amtx,25) in [0,5] then
25
else 0
Case "50" : if remainder(amtx,50) = 0 then
50
else 0
Case "100" : if remainder(amtx,100) = 0 then
100
else 0
) else
if {PAYDEDUCTN.DED_AMT} = 5 then (
Select {pay_type}
Case "25" : if remainder(amtx,25) = 0 then
25
else 0
Case "50" : if remainder(amtx,50) = 0 then
50
else 0
Case "100" : if remainder(amtx,100) = 0 then
100
else 0
) else
if {PAYDEDUCTN.DED_AMT} = 20 then (
//etc.

There must also be some logic to the assignment of deduction amount and paytype, I would think.

-LB

 
LB, Thank you so much for all your help. I think I will have to play with this some more. Your suggestions have been extremely helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top