Structured Control Language (SCL) Programming Example in Siemens TIA Portal
Published on Jun11, 2025 | Category: tia
Structured Control Language (SCL) is a powerful, high-level, statement-based programming language used in Siemens PLCs such as the S7-300, S7-400, S7-1200, and S7-1500 series. SCL is Siemens’ implementation of the IEC 61131-3 Structured Text (ST) standard and shares similarities with languages like Pascal and C.
Unlike graphical languages like Ladder Logic (LAD), SCL offers a clean and efficient text-based programming interface which is ideal for implementing complex logic, mathematical formulas, and structured algorithms in industrial automation.
Why Use SCL in Siemens PLC Programming?
While Ladder Logic is popular for its intuitive visuals, it becomes less efficient as program complexity grows. SCL allows you to:
- Write and manage complex logic more clearly
- Use conditional statements (IF, CASE) and loops (FOR, WHILE)
- Organize logic using functions and function blocks
- Minimize debugging time with structured, readable code
- Handle data processing and mathematical operations efficiently
Key Concepts in SCL Programming
Before creating a program in SCL, it is important to understand the following elements:
- Statements: Commands that execute specific actions (e.g., value assignment)
- Expressions: Combinations of values and operators that yield results
- Operators: Arithmetic (+, -, *, /), logical (AND, OR, NOT), relational (=, <, >)
- Conditional Statements: IF...THEN...ELSE, CASE for decision-making
- Loops: FOR, WHILE, REPEAT for repeated execution
Benefits of Using SCL
SCL simplifies the development and testing of automation programs by enabling engineers to focus on logic rather than visuals. Its similarity to high-level languages makes it easier for developers from software backgrounds to adapt quickly.
Common Use Cases for SCL in TIA Portal
- Complex condition handling and nested logic
- Mathematical calculations and comparisons
- Structured and modular code using reusable blocks
- Timers, counters, and state machines
Data Type Declaration in Siemens SCL with Examples
In Siemens Structured Control Language (SCL), declaring variables with the correct data type is crucial for reliable and efficient PLC programming. Each variable must be defined before use, specifying its data type, such as BOOL, INT, REAL, TIME, etc. Below are common data types used in SCL with examples:
1. Boolean (BOOL)
- start : BOOL; — Used for true/false logic such as input or output switches.
2. Integer (INT, DINT)
- counter : INT; — For whole numbers (−32,768 to 32,767).
- largeCounter : DINT; — For extended range integers (−2,147,483,648 to 2,147,483,647).
3. Real Numbers (REAL, LREAL)
- temperature : REAL; — For floating-point numbers like sensor readings.
- pressure : LREAL; — For high-precision measurements.
4. Time Data Types
- delay : TIME := T#5s; — For timer delays.
- preset : S5TIME := S5T#10s; — Used in legacy Siemens timers.
5. String and Character Types
- message : STRING[20]; — For storing text strings up to 20 characters.
Always ensure data types match when assigning or comparing variables. Mismatched types can cause compile-time or runtime errors in TIA Portal.
Timer Programming in SCL: IEC Timer and S_PULSE Example
In SCL, a timer is typically declared as a function block with specific parameters such as start input, preset time, and output. To implement a timer, you must first add the appropriate timer block and then declare all related tags with the correct data types.
In this example, we demonstrate two types of timers used in Siemens SCL programming within the TIA Portal: an IEC timer and a SIMATIC-specific S_PULSE timer.
1. IEC Timer
The IEC timer block IEC_Timer_0_DB.TP is used for generating a pulse. It has the following parameters:
- IN := "start_timer" – This is the input signal to start the timer.
- PT := t#10s – This sets the preset time of the timer to 10 seconds.
- Q := "timer_output" – This is the output of the timer, which turns true when the timer completes.
- ET := "timer_et" – This gives the elapsed time of the timer.
Additionally, the preset value is also assigned separately as:
"timer_pt" := t#10s, which sets the timer’s duration.

2. S_PULSE Timer (SIMATIC Timer)
The S_PULSE is a standard Siemens pulse timer. It is configured with the following parameters:
- T_NO := "timer_number" – The timer number (e.g., 2) to identify which timer to use.
- S := "start_timer" – The signal to start the timer.
- TV := "timer_preset" – The preset time value for the timer.
- R := "timer_reset" – The reset input for the timer.
- BI := "timer_bi" – Status or acknowledgment bit.
- Q := "timer_q" – The output of the timer.
The timer number and preset time are also defined:
- "timer_number" := 2 – Assigns timer number 2.
- "timer_preset" := s5time#10s – Sets the preset time to 10 seconds using the S5Time format.
Both timer types serve different use cases but can be used effectively depending on the requirement for time accuracy, compatibility, or readability.

Conditional Statement Example in Siemens SCL Programming Language
Conditional statements in SCL are used to control the flow of logic based on conditions such as true or false. One of the most common conditional structures is the IF...THEN...ELSE block.
In this example, we demonstrate how to check whether a given integer value is even or odd. Based on the result, the program sets appropriate boolean tags to indicate the outcome. This is useful for logic decisions in automation processes.
Even-Odd Detection Logic
- If the value is divisible by 2 (i.e., value MOD 2 = 0), then it is even.
- Otherwise, it is odd.
- We use the MOD (modulo) operator to get the remainder of division.
SCL Logic:
- IF value MOD 2 = 0 THEN
- is_even := TRUE;
- is_odd := FALSE;
- ELSE
- is_even := FALSE;
- is_odd := TRUE;
- END_IF;
Here, is_even and is_odd are boolean tags used to store the result. You can also link these to physical outputs or HMI indicators.

Multiple Conditional Statement Example in Siemens SCL Programming Language
In SCL (Structured Control Language), you can use multiple conditions combined with logical operators like AND, OR, and NOT to evaluate complex logic.
In this example, we check whether the value of a variable temperature lies within a defined safe range (between 30 and 50 degrees). If the condition is true, the output tag within_limit is set to TRUE; otherwise, it's set to FALSE.
SCL Logic:
- IF "temperature" >= 30 AND "temperature" <= 50 THEN
- "within_limit" := TRUE;
- ELSE
- "within_limit" := FALSE;
- END_IF;
This kind of conditional structure is especially useful in process control applications, where you need to monitor values like temperature, pressure, or flow to maintain safe operating conditions.

Arithmetic Operations in Siemens SCL Programming Language
Arithmetic operations are commonly used in SCL (Structured Control Language) for calculations such as addition, subtraction, averaging, and real-world formulas like tank volume or flow calculations. These operations support multiple data types including INT, DINT, REAL, and LREAL.
Example 1: Basic Arithmetic with Variables
- "add_value" := "value1" + "value2" + "value3" + "value4";
- "sub_value" := "value1" - "value2" - "value3" - "value4";
- "avg_value" := ("value1" + "value2" + "value3" + "value4") / 4;
In this example,
value1 and
value2 are of type
REAL, while
value3 and
value4 are of type
INT. The result variables (
add_value,
sub_value, and
avg_value) should also be declared as
REAL to support mixed-type operations.

Example 2: Tank Volume and Flow Calculation
- #volume := 3.1416 * #radius * #radius * #height * 1000; // Full tank volume in liters
- #currentVolume := 3.1416 * #radius * #radius * #currentLevel * 1000; // Volume based on current level
- #fillTime := #volume / #flowRate; // Time to fill tank in minutes
This example calculates the full volume and current volume of a cylindrical tank based on radius and height, and estimates the time to fill it at a given flow rate. All variables should be declared as
REAL or
LREAL for accurate precision.
