When to write in SCL instead of LAD and how does SCL differ from ST?

The SCL programming language (Structured Control Language) is the text-based language of Siemens SIMATIC controllers, in which a program is written with Pascal-like instructions instead of the contacts and coils used in LAD. In TIA Portal it is used to write blocks with calculations, data arrays and extensive conditional logic. It is the right choice wherever the ladder version becomes longer than the algorithm itself. It differs from ST in the IEC 61131-3 standard mainly through Siemens extensions.

SCL is Siemens’ implementation of the ST (Structured Text) language from the IEC 61131-3 standard, prepared for SIMATIC controllers. It offers IF and CASE conditional statements, FOR, WHILE and REPEAT loops, arithmetic operators and block calls, that is everything needed to write an algorithm.

In classic STEP 7 for the S7-300 and S7-400, SCL was a separate S7-SCL package bought on top of the basic environment. In TIA Portal it is one of the editors alongside LAD, FBD, STL and GRAPH, and the language is set individually for each block: organization block (OB), function (FC) and function block (FB). A single project can therefore contain blocks in several languages.

Siemens calls the ladder language LAD (Ladder) in the English version of TIA Portal and KOP (Kontaktplan) in the German one, while the IEC 61131-3 standard uses the abbreviation LD. A full overview of the languages in the standard is given in the post What are the PLC programming languages?.

SCL replaces LAD where a block processes data rather than just connecting binary signals. The criterion is simple: if the same fragment in ladder logic needs a dozen or so networks with MOVE, ADD and comparison blocks, and in SCL it fits in a few lines, the text version will be easier to read.

Typical tasks for SCL:

  • calculations and conversions: scaling of analog signals, process formulas, averages and measurement tolerances;
  • arrays and repeated objects: a FOR loop over an array of structures (ARRAY of UDT) handles 24 identical pallet slots with a single piece of code, without copying 24 networks;
  • text and telegrams: building and parsing strings, DMC codes for production traceability, communication frames;
  • state machines: the CASE statement describes the states of a device and the transitions between them clearly;
  • library blocks: reusable FBs and FCs that go into many machines and projects.

The problem starts when an algorithm stays in LAD out of habit. The program then grows to hundreds of networks, further changes are added next to the old ones, and during a review it is hard to check whether all the slots are handled in the same way. It is better to move data processing into an SCL block with a clearly described interface (inputs, outputs, static data), which is tested once and called many times.

When the logic of a slot changes, an SCL block with a loop over an array needs one correction instead of a separate one in each of the 24 networks, which shortens the time of changes during commissioning.

Looking for an experienced Siemens automation integrator? Get in touch and we will write your PLC program in TIA Portal and commission the machine.

LAD remains the better choice for logic that is diagnosed first by the maintenance team: interlocks, start conditions, enables, signalling and control of single drives. In online view a ladder diagram shows the signal flow, so an electrician can see which contact is not conducting and why a cylinder did not extend.

The same condition written in SCL has to be read from the code by following variable values line by line. For a programmer this is no problem, but for a technician on the night shift who has to get a station running again, it can be a barrier.

Risks of using SCL too widely:

  • longer diagnosis of downtime, because the cause is hidden in a logical expression instead of a visible path of contacts;
  • the plant depends on the programmer for minor faults that maintenance would find on its own in LAD;
  • non-compliance with the customer’s specification when a corporate standard defines the language for a given type of block.

The language of a block should be chosen for the person who will read it on the shop floor, not only for the programmer’s convenience, because this determines how quickly production is restored after a fault.

The most common split looks like this: machine logic and interlocks in LAD, data processing in FB and FC blocks written in SCL. An SCL block appears in a LAD network as a single element with inputs and outputs, so the technician sees which parameters it was called with and what it returned, without going into the code.

In S7-1200 and S7-1500 controllers you can also insert a single SCL network into a LAD or FBD block, for example with a short calculation. The reverse is not possible: an SCL block does not accept a LAD network. Such inserts work well for a few lines of calculations, while longer code is better moved to a separate block with its own interface.

Machine sequences can also be written in GRAPH, in which steps and transitions have a graphical form. Corporate standards combine these languages according to their own rules. In the VASS standard, for example, programmers are expected to know SCL and S7-Graph, and the division of the program into blocks follows from its libraries.

It is best to settle the split between languages before writing code and record it in the project guidelines: which types of blocks are created in LAD, which in SCL, how variables are named and how code is commented. Without this, in a project written by several programmers the same task is sometimes solved in three different styles.

SCL is an implementation of ST, so control statements (IF, CASE, FOR, WHILE), operators and assignments look the same as in other environments compliant with IEC 61131-3. The differences concern how variables are declared, how data is accessed and the elements added by manufacturers. SCL is most often compared with ST in CODESYS, on which Beckhoff’s TwinCAT 3 is also based.

ElementSCL (TIA Portal)ST (e.g. CODESYS)
Local variableswith the # prefix, e.g. #Counterno prefix
Global datadata block in quotation marks: "Pump_DB".Setpointglobal variable list (GVL), e.g. gvlPump.Setpoint
Variable declarationsblock interface editor (Input, Output, InOut, Static, Temp)sections VAR_INPUT, VAR_OUTPUT, VAR in the text
Code groupingREGION ... END_REGIONpragma {region}
Specific typese.g. VARIANT, S5TIMEe.g. POINTER TO, REFERENCE TO
Object-oriented programmingnarrower scopemethods, interfaces and inheritance from edition 3 of the standard

For a project this means that an algorithm moves between platforms almost unchanged, but whole blocks do not. A library written in ST for CODESYS requires rebuilding the interfaces, the references to global data and the pointer-based fragments in TIA Portal. The other way round is similar: SCL code with VARIANT types or references to Siemens data blocks has to be rewritten.

When estimating the transfer of an ST library between platforms, you need to allow for rebuilding the interfaces and data access, not just copying the program text.

Want to modify a machine program on Siemens S7? As an integrator, we will modify your existing program or migrate it to a new controller.

  • IEC 61131-3 “Programmable controllers – Part 3: Programming languages”, edition 3.
  • Siemens, STEP 7 / TIA Portal documentation and description of the S7-SCL package.
  • Otomakeit, “Codesys ST Through SCL Eyes – The Language Differences That Catch You First”: https://otomakeit-website.pages.dev/blog/codesys-st-through-scl-eyes/
Scroll to Top