Siemens TIA Portal: Updating Instance DBs After FB Interface Changes
Modifying the interface of a Function Block (FB) in a Siemens SIMATIC project is one of the most common maintenance operations, and one of the most common sources of compile errors. The standard library editing pattern in TIA Portal V15.1 through V19 (and the related Step 7 Classic V5.x toolchain) is to add, rename, or reorder IN, OUT, IN_OUT, STAT, and TEMP declarations. The instance Data Block (iDB) generated when the FB is called does not automatically reflow, which leaves the program in a state where the CPU returns consistency errors or the editor refuses to download. This article documents the four production-grade resolution paths: per-block Check and Update Accesses, project-wide Check Block Consistency, the architectural fix of switching to multi-instance FBs, and the source-file generation/recompile workflow for preserving live iDB values.
1. Block Architecture in TIA Portal and Step 7
Every SIMATIC S7-1200, S7-1500, S7-300, and S7-400 user program is composed of three block types relevant to this issue:
| Block | Mnemonic | Memory | Typical Use |
|---|---|---|---|
| Organization Block | OB | None (logic only) | Cyclic, startup, interrupt, error execution |
| Function | FC | Local stack only (no iDB) | Reusable stateless code |
| Function Block | FB | Instance DB (iDB) | Stateful code with retentive and static data |
| Data Block | DB | Global or instance | Shared or per-instance data |
Per the official S7-1200 programming reference, "You create data blocks (DB) in your user program to store data for the code blocks. All of the program blocks in the user program can access the data in a data block." When an FB is instantiated, the editor generates an instance DB (one per call) and binds the FB's STAT section to a fixed byte offset inside that iDB. Renaming or reordering the STAT section is what causes the iDB layout to drift out of sync with the call sites.
TIA Portal S7-1200 Manual Collection - Data Block (DB) Reference
2. Root Cause: Why FB Interface Changes Break Instance DBs
An iDB is a typed view of the FB's static section. The compiler emits it with a structure header that records:
- The FB number and FB version stamp
- The byte offset of every
STATvariable in declaration order - The initial value assigned at iDB generation time
- The retentivity flag for each variable
When the FB interface changes, the byte offsets in the iDB no longer match the offsets expected by the new compiled FB code. The editor can detect the mismatch at compile time, but in Step 7 Classic and older TIA Portal builds, the iDB itself is not regenerated automatically when a call site changes; it is regenerated only when the FB body is recompiled and the call site is reopened.
Three patterns produce the mismatch:
-
Inserted variable: A new
STATis added in the middle of the section. The iDB still points to the old offset for downstream variables. - Reordered section: Variables are moved up or down. The iDB's offset table is now wrong for every variable after the move point.
- Renamed or retyped variable: The symbolic name resolves to a different absolute address than the iDB expects. The CPU returns a "DB has wrong structure" diagnostic when the new code attempts the first access.
3. Symptom Identification
Before applying any fix, confirm the failure mode. The following table maps common symptoms to the underlying cause.
| Symptom in TIA Portal / Step 7 | Likely Root Cause | First Action |
|---|---|---|
| Compile error: "The block interface has changed. Update the call." | FB interface edited, call site not refreshed | Right-click call → Update block call |
| Online: SF LED on CPU; diagnostic buffer entry referencing DB number with "Structure error" | iDB layout does not match FB signature; iDB not refreshed after recompile | Reload iDB from project to CPU |
| Watch table shows iDB values stuck or zeroed after download | iDB regenerated with default initial values, overwriting live values | Use source-file generation to preserve values (Section 7) |
| Multi-instance DB shows wrong byte offsets for nested FB calls | Nested FB interface changed; parent iDB offset table not refreshed | Check Block Consistency project-wide |
| Editor offers only "Cancel" when reopening the call site | Interface change exceeds automatic update range (deleted variables, type changes) | Manual update of all call sites; recompile |
4. Resolution Path A: Per-Block "Check and Update Accesses"
The first and most surgical fix is invoked from inside the LAD/STL/FBD editor for the specific call site that lost sync. The procedure is:
- Open the block that contains the FB call (an OB, FC, FB, or another FB that uses the changed FB).
- Place the cursor anywhere in the LAD/FBD/STL network that calls the modified FB.
- Open the menu: File → Check and Update Accesses (German UI: Datei → Zugriffe prüfen und aktualisieren). The keyboard shortcut is
Ctrl+F7in classic Step 7. - The editor scans the open block for all access patterns to the modified FB's
STATsection and rewrites the call-site operand list to match the new interface. - Save the block with
Ctrl+Sand recompile.
Use this method when:
- The FB is called from one or two blocks only.
- You are working online against a running CPU and need to limit the recompile blast radius.
- You want to verify the new interface in a single call site before propagating the change everywhere.
5. Resolution Path B: Project-Wide "Check Block Consistency"
For projects where the modified FB is called from many blocks, the project-wide consistency check is the preferred path. It walks the entire compilation order and rewrites every call site plus every iDB in a single pass.
- In the project tree, right-click the Program blocks folder (or the PLC device, depending on TIA Portal version).
- Select Check Block Consistency (German: Bausteinkonsistenz prüfen). In TIA Portal V17 and later this command may also be available under Project → Compile → Software (rebuild all blocks).
- The compiler produces a list of inconsistencies in the Inspector window. Each entry identifies the affected block and the call that needs updating.
- Right-click the top-level result and select Compile → All blocks. The compiler rewrites all dependent iDBs to match the new interface.
- Re-run the check to confirm zero entries remain.
This path is the right choice for offline development, refactoring sessions, and any time the project is in a known-good backup state.
6. Resolution Path C: Multi-Instance Blocks (Architectural Fix)
The single best preventive measure against recurring instance-DB breakage is to convert call sites of an FB into multi-instance calls. A multi-instance call stores the called FB's STAT data inside the calling FB's own iDB, in a named substructure called a multi-instance DB (or "instance-of-instance").
Multi-instance declaration syntax in the calling FB's STAT section:
DATA_BLOCK "dbMultiInstanceExample"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
STRUCT
instMotorCtrl : "FB_MotorControl"; // multi-instance declaration
instValveCtrl : "FB_ValveControl";
END_STRUCT;
END_DATA_BLOCK
Or in the declaration table of FB_Coordinator (the parent FB):
| Name | Data Type | Initial Value | Comment |
|---|---|---|---|
| instMotorCtrl | FB_MotorControl | — | Motor control, multi-instance |
| instValveCtrl | FB_ValveControl | — | Valve control, multi-instance |
When the child FB's interface changes, only the parent iDB needs to be updated, and the offset table is regenerated inside the parent's structure automatically. There is no separate per-call iDB to manage. For projects with five or more call sites of the same FB, multi-instance is also the recommended pattern by Siemens for S7-1500 because it reduces the number of iDBs the CPU has to manage in its work memory.
Conversion steps:
- Open the parent block (FB or OB) that calls the modified FB.
- In the call's instance selector, choose Multi-instance and assign a name (e.g.,
instMotorCtrl). - Delete the now-orphaned per-call iDB from the project tree.
- Recompile and run Check Block Consistency.
7. Resolution Path D: Source File Generation and Recompile
This path is required when the iDB contains live process values that must survive the interface change. The source-file approach is the only one that lets you preserve actual values across a structural reflow.
-
Capture the current values. From the project tree, right-click the iDB and select Generate source file (Step 7 Classic) or PLC → Generate source from blocks (TIA Portal). The resulting
.sclor.dbsource contains the literal values that are currently in the iDB. - Modify the FB interface as required (add/rename variables, change data types).
- Compile the DB source to regenerate the iDB. In Step 7 Classic, the menu is File → Compile → DB after selecting the generated source in the Sources folder. In TIA Portal, right-click the source and choose Generate blocks from source.
- The new iDB is created with the original actual values populated into the variables that still exist by name. New variables take their declared initial values; deleted variables are simply gone.
- Download the regenerated iDB to the CPU.
8. Online vs Offline Maintenance Considerations
The risk profile of an FB interface change is fundamentally different depending on whether the program is running on a live CPU.
| Aspect | Offline Development | Online Maintenance (CPU running) |
|---|---|---|
| Recovery from mistake | Revert from backup or undo (Ctrl+Z) | No undo; CPU may be in a faulted state |
| iDB value preservation | Optional - controlled by initial values | Critical - live process depends on current values |
| Recommended fix path | Check Block Consistency (project-wide) | Source file generation + selective per-block update |
| CPU state during recompile | Project can be in any state | CPU may need STOP mode for full iDB download |
| Time to apply fix | Minutes | Hours (planning, fallback, witness) |
For online maintenance, the standard order of operations is:
- Take a backup of the online project (TIA: Online → Backup from online device).
- Bring the CPU to STOP if the FB signature change requires a full download.
- Generate source files for every iDB that will be affected.
- Apply the interface change offline in the engineering station.
- Run Check Block Consistency and resolve all entries.
- Recompile the DB sources to rebuild the iDBs with preserved values.
- Download the new blocks in the order OBs → FBs → FCs → iDBs.
- Restart the CPU and verify process state against a watch table or HMI.
9. Verification Procedure
After applying any of the four paths above, perform the following verification sequence before signing off the change.
- Compile clean. Project → Compile → All blocks. Zero errors, zero warnings related to interface changes.
- Consistency clean. Right-click Program blocks → Check Block Consistency. Zero inconsistencies remaining.
- Symbolic resolution. Open every call site of the modified FB and confirm that the editor no longer shows a red squiggle on the call's operand list.
- Cross-reference audit. Right-click the FB → Go to → Cross-references. Verify that the count of call sites matches the count you intended to update.
-
Watch table snapshot. Online → Watch and force tables. Open the iDB and force a read of every
STATvariable. Compare to the pre-change snapshot taken at the start of the change window. - CPU diagnostic buffer. Online → Diagnostics → Diagnostic buffer. Confirm no new SF entries, no "DB structure error", no STOP events.
- Functional test. Exercise the affected FB through a controlled HMI command or test sequence and confirm the expected output transitions occur.
10. Best Practices and Preventive Measures
The most reliable way to avoid the iDB drift problem in the first place is to adopt a few habits during FB design.
-
Append, do not insert. Add new variables to the end of the
STATsection instead of the middle. The iDB offset table remains valid for everything above the insertion point. - Never reorder without testing. If reordering is required, treat it as a refactor and run the full Check Block Consistency afterward.
- Use multi-instance for high-fanout FBs. If a single FB is called from more than three places, convert those calls to multi-instance as part of the same change.
- Version the FB interface in the comment. Add a header comment with a manual version stamp so you can correlate iDB breakage to a specific interface revision.
- Keep iDBs in optimized access (S7-1500). Optimized access removes the absolute-offset dependency entirely; the compiler tracks variables by symbolic name only. The cost is that external HMI tags must be updated through the symbol table rather than absolute addresses.
- Generate source files as part of the release process. The source file is the canonical record of an iDB and can be diffed across revisions to spot unintended value changes.
11. Decision Flow
Use the following flow to pick the right path for a given situation.
12. Frequently Asked Questions
Why does my CPU report a DB structure error after I change an FB interface?
The instance DB (iDB) was generated from the previous FB signature and its byte-offset table no longer matches the new compiled FB code. Recompile the project, run Check Block Consistency, and re-download the iDB to clear the diagnostic. If process values must be preserved, regenerate the iDB from a source file generated before the interface change.
What is the difference between Check and Update Accesses and Check Block Consistency?
Check and Update Accesses operates on a single block currently open in the LAD/STL/FBD editor and rewrites only the call sites in that block. Check Block Consistency walks the entire project and rewrites every call site plus every dependent iDB in one pass. Use the per-block command for surgical changes; use the project-wide command for refactors that touch more than two call sites.
How do I keep the live values inside an instance DB after changing the FB interface?
Generate a source file from the iDB before the interface change, apply the interface change, then recompile the DB source. Variables that still exist by name are repopulated with their previous actual values; new variables take their declared initial values; deleted variables are removed. Watch tables and HMI archives are useful as a secondary record of critical values.
Should I use multi-instance FBs in TIA Portal?
Yes, for any FB that is called from three or more places, or for nested FB hierarchies. Multi-instance calls store the child FB's STAT data inside the parent iDB, which means a single iDB update propagates the change to every call site. It also reduces the number of iDBs in the CPU's work memory, which is the recommended pattern for S7-1500 projects.
Can I rename a STAT variable in an FB without losing the iDB value?
No. Renaming is treated as a delete-plus-insert by the compiler. The variable under the old name is removed and a new variable with the new name is created at the next available offset with the declared initial value. Use a Watch Table export to capture the current value and write it back after the recompile, or use a separate renaming field in the HMI tag to keep the symbolic mapping stable.
Does optimized access (S7-1500) eliminate the instance DB sync problem?
Partially. Optimized access removes the absolute-offset dependency by indexing variables by symbolic name, so a reordering or insertion at the end of the STAT section is transparent to the CPU. However, any insertion in the middle of the section, a type change, or a rename still requires the editor to update the iDB and you still need to run Check Block Consistency to propagate the change to every call site.