Siemens TIA Portal: Updating Instance DBs After FB Changes

David Krause13 min read
SiemensTIA PortalTroubleshooting
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

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.

Production warning: All interface edits and consistency operations should be performed offline against a backed-up project before being applied to a live CPU. The order in which the editor rewrites iDBs is deterministic, but in-place modification of an iDB whose structure has shifted can corrupt the actual values that the running process depends on.

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 types and their memory roles
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:

  1. The FB number and FB version stamp
  2. The byte offset of every STAT variable in declaration order
  3. The initial value assigned at iDB generation time
  4. 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 STAT is 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-to-cause diagnostic matrix
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:

  1. Open the block that contains the FB call (an OB, FC, FB, or another FB that uses the changed FB).
  2. Place the cursor anywhere in the LAD/FBD/STL network that calls the modified FB.
  3. Open the menu: File → Check and Update Accesses (German UI: Datei → Zugriffe prüfen und aktualisieren). The keyboard shortcut is Ctrl+F7 in classic Step 7.
  4. The editor scans the open block for all access patterns to the modified FB's STAT section and rewrites the call-site operand list to match the new interface.
  5. Save the block with Ctrl+S and recompile.
Scope limitation: This operation only updates the block that is currently loaded in the editor. If the modified FB is called from N other blocks, those N blocks must be opened and updated individually. For projects with more than a handful of call sites, Path B (project-wide consistency check) is faster.

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.

  1. In the project tree, right-click the Program blocks folder (or the PLC device, depending on TIA Portal version).
  2. 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).
  3. The compiler produces a list of inconsistencies in the Inspector window. Each entry identifies the affected block and the call that needs updating.
  4. Right-click the top-level result and select Compile → All blocks. The compiler rewrites all dependent iDBs to match the new interface.
  5. Re-run the check to confirm zero entries remain.
Compilation order dependency: In Step 7 Classic V5.x, OBs are compiled first, then FBs and FCs in numeric order, then DBs last. If a higher-numbered FB is updated and a lower-numbered FB calls it, the lower-numbered FB's iDB may not be rewritten until the next full pass. Always re-run the check at least twice when the project has cross-FB dependencies.

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):

Multi-instance declaration in FB_Coordinator.STAT
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:

  1. Open the parent block (FB or OB) that calls the modified FB.
  2. In the call's instance selector, choose Multi-instance and assign a name (e.g., instMotorCtrl).
  3. Delete the now-orphaned per-call iDB from the project tree.
  4. 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.

  1. 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 .scl or .db source contains the literal values that are currently in the iDB.
  2. Modify the FB interface as required (add/rename variables, change data types).
  3. 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.
  4. 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.
  5. Download the regenerated iDB to the CPU.
Value preservation caveat: Name-based matching is the only safe way to retain values. If you have renamed a variable in the FB interface, the source-file recompile treats the renamed item as a new variable and the old actual value is lost. Always take a Watch Table or archive dump of critical values before changing variable names.

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.

Offline vs online interface change comparison
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:

  1. Take a backup of the online project (TIA: Online → Backup from online device).
  2. Bring the CPU to STOP if the FB signature change requires a full download.
  3. Generate source files for every iDB that will be affected.
  4. Apply the interface change offline in the engineering station.
  5. Run Check Block Consistency and resolve all entries.
  6. Recompile the DB sources to rebuild the iDBs with preserved values.
  7. Download the new blocks in the order OBs → FBs → FCs → iDBs.
  8. 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.

  1. Compile clean. Project → Compile → All blocks. Zero errors, zero warnings related to interface changes.
  2. Consistency clean. Right-click Program blocks → Check Block Consistency. Zero inconsistencies remaining.
  3. 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.
  4. 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.
  5. Watch table snapshot. Online → Watch and force tables. Open the iDB and force a read of every STAT variable. Compare to the pre-change snapshot taken at the start of the change window.
  6. CPU diagnostic buffer. Online → Diagnostics → Diagnostic buffer. Confirm no new SF entries, no "DB structure error", no STOP events.
  7. 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 STAT section 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.

FB interface changed Called in >2 blocks? Or live values matter? Path A Check and Update Accesses per call site Path B Check Block Consistency project-wide Path D Source file generation + DB recompile Same FB called ≥3 places? Convert to multi-instance (Path C) No Yes Live values Yes

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.

Back to blog