# LGF_CompareVariant (FC / 3.0.1)

Overview

Author: Siemens Digital Industry

## Short description

The function compares two structured actual parameters (array, PLC data type) and outputs whether they are of the same type and have the same values.

Compare arrays or plc datatypes and their values up to a max lengh of 200 Bytes of the connected variables. If at least one value of an element is not identical --> set function result = false

Restrictions:
The attached structure must not include Strings
The attached structure can not exceed 200 bytes, because of the internal buffer size

### Block Interface

| LGF_CompareVariant (FC) |
--- | --- | ---
|  |  |  |  | Ret_Val |  |  | Bool
|  |  |  |  | error |  |  | Bool
|  |  |  |  | status |  |  | Word
|  |  |  |  | subFunctionStatus |  |  | Word
Variant |  |  | variableA |  |  | Variant
Variant |  |  | variableB |  |  | Variant

### Output parameter

Identifier | Data type | Description
--- | --- | ---
Ret_Val | Bool | FALSE: Values of comparison variables or PLC data types are different. TRUE: Values of the comparison variables are equal and PLC data types are identical.
error | Bool | FALSE: No error / TRUE: An error occurred during the execution of the FB
status | Word | 16#0000-16#7FFF: Status of the FB / 16#8000-16#FFFF: Error identification (see following Table)
subFunctionStatus | Word | Status or return value of called FB's, FC's and system blocks

### In/Out parameter

Identifier | Data type | Description
--- | --- | ---
variableA | Variant | First comparison variable with any data type
variableB | Variant | Second comparison variable with any data type

### Status & Error codes

Code / Value | Identifier / Description
--- | ---
16#0000 | STATUS_NO_ERROR Execution finished without errors
16#8201 | ERR_INPUT_TYPES_MUST_MATCH Error, the input types must match, e.g. STRUCT
16#8202 | ERR_INPUT_TYPES_LENGTH_NOT_EQUAL Error, the input types have different lengths after serialization, `subFunctionStatus` provides an indicator of the different size
16#8601 | ERR_SERIALIZE_VARIABLE_A Error occured while serialize variableA into Bytearray - see `subFunctionStatus` for detailed information
16#8602 | ERR_SERIALIZE_VARIABLE_B Error occured while serialize variableB into Bytearray - see `subFunctionStatus` for detailed information

## Functional description

NOTE
  The status of called commands is output in `subFunctionStatus`. In this case, the output value in `status` indicates which command caused the error. In this case, refer to the TIA Portal Online Help section for information on the respective commands.

This block compares two (structured) actual parameters and shows whether they equate to the same value.

Note

  The following differences cannot be detected with the comparison method (byte level):

  - Variables of the data type `Struct` cannot be compared.
  - For strings, there may be differences in the range between the actual length and the maximum length.
  - With `REAL` numbers in the structure, a disparity can also be displayed for "same" variables.
  - Variables of the type `ARRAY of BOOL` cannot be checked for equality with the function, because the command used, `CountOfElements`, also counts the filling elements (e.g. 8 is returned with an `ARRAY[0..1] of BOOL`).

## Change log

Version & Date | Change description
--- | ---
| 1.0.0 | Siemens Industry Online Support
| 03.09.2015 | First released version
| 1.0.1 | Siemens Industry Online Support
| 11.02.2015 | Bug fix
| 1.0.2 | Siemens Industry Online Support
| 02.01.2017 | Upgrade: TIA V14 Update 1
| 1.0.3 | Siemens Industry Online Support
| 17.08.2018 | Upgrade: TIA V15 Update 2
| 1.0.4 | Siemens Industry Online Support
| 23.11.2018 | Upgrade: TIA V15.1
| 1.0.5 | Simatic Systems Support
| 03.06.2019 | Refactoring and performance improvment Change error handling to status and subFctStatus update serialize instruction add eno handling
| 3.0.0 | Simatic Systems Support
| 23.04.2020 | Set version to V3.0.0, harmonize the version of the whole library
| 3.0.1 | Simatic Systems Support
| 19.01.2020 | Insert documentation