Using Transformation mapping to return SAP binary data to SmartObjects

The example cited here illustrates how a developer can create a solution to return Binary Data in SAP, and surface the data return via SmartObjects. When creating the solution, the data returned must be transformed as the data returned form SAP is in standard binary format, whereas SmartObjects handle Binary Data in base 64 encoded format. A direct mapping would therefore not work as the binary data formats differ.

The custom mapping feature is used in this case and the transformation handler allows code to be embedded to manipulate the data within the mapping. This is similar to retrieving a PDF that was stored in SAP. The file property in the SAP BAPI call is mapped to the PDF_DOC property in the service object.

The transformation code sample is listed below:

Transformation Code

private void Transform (System.Byte[] PDF_DOC, ref System.String File)

{

File=String.Empty;

try

{

if (PDF_DOC.Length > 0)

{

long length = 0;

length = PDF_DOC.Length;

string encodedData = Convert.ToBase64String(PDF_DOC, Base64FormattingOptions.None);

File = encodedData;

}

}

catch (Exception ex)

{

File = ex.StackTrace;

}

}

This code sample executes for every record returned and this could potentially create a heavy load on your server if a large number of records is returned.