Using recommended engineering practices > Recommended practices for creating the control strategy

Tips for writing expressions

Here are some tips for writing expressions:

The following example shows the original expression and the same expression improved through a reduced number of reads:

Original

IF OUT1 = 1 AND IN2 = 1 AND 'A_UNIT/B_MODE.CV' = 3 THEN
    'A_UNIT/STEP.CV' := 7;
ENDIF;
IF OUT1 = 1 AND IN2 = 0 AND 'A_UNIT/B_MODE.CV' = 2 THEN
    'A_UNIT/STEP.CV' := 5;
ENDIF;

Improved with Reduced Reads

IF OUT1 = 1 THEN
    IF IN2 = 1 AND 'A_UNIT/B_MODE.CV' = 3 THEN
         'A_UNIT/STEP.CV' := 7;
    ENDIF;
    IF IN2 = 0 AND 'A_UNIT/B_MODE.CV' = 2 THEN
        'A_UNIT/STEP.CV' :=5;
    ENDIF;
ENDIF;

The following example shows the original expression and the same expression improved through the use of a temporary variable TEMPMODE:

Original

IF 'A_UNIT/B_MODE.CV' = 4 THEN
    'A_UNIT/STEP.CV' :=9;
ENDIF;

IF 'A_UNIT/B_MODE.CV' = 5 THEN
    'A_UNIT/STEP.CV' := 11;
ENDIF;

Improved with Temporary Variable

TEMPMODE := 'A_UNIT/B_MODE.CV':

IF TEMPMODE = 4 THEN
    'A_UNIT/STEP.CV' := 9;
ENDIF;

IF TEMPMODE = 5 THEN
    'A_UNIT/STEP.CV' :=11;
ENDIF;

The following example shows the original expression and a more readable and informative version of the same expression that uses the Named Set Reference:

Original

IF 'UNIT/B_MODE.CV' = 3 THEN
    'A_UNIT/STEP.CV'  := 7;
ENDIF;

Improved with Named Set Reference

IF 'A_UNIT/B_MODE.CV' = 'Bch_Mode: Auto' THEN
    'A_UNIT/STEP.CV' := 'Step_Cmd: Step7';
ENDIF;