Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 10 Conditional Processing : Examples of Conditions

Examples of Conditions
Types of Examples
The following are examples of conditions as:
A table.field reference
Expression as a Condition
In the following example:

 
RULE EDITOR ===> SCROLL: P
EMPLOYEE_COUNT(DEPT);
_ LOCAL COUNT;
_ ---------------------------------------------------------------------------
_ DEPT > 0; | Y N
_ ------------------------------------------------------------+--------------
_ COUNT = 0; | 1 1
_ FORALL EMPLOYEES WHERE REGION = 'MIDWEST' & DEPTNO = DEPT | 2
_ ORDERED DESCENDING LNAME : |
_ CALL MSGLOG(EMPLOYEES.LNAME); |
_ COUNT = COUNT + 1; |
_ END; |
_ CALL ENDMSG(COUNT || ' EMPLOYEES IN DEPARTMENT# ' || DEPT) | 3 2
_ ; |
_ ---------------------------------------------------------------------------
_ ON CONVERSION:
_ CALL ENDMSG('Value for DEPT must be numeric');
 
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
Argument as a Condition
In the following example, actions under the Y column are performed only when the argument NEW has a value of Y. If the value is N, actions under the N column are performed.

 
RULE EDITOR ===> SCROLL: P
EMPLOYEE_UPDATE(NEW);
_
_ ---------------------------------------------------------------------------
_ NEW ; | Y N
_ ------------------------------------------------------------+--------------
_ CALL ENDMSG('NEW EMPLOYEE'); | 1
_ CALL ENDMSG('EXISTING EMPLOYEE'); | 1
_-------------------------------------------------------------+--------------
 
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
When using an argument as a condition, any character value passed into the argument other than Y is evaluated as if it is N. An error occurs if a numeric value is passed in.
table.field as a Condition
In the following example:
1.
2.
3.
4.

 
RULE EDITOR ===> SCROLL: P
GET_EXEMPT1(NAME);
_
_ ---------------------------------------------------------------------------
_ -----------------------------------------------------------+--------------
_ GET MANAGER WHERE MANAGER_NAME = NAME; | 1
_ CALL GET_EXEMPT2(NAME); | 2
_ --------------------------------------------------------------------------
_ ON GETFAIL :
_ CALL ENDMSG(NAME || ' IS AN INVALID NAME');
 
 
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
 
RULE EDITOR ===> SCROLL: P
GET_EXEMPT2(NAME);
_
_ ---------------------------------------------------------------------------
_ MANAGER.EXEMPT; | Y N
_ -----------------------------------------------------------+---------------
_ CALL ENDMSG(NAME || ' IS EXEMPT'); | 1
_ CALL ENDMSG(NAME || ' IS NOT EXEMPT'); | 1
_----------------------------------------------------------------------------
 
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
Functional Rule as a Condition
To handle more complicated situations, you can invoke a functional rule as a condition. The following rule illustrates the use of a function, in this case the PATTERN_MATCH tool. In the example:
The rule checks to see if the commands SELECT or DELETE, or an abbreviation of these commands, such as SEL or DEL, are valid.
If the command is a valid SELECT or DELETE command, the appropriate rule is called.
If the command is not valid, the user gets a message on the screen explaining that the command is not acceptable. The following illustrates a rule using PATTERN_MATCH:

 
RULE EDITOR ===> SCROLL: P
PROCESS_CMD(USER_COMMAND);
_
_ ---------------------------------------------------------------------------
_ PATTERN_MATCH(COMMAND, 's*'); | Y N N
_ PATTERN_MATCH(COMMAND, 'd*'); | Y N
_ ------------------------------------------------------------+--------------
_ CALL SELECT_COMMAND; | 1
_ CALL DELETE_COMMAND; | 1
_ CALL SCREENMSG(USERCOMMAND ||' IS AN INVALID COMMAND'); | 1
_-------------------------------------------------------------+--------------
 
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
When using a functional rule as a condition, any character value returned other than Y is evaluated as if it is N. An error occurs if the functional rule returns a numeric value.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved