Configuring WinCC v6.2 Batch Reports via SQL and User Archive

David Krause12 min read
HMI / SCADASiemensTechnical Reference
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

1. Overview

Batch reporting in Siemens WinCC V6.2 (released 2008, current branch on Windows XP/Server 2003 32-bit platforms) requires assembling process tag values, batch identity, timestamps, and operator inputs into a single document keyed to a batch ID. Unlike continuous trending, a batch report has a defined start/stop envelope, an ISA-88-style recipe context, and is typically emitted as either a PDF, a printout, or a CSV/XLSX row group. WinCC V6.2 does not ship a single "batch button"; the engineer composes the report by combining one of three primary data sinks (User Archive, Tag Logging archive, or direct SQL database) with one of three rendering layers (Report Designer, DataMonitor, or a custom C/VB export).

The matrix that follows is the technical center of this reference. The trade-off is always between license cost, engineering effort, and conformance to ISA-88. Choosing a path before commissioning the batch faceplate avoids costly retrofitting once the recipe state machine is in production.

2. Batch Report Architecture in WinCC V6.2

A WinCC batch report pipeline is composed of four logical blocks:

  1. Data acquisition: Process tags, archive tags, and User Archive columns are populated by the WinCC data manager.
  2. Trigger logic: A C or VB action detects the rising edge of the batch start bit, snapshots the recipe header, and increments a batch counter.
  3. Storage: Data is persisted either in the WinCC archive database (CC_Logger / CC_UserArchive on the embedded SQL Server) or in an external MSDE/SQL Server 2005 instance via a database tag or ODBC connection.
  4. Rendering: Report Designer (RT/DOCX) reads the stored rows and formats them into a printable layout, or DataMonitor publishes the same data via the WinCC WebNavigator portal.

The default WinCC V6.2 install ships MSDE 2000 (Microsoft SQL Server Desktop Engine) as the embedded database engine. Tag logging goes to CC_Logger_<ServerName>_<TimeStamp>.mdf and User Archives to CC_UserArchive_<ServerName>_<TimeStamp>.mdf, both in \Siemens\WinCC\SQL\. To attach SQL Server Management Studio for inspection, see the Siemens Knowledge Base entry 22956114 on WinCC V6.x SQL configuration.

3. Method 1 - User Archive-Based Batch Reporting

User Archive is the recommended native path for batch reports when the customer is unwilling to purchase PM-Quality. It exposes a tabular view backed by SQL Server and is fully scriptable.

3.1 Install the User Archive Option

The User Archive option is not selected by default and requires a license key. Re-run the WinCC setup, choose User-defined installation, and tick User Archive under WinCC Options. After install, the WinCC Explorer gains a User Archive editor and the runtime gets the UA subsystem.

3.2 Define the Archive Schema

Open the User Archive editor and create a new archive named BatchReport with the following columns (representative of an ISA-88 batch header):

Column Type Length Purpose
BatchID Text 32 Primary key, also printed on the report
RecipeName Text 64 Recipe ID from the S7 DB
StartTime Date/Time 8 Batch start timestamp UTC
EndTime Date/Time 8 Batch end timestamp UTC
Operator Text 32 Logged-in WinCC user
SetpointTemp Floating point 8 Recipe parameter
ActualTempAvg Floating point 8 Calculated at end of batch
ResultCode Integer 4 0=PASS, 1=FAIL, 2=ABORTED

Mark BatchID as the primary key. Set the archive to allow runtime modifications so that the C-script can append rows without a server restart.

3.3 Connect an Internal Tag to the Archive

Create a WinCC tag batch_ua_id (Text, length 32) and link it to the User Archive column BatchID via the Tag property of the column. This makes the value visible as a normal tag in Graphics Designer and usable in faceplate displays.

4. Method 2 - Direct SQL Server Logging

For sites that already maintain a plant-wide SQL Server (e.g., SQL Server 2005 Standard on a SCADA server) and want zero-cost batch persistence, use WinCC's database tag or a C-script with ODBC.

4.1 Configure the ODBC Data Source

  1. On the WinCC server, run Data Sources (ODBC) from Control Panel → Administrative Tools.
  2. Add a System DSN named DSN_BatchSQL pointing to the SQL Server instance PLANT-SQL01 using SQL Server Native Client 2005.
  3. Authenticate with a dedicated service account (do not use sa).
  4. Create the target database WinCC_Batch with a table BatchHeader mirroring the User Archive schema in §3.2.

4.2 Test the Connection

Use a minimal C script (see §6) that calls SQLConnect() against DSN_BatchSQL and writes a single row. If SQLConnect returns SQL_ERROR, confirm that the SQL Server Browser service is running and that the firewall allows TCP/1433 from the WinCC server.

Note: WinCC V6.2 runtime is 32-bit only. Even on a 64-bit Windows Server 2008 R2 host, you must install the 32-bit ODBC administrator (C:\Windows\SysWOW64\odbcad32.exe) and configure the DSN there, not in the default 64-bit panel.

5. Method 3 - Report Designer Layouts

Open the WinCC Report Designer (start menu → SIMATIC → WinCC → Report Designer). It contains three layout editors: Page Layout (printable page), Line Layout (continuous line printer), and Documentation Layout (project documentation). For batch reports, use Page Layout.

5.1 Build the Layout

  1. Create @BatchReport.rpl under Page Layouts.
  2. Insert a Static text field for the company logo and report header.
  3. From the toolbox palette, drag the User Archive Table object onto the page. Bind it to archive BatchReport and enable the filter property with the condition BatchID = '$(GetTag("batch_ua_id"))'.
  4. Add a Tag Table object to print the live process values at the moment of report generation.
  5. From Print Job Properties, set the trigger tag to batch_report_trigger (a binary tag pulsed for 1 second at batch end).

5.2 Configure the Print Job

In the Print Jobs editor, create a new print job BatchReport_Print referencing @BatchReport.rpl. Set output to File: PDF with a dynamic file name pattern C:\Reports\Batch_$(GetTag("batch_ua_id")).pdf. The WinCC spooler writes the PDF via the included WinCC PDF Print driver, which is installed together with the PrintMonitor option.

6. Method 4 - C-Script Implementation

WinCC V6.2 supports ANSI C in the action editor. The following action, attached to the rising edge of batch_start, writes a row into the User Archive via the UA API. The C path is preferred over VB for engineers migrating from Step 7 STL and for performance on long batches (> 50 k samples).

6.1 Header and Includes

#include "apdefap.h"
#include "GlobalDef.h"
#include "us_arc_api.h"   // User Archive C API, ships with WinCC V6.2

void OnBatchStart(char* lpszPictureName, char* lpszObjectName,
                  char* lpszPropertyName)
{
    // Acquire the archive handle for "BatchReport"
    UAHARCH  hArchive = uaOpenArchive("BatchReport");
    if (hArchive == 0) {
        printf("User Archive open failed, code %d\n", uaGetLastError());
        return;
    }

    // Move to a new row at the end of the archive
    uaArchiveMoveLast(hArchive);
    uaArchiveMoveToAppend(hArchive);

    // Populate columns by name (case sensitive)
    uaArchiveSetFieldValueChar(hArchive, "BatchID",
        GetTagChar("batch_ua_id"));
    uaArchiveSetFieldValueChar(hArchive, "RecipeName",
        GetTagChar("recipe_name"));
    uaArchiveSetFieldValueDouble(hArchive, "SetpointTemp",
        GetTagFloat("recipe_sp_temp"));

    // Set start time to "now" using WinCC helper
    SYSTEMTIME st;
    GetLocalTime(&st);
    uaArchiveSetFieldValueDateTime(hArchive, "StartTime",
        SystemTimeToVariantDate(&st));

    // Commit the row to SQL Server
    uaArchiveWrite(hArchive);
    uaCloseArchive(hArchive);

    // Pulse the report trigger for 1 s to fire the print job
    SetTagBitWait("batch_report_trigger", 1);
    SetTagWait(1000);
    SetTagBitWait("batch_report_trigger", 0);
}

