Converting Siemens S5 C DB 0 to STEP 7: Migration Guide
When modernising a SIMATIC S5 application, one of the most common stumbling blocks is the data block call sequence. The S5 source fragment below contains a complete conditional branch built around the C DB 0 instruction. STEP 7 (S7-300/S7-400) does not expose C DB directly — the instruction is replaced by OPN DB (German AUF DB), and several related operands must be rewritten. This article walks through every line of the example, the S5-to-S7 mapping rules, and the verification steps required to commission the converted STL.
:L KF 261
:-F
:L FW 205
:SLW 1
:>=F
:JC =M006
:L KH F002
:C DB 0
M006 :L KB 31
M008 :T DW 1
:DO DW 1
:L DW 0
:T FW 220
1. Overview
Siemens introduced the SIMATIC S5 family in 1975 and supported it through several CPU generations (S5-90U, S5-95U, S5-100U, S5-115U, S5-135U, S5-155U). S5 programs were written in STL (Statement List), LAD (Ladder Diagram), or CSF (Control System Flowchart). The data block model used the call syntax C DB <number> to activate a DB for the subsequent DO (Datenoperand) accesses.
STEP 7, the programming environment for the SIMATIC S7-300 and S7-400 (and later the S7-1200/1500 in TIA Portal), introduced a more explicit data block model. The DB must be opened with OPN DB (or OPN DI for instance DBs), and the absolute data word inside the block is addressed as DBW n, DBB n, or DBD n with byte-based offsets. S7 drops the DO prefix entirely: with a DB open, the operand is just DBW, DBB, or DBD.
The conversion path for the source fragment requires three distinct translations:
- Replace the S5 constant load mnemonic
L KHwith the S7 word-typed literalL W#16#. - Replace the S5
C DB xinstruction with the S7OPN DB xinstruction. - Replace the S5
DO DW ndata operand with the S7 absolute operandDBW (2*n)referencing the previously opened DB.
2. Prerequisites
Perform the conversion on a workstation that meets the STEP 7 installation requirements and that has access to the official Siemens documentation portal.
| Item | Version / Identifier | Purpose |
|---|---|---|
| STEP 7 (SIMATIC Manager) | V5.5 or V5.6 | Target programming environment for S7-300/S7-400 |
| S5 to S7 Converter | Entry ID 1118413 | Official Siemens migration utility and reference manual |
| Source S5 program | S5 STL (S5-DOS / S5 file) | Original code to be migrated |
| Target S7 CPU | S7-300 (e.g. CPU 315-2 PN/DP, 6ES7315-2EH14-0AB0) or S7-400 | Target hardware for the converted program |
| S7-PLCSIM (optional) | Included with STEP 7 Professional | Offline simulation before live download |
| STEP 7 STL reference | “S7-300/400 STL” documentation set | STL operator reference for S7 |
Reference documentation is available from the Siemens Industry Online Support portal at support.industry.siemens.com. The migration manual cited in the original inquiry is the “From S5 to S7 Converter Manual”, published under entry ID 1118413.
3. Anatomy of the Source S5 Code Block
The S5 fragment is a conditional branch with a real-arithmetic preamble, a comparison against a flag-word-derived threshold, a conditional jump, and a data block activation that is only reached when the comparison fails. The final four instructions are common-path operations that run regardless of the branch outcome.
| Line | S5 Instruction | Function | Operands Affected |
|---|---|---|---|
| 1 | L KF 261 |
Load fixed-point constant 261 into ACCU 1-L | ACCU 1 |
| 2 | -F |
Negate the floating-point value in ACCU 1 (treats 261 as a real, -261.0) | ACCU 1 |
| 3 | L FW 205 |
Load flag word 205 into ACCU 1-L (ACCU 1 prior content moves to ACCU 2) | FW 205 |
| 4 | SLW 1 |
Shift left word by 1 bit (multiplies by 2) | ACCU 1-L |
| 5 | >=F |
Real comparison: ACCU 2 >= ACCU 1? Sets BR/CC1/CC0 | ACCU 1, ACCU 2 |
| 6 | JC =M006 |
Conditional jump to label M006 if the comparison was true | — |
| 7 | L KH F002 |
Load constant hex F002 into ACCU 1-L | ACCU 1 |
| 8 | C DB 0 |
Call (open) data block 0 | DB 0 (registry) |
| 9 | M006 :L KB 31 |
Load constant byte 31 into ACCU 1-LL | ACCU 1 |
| 10 | M008 :T DW 1 |
Transfer ACCU 1-LL to data word 1 of the open DB | DBx.DW 1 |
| 11 | :DO DW 1 |
Read data word 1 of the open DB into ACCU 1 | DBx.DW 1 |
| 12 | :L DW 0 |
Load data word 0 of the open DB into ACCU 1 | DBx.DW 0 |
| 13 | :T FW 220 |
Transfer ACCU 1-L to flag word 220 | FW 220 |
M006 as a jump target and M008 as a sequential marker). In practice only the labels at the start of a network (M006, M008) become jump targets or anchors. STEP 7 uses alphanumeric labels of up to 24 characters — names such as M006 and M008 are legal but modern convention recommends descriptive names (for example, JMP_OVER and WRITE_DB).
4. S5 Instruction Reference Table
Use this lookup table to translate other S5 operations that may appear in the same program block. Only the operators encountered in this example and their direct S7 equivalents are listed; consult the Siemens S7-300/400 STL manual for the complete instruction set.
| Category | S5 Mnemonic | S5 Operation | S7 Mnemonic | S7 Operation | Notes |
|---|---|---|---|---|---|
| Constant load | L KF n |
Load 16-bit fixed-point | L n |
Load integer | Drop KF prefix in S7 |
| Constant load | L KH hhhh |
Load 16-bit hex constant | L W#16#hhhh |
Load 16-bit word | Use W#16# prefix |
| Constant load | L KB n |
Load 8-bit constant |
L B#16#n or L n
|
Load byte | For BCD, use B#16# prefix |
| Arithmetic | -F |
Negate real (ACCU 1) | NEGR |
Negate real (32-bit) | — |
| Logic | SLW n |
Shift left word by n |
SLW n or SHL_W
|
Shift left word | Range 0..15 in S7 |
| Compare | >=F |
Real greater-or-equal | >=R |
Real greater-or-equal | Use R for REAL in S7 |
| Branch | JC =label |
Conditional jump on RLO=1 | JC label |
Conditional jump | S7 does not use = before label |
| Block call | C DB n |
Open (call) data block | OPN DB n |
Open data block | English STL: OPN, German: AUF
|
| Block call | C FB n |
Call function block | CALL FB n, DBx |
Call FB with instance DB | Instance DB must be specified in S7 |
| Data access | DO DW n |
Load data word from open DB | L DBW (2*n) |
Load data word from open DB | S7 is byte-addressed |
| Data access | T DW n |
Transfer to data word in open DB | T DBW (2*n) |
Transfer to data word in open DB | — |
| Data access | L DW 0 |
Load data word 0 of open DB | L DBW 0 |
Load data word at byte 0 | — |
| Flag access | L FW 205 |
Load flag word | L MW 205 |
Load Merker word | FW → MW in S7 |
| Flag access | T FW 220 |
Transfer to flag word | T MW 220 |
Transfer to Merker word | — |
5. Mapping S5 C DB 0 to STEP 7 OPN DB 0
The S5 C DB 0 instruction performs two semantic actions in a single statement:
- It registers data block 0 as the “currently open” DB for the program scope.
- It pushes the previously open DB and the previous DB register onto the S5 call stack (binary stack) so that
DOandTdata-operand accesses target DB 0 until a newC DBis issued.
STEP 7 exposes the same concept with OPN DB n (English; German AUF DB n). Unlike S5, S7 does not maintain a deep call stack for DB activations — the most recently opened DB and instance DB are held in two dedicated registers (DB and DI). For a single-thread conversion the S5 behaviour maps directly to S7 OPN DB.
// S5
:L KH F002
:C DB 0
M006 :L KB 31
M008 :T DW 1
:DO DW 1
// S7 (English STL)
L W#16#F002
OPN DB 0 // activate DB 0
M006: L B#16#31
M008: T DBW 2 // DW 1 in S5 = byte offset 2 in S7
L DBW 2 // read back DW 1 from DB 0
For multi-instance scenarios, where a function block already opened an instance DB with OPN DI, the S5 stack behaviour must be re-implemented using temporary DB pointers or by passing the DB number via an input parameter. The original S5 fragment does not use instance DBs, so a plain OPN DB is sufficient.
6. Handling L KH F002 → L W#16#F002
The S5 mnemonic L KH stands for “Lade Konstante Hexadezimal” (load hexadecimal constant). The operand is a four-digit hexadecimal value, e.g. F002, that is loaded into the low word of accumulator 1. The high word of ACCU 1 is cleared.
STEP 7 requires the operand type to be specified explicitly. The S7 equivalent of a 16-bit hexadecimal constant is the word-typed literal W#16#hhhh. The mapping is:
| S5 Mnemonic | Value (hex) | S7 Equivalent | Value (decimal) |
|---|---|---|---|
L KH F002 |
0xF002 | L W#16#F002 |
61442 |
L KH 0000 |
0x0000 | L W#16#0000 |
0 |
L KH FFFF |
0xFFFF | L W#16#FFFF |
65535 |
L KH 0001 |
0x0001 | L W#16#0001 |
1 |
L KH 1234 |
0x1234 | L W#16#1234 |
4660 |
For 32-bit hex constants, S5 had no direct equivalent; users loaded two words in sequence. S7 supports L DW#16#hhhh_hhhh for double-word hex literals, and L 2#0000_0000_0000_0010 for explicit binary literals when the bit pattern is more readable than hex.
7. Translating DO DW 1 to DBW 2
The S5 DO DW n (Datenoperand Datenwort n) reads a 16-bit word at position n from the open DB. The numbering convention is word-indexed: DW 0 occupies the first 16 bits (bytes 0–1), DW 1 the next 16 bits (bytes 2–3), and so on.
STEP 7 addresses data words by byte offset, not by word index. DBW 0 covers bytes 0–1, DBW 2 covers bytes 2–3, etc. The conversion rule is therefore:
S7 offset (bytes) = 2 × S5 word index
| S5 Operand | Bit range in DB | Byte offset | S7 Operand (DBW form) |
|---|---|---|---|
DW 0 |
Bits 0–15 | 0 | DBW 0 |
DW 1 |
Bits 16–31 | 2 | DBW 2 |
DW 2 |
Bits 32–47 | 4 | DBW 4 |
DW 5 |
Bits 80–95 | 10 | DBW 10 |
DW 10 |
Bits 160–175 | 20 | DBW 20 |
DL (low byte), DR (high byte), DH (high byte of the next word in 32-bit context), and DD (double word). The byte-addressed equivalents in S7 are DBB, DBD, and so on. Always verify the source declaration view in the S5 program to know whether the operand is bit, byte, word, or double-word oriented before performing the conversion.
8. Full S7 STL Equivalent with Comments
The complete converted routine, preserving the original control flow, looks as follows. The branch structure is identical; only the operator mnemonics and operand addresses change.
// S7-300/400 STL (English) - converted from S5 source
// Source: S5-115U STL listing, 13 instructions
// Target: STEP 7 V5.x, S7-300 CPU 31x
L 261 // S5: L KF 261
NEGR // S5: -F (negate real, treats 261 as REAL)
L MW 205 // S5: L FW 205 (flag word 205 → merker word 205)
SLW 1 // S5: SLW 1 (shift left word by 1 bit)
>=R // S5: >=F (real greater-or-equal compare)
JC JMP_OVER // S5: JC =M006
// Fall-through path (comparison false)
L W#16#F002 // S5: L KH F002 (hex constant F002)
OPN DB 0 // S5: C DB 0 (open data block 0)
// Common path
JMP_OVER:
L B#16#31 // S5: L KB 31 (load byte 31)
T DBW 2 // S5: T DW 1 (write to DW 1, byte offset 2 in DB 0)
L DBW 2 // S5: DO DW 1 (read back DW 1)
L DBW 0 // S5: L DW 0 (read DW 0)
T MW 220 // S5: T FW 220 (transfer to flag word 220 → merker word)
Four subtle differences are worth flagging:
-
Real vs integer arithmetic. S5's
-Fand>=Foperate on the 16-bit fixed-point operand loaded byL KF 261as if it were a real (16-bit floating-point in S5). STEP 7 separates integer and real arithmetic. The literal261loaded into ACCU 1 is treated as a 16-bit integer;NEGRthen negates the integer.>=Rwill interpret both operands as 32-bit IEEE-754 reals. If the source S5 program uses 16-bit reals, you must convert to 32-bit REAL or replace the comparison with>=I(integer compare). -
Merker word address collision. Flag words (FW) in S5 are mapped to merker words (MW) in S7, but the byte/word bit boundary must be aligned. S5 flag words are 16-bit, while S7 merker words may share bytes between adjacent words. If the program accesses both
MW 205andMW 204, the S7 mapping can produce byte overlap that did not exist in S5. Use bit-granular merker addresses (M 0.0,MB 200, etc.) for clarity. -
DB 0 content. In S5, DB 0 is reserved and cannot be edited by the user. In S7, DB 0 is also reserved by the system for the bit memory image. Writing to
DBW 0in S7 will fail at compile time or in the CPU diagnostic buffer with SF (system fault). Replace the target with a custom data block such asDB 100and update theOPNaccordingly. -
SLW shift count limit. S5
SLWpermitted shift counts of 0 to 15 (and in some dialects 0 to 16). S7 restrictsSLWto 0 to 15. A shift count of 16 must be implemented withSLDon a double word, or by splitting the operation.
9. Using the Official Siemens S5 to S7 Converter
Siemens publishes a free conversion utility and accompanying manual under the title “From S5 to S7 Converter Manual”, entry ID 1118413 in the Siemens Industry Online Support portal. The converter automates the bulk of mechanical translation (mnemonic replacement, block structuring) but leaves semantic decisions to the engineer.
- Open the S5 project in STEP 7 (V5.5 or later) using the S5 to S7 Converter wizard from the SIMATIC Manager File menu.
- Select the S5 program files (.S5D) to be converted. The tool produces a sibling S7 project with the same name.
- Review the conversion log. The tool emits warnings for any S5 constructs it cannot map one-to-one. Pay special attention to warnings about
C DBwith non-constant operand numbers and toDO FW/DWaccesses with index expressions. - Open the converted STL blocks in the LAD/FBD/STL editor. Replace any user-opened
DB 0with a project-specific data block. The converter cannot determine the user's intent for DB 0 because the system reserves it in both S5 and S7. - Insert the S7 program into the target S7 CPU. Compile with Build / Save All and resolve any remaining syntax errors.
- Download to the S7 CPU (online → download to target device). Observe the diagnostic buffer for any block-consistency errors at start-up.
The full manual is available at Siemens Industry Online Support — entry 1118413.
10. Verification & Commissioning
After the conversion, perform a structured verification on the S7 CPU before the program touches the process.
-
Static review. Open the converted STL block and check the sequence against the original S5 listing. Confirm that every
C DB nin S5 becameOPN DB nin S7, and that noDO DWsurvives unconverted. The STEP 7 compiler will accept a strayDOonly as an undefined symbol, so any left-over S5 mnemonic will fail compilation. - Compiler feedback. Use PLC → Compile All (or the menu command Program → Compile). Resolve all warnings, not just errors. The Siemens compiler often flags “address area overlap” between adjacent merker words — fix these by re-aligning the merker declarations.
-
Offline simulation. Use the S7-PLCSIM optional package to run the converted program against simulated I/O. Force
MW 205to 130 (so thatMW 205 × 2 = 260 < 261) and observe whether the fall-through path executes. Then forceMW 205to 131 (so thatMW 205 × 2 = 262 ≥ 261) and confirm theJCbranch is taken. The expected outputs are:- At MW 205 = 130:
DBW 2 = 31written at M008,MW 220receives the value ofDBW 0. - At MW 205 = 131:
DBW 2 = 31written at M006,MW 220receives the value ofDBW 0; theL KH F002andC DB 0instructions are skipped.
- At MW 205 = 130:
-
Online check on real CPU. Connect the programming device online, place the program in RUN, and use a VAT (Variable Table) to monitor
MW 205,DB0.DBW 0,DB0.DBW 2, andMW 220. Toggle the inputs that driveMW 205in the source process to verify both branches of the conditional. - Diagnostic buffer. Read the CPU diagnostic buffer with PLC → Diagnostic Buffer. Look for “block not found” (DB not loaded), “addressing error”, or “FATAL error”. Any of these indicates a residual S5 construct that the converter could not translate.
11. Common Pitfalls and Field Notes
| Pitfall | S5 Source Symptom | S7 Failure Mode | Resolution |
|---|---|---|---|
| Writing to DB 0 |
C DB 0 followed by T DW x
|
Compile error: “Write access to system DB” | Create a custom DB (e.g. DB 100) and re-target |
| Real-vs-integer promotion |
L KF 261 + -F + >=F
|
S7 compares 16-bit int with 32-bit REAL — overflow at > 32767 | Load 261 as REAL (L 261.0) and use >=R
|
| SLW with shift count > 15 |
SLW 16 in S5 (allowed) |
Compile error in S7 (range 0..15) | Use SLD for double word or mask the count |
| JC to forward label |
JC =M006 with M006 ahead |
S7 STL accepts forward jumps; SCL requires declaration first | Reorder or use symbolic jump labels |
| Indirect DB call |
L KB n + C DB (no operand) |
Not supported in S7 STL | Use AUF DI [MD n] with index register, or call FB with instance DB |
| Merker overlap | Adjacent FW with byte overlap | Unexpected bit flips in process I/O | Reassign merker addresses, use MB granularity |
| Stack limit on C DB | Deep nesting of C DB calls |
S5 allows; S7 only holds two open DBs (DB, DI) | Refactor to use instance DBs and FB parameters |
| Missing segment prefix | S5 STL entered without :
|
No effect — STEP 7 ignores the prefix | Cosmetic only; no action required |
| Time-tick carry from S5 | Reliance on 16-bit real range of -F
|
S7 REAL is 32-bit, value range changes | Verify the comparison threshold is still satisfied |
When the converted program enters service, document the mapping in a migration memo. Record the S5 source block number, the S7 target block (FB / FC / DB), the merker remapping table, and any S5 instructions that required semantic changes. The memo becomes the authoritative cross-reference for the next maintenance engineer.
OPN DB; you reference DBs symbolically ("MyData".MyWord). The same logic written for S7-1500 in TIA Portal is more compact and easier to maintain, and benefits from the diagnostic and security features of the newer CPU generation.
FAQ
Why does STEP 7 not have a direct C DB instruction?
STEP 7 (S7-300/S7-400) replaces the S5 C DB n instruction with OPN DB n (German: AUF DB n). The new mnemonic explicitly opens the data block and sets the DB register for subsequent DBW/DBB/DBD accesses, but unlike S5 the block number is always specified directly in the instruction — there is no accumulator-based variant in standard S7 STL.
What is the S7 equivalent of L KH F002?
L KH F002 in S5 loads the 16-bit hexadecimal constant F002 (61442 decimal) into accumulator 1. The STEP 7 equivalent is L W#16#F002. Use the W#16# prefix for any 16-bit hex word, and DW#16# for a 32-bit double-word constant. The bare KH mnemonic has no direct S7 form.
How do I convert DO DW 1 to STEP 7?
DO DW 1 in S5 reads word index 1 from the open data block. STEP 7 addresses DBs by byte offset, so the equivalent is L DBW 2 (the byte offset is twice the S5 word index: 1 × 2 = 2). The same rule applies to the transfer form: T DW 1 becomes T DBW 2. For DW 0, the offset is 0 (DBW 0); for DW 5, the offset is 10 (DBW 10).
Can I keep writing to DB 0 in S7?
No. Data block 0 in S7 is reserved by the system for the bit memory image and cannot be used as a user data block. The STEP 7 compiler will reject any T DBW, T DBB, or T DBD instruction that targets DB 0. Create a custom data block (for example DB 100) and re-target the original S5 C DB 0 to OPN DB 100.
Where is the official S5 to S7 conversion manual?
The Siemens “From S5 to S7 Converter Manual” is published in the Industry Online Support portal under entry ID 1118413. The document is available at https://support.industry.siemens.com/cs/document/1118413 and contains the full mapping table from S5 STL constructs to STEP 7 STL.
Does the S5 to S7 converter handle the C DB 0 instruction automatically?
The official Siemens converter translates C DB n to OPN DB n for constant DB numbers, but it cannot determine whether the original program intended DB 0 to be used as a user data block. In both S5 and S7, DB 0 is reserved. After conversion you must re-target the OPN to a custom DB and verify that no S5 DO DW / T DW reference survives unconverted in the STL output.