Simatic Step7: ANY pointer Input parameter

In this article I'll describe how to use an ANY data type as pointer input in a simple subroutine in Simatic Step 7 v.5.5. ANY parameter type, according to Simatic on-line help, is a 10 byte length with the following structure:

First of all I create a simple S7 project : CPU S7-315 6ES7 315-2EH14-0AB0

then in the project I define a new UDT1 (mnemonic name ANY_UDT) data type with length 1 word: 8 bit In + 8 bit Out. Scope of the subroutine is map the 1st Input bit of UDT to 1st Output bit

I define now the subroutine as FC1 (ANY_Pointer) containing:

IN: InData: ANY

TEMP: In :UDT1 // UDT1 data type in order to easily access the structure bits into subroutine logic

TEMP: InLaddr: DWORD // pointer to "In" area

TEMP: InDBNum: INT // "In" area DB number

This is the subroutine code:

Recall the sub into OB1 and assign it the input parameter (P#DB1.DBX0.0 BYTE 2) (=DB1.Sample1 ANY data)

And this is the PLC SIM runtime that show the subroutine job

The advantage of using ANY data as input parameter are:

Low Work Memory Requirement (this sample FC need 104 bytes. Defining directly in parameters as UDT the Work Memory requirement is higher) : the subroutine define not entire UDT, just pointer to it (ANY). Struct data are defined as TEMP data

Few In, Out, InOut parameters=clean code view

Here follow I share this sample project hoping it can be hopeful for you. If you have any question, doubt, request, feel free to contact me