If/DoWhen

If and DoWhen logic commands are same and can be used interchangeably.

Syntax

IF { expression | class_attribute [NOT] NUMERIC }
    <logic_block>
[ ELSE
    <logic_block> ]
END | ENDEXIT ENDNOPRINT

Parameters

If is the preferred usage of the DoWhen logic command.

The If logic command is followed by a sequence of logic statements, then an optional Else logic statement, and then by an End, EndExit, or EndNoPrint logic statement.

Description

The If logic command introduces a sequence of logic statements to execute if a specified conditional expression is evaluated as true. This sequence of logic statements is terminated by an Else, End, EndExit, or EndNoPrint logic statement following the If logic statement.

Use the Else logic command to introduce a sequence of logic statements to execute if the specified conditional expression is evaluated as false.

Refer to Case (CS) for more information on different actions to take depending on evaluation of an expression against multiple conditions.

Note: Partial loads, using substitute conflict resolution, of a standard component containing the conditional profile If MAINT NOT=(D), do not clear the conditional profile.

Extract objects related to the component to avoid losing the conditional profile. For example, extract the standard component and related profile to ensure that conditions are restored when the component and objects are loaded. This applies to the MAINT attribute only.

Failure behavior

In an If logic statement specifying a compound conditional expression, the last array reference (if any) sets the Glb.Status built-in segment attribute. This occurs regardless of prior array references in the same If logic statement or whether the conditional expression is true or not overall.

Most processes that set Glb.Status on an error condition also set Glb.Status to spaces if no errors are detected.

As various conditions can set Glb.Status, exercise care when coding complex decision logic that involves multiple If logic statements. Consider the following logic:

If (Glb.Status <> Glb.Spaces && Array_Item <> Value)

The intent of the first condition is to check the result of a previous action. However, the evaluation of Array_Item takes place before this, and sets the Glb.Status built-in segment attribute before the first condition is evaluated.

It would be safer to write this as two separate if statements:

If Glb.Status <> Glb.Spaces
	    If Array_Item <> Value
		        : logic
	    End
End

Example

If (Customer <> Glb.Spaces) And (Override <> "OK")
       Determine Every PTransNum (TransNum)
             : Logic
       EndExit
EndNoPrint
If Quantity > (-12.34)
       Frame27.Print()
End
If Cust.AreaCode < 7
     If Cust.AreaCode > 4
           Run CtyRef : List city customers
     Else
           Run SubRef : List suburban customers
     EndExit
Else
     Run RrlRef : List rural customers
End