GROUP command

Used to execute a series of ACLScript commands on each record that matches the specified conditions with only one pass through the ACL table.

Syntax

GROUP <IF test> <WHILE test> <FIRST|NEXT range>
  command
  <...n>
<ELSE IF test>
  command
  <...n>
<ELSE>
  command
  <...n>
END

Parameters

IF test

Optional. Specifies a condition that must be met. The commands under the GROUP command are only executed on records that pass the test.

WHILE test

Optional. Specifies a condition that must be met for the GROUP command to continue executing.

FIRST|NEXT range

Optional. Specifies that the GROUP command should only be executed for the number of records specified by the range parameter. If FIRST is specified the range of records is selected starting at the first record in the table. The one exception is if the LOCATE command has been used to select a record in the table, which results in ACL starting the range from this record. If NEXT is specified the range of records is selected starting at the currently selected record in the table.

command

The ACLScript command to execute if the preceding IF or ELSE IF test evaluates to true. If the command is listed under an ELSE parameter, the command is executed if there are records that have not been processed by any of the preceding commands. You can include multiple commands, with each command starting on a separate line.

ELSE IF test

Optional. Specifies a condition to test for records that did not match the GROUP command test, or any previous ELSE IF tests. You can include multiple ELSE IF test and they are evaluated from top to bottom, until the record evaluates to true and the commands that follow that ELSE IF statement are executed.

ELSE

Optional. Specifies that the commands that follow should be executed for records that evaluated to false for all of the previous tests.

END

Specifies the end of the GROUP statement.

Remarks

Table 1. Commands that can be used inside the GROUP command
AGE ASSIGN BENFORD
CLASSIFY COMMENT COUNT
CROSSTAB DUPLICATES EXPORT
EXTRACT GAPS GROUP
HISTOGRAM JOIN LIST
LOOP MERGE PROFILE
REPORT SEQUENCE STATISTICS
STRATIFY SUMMARIZE TOTAL
VERIFY    

The GROUP command allows you to execute several commands on a record before moving to the next record in the table, which can significantly reduce processing time.

You can use the LOOP command inside the GROUP command if you need to execute a series of commands more than once against repeating information in a particular record.

The multiline syntax listed for the GROUP command is required, and therefore the GROUP command cannot be entered in the command line.

Each GROUP command must be terminated with an END command.

When you use the GROUP command in your scripts, you can improve the readability of the command block by indenting the commands listed inside the group.

Examples

a. GROUP

Simple groups start with a GROUP command, are followed by a series of commands, and terminate with an END command. For example:

GROUP
  COUNT
  HISTOGRAM ON Quantity MINIMUM 0 MAXIMUM 100 INTERVALS 10
  CLASSIFY ON Location SUBTOTAL Quantity
END

b. GROUP IF

Conditional groups execute commands based on whether a condition is true or false. For example, the following GROUP command is executed only on records with a Product_class field whose value is less than 5:

GROUP IF Product_class < "05"
  COUNT
  HISTOGRAM ON Quantity MINIMUM 0 MAXIMUM 100 INTERVALS 10
  CLASSIFY ON Location SUBTOTAL Quantity
END

c. GROUP IF...ELSE

Records that do not meet the test condition are ignored unless you include an ELSE statement. Any number of commands can follow an ELSE statement. In the following example, all records that do not meet the condition are processed by having their Quantity field totalled.

GROUP IF Product_class < "05"
  COUNT
  HISTOGRAM ON Quantity MINIMUM 0 MAXIMUM 100 INTERVALS 10
  CLASSIFY ON Location SUBTOTAL Quantity
ELSE
  TOTAL Quantity
END

d. GROUP IF...ELSE IF...ELSE

You can include multiple ELSE IF statements within a group, as long as each ELSE IF statement contains a different test. In the following example, the ELSE IF statements produce four totals:

GROUP IF Product_class < "05"
  COUNT
  HISTOGRAM ON Quantity MINIMUM 0 MAXIMUM 100 INTERVALS 10
  CLASSIFY ON Location SUBTOTAL Quantity
ELSE IF Product_class = "05"
  TOTAL Quantity
ELSE IF Product_class = "06"
  TOTAL Quantity
ELSE IF Product_class = "07"
  TOTAL Quantity
ELSE
  TOTAL Quantity
END

e. Nested groups

Nested groups refer to groups contained within other groups. Nested groups provide a powerful way for you to control which commands are executed for which records. Most applications do not require such an advanced level of functionality, but it is available, if necessary.

As with other groups, use the END command to terminate a nested group. ACL starts processing the data only after all group commands have been terminated. For example:

GROUP IF Product_class < "05"
  COUNT
  STRATIFY ON Quantity SUBTOTAL Quantity MIN 0 MAX 100 INT 10
  GROUP IF Quantity > 0
    STATISTICS ON Quantity
    HISTOGRAM ON Quantity
  END
ELSE
  TOTAL Quantity
END

In this example, all of the commands from COUNT up to and including the next GROUP are executed only if Product_class is less than 05.

The STATISTICS and HISTOGRAM commands are executed if Quantity is greater than zero. However, because the second GROUP command is nested, the STATISTICS and HISTOGRAM commands are executed only for records that meet the conditions Product_class < “05” and Quantity > 0.

Related reference
LOOP command


(C) 2015 ACL Services Ltd. All Rights Reserved.