Syntax
{ CASE value [ ,...n ] : <logic_block> } [ ... n] [ OTHERWISE : <logic_block> ]
Parameters
Case can be abbreviated as CS.
The Case logic command is preceded by a BeginCase logic statement, followed by logic statements to execute if the specified case is true, further optional additional Case logic statements, then by an optional Otherwise logic statement, and finally by an EndCase logic statement.
value
A value that defines a specific case. Multiple values can be used to define any one case provided they are separated by commas.
If an application uses a comma (,) as the decimal character, it is recommended that in a Case list containing a list of numbers, the numbers are separated by a comma and a space to explicitly indicate each individual case number. For example, Case 1, 2, 3, 4 Case 1,2, 3,4 Case 1, 2,3, 4 The first case list consists of the numbers 1, 2, 3 and 4. The second case list consists of the numbers 1.2 and 3.4. The third case list consists of the numbers 1, 2.3 and 4. |
Description
The Case logic command specifies values that, if matched by the control variable specified by the associated BeginCase logic statement, direct logic flow to subsequent logic statements.
The following table lists the compatible control variable primitives that can be compared to each value primitive. For example, if the value is a national string, it can only be compared with a national string-primitive control variable.
Value | Compatible Control Primitives | |||||
---|---|---|---|---|---|---|
String | Number | Signed number | Decimals | Date | National string | |
String | X | X |
|
| X |
|
String literal | X |
|
|
|
|
|
Number | X | X | X | X | X |
|
Numeric literal | X | X | X | X | X |
|
Signed |
| X | X | X | X |
|
Signed numeric literal | X | X | X | X | X |
|
Decimals |
| X | X | X | X |
|
Date | X | X | X | X | X |
|
National string |
|
|
|
|
| X |
Glb.Zeros | X | X | X | X | X |
|
Glb.Spaces, Glb.High, Glb.Low | X |
|
|
|
|
|
Case logic commands function as the central part of a case statement. Using a case statement is an efficient alternative to multiple DoWhen logic statements.
The commands used to define a case statement are listed in the following table.
Command | Function |
---|---|
BeginCase | Start of the case statement, specifies the control value. |
Case | Case condition, specifies specific values of the control variable and corresponding logic. |
Otherwise | Default case condition. |
EndCase | End of the case statement. |
The BeginCase logic command specifies the control variable against which values defined by the Case logic statements are compared. If any of the values specified matches that of the control variable, the following logic (up to the next case condition) is executed and logic flow continues from the EndCase logic command that terminates the case statement.
The Otherwise logic command can be used to specify logic to be performed when no other case conditions apply. Case logic statements can also be nested within Otherwise logic statements.
Refer to If/DoWhen and JumpTo for more information on restrictions on branching and case statements.
Example
This example, in the Main method of a report, accesses all Emply ispecs to obtain employee details. Depending on the department each employee works in, their details are either extracted to one of four predefined extract files (FileA, FileJ, FileM, or FileC), or ignored (for departments S and T, and invalid departments). Employees with invalid department codes are listed (by printing Frame90).
LookUp Every Emply BeginCase Emply.Dept Case "A", "B", "C" Extract Emply As FileA: Do this if Emply.Dept is "A", "B", or "C". Case "J" Extract Emply As FileJ: Do this if Emply.Dept is "J". Case "M" Extract Emply As FileM: Do this if Emply.Dept is "M". Case "S" : Do nothing if Emply.Dept is "S". Case "T" : Do nothing if Emply.Dept is "T". Case "Z" Extract Emply As FileZ: Do this if Emply.Dept is "Z". Otherwise Frame90.Print(): Do this if Emply.Dept is not "A", "B", : "C", "J", "M", "S", "T", or "Z". EndCase End