The Number 1 independent website for ACL information!

TexasACL User Group
About Us
Training
Why ACL
Essays & Scripts
ACL News
Events
Links
FAQ
Site Map
Support Us
How to Debug Groups?
 
This was derived from an actual discussion on the ACL User Forum:
 
A user had been struggling with a GROUP command that utilized multiple conditions.  The sample data looked like:

N 11             C 5             C 25                       C 100      N 7

EncntrID     PlanName     NameFullFormatted     ALIAS     AliasTypeCd
11801010     Plan1          ALPHA, BRAVO           611899     1079
11801010     Plan1          ALPHA, BRAVO           8650505     1077
11801010     Plan2          ALPHA, BRAVO           611899     1079
11801010     Plan2          ALPHA, BRAVO           8650505     1077
11801010     Plan3          ALPHA, BRAVO           611899     1079
11801010     Plan3          ALPHA, BRAVO           8650505     1077
11878300     Plan4          CHARLIE, DELTA         2055504     1079
11878300     Plan4          CHARLIE, DELTA         8672685     1077
11878300     Plan5          CHARLIE, DELTA         2055504     1079
11878300     Plan5          CHARLIE, DELTA         8672685     1079

Here's his script:

finNbr = blanks(10)
mrn = blanks(10)
eid = 0
pn = blanks(5)
GROUP IF eid=encntrID AND pn=planName
       finNbr=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1077
       mrn=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1079
    ELSE
       EXTRACT finNbr mrn eid AS "encntrID" nameFullFormatted AS "Name" pn as "PlanName" IF recno()<>1 TO extract1 LOCAL EOF
       eid = encntrID
       pn = planName
       finNbr=blanks(10)
       mrn=blanks(10)
       finNbr=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1077

       mrn=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1079
END
 
Results:
 
His end results were to look like this:

finNbr         mrn         encntr_id      name                 planName
8650505     611899     11801010     ALPHA, BRAVO     Plan1
8650505     611899     11801010     ALPHA, BRAVO     Plan2
8650505     611899     11801010     ALPHA, BRAVO     Plan3
8672685     2055504   11878300     CHARLIE, DELTA   Plan4
8672685     2055504   11878300     CHARLIE, DELTA   Plan5

Instead the user got this:

finNbr         mrn         encntr_id      name                 planName

8650505     611899     11801010     ALPHA, BRAVO     Plan1
8650505     611899     11801010     ALPHA, BRAVO     Plan2
8650505     611899     11801010     CHARLIE, DELTA   Plan3
8672685     2055504   11878300     CHARLIE, DELTA   Plan4
8672685     2055504   11878300     ALPHA, BRAVO     Plan5
 
How to Debug the Group:
 
One way to test GROUPS if they aren't behaving the way you expect them to is to manually perform the test.  In other words, a GROUP will perform a number of commands on every record. To simulate this, one would need to identify the record and perform the actions of the code on individual lines.
 
First, one can use the "LOCATE RECORD" command to identify a record---if you know where the code is having problems, you might select the record just before the error.  
 
Second, if the code uses a condition such as IF or WHILE, you can test the results by using "DISPLAY IF <Condition>."  If the result is "True", then you would perform the actions in that section.  If it is "False", you would skip to the next "ELSE" option.
 
Third, if you are performing an EXTRACT, make sure that you modify the EXTRACT command to include the condition "IF RECNO() = [the record being analyzed] and the option "APPEND."
 
Fourth, when you finish running through the GROUP on a given record, perform a "DISPLAY VAR"   DISPLAY VAR will display all the variables in the system.  Use that to compare what the values in the system match the values you expected them to be.
 
Fifth, after performing it on on record, redo the entire GROUP command after advancing to the next record via the LOCATE RECORD command.
 
At each point, check the results to see if they are what you expected them to be.  If they are not, figure out what you need/want.
 
What was Happening:
 
On the first record, ACL skipped the first section and went straight to the ELSE statement.  As the RECNO() =1, it skipped the EXTRACT and immediately defined the variables you used.  Everything is fine so far.

On the second record, ACL recognized that the the EID and encntrID matched as well as the pn and planname.  It correctly defined the variable you sought.

On the third record, ACL recognized that the EID/PN didn't match the encntrID/PlanName.  So it went to the EXTRACT STATEMENT.  In the EXTRACT statement, you were extracting:

FinNbr ---a value computed from the previous records.
Mrn --- a value computed from the previous records.
eid --- a value computed from the previous records.
NameFullFormatted --- the value from RECORD 3

As for the final record... since you were using EOF, and the value wasn't defined, it looks as if the defaulted back to the NameFullFormatted of the first record.
 
How to Correct the Code:
 
finNbr = blanks(10)
mrn = blanks(10)
eid = 0
pn = blanks(5)
name=blanks(15)
GROUP IF eid=encntrID AND pn=planName
   finNbr=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1077
   mrn=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1079
ELSE
   EXTRACT finNbr mrn eid AS "encntrID" Name pn IF recno()<>1 TO extract1 EOF
   eid = encntrID
   pn = planName
   finNbr=blanks(10)
   mrn=blanks(10)
   finNbr=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1077
   mrn=substring(alltrim(alias)+blanks(10),1,10) IF encntrAliasTypeCd=1079
   name=namefullformatted
END