Simple and Complex Data Structures
Advanced knowledge of BAPIs is required for understanding the concepts in this topic. A full discussion of BAPIs is beyond the scope of this help file. Consult the SAP documentation for further details.
The SAP BAPIs may require one or two parameters or a single row table structure. You must determine what the input requirements are.
To return data from a BAPI you must pass data parameters into the BAPI structure. The BAPI, even in it's simplest form, is still a complex data structure. When the data is returned via the service broker layer and into the SmartObject, the ADO.NET provider can be leveraged to flatten the data structure into a structure useable by the SmartObject. Another option is to set the structure of properties of a field in the BAPI to an XML type, which will create a SmartObject for the field with serialization methods. These methods can Serialize or Deserialize the data structures when executed.

Returning data from a SAP BAPI is highly dependent on how the BAPI allows data to be returned, or what the BAPI allows to be returned when query criteria are passed into it. For example a data table, IDRange, can be used to return record instances from a BAPI as shown below from the K2 connect test cockpit.
Returning and writing single record instances is simple and can be handled easily by the service broker. A data record range i.e. an IDRange of records can also return as the result of a query and this is a complex type. The complex type is a data table or structure that is returned from SAP when a query is run against the BAPI and more than one record is returned. The returning query can be flattened, or converted to an XML data structure for use by the K2 connect Service Object.

Sending data to a SAP BAPI is dependent on how the BAPI reads the data sent or what the BAPI allows as input. Using the data table IDRange as an example, to send complex types to a BAPI, setting the IDRange XML property creates a complex type serialization object for the table.
Executing the Serialize Add Item to Array method allows for complex types. The complex type is a data table or structure that is sent to a BAPI when a query is run and more than one record needs to be sent.

Complex data structures can easily be sent to SAP or received using Serialization or Deserialization methods. These methods are created for specified fields of a BAPI when the data structure is selected as an XML property.
Serialization is when the state of an object is changed to a form that can be imported or exported. Deserialization converts it back to an object.
To select the data structure as an XML property, locate a suitable BAPI service method. Select the field that requires the XML property and click on Show Structure as per the image below. The Show Structure UI will enable the developer to select the properties required.
The XML Property option is circled in red below. By default all items in the structure declaration are enabled and it's up to the developer to exclude items that are not required by disabling them.
If the XML property is disabled, the Serialization and Deserialization methods will not be created.

When you select to create a structure or collection as an XML property, K2 connect will create the following methods for the corresponding Service Object of the Service Instance:

To see how these methods are created, open the K2 Object Browser from the View menu in K2 Designer for Visual Studio. Expand the Service Object Server(s) node. You will now see two folder nodes named Connect Objects and Object Types. Each fields selected in the Service Object will be listed as an Object Type. Expand Object Types and note that all the published Service Objects are listed. Expand the Service Object. Expand the Service Object field for which the XML property was created. The new methods are listed for the Service Object field. See image below:
These methods can now be used to Serialize or Deserialize the data structures to either send data to SAP or receive data from SAP.
When creating the serialization objects, each BAPI will be created as a sub folder to the Object Types folder.
For more information and Examples on how to use these methods see KB000712 - How to use the Serialize and Deserialize functionality for Data Structures in K2 connect for SAP.