Using the Serialize and Deserialize functionality for data structures
You can send complex data to and from SAP with K2 connect by using XML data based on a schema, and using serialization and deserialization methods to work with the data. The XML schema is generated during the Service Object configuration when you activate the XML Properties option. When you publish the Service Object, K2 creates methods to serialize or deserialize the XML data structures. These additional methods make it easier to read the data structure of complex data in SAP, and easier to pass data back to SAP.
Serializing data using the Serialize SmartObject Methods
Scenario
You have an Employee BAPI in SAP and need to easily work with the complex data in the Employee_List function, by adding the ability to use XML and serialize and deserialize Employee information.
Steps
Use Visual Studio to configure and publish a Service Object mapped to the BAPI_EMPLOYEE_GETLIST BAPI, with the EMPLOYEE_LIST function's XML Properties option activated. You then test the resulting SmartObject in K2 Management site, serializing and deserializing your data.
Setup Steps
The following steps set up the scenario from start to finish. If you want to skip the setup steps and view the topic step, go to Configure the K2 connect Service Object EMPLOYEE_LIST function to use the XML Property option.
-
Create a K2 Empty Project in Visual Studio named Employees.
- In Visual Studio, click File > New > Project.
- Select K2 Empty Project from the K2 templates.
- Specify Employees as the project name.
- Click OK.
-
In the Employees project, create a new K2 connect Service Object.
- Click Project > Add New Item....
- Select K2 connect Service Object.
- Specify Employees.svd as the service object file name.
- Click Add.
- Click Project > Add New Item....
-
Add a new service in the K2 connect Service Object Designer, and add BAPI_EMPOYEE_GETLIST to it.
- In the service object designer click Add Service.
- In the K2 Service Object Designer window expand the Development Kit node to the BAPI you want to use. In this example, the path is Connect47 > SAP > SAPSA > Rfc / Bapi Explorer > BAPI_EMPLOYEE_GETLIST.
- Drag and drop the BAPI_EMPLOYEE_GETLIST BAPI method to the Service1 object.
- In the service object designer click Add Service.
Configure the K2 connect Service Object EMPLOYEE_LIST function to use the XML Property option.
Configure the Service Object to create Serialize and Deserialize SmartObject methods by activating the XML option in the Employee_List functions structure.
-
Configure the EMPLOYEE_LIST function to use the XML Property option.
- In the Function Interface page of the BAPI_EMPOYEE_GETLIST function select EMPLOYEE_LIST.
- Click Show Structure. Only functions with both In and Out properties will display the Show Structure option.
- Activate the XML Property check box. This configures the Service Object to create the serialize and deserialize methods.
- Save your Employees project.
- Click Publish Service Object. This creates the Employees connect service object, and the Employees and Employees EMPLOYEE_LIST SmartObjects.
- Test the Employees EMPLOYEE_LIST > Serialize method using K2 Management.
- In K2 Management navigate to Categories > Employees and double click the Employees EMPLOYEE_LIST SmartObject.
- Select the Serialize method in the Methods section.
- Click Execute.
- The Serialize method displays in the Execute SmartObject Method page. Specify values for the SmartObject properties. You can use the example values shown in the following image:
- Click Execute.
- The Results tab displays the serialized data.
- Select the serialized data and click CTRL-C to copy the data string. You use this data to test the deserialize method in the next step.
- You may need to allow webpage access to your clipboard. If so, click Allow access.
- Click Done to close the Execute SmartObject Method page.
- In K2 Management navigate to Categories > Employees and double click the Employees EMPLOYEE_LIST SmartObject.
-
Test the Employees EMPLOYEE_LIST > Deserialize method.
- Select the Deserialize method and click Execute.
- Click CTRL-V to paste the serialize string from the previous step into the Serialized Item (Employee_List) property.
- Click Execute.
- The Results tab displays the deserialized values.
- Click Done to close the Execute SmartObject Method page.
- Select the Deserialize method and click Execute.
Review
You used Visual Studio to configure and publish a Service Object mapped to the BAPI_EMPLOYEE_GETLIST BAPI, with the EMPLOYEE_LIST function's XML Property activated. You then test the resulting Employee EMPLOYEE_LIST SmartObject in K2 Management site, serializing and deserializing your data.