Learn PLCs free
Programming LanguagesIntermediateEssential
9 min read
Updated
Intermediate

Structured Text (ST): PLC Syntax, Example & Pitfalls

ST - Structured Text Programming Language

Quick answer

Structured Text (ST) is the textual PLC programming language in IEC 61131-3. It uses assignments, expressions and control structures such as IF, CASE and loops. An ST routine still runs within the controller task model, so scan order, retained state, data types and vendor-specific instructions must be verified.

Key Takeaways

  • Structured Text (ST) is the textual PLC programming language in IEC 61131-3. It uses assignments, expressions and contro...
  • Intermediate-level topic in Programming Languages
  • Commonly used in: State machines and sequence selection with CASE, Analog scaling, calculations and data conversion
  • Related to: IEC 61131-3, Function Block, Ladder Logic

Detailed Definition

Structured Text (ST) is the textual programming language in the IEC 61131-3 suite. The valid 2025 Edition 4 standard specifies ST alongside Ladder Diagram and Function Block Diagram, with Sequential Function Chart elements for organizing programs and function blocks. ST is useful when a requirement is clearer as assignments, calculations, CASE branches, array processing or bounded loops than as a large graphical network.

A typical assignment uses the form Destination := Expression; and a statement ends with a semicolon. IF…THEN…ELSIF…ELSE, CASE, FOR and WHILE provide control flow, while functions and function blocks encapsulate reusable behavior. These familiar constructs do not turn a PLC into a general-purpose script runtime: the program organization unit is invoked by a configured task or caller, and its execution time contributes to that task scan.

IEC syntax is a shared foundation, not a guarantee of project portability. Siemens commonly labels the language SCL inside STEP 7, Rockwell documents Structured Text for Logix controllers, and CODESYS offers ST plus vendor-specific Extended Structured Text features. Libraries, function-block interfaces, numeric conversions, supported language subsets, initialization, task scheduling and online-change behavior vary. Rebuild and test the behavior in the destination platform rather than pasting source and assuming equivalence.

Use ST where it reduces accidental complexity, then make execution observable. Bound loops, define default output states, separate command logic from safety functions, expose sequence and fault state, and test startup, overflow, edge detection and abnormal inputs. A concise ST routine with a written test table is maintainable; a dense routine with hidden side effects is not.

Evidence and scope

The language scope was checked against IEC 61131-3:2025 Edition 4 and current Siemens STEP 7 V21, Rockwell Studio 5000 V38 and CODESYS documentation. The example uses portable IEC-style Boolean syntax, but task execution, libraries, instructions, data conversion, initialization and project files remain platform-specific.

Technical review:

Structured Text PLC program flow from declared variables through IF and CASE decisions to bounded loop processing and explicit output assignments
Editorial illustration: A maintainable ST routine makes its data, decisions, bounded iteration and output writes visible.
Industrial controller workbench showing a Structured Text editor beside deterministic PLC input, logic and output execution stages
Editorial illustration: Structured Text is textual, but it still executes inside the PLC task and I/O update model.

Critical behavior

  • ST executes when its routine, program organization unit or action is called by the configured controller task; it does not run independently of scheduling.
  • An assignment writes its destination whenever execution reaches that statement. A skipped branch does not automatically clear a value written on an earlier scan.
  • FOR, WHILE and REPEAT-style loops execute within a scan. An unbounded loop or unexpectedly large iteration count can overrun the task or trigger a watchdog.
  • Stateful timers, counters, edge detectors and custom function blocks need persistent instances. Recreating or conditionally skipping an instance changes behavior.
  • Implicit conversion, integer overflow, REAL precision, array bounds and evaluation order must be tested in the selected compiler and controller.
  • IEC language similarity does not make native Siemens, Rockwell, CODESYS or other vendor projects interchangeable.

Verification checklist

  1. 1Declare every variable with an intentional type, scope, initialization and retention policy.
  2. 2List every destination write and confirm the value produced on each branch and skipped path.
  3. 3Bound loops and measure worst-case execution time against the configured task and watchdog.
  4. 4Test minimum, maximum, overflow, division-by-zero and invalid-index cases for calculations.
  5. 5Test cold start, warm restart, program-to-run transition and recovery from every sequence state.
  6. 6Compile and run the example in the exact target IDE, controller family and firmware release.
  7. 7Keep safety functions in the approved safety architecture and validation lifecycle.

IEC and vendor terminology

Similar-looking instructions do not always have identical execution, initialization or storage behavior.

PlatformCommon termWhat to verify
IEC 61131-3:2025Structured Text (ST)Edition 4 specifies ST syntax and semantics; target implementations may support documented extensions or restrictions.
Siemens STEP 7 V21SCLSiemens uses SCL for its structured-text environment. Confirm CPU family, optimized access, instruction support and block interface behavior.
Rockwell Studio 5000 V38Structured TextAssignments, constructs and instructions follow Logix syntax and execution rules. Some instructions need explicit conditioning for one-scan behavior.
CODESYSST / ExSTST implements the IEC language; Extended Structured Text adds CODESYS-specific features that may reduce portability.

The same motor command in Ladder and ST

The two representations can express the same normal-control requirement. Test the same input sequence in both and keep emergency-stop safety outside this ordinary command example.

Structured Text vs Ladder: choose by review task

Both languages can be correct. Prefer the representation that makes the requirement easiest to inspect, test and maintain on the target platform.

