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.

Serialization converts an object to a string format for importing and exporting. Deserialization converts a string to an object for working with data.

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.

  1. Create a K2 Empty Project in Visual Studio named Employees.
    1. In Visual Studio, click File > New > Project.
    2. Select K2 Empty Project from the K2 templates.
    3. Specify Employees as the project name.
    4. Click OK.
  2. In the Employees project, create a new K2 connect Service Object.
    1. Click Project > Add New Item....
    2. Select K2 connect Service Object.
    3. Specify Employees.svd as the service object file name.
    4. Click Add.
  3. Add a new service in the K2 connect Service Object Designer, and add BAPI_EMPOYEE_GETLIST to it.
    1. In the service object designer click Add Service.
    2. 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.
    3. Drag and drop the BAPI_EMPLOYEE_GETLIST BAPI method to the Service1 object.

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.

  1. Configure the EMPLOYEE_LIST function to use the XML Property option.
    1. In the Function Interface page of the BAPI_EMPOYEE_GETLIST function select EMPLOYEE_LIST.
    2. Click Show Structure.
      Only functions with both In and Out properties will display the Show Structure option.

    3. Activate the XML Property check box. This configures the Service Object to create the serialize and deserialize methods.
    4. Save your Employees project.
    5. Click Publish Service Object. This creates the Employees connect service object, and the Employees and Employees EMPLOYEE_LIST SmartObjects.
  2. Test the Employees EMPLOYEE_LIST > Serialize method using K2 Management.
    1. In K2 Management navigate to Categories > Employees and double click the Employees EMPLOYEE_LIST SmartObject.
    2. Select the Serialize method in the Methods section.
    3. Click Execute.
    4. 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:
    5. Click Execute.
    6. The Results tab displays the serialized data.
    7. 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.
    8. You may need to allow webpage access to your clipboard. If so, click Allow access.
    9. Click Done to close the Execute SmartObject Method page.
  3. Test the Employees EMPLOYEE_LIST > Deserialize method.
    1. Select the Deserialize method and click Execute.
    2. Click CTRL-V to paste the serialize string from the previous step into the Serialized Item (Employee_List) property.
    3. Click Execute.
    4. The Results tab displays the deserialized values.
    5. Click Done to close the Execute SmartObject Method page.
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.