HP 3000 Manuals

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


HP ALLBASE/4GL Developer Reference Manual Vol. 2

IFLOOP Command 

The IFLOOP command performs a conditional IF test repeatedly.

Format 

IFLOOP loop_count condition THEN command(s) [ ELSE command(s)]

where condition may be:

   *   operand step_factor relational_operator operand step_factor 

   *   operand step_factor *BLANK

   *   operand step_factor *ALPHA

   *   operand step_factor *NULL

   *   operand step_factor *NUMERIC

   *   switch_name 0 *ON

   *   switch_name 0 *OFF

Window 

[]
Parameters loop_count A number specifying the number of times the test is performed. condition The condition being tested. operand The item being compared or tested. 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. step_factor A number specifying the increment to be applied to the operand name to obtain the operand to be tested on the next loop of the command. The step factor may be a positive or negative number, or zero. The increment is applied to the operand name, and not to its value. This enables the IFLOOP command to test successive fields on a screen or file record. The step factor may be zero. A zero step factor causes the IFLOOP command to test the same operand each time. You must use a zero step factor for the following: * Numeric or alphanumeric constant. * Variable or calculated item. * Literal or number. * Switch. 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 A reference to a system or user switch. This may be one of the following: * A number between 1 and 8 representing one of the user switches. * *BYPASS * *ENDLINE * *ENTERED * *SHOWING * *MOREREC You must use a step factor of 0 with switches. The status of the switch may be *ON or *OFF. commands May be any logic 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 IFLOOP 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 IFLOOP command repeatedly performs a conditional test. The command operates in a similar manner to the IF command except that the system repeats the conditional test for each occurrence of the loop_count. In the IFLOOP command, each operand within a condition incorporates a step factor. The step factor determines, on each successive iteration of the loop, the next operand to be tested. If an operand is a file record field reference or a work area field reference, HP ALLBASE/4GL steps through the fields on the record(s) according to the step factor. HP ALLBASE/4GL will step through multiple occurrences of fields defined as having more than one occurrence in the dictionary. The IFLOOP command can test the following conditions: * Status of a switch. * Contents of an operand. * Relationship between two operands according to a relational operator. You can test combinations of conditions with a decision table. Refer to the DECISION command for further details. When the system is comparing two operands of unequal length according to a relational operator, it extends the shorter of the two operands with the spaces until it is the same length as the other operand. The IFLOOP command is typically used to: * Test a number of consecutive fields. * Repeatedly test a switch. If one of the commands after the THEN or ELSE is PROCEED, TOP, ENTER, or EXIT, the IFLOOP command terminates when the test reaches the specified condition. That is, the IFLOOP command may not be executed for the full loop_count number of times. Example 1 IFLOOP 10 1 0 *OFF THEN VISIT update_data ELSE VISIT delete_data This command tests the status of user switch number 1 ten times (with a step factor of 0). If the switch is off, HP ALLBASE/4GL executes the function update_data. Otherwise, HP ALLBASE/4GL executes the function delete_data. The functions can set or reset switch number 1 as part of their logic. Example 2 IFLOOP 7 S-acc_no.updt_acc 1 &<> F-account.act_mast 1 THEN MOVE "CHANGED" V-status; ENTER 12 This command checks (at most) the seven fields on the screen updt_acc, starting with acc_no, against the seven fields on the record act_mast, starting with account. If there is any difference, the system sets the value of the variable status to CHANGED and then executes step 12. Example 3 IFLOOP 10 *S01 1 *NUMERIC THEN VISIT numeric_field ELSE VISIT alpha_field This command checks the first 10 fields of the current screen and for each field, executes the function numeric_field if the field is numeric. If the field is not numeric, the function alpha_field is executed.


MPE/iX 5.0 Documentation