State / phaseStructured TextLadder DiagramVerification focus
Boolean interlocksCompact expression, but parentheses and write order matterCondition path is visually traceable onlineTest every permissive false and simultaneous-command case
Calculations and scalingReadable formulas, conversions and reusable functionsCan become wide or instruction-heavyTest units, limits, division by zero, overflow and precision
SequencesCASE gives explicit named or enumerated statesStep bits can be visible but duplicate transitions are easy to createTest abort, hold, restart, timeout and recovery from every state
Repeated dataBounded loops and arrays reduce duplicationRepeated rungs are verbose but individually visibleMeasure worst-case iterations and task execution time
Language selection is a maintainability decision constrained by controller support, team skills, safety rules and testability.
Matched motor control requirement represented in Ladder Diagram, Structured Text and Function Block Diagram for behavior comparison
Editorial illustration: Compare languages with one requirement and one test matrix, not unrelated screenshots.
PLC programming portability boundary separating reusable requirements and tests from vendor-specific projects, libraries, hardware and diagnostics
Editorial illustration: The requirement and test cases transfer more reliably than native project files or vendor instructions.

Working LD and ST example

Runnable start/stop command with an explicit fault state

Implement the same normal motor command in LD and ST, then verify it with a scan-by-scan input table.

Ladder Diagram

|--[ StopHealthy ]--[ OverloadHealthy ]--+--[ StartRequest ]--( MotorCommand )--|
|                                        +--[ MotorCommand ]--+
|--[/ OverloadHealthy ]----------------------------------------( Faulted )--|

Structured Text

MotorCommand := StopHealthy
                AND OverloadHealthy
                AND (StartRequest OR MotorCommand);

Faulted := NOT OverloadHealthy;

Expected result: StartRequest seals in MotorCommand while StopHealthy and OverloadHealthy remain true. A stop or overload clears the command on the next execution. This is ordinary process control, not a validated safety function.

IEC 61131-3 Structured Text variable scope diagram distinguishing local, input, output, in-out, global and retained controller data
Editorial illustration: Scope and retention are design decisions; identical variable names do not imply identical lifetime or access.
PLC task execution model showing periodic scheduling, program organization unit calls, execution time and watchdog verification for Structured Text code
Editorial illustration: Loops and function-block calls consume time inside a scheduled task and must fit its execution budget.

Failure modes and diagnostic checks

SymptomLikely causeCheck next
An output stays true after a branch is no longer enteredNo default assignment or false write executes on that pathTrace every write to the tag and define its value on every required state path.
The controller watchdog trips or task time spikesA WHILE loop cannot terminate or an array loop has an excessive boundUse bounded iteration, validate limits and measure worst-case task execution time.
A timer or edge detector resets unexpectedlyIts function-block instance is temporary, recreated or skipped by conditional executionInspect instance storage and call it consistently before using its outputs.
The same code produces different values on another PLCData widths, conversion, overflow, operator or library behavior differsUse explicit types and conversions, then rerun boundary tests in the target compiler.
A sequence advances more than one state in one scanIndependent IF statements modify and re-evaluate the state during the same executionUse an exclusive CASE or next-state pattern and log the transition.
A rising-edge action repeats every scanA level condition was used where a retained edge detector was requiredUse the platform-approved edge block or explicit prior-state logic and test task-call frequency.

Current primary and technical sources

These sources support the behavior summarized on this page. The project's controller, firmware and IDE help remain authoritative for implementation.

Continue with the practical guide

Common Questions

What is Structured Text?

Structured Text (ST) is the textual PLC programming language in IEC 61131-3. It uses assignments, expressions and control structures such as IF, CASE and loops. An ST routine still runs within the controller task model, so scan order, retained state, data types and vendor-specific instructions must be verified.

When should I use Structured Text?

Structured Text is particularly useful in scenarios such as State machines and sequence selection with CASE and Analog scaling, calculations and data conversion. Consider implementing it when you need reliable, efficient solutions for these types of applications.

What should I verify before using Structured Text?

Declare every variable with an intentional type, scope, initialization and retention policy. List every destination write and confirm the value produced on each branch and skipped path. Bound loops and measure worst-case execution time against the configured task and watchdog. Test minimum, maximum, overflow, division-by-zero and invalid-index cases for calculations. Test cold start, warm restart, program-to-run transition and recovery from every sequence state. Compile and run the example in the exact target IDE, controller family and firmware release. Keep safety functions in the approved safety architecture and validation lifecycle.

What are related concepts I should learn?

To fully understand Structured Text, you should also familiarize yourself with IEC 61131-3, Function Block, and Ladder Logic. These concepts work together in industrial automation systems.

Also Known As

You may also see Structured Text referred to as:

STStructured Control LanguageSCL (Siemens)

Was this helpful?

Let us know if this glossary term helped you understand Structured Text better.

Your feedback helps us improve our glossary and create better content for the PLC programming community.

Quick Info

Difficulty
Intermediate
Tier
Essential

About Programming Languages

IEC 61131-3 standard programming languages and syntax

Total Terms:25
Difficulty:Beginner to Advanced

Free PLC simulator

Stop reading, start doing

Write ladder logic in your browser, hit Run, and watch machine scenarios react. A 12-lesson curriculum across 8 PLC dialects — free account, no credit card.

Practice PLCs free →