HP 3000 Manuals

IF Command [ HP ALLBASE/4GL Developer Reference Manual Vol. 2 ] MPE/iX 5.0 Documentation


HP ALLBASE/4GL Developer Reference Manual Vol. 2

IF Command 

The IF command conditionally executes some logic commands as a result of
testing one condition or a combination of two conditions.

Formats 

IF condition_1 [{&}condition_2] THEN command(s) ELSE command(s)]
               [{|}           ]
Where & - AND, and | - OR

and condition_1 and condition_2 can be:

       operand relational_operator operand 

              operand *BLANK

              operand *ALPHA

              operand *NULL

              operand *NUMERIC

              switch_name *ON

              switch_name *OFF

Window 

[]
Parameters condition_1, condition_2 The condition being tested. The condition may be testing the relationship between two operands, the content of an operand, or the status of a switch. operand The item being compared. This item may be compared with another item, or its content may be tested for a certain status. The operand may be one of the following: * Whole number. * Literal. * Numeric or alphanumeric constant. * Variable or calculated item. * Screen field reference. * Scratch-pad field reference. * File record field reference. * Work area field reference. * Communication area field. Operand Content Test. Tests the contents of one operand. The test can be one of the following: Test Name Meaning *BLANK Is operand all spaces? *ALPHA Is operand all letters? (Leading and trailing spaces are ignored) *NULL Does operand contain a null value? This test is only valid if the operand is a field on a record layout for an HP ALLBASE/SQL table or a select list. *NUMERIC Does operand meet N or S edit code requirements? You cannot use these tests if the operand is a literal. relational_operator Tests the relationship between two operands. The relational operator may be one of the following: Relational Meaning Operator = equal to <> not equal to > greater than >= greater than or equal to < less than <= less than or equal to When you use a relational operator to compare two operands, the edit code of the operands determines the nature of the relational comparison. If you compare two numeric fields, the comparison is made on strict numeric order. If you compare two alphanumeric fields, or compare an alphanumeric field against a literal, the comparison is made on a character-by-character basis using the system collating sequence (refer to appendix A).
NOTE If you use a relational operator to compare two fields, make sure that both fields have the same edit code, or contain similar types of data.
switch_name The name of the switch to be tested. The switch name can be one of the following: * A number in the range 1 to 8, representing one of the eight user switches. * *SHOWING. * *ENTERED. * *BYPASS. * *ENDLINE. * *MOREREC. The status of the switch may be *ON or *OFF. command May be any logic block commands except: * IF. * IFLOOP. * SELECT. If you use more than one command, separate the commands with semicolons. Some logic commands allow you to specify an optional command to be executed if an error condition occurs. These are the CALC, DATE, FILE, MATH, MATHLOOP and VALIDATE commands. If you use one of these commands in the THEN command list or the ELSE command list of an IF command, you must include the error condition command. If you don't, HP ALLBASE/4GL interprets the next command in the command list as the error command, and will only execute it if an error occurs in the previous command. Description The IF command tests one or two conditions and then performs one or more commands, depending upon the result of the conditional test. For repeatedly performing a conditional test, use the IFLOOP command. The IF command can test the following conditions: * The status of a switch. * The contents of an operand. * The relationship between two operands according to a relational operator. You can test more complex combinations of conditions with a decision table. Refer to chapter 11 for more information about decision tables. When HP ALLBASE/4GL is comparing two operands of unequal length according to a relational operator, it extends the shorter of the two operands with spaces until it is the same length as the other operand. The IF command tests if the condition is true or false: * If the condition is true, the THEN command(s) are executed. * If the condition is false, the ELSE command(s) are executed if you have specified any. The argument ELSE and its associated commands are optional. If you don't specify any ELSE arguments, no commands are executed if the condition is false. The IF command can test a compound condition consisting of two different conditions. In this case, a Boolean or logical AND or logical OR operator links the two conditions. The system tests the compound condition as one condition. The following statements illustrate the use of the AND/OR logic: condition_1 AND condition_2 In this situation both condition_1 and condition_2 must be true before the compound condition is true. If either condition is false, then the compound condition is false. condition_1 OR condition_2 In this situation at least one of condition_1 or condition_2 must be true before the compound condition is true. If both conditions are false, then the compound condition is false. HP ALLBASE/4GL uses the following symbols to specify the AND or OR logical connectives: Symbol Meaning & AND | OR Example 1 IF *ENTERED *OFF THEN CLEAR *S; EXIT This command tests the status of the *ENTERED switch. If *ENTERED is off then HP ALLBASE/4GL clears all screen fields and then exits the logic block. If *ENTERED is on, HP ALLBASE/4GL executes the next logic command. Example 2 IF * = "A" | * = "C" THEN ZIP ELSE VISIT delete_rec This command checks the contents of the current screen field. If the field contains either the letter A or C, no action is taken. If the field contains neither of these letters, HP ALLBASE/4GL executes the function delete_rec. In either case, HP ALLBASE/4GL then executes the next command after the IF command. Example 3 IF V-code &<> "NEW" THEN SERIES 10 20; ENTER 1 This command tests the content of the variable code. If the variable doesn't contain the string NEW, HP ALLBASE/4GL executes command step numbers 10 through 20. Processing then returns to step 1.


MPE/iX 5.0 Documentation