6.2 Linked Trigger

Open the tag batch_start in Graphics Designer, select Properties → Events → OnChange, and assign the C action above. The trigger fires only on the 0 → 1 transition; the reset to 0 at batch end is handled by a separate edge-detected action that writes EndTime, ActualTempAvg, and ResultCode into the same row.

Caution: The UA C API is synchronous. If the SQL Server is unreachable, the action blocks the WinCC scheduler for the entire ODBC timeout (default 60 s) and freezes all graphics. For mission-critical lines, use the UA Async variant or wrap the call in a worker thread created via CreateThread().

7. Method 5 - VB-Script Alternative

Engineers familiar with VBScript can use the same UA API through the COM wrapper WinCCUAConnector. The VB path is slower (≈ 3× the wall-clock time of C for the same row count) but easier to debug because errors are reported through Err.Number rather than return codes.

Dim ua As Object
Set ua = CreateObject("WinCCUAConnector.UAArchive")

ua.Open "BatchReport"
ua.MoveLast
ua.AppendRow

ua.SetFieldValue "BatchID",      HMIRuntime.Tags("batch_ua_id").Read
ua.SetFieldValue "RecipeName",   HMIRuntime.Tags("recipe_name").Read
ua.SetFieldValue "SetpointTemp", CDbl(HMIRuntime.Tags("recipe_sp_temp").Read)

ua.Write
ua.Close

Set ua = Nothing

To schedule the VB action, attach it to the same batch_start tag event under Properties → Events → OnChange and select VBS Action instead of C Action. Mixing C and VBS on the same tag event is allowed but discouraged; pick one language per tag to keep the call stack legible.

8. Method 6 - DataMonitor Web Reporting

WinCC/DataMonitor is a licensable option that exposes Tag Logging, Alarm Logging, and User Archives through an IIS-hosted web portal. The Reports tab of the DataMonitor site allows operators to select a time range, export to Excel, or subscribe to a published report that refreshes hourly. For batch reports, configure the WinCC DataMonitor Report template to query the BatchReport User Archive with a parameter prompt for the batch ID.

Installation is documented in the Siemens KB 22721426 - DataMonitor configuration for WinCC V6.2. The DataMonitor Client does not require a separate license for read-only report viewing, but the DataMonitor Server does.

9. Method 7 - PM-Quality Add-on

When the customer requires ISA-88-compliant electronic batch records with full audit trail, electronic signatures (21 CFR Part 11), and recipe versioning, the SIMATIC PM-Quality add-on is the engineered answer. PM-Quality integrates with the S7 recipe control (typically PCS 7 or Route Control) and generates XML/PDF batch reports whose structure is fixed by the standard.

PM-Quality is licensed per server plus per operator station. The implementation effort is measured in weeks, not days, because the recipe state machine must be reworked to call the PM-Quality API at each phase transition. Refer to the SIMATIC PM-Quality V6.2 manual for the full API reference and the configured phases.

10. Excel Export Workflow

For sites that consume reports in Excel rather than PDF, the User Archive editor provides a built-in export. Right-click the archive in runtime → Export to CSV writes a comma-separated file that Excel imports cleanly. For a template-driven approach:

  1. Author BatchTemplate.xltx with named ranges BatchID, RecipeName, SetpointTemp.
  2. Use a C action that calls uaArchiveExportToFile() to dump to batch_<ID>.csv.
  3. Drive Excel via COM: CreateObject("Excel.Application"), open the template, and use Data → Get Data → From Text/CSV through the Office automation model.

Note that Office automation on the WinCC server is unsupported by Microsoft for unattended use; deploy Excel on a separate reporting workstation and copy the CSV over the network share, or use Power Query as the integration layer.

11. Method Comparison Matrix

