Compound WHEN statements are used when multiple search criteria must be met before Control-M/Analyzer processes DO statements.
Each WHEN block has a single or compound WHEN statement and one or more DO statements associated with it. The search is conducted as follows:
If the string is not found, the WHEN block, including its DO statements, are skipped and rule processing continues.
If the string is found (for example, the WHEN criteria are met), the current position is set to the position of the first character of the located string in the data source. This position is stored for every WHEN statement and can be referenced by the LEVEL parameter in a DO EXTRACT statement. Control-M/Analyzer then searches for the string specified by the next WHEN statement of the current WHEN block.
Note: If there are two or more compound WHEN statements, after the first has been found, the search continues for the next WHEN, and so on. The process is repeated for each page.
After performing the DO statements, Control-M/Analyzer continues to search for the string specified in the last (lowest) WHEN statement. Each time the string is found, the DO statements are performed again.
Note: If only one WHEN statement exists in the block, it is considered the last. Therefore, it is searched for repeatedly. Each time its criteria are met, the DO statements are performed. If the EXECUTE block consists of several WHEN blocks, the WHEN blocks are executed in parallel and independently of each other. This enables the simultaneous search for unrelated criteria in the same data.
Example 1
A large company is divided into several departments. Each department contains many employees. A report exists that is grouped by department. Within each department, employees and corresponding salary information are listed in alphabetical order.
Figure 280 Data for WHEN Structure – Example 1
COMPUTER ENTERPRISES, INC. 05/05/00 PAGE: 1
DEPT. NO DEPT. TITLE
/EMP. NO /EMP. NAME START SALARY
============================================================================
001 MARKETING DEPARTMENT
-----------------------------------
002201 GRANT, THOMAS 04/09/96 40,000
002015 JAMES, KAREN 02/01/97 45,000
001839 JONES, BARRY 03/08/94 36,000
002345 ROBERTSON, JANE 03/10/99 20,000
020 ACCOUNTING DEPARTMENT
------------------------------------
002154 JONES, BOB 04/11/98 35,000
001454 SMITH, BARBARA 02/02/00 45,000
002002 WILLIAMS, SALLY 01/10/99 35,000
The salary information for an employee named Jones in the accounting department is desired. A compound WHEN statement is specified:
Table 271 Compound WHEN Statement for WHEN Structure – Example 1
WHEN Statement Level Number |
String to Search for |
STOP String |
---|---|---|
1 |
ACCOUNTING |
BRANCH: |
2 |
JONES |
|
STOP Criteria
After DO statements of a WHEN block are performed, the search continues for the last (lowest) WHEN statement.
STOP criteria provide a means to restart searches from higher level WHEN statements (of the current WHEN block).
If the criteria of a WHEN statement are met, Control-M/Analyzer searches for the STOP criteria specified in that WHEN statement. This search begins on the next line after the line containing the WHEN statement criteria.
If the STOP criteria are not met, processing continues as described in "Compound WHEN Statements" above.
If the STOP criteria are met, Control-M/Analyzer stops searching for strings specified by lower WHEN statements and resumes searching for the string specified in the WHEN statement whose STOP criteria were met. This search begins with the line containing the STOP criteria.
Example 2
A large restaurant chain has several branches. Each branch employs several individuals. A report exists that is grouped by branch. Each branch name is preceded by the string BRANCH:. Within each branch, employees and their salary information are listed. Each employee name is preceded by the string EMPLOYEE:.
Figure 281 Data for WHEN Structure – Example 2
FAST-FOOD, INC. 05/05/00 PAGE:51
==============================================================================
BRANCH: MIAMI BEACH
------------------------------------------------------------------------------
EMPLOYEE: GRANT, THOMAS 04/09/96 40,000
EMPLOYEE: JAMES, KAREN 02/01/97 45,000
EMPLOYEE: JONES, BARRY 03/08/94 36,000
EMPLOYEE: ROBERTSON, JANE 03/10/99 20,000
BRANCH: NEW YORK CITY
------------------------------------------------------------------------------
EMPLOYEE: JONES, BOB 04/11/98 35,000
EMPLOYEE: SMITH, BARBARA 02/02/00 45,000
EMPLOYEE: WILLIAMS, SALLY 01/10/99 35,000
BRANCH: PHILADELPHIA
------------------------------------------------------------------------------
EMPLOYEE: MCPHEARSON, BRIAN 10/10/98 25,000
EMPLOYEE: PETERS, KEITH 04/04/97 50,000
Salary information for all employees of the New York City branch is desired. STOP criteria are specified within a compound WHEN statement:
Table 272 Compound WHEN Statement for WHEN Structure – Example 2
WHEN Statement Level Number |
String to Search for |
STOP String |
---|---|---|
1 |
NEW YORK CITY |
BRANCH: |
2 |
EMPLOYEE: |
|
Parent Topic |