WinCC Report Designer: Custom Start/End Time Report Printing

David Krause10 min read
SiemensTutorial / How-toWinCC
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. Problem Overview

The default WinCC Report Designer layout prints a fixed sliding window (for example, "last 12 hours") of the WinCC Online Trend Control. Operators frequently require an ad-hoc report that covers a user-defined interval such as a shift, a batch, or a fault investigation window. The layout file (RDL) is static, but the underlying trend object exposes two dynamic properties — BeginTime and EndTime — that can be driven from internal string tags at print time.

This article documents the complete procedure to:

  1. Declare two internal WinCC tags of type Text variable 16-bit (WinCC string) to hold the interval boundaries.
  2. Bind them to the BeginTime and EndTime properties of the Online Trend Control inside the RDL layout.
  3. Write the desired start and end timestamps to those tags from VBScript, C script, or the PLC before the print job is triggered.
  4. Print to a physical printer, PDF, or file using the RPTRunPrintJob / PrintReport function.

The technique is officially supported on WinCC Runtime V7.4 SP1 and later, including V7.5 SP2, V7.5 SP3, and the V8.x line. The companion engineering system tested against is STEP 7 V5.5 SP4 HF11; TIA Portal V15.1+ with WinCC Professional/Comfort uses a different (C#/VB .NET) approach that is out of scope here.

2. Prerequisites

Component Minimum Version Notes
WinCC Explorer / WinCC Configuration Studio V7.4 SP1 For RDL layout editing and tag management
WinCC Runtime V7.4 SP1 or later Tested through V8.0
Report Designer license WinCC RC / RT option Provides the RDL editor and runtime print engine
Online Trend Control OCX shipped with WinCC Embedded inside the RDL layout
STEP 7 (optional) V5.5 SP4 HF11 For PLC-side trigger over WinCC internal variables
VBScript or ANSI-C interpreter Built into WinCC RT Used to write the time strings before print

Verify the WinCC Online Trend Control version on the target system:

  1. Open the RDL layout in the Report Designer.
  2. Right-click the embedded trend object → Properties → General tab.
  3. Confirm the OCX Version field shows at least 7.4.1.x.
Note: Mixed-version installations (RT V7.4 + OCX V7.3) cause silent fallback to fixed time range. Always deploy matching RT/OCX builds from the same installation media.

3. Architecture: How the Layout Resolves Time Range

When the Report Designer prints, it instantiates the embedded WinCC Online Trend Control as an ActiveX object and queries its BeginTime and EndTime properties. These are Date/Time values internally, but the control accepts and displays them in two ways:

  • Static configuration in the layout editor (locks the window).
  • Dynamic binding to a WinCC tag via the OCX property dialog.

Dynamic binding is the key. By wiring each property to an internal string tag, the runtime evaluation happens at the moment the print job starts, not at layout load time. The control parses the string using the WinCC regional format configured under Computer Properties → Graphics Runtime → Regional Settings.

4. Step-by-Step: Declare the Internal Tags

  1. Open WinCC Explorer and select the Tag Management editor.
  2. Right-click Internal Tags → Add New Tag.
  3. Create the following two tags:
Tag Name Data Type Length Initial Value
Report_BeginTime Text variable 16-bit 32 (empty)
Report_EndTime Text variable 16-bit 32 (empty)
Report_Trigger Binary Tag 1 0
Why "Text variable 16-bit"? WinCC inherits the S7 naming convention: "Text variable 16-bit" is a Unicode/ANSI string of up to 255 characters (effectively 16-bit character width for international character sets). The trend control parses the first 19 characters; the rest is ignored. Length 32 gives ample headroom for any locale's full timestamp plus milliseconds.

5. Step-by-Step: Bind Properties in the RDL Layout

  1. In WinCC Explorer, double-click Report Designer and open the existing RDL layout (e.g. ShiftReport.rdl).
  2. Click the embedded Online Trend Control object inside the layout canvas to select it.
  3. Right-click → Configuration Dialog → switch to the Time Axis tab.
  4. Uncheck Use fixed time range. The fields Start time and End time become editable and show small ... buttons.
  5. Click the ... button next to Start time and select Report_BeginTime.
  6. Click the ... button next to End time and select Report_EndTime.
  7. Save the layout and close the editor.

The binding is persisted in the RDL XML. Verify by opening the RDL in a text editor and searching for:

BeginTime="Report_BeginTime" EndTime="Report_EndTime"

If both attributes appear, the dynamic binding is active.

6. Step-by-Step: Populate the Tags Before Printing

6.1 VBScript Method (Recommended)

Attach a VBScript action to the button (or scheduled event) that triggers the report. A clean, locale-independent implementation reads the target interval from operator-entered fields on the screen:

' --- WinCC VBScript: Write BeginTime / EndTime from screen fields ---
Option Explicit

Dim sBegin, sEnd
sBegin = HMIRuntime.Screens("ScreenOverview").ScreenItems("dtBegin").OutputValue
sEnd   = HMIRuntime.Screens("ScreenOverview").ScreenItems("dtEnd").OutputValue

' Normalize to runtime regional format expected by the trend control
Dim oFmt : Set oFmt = CreateObject("MSWC.Tools") ' not used; built-in helper

HMIRuntime.Tags("Report_BeginTime").Write sBegin
HMIRuntime.Tags("Report_EndTime").Write sEnd

' Optional: small delay to ensure the control polls the new values
HMIRuntime.Wait 250

' Trigger the print
HMIRuntime.Trace "Printing report from " & sBegin & " to " & sEnd & vbCrLf
Dim sRet
sRet = HMIRuntime.Report.PrintReport("ShiftReport@WINCC_RT_DEFAULT.PDL", _
                                    "\\\\PRINTSVR\\ShiftReports", _
                                    "\\\\FILESVR\\PDF\\ShiftReport_*.pdf")
If sRet <> "" Then
    HMIRuntime.Trace "Print error: " & sRet & vbCrLf
End If

Note that HMIRuntime.Wait 250 is a 250 ms pause giving the OCX one full pump cycle to refresh its bound properties. Increase to 500 ms on slower HMI panels.

6.2 C-Script Method (Classic WinCC)

For projects still on ANSI-C, the equivalent is:

/* WinCC ANSI-C: Populate begin/end then print */
#include "apdefap.h"
void OnPrintReport(char* lpszPictureName, char* lpszObjectName)
{
    char szBegin[32], szEnd[32];
    char* pszFile = "C:\\Reports\\ShiftReport.prn";

    /* Read operator-entered times from the screen */
    szBegin[0] = '\0'; szEnd[0] = '\0';
    GetOutputValueChar(GetScreenItem(lpszPictureName, "dtBegin"), szBegin);
    GetOutputValueChar(GetScreenItem(lpszPictureName, "dtEnd"),   szEnd);

    /* Write to internal tags */
    SetTagChar("Report_BeginTime", (LPSTR)szBegin);
    SetTagChar("Report_EndTime",   (LPSTR)szEnd);

    /* Trigger print job via internal API */
    RPTJobStart(pszFile);
    RPTJobPrint(NULL);
}

6.3 PLC-Triggered Method (STEP 7)

When the start/end timestamps originate in the S7 PLC, write them to the WinCC internal tags over the WinCC-S7 connection using raw PUT on the configured area pointer:

  1. Declare two STRING[32] variables in the STEP 7 DB, e.g. DB100.DBB0 (Report_BeginTime) and DB100.DBB36 (Report_EndTime).
  2. Add an Area Pointer "Date/Time" or a custom Raw area pointer of 64 bytes in the WinCC channel.
  3. Format the strings in the S7 to match the WinCC regional format (see Section 7) using FC5 / FC6 (DT to String conversion) or SCL.
  4. On a rising edge of the Report_Trigger bit, fire the print job from a WinCC global script (see Section 6.1).
Caution: The default area pointer for internal tags is local. If the PLC writes the same tags, configure a separate Tag connection or expose them as External WinCC tags whose name matches the internal ones, otherwise the write will be silently dropped by the tag manager's priority rules.

7. Date/Time String Format Specification

The Online Trend Control parses the bound string using the regional format configured at the WinCC station, not the HMI panel's locale. To inspect or change it:

  1. Open Computer Properties on the WinCC server/HMI.
  2. Navigate to Graphics Runtime → Runtime Settings → Regional Settings.
  3. Note the Short date format, Long time format, and Date separator.
Locale (sample) BeginTime / EndTime expected
English (US) MM/DD/YYYY HH:MM:SS e.g. 03/14/2024 06:00:00
German (DE) DD.MM.YYYY HH:MM:SS e.g. 14.03.2024 06:00:00
English (UK) DD/MM/YYYY HH:MM:SS e.g. 14/03/2024 06:00:00
ISO 8601 (forced) YYYY-MM-DD HH:MM:SS e.g. 2024-03-14 06:00:00 (only if Windows regional is set to ISO)
Milliseconds are optional. The control accepts HH:MM:SS.fff; the value is parsed and used for trend interpolation. If omitted, :00 is assumed.

Hard rule: The string length, separator characters, leading zeros, and 12/24-hour flag must match the runtime locale. A US-formatted string sent to a German runtime logs "CWTRC: Invalid time string" in WinCC_Sys_xx.log and prints the default window (12 h or whatever the static config was).

8. Triggering the Print

Output Target WinCC Function Notes
Default printer PrintReport(szLayout, szPrn, "") Use empty string for output path
Network printer PrintReport(szLayout, "\\\\PRINTSVR\\Reports", "") UNC path required
PDF file PrintReport(szLayout, "", "C:\\PDF\\Shift_*.pdf") Wildcard * substituted with timestamp
File with layout-specific stamp Use RPTRunPrintJob via C-script Suppresses dialog

For batch/unsupervised printing, prefer RPTJobPrint (C) or HMIRuntime.Report.PrintReport (VBS) over the legacy ReportJob COM object, which is deprecated in V7.5+.

9. Verification Procedure

  1. Open the project in WinCC Runtime, navigate to the print screen, enter 03/14/2024 06:00:00 as start and 03/14/2024 14:00:00 as end.
  2. Click the print button. The WinCC_Sys_xx.log should contain a line "Print job 'ShiftReport' started, pages=...".
  3. Open the resulting PDF or printed page. The trend's X-axis must show the 8-hour interval 06:00 → 14:00 on 14 Mar 2024 only.
  4. Enter a deliberately invalid range (End < Begin). The trend control falls back to the static configured window; no error dialog is raised. Validate input upstream to prevent silent fallback.
  5. Re-run with end-time in the future. The control clamps to "now"; curve stops at the last available archive data point. Acceptable for live dashboards.

10. Troubleshooting Matrix

Symptom Likely Cause Fix
Always prints the same fixed window Property binding not saved in RDL Re-open layout, re-bind, save, re-deploy to RT
Prints 12 h sliding window from current time Tags empty when print fires Add HMIRuntime.Wait 250 after Tags(...).Write
"Invalid time string" in log Locale mismatch between string and runtime Match separator and order to Computer Properties → Regional
PDF file empty (0 bytes) Output path lacks write permission for Runtime user Grant WinCC Runtime account write access; use local C:\Temp for test
Trend control not visible in PDF Online Trend Control OCX not registered on target Run regsvr32 "C:\Program Files\Siemens\Automation\WinCC\bin\WCCOCXTrend.dll" on RT
Works in CS, fails in RT Tags declared in CS only, not exported Right-click tag group → Export → reimport on RT; verify Tag Management Online shows green
Time written but report uses old archive range Tag is of type "Binary" instead of "Text" Recreate as Text variable 16-bit with length 32
Prints multiple times on one click Trigger bit not auto-reset Reset Report_Trigger in VBS after PrintReport returns

11. Extended: Multiple Pages with Different Ranges

To produce a daily report (24 pages, one per hour) from a single VBScript loop:

  1. Pre-allocate Report_BeginTime and Report_EndTime as above.
  2. Loop over the day, calling HMIRuntime.Tags(...).Write and PrintReport inside the loop body.
  3. Sleep HMIRuntime.Wait 500 between iterations to avoid OCX queuing.
  4. Append a counter to the output filename: "C:\\PDF\\Shift_2024-03-14_##.pdf".

A 24-page batch typically takes 12-25 seconds on a WinCC V7.5 server with a 30 ms/h process value archive.

12. References Within the WinCC Information System

For further reading inside the installed WinCC Information System (Start → Programs → Siemens Automation → Documentation):

  • WinCC Information System → Working with WinCC → Creating Reports → Layout of the Page Layout → Working with Objects in the Page Layout
  • WinCC Information System → Options → Report Designer → Working with the Report Designer → Configuring the Online Trend Control
  • WinCC Information System → Communication → SIMATIC S7 → Area Pointer for S7 Communication

These are bundled with the WinCC installation media and the matching Service Packs.

What is the correct WinCC internal tag data type for BeginTime and EndTime?

Use Text variable 16-bit (string), length 32. The Online Trend Control parses the string at print time. Binary, signed, or unsigned tags are silently ignored and the report falls back to the static time window.

What date/time format does the Online Trend Control expect?

The format must match the Regional Settings of the WinCC Runtime station (Computer Properties → Graphics Runtime). A US runtime expects MM/DD/YYYY HH:MM:SS; a German runtime expects DD.MM.YYYY HH:MM:SS. Leading zeros, the date separator, and 24-hour clock must be consistent.

Why does the report still print the last 12 hours after I change the tags?

The two most common causes: (1) The tags are written but the print is triggered immediately, so the OCX has not yet polled the new values — insert a 250-500 ms HMIRuntime.Wait after the Tags(...).Write call. (2) The RDL still has the static "Use fixed time range" checkbox enabled, which overrides the bound properties — open the layout and uncheck that option on the Time Axis tab.

Can the PLC write the start and end times directly?

Yes. Declare two STRING[32] variables in a STEP 7 DB, format them in SCL or with FC5/FC6 to match the WinCC runtime locale, and either (a) expose them as external WinCC tags on the S7 channel, or (b) use a Raw area pointer mapped to the DB range. Do not write to internal tags from the PLC — internal tags are not accessible over the S7 protocol.

Which WinCC versions support the BeginTime/EndTime property binding?

The feature is supported from WinCC V7.0 SP3 onward via the WinCC Online Trend Control OCX, and is fully documented in the Report Designer for V7.4 SP1, V7.5, V7.5 SP2, and V8.0/8.1. Always match the OCX version to the runtime version to avoid silent fallback to the static window.

Back to blog