PLCcheck

S5 AWL Command: A DB (Open Data Block)

S5 AWL instruction A DB: Opens a data block for subsequent DW/DL/DR/D access. The DB stays open until another A DB is called.

·4 min read
S5AWLA DBdata blockopenOPNDatenbaustein

Diesen Artikel auf Deutsch lesen

S5 AWL Command: A DB (Open Data Block)

A DB opens a data block for subsequent data access. All DW, DL, DR, and D instructions after A DB refer to the opened block. The DB stays open until another A DB instruction is executed or the block ends.

Syntax

A  DB 10            // Open data block DB10
L  DW 5             // Load word 5 from DB10
T  MW 20            // Store in marker word

S7 Equivalent

S5 AWLS7 STLS7 SCL
A DB 10OPN DB 10Not needed — use DB10.DBW10 directly

S7 advantage: In S7, you can access data blocks directly without opening them first: L DB10.DBW10. The OPN instruction still exists for compatibility but is rarely used in new code.

Critical Behavior: DB Stays Open

A  DB 10            // DB10 is now open
L  DW 0             // Reads DB10.DW0
...                  // 50 lines of code later...
L  DW 5             // STILL reads from DB10!
...
SPA FB 20           // FB20 may open a DIFFERENT DB internally!
L  DW 3             // WARNING: Which DB is open now? Not necessarily DB10!

The trap: If a called FB opens its own DB, the originally opened DB is replaced. After returning from the FB, the "current DB" may not be what you expect. This is the most common DB-related bug in S5 programs.

S7 solution: Always use fully qualified access (DB10.DBW10) instead of relying on the "current DB" concept. This eliminates the entire class of bugs.

Common Patterns

// Read from one DB, write to another
A  DB 10
L  DW 5             // Read from DB10
A  DB 20            // Now DB20 is open (DB10 is "closed")
T  DW 3             // Write to DB20

Part of the S5 AWL Command Reference. Maintained by PLCcheck.ai.


Analyze Your S5 Code Automatically

PLCcheck Pro reads your complete S5 AWL program and explains every instruction — including this one — in plain language. Upload your code and get instant documentation, S7 equivalents, and migration guidance.

Upload S5 code for free analysis → | S5→S7 Migration Guide →

Related Articles

Analyze your PLC code with AI

PLCcheck Pro explains, documents, optimizes, and migrates PLC code — automatically.

Try PLCcheck Pro →
← Back to Blog

Not affiliated with Siemens AG. S5, S7, STEP 5, STEP 7, and TIA Portal are trademarks of Siemens AG.