CASE: Create multiway branch (S7-1200, S7-1500, S7-1200 G2) - STEP 7

SCL (S7-1200, S7-1500, S7-1200 G2)

ft:publication_title
SCL (S7-1200, S7-1500, S7-1200 G2)
Product
STEP 7
Version
V21
Publication date
11/2025
Language
en-US
CASE: Create multiway branch

Description

The instruction "Create multiway branch" executes one of several instruction sequences depending on the value of an expression.

The value of the expression must be an integer or a bit string. When the CASE instruction is executed, the value of the expression (tag) is compared with the values of several constants. If the value of the expression (tag) agrees with the value of a constant the condition is fulfilled and the instructions that are programmed directly after this constant are executed. The constants can assume various values.

You can declare the instruction as follows:

CASE <Tag> OF

<Constant1>: <Instructions1>;

<Constant2>: <Instructions2>;

<ConstantX>: <InstructionsX>; // X >= 3

ELSE <Instructions0>;

END_CASE;

Parameters

The following table shows the parameters of the instruction:

Parameters

Data type

Memory area

Description

<Tag>

Bit strings, integers

I, Q, M, D, L

Value which is compared to the programmed constant values.

<Constant>

Local and global constants can be programmed.

Bit strings

-

The constants can assume the following values in case of a bit string:

  • A binary number (for example, 2#10)

  • An octal number (for example, 8#77)

  • A hexadecimal number (for example 16#AD)

  • An untypified constant (for example, 1000)

In the case of a typified byte tag, byte constants (for example, BYTE#2) must be programmed.

In the case of a typified Word tag, byte or word constants (for example, BYTE#2, WORD# 2) can be programmed.

In the case of a typified DWord tag, byte, Word, or DWord constants (for example, BYTE#2, WORD#2, DWORD#2) can be programmed.

In case of a typified LWord tag, byte, Word, DWord or LWord constants (for example, BYTE#2, WORD#2, DWORD#2, LWORD#2) can be programmed.

Integers

The constants can assume the following values in case of an integer:

  • An integer (for example, 5)

  • A range of integers (for example 15...20)

  • An enumeration consisting of integers and ranges (for example, 10, 11, 15...20)

<Instruction>

-

-

Any instruction that is executed when the value of the expression agrees with the value of a constant. An exception are instructions programmed after the ELSE. These instructions are executed if the values do not agree.

For additional information on valid data types, refer to "See also".

If the value of the expression agrees with the value of the first constant (<Constant1>), the instructions (<Instructions1>) which are programmed directly after the first constant are executed. Program execution subsequently resumes after the END_CASE.

If the value of the expression does not agree with the value of the first constant (<Constant1>), this value is compared to the value of the constant which is programmed next. In this way, the CASE instruction is executed until the values agree. If the value of the expression does not correspond to any of the programmed constant values, the instructions (<Instructions0>) which are programmed after the ELSE are executed. ELSE is an optional part of the syntax and can be omitted.

The CASE instruction can also be nested by replacing an instruction block with CASE. END_CASE represents the end of the CASE instruction.

Example

The following example shows how the instruction works:

SCL Copies the following program code to clipboard.

CASE "Tag_Value" OF

0 :

"Tag_1" := 1;

1,3,5 :

"Tag_2" := 1;

6...10 :

"Tag_3" := 1;

16,17,20...25 :

"Tag_4" := 1;

ELSE

"Tag_5" := 1;

END_CASE;

The following table shows how the instruction works using specific operand values:

Operand

Values

Tag_Value

0

1, 3 , 5

6, 7, 8, 9, 10

16, 17, 20, 21, 22, 23, 24, 25

2

Tag_1

1

-

-

-

-

Tag_2

-

1

-

-

-

Tag_3

-

-

1

-

-

Tag_4

-

-

-

1

-

Tag_5

-

-

-

-

1

1: The operand is set to the signal state "1".

-: The signal state of the operand remains unaltered.