Sap serviceobjects is an integration of SAP system, the integration consists of two parts. Developers must provide a destination sap system by giving necessary informations that depend on usage and access cases, the developer must provide satisfying values. For example the destination user must be able to access given functions on SAP systems to be able to access from application side. Maximum number of connections and pool size must be provided dependently. Sap serviceobjects can use multiple destinations but multiple destinations decrease performance slightly because of sap connector that provided by SAP company. Second part is network side. SAP system must be accessible from Livomobile middleware.

 

Sap Data Types and Relational Json Types

Basic Types (Fields)

SAP Type JSON Structure JavaScript
Char {(Field Name)key: value} String
Num {(Field Name)key: value} String
Byte {(Field Name)key: value} Byte
Bcd {(Field Name)key: value} Big Decimal
int {(Field Name)key: value} int
int1 {(Field Name)key: value} int
int2 {(Field Name)key: value} int
Float {(Field Name)key: value} Double
Date {(Field Name)key: value} Long value of date
Time {(Field Name)key: value} Long value of date
DECF16 {(Field Name)key: value} Big Decimal
DECF32 {(Field Name)key: value} Big Decimal
String {(Field Name)key: value} String
xString {(Field Name)key: value} int

Complex Types

SAP has two complex types that are ‘Structure’ and ‘Table’ but when you call a SAP function with its parameters, it will be group of sub fields that will be processed like complex types on middleware such as import parameters, changing parameters, export parameters and tables. A Sap function is called with import parameters and changing parameters, after execution it will provide data in export parameter list, changing parameter list and tables if no error occurs else SAP system will return null parameters or an exception that defines the problem. If it returns null parameters, it can return extra field that defines problem or basically returns null fields, which is not an exception but a problem caused by wrong parameters.

A structure theoretically can consist basic types, other structures and tables recursively. In reality this recursion will not go so far. Tables can consist of basic types, structure or other tables.

Import and changing parameters are like structures. They are group of basic and complex types. They are not complex types but they are groups of data so they are acting like so.

SAP Type JSON Structure
Structure Its a json object that name is key and value is a json array of json objects such as this;

“Structure Name”:[{“Field Name”:”Field Value”},{“Field Name”:”Field Value”},…]

It can go deeper if there is other complex types.

 

Table Tables are json objects that name is key and value is json array of json arrays such as this;

“Table Name”:[[{“Field Name”:”Field Value”},{“Field Name”:”Field Value”},..],…]

Import Parameters List Import parameters are the values that will be sent to SAP system. Its name is “imports”. Will be json array of json objects basically, if it consists complex   types, it will go on deeper dependently.

“imports”:[{“Field Name”:”Field Value”},{},..]

Changing Parameters List Changing parameters are that will be sent to SAP system and will be gotten back after execution. Its structure same with import parameters. Its name is “changins”.
Export Parameters List Export parameters are after execution values so it will only appear after execution. Its structure same as import parameters.

Examples

The data that will be sent from client side must consist of imports and changings only. Every value will be under this two Json objects. Incoming data will have exports, changings and tables.
Livo.ServiceObjects has 3 functions on JavaScript side that are, listServiceobjects() that return available serviceobject , getServiceObject() method creates service specific functions. Finally you can perform created functions.

Example SAP Service Usage:

  var SapObject = {
    name:"SAPService",
    type:"json",
    operationNames:["getImportStructure","getExportStructure","importAndGetExport"]
  };

SAP service needs additional  configuration from javascript side which defines the name of the sap function that will be used from middleware. Lets create our operations that defined in SapObject. These operations defined by middleware but they needs to be appear in JavaScript side too. These operation names are same for SAP services.

  var operations; //Operations holder

 /*
  * Configuration holds destination name and function name, destination name represents SAP
  * integration name from web-ui and function name is the function you will work on.
  */

  var conf={
    functionName:" BAPI_COMPANYCODE_GETDETAIL"
  };

  Livo.ServiceObjects.getServiceObject(SapObject,conf,function(success) {
  /*
   * Now operations object have "getImportStructure","getExportStructure","importAndGetExport".
   */
    operations = success;
  
   },function(error){
    // do whatever you want with error,
    // it means it could not create operations.

    console.log(error);
   });

getImportStructure and getExportStructure functions are helper functions to see structures of import and export, it field types, size of the field to be used during development. A complete basic example that alerts return values;

var operations;

//Constructed serviceobject. No need to ask server again for this application.

var SapObject = {
  name:"SAPService", //can be used instead of whole object if name is unique.
  type:"json",
  operationNames:["getImportStructure","getExportStructure","importAndGetExport"]
};

getOperations=function () {
  var conf = {
    functionname:" BAPI_COMPANYCODE_GETDETAIL"
  };

  Livo.ServiceObjects.getServiceObject(SapObject,conf, 
    function(a){
     operations=a;

    }, function(error){
    
     alert(error);
   });

};

successImportCallback = function(a) {
  alert(JSON.stringify(a));// to see import structure
};

successExportCallback = function(a) {
  alert(JSON.stringify(a)); // to see export structure
};

successIECallback = function(a) {
  alert(JSON.stringify(a)); // Use something else that fits your needs.
};

errorCallback=function(error){alert(error);};

getImportStructure = function() {
  var payload = {imports:new Array(), changins:new Array()}; // null payload=null data
  operations.getImportStructure(payload,successImportCallback,errorCallback);
};

getExportStructure=function() {
  var payload = {imports:new Array(), changins:new Array()}; // null data
  operations.getExportStructure(payload,successExportCallback,errorCallback);
};

getIE=function(payload) {
  operations.importAndGetExport(payload,successExportCallback,errorCallback);
};

After calling getOperations() you can play with getImportStructure and getExportStructure functions as much as you like. If you execute getIE() like this;

  var payload = {"imports":[{"COMPANYCODEID":"1000"}]}; 

  getIE(payload);

You will get the company detail.

About The Author

Leave a Reply

Your email address will not be published. Required fields are marked *