show the entry list
STEP 7 -- Creating S7 programs -- Calling blocks and functions
What are the block protection facilities available in STEP 7 to protect the the know-how of your blocks?
What is the maximum number of parameters that can be assigned to an FC and FB in the S7-300 CPU?
How can you install block protection for self-created blocks?
Tips and tricks for calling and parameterizing SFBs, SFCs and IEC standard functions
How do you transfer string variables from a data block to a function blocks, for example?
Information about "Calling blocks and functions"
How do you parameterize a structured data type in the IN_OUT area of an FB and a function call with an ARRAY variable?
How do you create and update multiple instances?
How do you update invalid block calls (time stamp conflicts) in calling blocks?
How do you perform a block-consistency check following changes in the STEP 7 program?
How do you determine the block number of the "Data Types for Parameters" in the program and how can you pass this parameter on to an FC?
What is the difference between the CALL statement and the UC or CC call statement?
What is the difference between an instance data block and a global data block and how does a CALL call influence the DB register?
How do you parameterize a structured data type in the IN_OUT area of an FB and a function call with an ARRAY variable?
Part number:

Instructions  
Variables with structured data types are saved with transit parameters (IN_OUT) of the FB as reference with a 6-byte POINTER (48 bits) in the instance DB. This means that there is not a value, but a six-byte POINTER in the instance DB. This POINTER indicates the actual parameter; therefore, it is imperative that it is parameterized. STEP 7 identifies the following structured data types: "Date_and_Time", "String, Array", "Struct" and "UDT".

Fig. 01 contains an example of how to program indirect access to the first byte of this data type. This procedure from the example is for data backup.


Fig. 01

The 6-byte POINTER is loaded via the IN_OUT variable "Symbol_of_InOut". The number of the data block is then transferred from the 6-byte POINTER into a temporary variable "DB_Num". The DB is opened with this saved DB number via the statement "AUF DB[#DB_Num]" and then the address is loaded into address register 1.

The "+AR1" instruction interprets the value in ACCU1 as a number in the INT format, extends it with the correct +/- sign to 24 bits and adds it to the content of the address register. If the maximum range of the byte address is overshot or undershot (0 ... 65535), this has no effect, because the upper bits are truncated.

The statement "L B[AR1,P#0.0]" provides you with the saved data and correct address. If you were to use the statement "L Symbol_des_InOut[1]" instead of this example, then you would not load the saved data from the address register, but the data directly from the IN_OUT parameter. However, these values might have changed. Please also refer here to the relevant information in the STEP 7 Online Help under

  • "Avoiding errors when calling blocks".

Note
The example described is valid only for DB areas, because otherwise the CPU goes into "STOP". Numbering with 0 (DB0) is not permitted.

The "InOutvar.zip" file includes a STEP 7 project with two S7 stations for the sample program described above:

  • Station: "Beispiel in deutsch" mit den deutschen Kommentaren
  • Station: "Example in English" with English comments

InOutvar.zip ( 222 KB )

Assign parameters to a function call with structured data types
The parameters of a structured data type (ARRAY and STRUCT) offer an efficient way of transferring larger, inter-related volumes of data between the calling block and the block being called. A field or a structure can be transmitted as a complete variable to a called function.

The variables of structured data types can only be saved in a data block or in the local data stack. Consequently, the actual parameter must be declared either in a data block (global or instance DB) or in the local data stack for the called block.

For the purposes of the transfer, a parameter of the same data type as the actual parameter being transferred must be declared in the called function. The supply of these parameters (data type: ARRAY, STRUCT, DATE_AND_TIME and STRING) must take place symbolically.

The LAD/STL/FBD editor checks the compatibility of the data types of the actual parameter and block parameter during transfer of parameters to a function. The actual parameter transfer to the called function is performed by a pointer with a DB number and area-crossing pointer. This pointer is created in the L-stack of the calling block by the CALL macro.


Fig. 02

The variables of a structured data type may only be saved in the local data stack (TEMP variable in the FC12) or in a data block (DB5).

Creation environment
The pictures and downloads in this FAQ were created with STEP 7 version V5.4.

Keywords
Structured

 Entry ID:19106712   Date:2010-04-15 
I regard this article....as helpfulas not helpful                                 
mySupport
My Documentation Manager 
Newsletter 
CAx-Download-Manager 
Support Request
To this entry
Print
Create PDF 
Send to a friend
QuickLinks
Compatibility tool 
Topics
Help
Online Help
Guided Tour