Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
stefan_schnell
Active Contributor
I describe here how to extend your copy of the function module (FM) RFC_READ_TABLE to get the result also in JSON format. On this way you have the tiny possibility to get a little bit the feeling of OData via SAP Gateway interface, e.g. if you are using an older version of an SAP AS.

Here I describe how to call a VBScript from JavaScript with IE 11 in edge mode.

With this descriptions and the COM Connector (CCo) is it now possible to realize a solution in the UI5 context. We will start with the html file:
<!doctype html>
<html>

<head>

<title>Table SFLIGHT</title>

<meta http-equiv=”Content-Type” content=”text/html” />
<meta charset=”ISO-8859-1″ />
<meta http-equiv=”X-UA-Compatible” content=”IE=edge” />

<script src=”resources/sap-ui-core.js”
id=”sap-ui-bootstrap”
data-sap-ui-libs=”sap.ui.commons, sap.ui.table”
data-sap-ui-theme=”sap_bluecrystal”>
</script>

<script language=”JavaScript”>

function getData(TableName) {
var wsh, pathName;
if (“ActiveXObject” in window) {
wsh = new ActiveXObject(“WScript.Shell”);
if (typeof(wsh) == ‘object’) {
pathName = location.pathname.substr(0,
location.pathname.lastIndexOf(“/”))+”/”;
pathName = pathName.slice(1);
wsh.run(“wscript.exe \”” + pathName +
“ReadTableJSON.vbs\” ” + TableName + ” \”” + pathName +
“\””, 1, true);
wsh = null;
}
}
else {
alert(“Your Browser doesn’t support ActiveXObject”);
}
}

function Column(Text, Width) {
var oLabel, oTemplate, oColumn;
oLabel = new sap.ui.commons.Label();
oLabel.setText(Text);
oTemplate = new sap.ui.commons.TextView();
oTemplate.bindProperty(“text”, Text);
oColumn = new sap.ui.table.Column();
oColumn.setLabel(oLabel);
oColumn.setTemplate(oTemplate);
oColumn.setWidth(Width);
return oColumn;
}

function main() {
var oModel, oTable;
getData(“SFLIGHT”);
oModel = new sap.ui.model.json.JSONModel();
oModel.loadData(“SFLIGHT.json”);
oTable = new sap.ui.table.Table();
oTable.setTitle(“Table SFLIGHT”);
oTable.setVisibleRowCount(15);
oTable.setFirstVisibleRow(0);

//-Add the columns———————————————-
oTable.addColumn(Column(“CARRID”, “35px”));
oTable.addColumn(Column(“CONNID”, “35px”));
oTable.addColumn(Column(“FLDATE”, “50px”));
oTable.addColumn(Column(“PRICE”, “50px”));
oTable.addColumn(Column(“CURRENCY”, “50px”));
oTable.addColumn(Column(“PLANETYPE”, “50px”));

oTable.setModel(oModel);
oTable.bindRows(“/SFLIGHT”);
oTable.placeAt(“content”)
}

</script>
</head>

<body class=”sapUiBody” role=”application” onLoad=”main()”>
<div id=”content” />
</body>

</html>

 

As you can see it is not really the known standard. The main function gets at first the data as local JSON file via our copy of RFC_READ_TABLE from the table SFLIGHT. It loads the data, creates the table and adds the columns via an own function. I use only the set and get methods, it is better readable I think. Here now the VBScript file to get the data in JSON format:
'-Begin-----------------------------------------------------------------

'-Directives----------------------------------------------------------
Option Explicit

'-Constants-----------------------------------------------------------
Const RFC_OK = 0
Const ForWriting = 2

'-Sub getData---------------------------------------------------------
Sub getData(tableName, pathName)

'-Variables-------------------------------------------------------
Dim SAP, hRFC, rc, hFuncDesc, hFunc, hTable, RowCount, i, hRow
Dim charBuffer, charFile, FSO, F

Set SAP = CreateObject("COMNWRFC")
If IsObject(SAP) Then
hRFC = SAP.RfcOpenConnection("ASHOST=ABAP, SYSNR=00, " & _
"CLIENT=000, USER=BCUSER")
If hRFC Then
hFuncDesc = SAP.RfcGetFunctionDesc(hRFC, "Z_RFC_READ_TABLE_JSON")
If hFuncDesc Then
hFunc = SAP.RfcCreateFunction(hFuncDesc)
If hFunc Then
rc = SAP.RfcSetChars(hFunc, "QUERY_TABLE", tableName)
rc = SAP.RfcSetChars(hFunc, "DELIMITER", "~")
If SAP.RfcInvoke(hRFC, hFunc) = RFC_OK Then
If SAP.RfcGetTable(hFunc, "DATA_JSON", hTable) = RFC_OK Then
rc = SAP.RfcGetRowCount(hTable, RowCount)
rc = SAP.RfcMoveToFirstRow(hTable)
For i = 1 To RowCount
hRow = SAP.RfcGetCurrentRow(hTable)
rc = SAP.RfcGetChars(hRow, "LINE", charBuffer, 1024)
charFile = charFile & RTrim(charBuffer) & vbCrLf
If i < RowCount Then
rc = SAP.RfcMoveToNextRow(hTable)
End If
Next

'-Write JSON file-------------------------------------
Set FSO = CreateObject("Scripting.FileSystemObject")
If IsObject(FSO) Then
Set F = FSO.OpenTextFile(pathName & tableName & _
".json", ForWriting, True)
F.Write charFile
F.Close
Set FSO = Nothing
End If

End If
End If
rc = SAP.RfcDestroyFunction(hFunc)
End If
End If
rc = SAP.RfcCloseConnection(hRFC)
End If
Set SAP = Nothing
End If

End Sub

'-Main----------------------------------------------------------------

getData WScript.Arguments.Item(0), WScript.Arguments.Item(1)

'-End-------------------------------------------------------------------

 

With this mixture of RFC libary via CCo, VBScript and JavaScript in IE 11 you can easily simulate an UI5 environment on the presentation server, without any other server. Also it is not necessary, with the modifiaction of your copy of RFC_READ_TABLE, to have the newest AS environment.



On this way you can realize a relatively lightweight solution, to simulate OData via SAP Gateway and to use it in your UI5 environment on your presentation server.

Enjoy it.
2 Comments
Labels in this area