Method License Effort Output Best for
User Archive + C-script User Archive option Low (1-2 days) PDF, CSV, RTF Small/medium sites without 21 CFR
User Archive + VB-script User Archive option Low (1-2 days) PDF, CSV, RTF Engineers fluent in VB
Direct SQL via ODBC None (uses MSDE/SQL) Medium (3-5 days) Custom via SELECT Plant-wide data warehouse
Report Designer only None (bundled) Low (½ day) Print/PDF Static reports from existing archives
DataMonitor Reports DataMonitor server Medium (1 week) Web Excel/PDF Multi-site viewing
PM-Quality PM-Quality server + client High (weeks) XML/PDF with e-sig Regulated pharma/food

12. Verification and Commissioning Checklist

  1. Start a manual batch from the operator faceplate; confirm that the batch_start edge writes exactly one row into the User Archive.
  2. Verify in SQL Server Management Studio (or Enterprise Manager on MSDE) that the BatchReport table contains the row with non-null BatchID, StartTime, RecipeName.
  3. Pulse batch_report_trigger from the WinCC debugger; confirm that C:\Reports\Batch_<ID>.pdf is created and the PDF contains the expected row.
  4. Open the PDF in Adobe Reader and verify that the page count, header, and data table render without clipping.
  5. Inject a SQL outage (stop the SQL service) and confirm that the C action times out within 60 s and that the operator faceplate displays Archive write failed - retry.
  6. Restore the SQL service and re-trigger the batch; confirm that the new row is written and no orphan rows are produced.
  7. Validate operator login in Operator column matches the Windows account name (case sensitive).
  8. For DataMonitor, browse to http://<wincc-server>/WebNavigator from a client, open the report, and export to Excel.

13. Field-Proven Caveats

  • Time zone drift: WinCC V6.2 stores Date/Time in local time on the server. If the SCADA server is in one time zone and the report viewer in another, normalize to UTC at write time and re-convert on the client.
  • MSDE 2000 limit: 2 GB database, max 5 concurrent batch inserts. Above that, migrate to SQL Server 2005 Express (free) or full Standard.
  • User Archive license per server: The runtime license is keyed to the WinCC server name. A redundant pair requires two licenses.
  • Report Designer RT: The RT (runtime) layouts are limited to a subset of the Configuration layout features. If you need a bar chart, author it in Configuration and ship the .rpl to the RT folder.
  • C-script heap: The WinCC action workspace is a fixed 1 MB heap. Use static buffers and avoid malloc() in long-running loops.
  • Excel 2007+: The Export to CSV from User Archive writes a UTF-8 BOM-less file. Excel 2007 may misinterpret the encoding; add a BOM or use Unicode comma-separated text.

14. Frequently Asked Questions

Do I need an extra license for the User Archive option in WinCC V6.2?

Yes. The User Archive is an optional component and requires a separate license key. Select User-defined installation during WinCC setup and tick User Archive; the license is bound to the server name.

Can I write batch data to SQL Server 2005 without buying the User Archive option?

Yes. Use a C-script with SQLConnect() against a 32-bit ODBC System DSN that points to SQL Server 2005. The DSN must be created in the 32-bit ODBC administrator (%windir%\SysWOW64\odbcad32.exe) on 64-bit hosts.

What is the difference between Report Designer and DataMonitor for batch reports?

Report Designer produces print/PDF output triggered by a WinCC tag and runs on the SCADA server. DataMonitor publishes the same data through an IIS web portal and supports remote viewing, Excel export, and timed subscriptions but requires the DataMonitor server license.

Is PM-Quality the only way to produce ISA-88 batch records?

PM-Quality is the engineered Siemens solution. For a lower-effort path, you can use User Archive + Report Designer with a custom schema that follows ISA-88 fields, but the resulting report will not have built-in electronic signatures or recipe versioning.

Can I mix C and VBScript in the same WinCC project?

Yes, both can coexist on different tag events. Mixing them on the same event is allowed but discouraged because the call ordering becomes hard to debug. Pick one language per tag and document the choice in the comment header of each action.

Why does the C-script freeze the screen when SQL Server is offline?

The WinCC User Archive C API is synchronous and blocks the scheduler for the full ODBC timeout (default 60 s). Use the async API variant or run the SQL call in a worker thread created with CreateThread().

Back to blog