Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Unable to iterate Post Reply Post New Topic
Author Message
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Topic: Unable to iterate
    Posted: 17 Aug 2022 at 2:45am
There are sections of Test/Analytes (Grouped by a particular field) which have multiple rows of Status value.
we need to iterate over all the status values for the particular Test/Analytes section and if the status value is OOS-A only or combination of OOS-A with OOS-B or Done then the summarized status value should be OOS .
If the Status value is in combination of OOS-B and Done or only OOS-B or only Done then the summarized status value will be Done

Following code has been tried,
if(not isnull({Grouping field})) and ( (({Status}= "OOS-A")
and ({Status}= "Done"))or ({Status}= "OOS-A") or ({Status}="Done"
and ({Status}= "OOS-B") and ({Status}= "OOS-A")) then "OOS"
else "Done"

but it is taking only first row of the status field. It is not iterating.
Please help me to iterate the field
IP IP Logged
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Posted: 17 Aug 2022 at 6:27am
could you please give any suggestion trying with for loop or any other functions?

I tried the below one, but it is showing syntax error.

counter :=Count ({Status})
for i := 1 To counter Do
(
if
{Status}="OOS-A" or
{Status}="OOS-B"
then str := "OOS"
else str := "Done");
str



Edited by Reva - 17 Aug 2022 at 10:31pm
IP IP Logged
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Posted: 17 Aug 2022 at 10:29pm
whileprintingrecords;


Local StringVar str := "";
Local NumberVar i;

numbervar counter;
counter :=Count ({Status})
for i := 1 To counter Do
(
if
{Status}="OOS-A" or
{Status}="OOS-B"
then str := "OOS"
else str := "Done");
str


I'm getting the remaining text doesn't appear to be part of the formula error for below part.


for i := 1 To counter Do
(
if
{Status}="OOS-A" or
{Status}="OOS-B"
then str := "OOS"
else str := "Done");
str


Please advise me the syntax or guide me the code.

Edited by Reva - 17 Aug 2022 at 10:42pm
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 18 Aug 2022 at 3:53am
For one you are missing a semicolon after the number :=count({Status}).  Not sure about the rest of the code.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 23 Aug 2022 at 7:12am
If the status is in multiple records, you can't use a loop to do this. Instead, you'll need to use a couple of variables to track which of the statuses the test has and then calculate the final status in the group footer. The formula might look like this (you may have to tweak the location of some semi-colons...):

BooleanVar hasA;
BooleanVar hasB;
BooleanVar hasDone;

//initialize the variables for each group
If OnFirstRecord or {GroupingField} <> Previous({GroupingField}) then (
hasA := false;
hasB := false;
hasDone := false;
);

If {Status} = "OOS-A" then hasA := true
Else if {Status} = "OOS-B" then hasB := true
else if {Status} = "Done" then hasDone := true;
""

Put this formula in the details section - even if details are suppressed. The "" at the end makes sure nothing will actually show up on the report, but the formula will be processed.

If you want to just show the data about the test, suppress the group header and the details and put all of the test fields in the group footer. Then use the following formula to display the correct status:

BooleanVar hasA;
BooleanVar hasB;
BooleanVar hasDone;

If hasA then "OOS"
Else If hasB or hasDone then "Done"
Else {Status}


Because the logic is if A or (A and B) or (A and Done) or (A and B and Done), you only need to look for A to determine whether the status is A - you don't have to worry about any of the other tests because A is always a part of them.

The same type of thing applies for the logic for (not A) and (B or (B and Done) or Done) - you only have to check for either B or Done to determine if the status is Done.

-Dell
IP IP Logged
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Posted: 24 Aug 2022 at 9:41pm
Thank you so much for your time hilfy. It means lot to me.. and sorry for late reply!

I tried above code but it didn't take second row of the result. It is only checking first row. For instance,

TestName             criteria                  Result
Testname1             1                        OOS-A
                      2                        OOS-B
                      3                        Done            --> output here showing as OOS-A

Testname2             1                        Done
                      2                        OOS-B
                      3                        OOS-A            --> output here showing as Done but output should be OOS-A
                            
Testname3            1                        Done
                      2                        OOS-A           --> output here showing as Done but output should be OOS-A

It is not iterating in the field.. Please enlighten me your thoughts. Thanks early!!                            

Edited by Reva - 24 Aug 2022 at 9:43pm
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 13 Sep 2022 at 12:38pm
Sorry for the late reply... I don't come to the forum very often.

Do you want the result for the Test as a whole or for each of the separate criteria? If you want it for the test as a whole, you'll do the following, assuming that you've grouped on the TestName:

1. Suppress the details and the TestName group header sections.

2. Put the test name and the result in the Test Name group footer.

If you need to show the criteria and their results, put them in the details and use the result field, not the formula.

Or you might have to put the word "Global" at the beginning of each of the variable declarations (but you shouldn't need to...)

-Dell

-Dell
IP IP Logged
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Posted: 14 Sep 2022 at 12:52am
Thank you so much for your time.

I have tried above steps and my findings as follows,
I need Test as a whole but the result part should display OOS if any of the row contains OOS-A, otherwise it should return Done.

Here, If I put test name and the result in the Test Name group footer, I'm getting only last record of result.

If I put test name and the result in the Test Name group Header, I'm getting only first record of result.

It is not getting the actual output.

Example:

let us take 2 examples of Result field:
Ex:1
OOS-A
Done
Done
If I put:
Test name and the result in the Test Name group Header - Output is OOS

Test name and the result in the Test Name group Footer - Output is Done

Ex:2
Done
Done
OOS-A
If I put:
Test name and the result in the Test Name group Header - Output is Done

Test name and the result in the Test Name group Footer - Output is OOS

So, It is not reading the next data or rest of data.

In this case, could you please provide your insights?
Thanks in Advance!!

Edited by Reva - 14 Sep 2022 at 12:57am
IP IP Logged
Reva
Newbie
Newbie


Joined: 21 Aug 2020
Online Status: Offline
Posts: 11
Quote Reva Replybullet Posted: 20 Sep 2022 at 12:57am
Hello,

I found that we can get only first record in header and only last record in footer.

Hence, I tried in details section.

After I suppressed duplicate values and blank section I am having Result as OOS and Done for some of the test. But I should get OOS for the test if any of the result as OOS.
For instance,
Test    Criteria    Result
T1        1          OOS

T2        2          OOS
                     Done
T3        3          Done
                     OOS
T4        4          Done

I have grouped test field.
I tried to suppress Done row if OOS presents for the test
and tried to change OOS to Done.

But I couldn't get the results.
Please provide your insights.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.