# Understanding Structured Control Language (SCL) Elements

**Introduction**

Structured Text (ST) is an advanced PLC programming language established in the IEC 61131-3 standard, also known as Structured Control Language (SCL) in Siemens software. If youâ€™re looking to become a Senior Automation Engineer, learning how to program Siemens PLCs using SCL is an important skill to have.

SCL is an important programming language for applications where industrial automation and IT overlap, such as smart factories, additive manufacturing, oil and gas, and networked control systems, to name a few.

In this tutorial, we will go over the fundamental elements of the SCL programming language. First, weâ€™ll look at arithmetic, logical, and relational expressions. Next, we go over the different operators available within expressions. And finally, we look at how to assign expressions to tags using value assignments.

**Prerequisites**

To follow along with this tutorial, youâ€™ll need:

- An installation of Siemens TIA Portal. We'll be utilizing TIA Portal version 16; however other versions of TIA Portal are also suitable
- Know how to create SCL Programming Block in the TIA Portal.

**SCL Elements**

In addition to common PLC elements such as counters, inputs, coils, or memory bits, SCL has advanced elements including:

- Expressions
- Operators
- Value assignments

As a result, SCL is well suited for applications such as data administration in IIoT systems, process improvement in the automotive industry, recipe control in food and beverages, and statistics and math challenges in equipment manufacturing.

**Understanding SCL Expressions**

Expressions are computed during program execution or program compilation and return a value. An Expression is made up of operands (for example, tags or constants) and possibly operators (for example, power (**) or subtraction (-)).

Expressions may be connected or nested inside of one another by operators.

According to the operator, there are three types of Expressions available:

- Arithmetic expressions
- Relational expressions
- Logical expressions

You will learn each one of them in detail in the next few sections.

**Understanding SCL Arithmetic Expressions**

Numerical values or combinations of two expressions or values using arithmetic operators make up arithmetic expressions. In figure 2.1, you can see some examples representing arithmetic expressions.

Arithmetic operations can process the permitted data types for the active CPU. If an arithmetic operation uses two operands, the data type of the result is decided based on the following standards: (Since there are many standards, we'll focus on the most common criteria)

- A) The output is given the data type of the lengthier operand if both operands are integers with signs and of different lengths.
- B) The output is given the data type of the lengthier operand if both operands are integers without signs and of different lengths.
- C) If one integer operand has a sign and the other integer operand has no sign, the output is the next more extensive data type with a sign, which includes the integer without a sign.
- D) When a floating-point number and an integer are both used as operands, the result is given the data type of the floating-point number.
- E) The output is given the data type of the lengthier operand if both operands are floating-point numbers and of different lengths.

**Understanding SCL Relational Expressions**

A Relational expression provides a Boolean value by comparing the data types or values of two operands. If the comparison holds correct, the outcome is True; else, it is False.

For example, look at the relational expression in the first sentence of the following IF statement. If the boiler temperature is below 100.00 Fahrenheit, the relational expression yields a Boolean value of True. And if the temperature sensor senses above 100.00 Fahrenheit, the relational expression returns a Boolean value of False.

**Understanding SCL Logical Expressions**

Logical expressions use logical operators such as NOT, And or &, XOR, and OR to join two operands. If both operands of a logical expression have the data type Boolean, the result will also have this data type.

If at least one of the operands is a bit string, the result is also a bit string, and the type of the highest operand determines the result type. For instance, when a Word type operand is linked to a Byte type operand, the outcome is of type Word.

If you want to connect a Boolean type operand to a bit string, you must correctly convert it to a bit string.

**Understanding SCL Operators**

The most common operators used in arithmetic expressions, in order of precedence, are power, followed by multiplication, and division, followed by addition and subtraction. However, other operators such as unary plus, unary minus, modulo function, and combined value assignments are also available in arithmetic expressions as operators.

In order of precedence, the operators used in relational expressions are less than, greater than, less than or equal, greater than or equal, equal, and not equal.

And in order of precedence, the operators used in logical expressions are Negation, Boolean And, Exclusive OR, and Boolean OR.

Arithmetic operators are assessed first, followed by relational operators, and then by logical operators. Also, it is vital to keep in mind that whenever you see operations between brackets, they should be evaluated first.

For example, if you look at the following equations, you will understand that by using brackets, the order of priority can be changed, and thus, the output result can be altered.

**Understanding Value Assignments in SCL**

The value of an expression can be assigned to a tag by using a value assignment, which can be numerical or logical in arithmetic and logical expressions. The tag that accepts the value of the expression on the right is on the assignment operatorâ€™s (: =) left side.

A function's name can also be given as an expression. Value assignment calls the function, which then sends its function value to the tag on the left.

The tag data type on the left determines the data type of value assignment. There must be a match between this type and the data type of the expression on the right.

The following choices are available when you are dealing with programming value assignments:

**Single value assignments:**When using single value assignments, a tag or an expression is only assigned to one tag. You can find the following assignments shown in figure 6.4.

- Assignment of a tag
- Assignment of an expression
- Assignment of a tag to a structure element
- Assignment of a tag to an ARRAY element
- Assignment of an ARRAY element to a tag
- Assignment of a STRING element to another STRING element

**Multiple value assignments:**When assigning multiple values, several assignments can be carried out by a single instruction. For example, a := b := c; which is equivalent to the following notation: b := c; and a := b; You can find the following assignments in the picture below the list. shown in figure 6.5.

- Assignment of a tag
- Assignment of an expression
- Assignment of a tag to two structure elements
- Assignment of a tag to two ARRAY elements
- Assignment of an ARRAY element to two tags
- Assignment of a STRING element to two STRING elements

**Combined value assignments:**The addition (+), subtraction (-), multiplication (*), and division (/) operators can be used in conjunction with the assignment operator in the case of combined value assignments. For example, a += b; which is equivalent to the following notation: a := a + b; Additionally, you can repeat the assignment of combination value assignments. For instance, a += b += c *= d; which is equivalent to the following notation: c := c * d; and b := b + c; and a := a + b; In the picture below figure 6.6, you can see another example of this type of assignment.

**Conclusion**

In this tutorial, you learned about SCL elements, expression function, different types of expressions, operator function, different types of operators, value assignment functions, and the different kinds of value assignments available in SCL elements.

Understanding SCL programming elements is essential in getting started with Siemens PLC programs using Structured Control Language (SCL).