After seeing all the interest in Enterprise Widgets, specially inside of SAP, I thought of having a go at it. SDN already has some wonderful examples and from the blogs here I also gathered that SAP was already working on a foundation called the SAP Widget Foundation to make the job easier for us coders.
After a bit of luck, I happened to lay my hands on an alpha release of SAP Widget Foundation and also some code which happened to be using it. I found no information on it here on SDN, so here goes a small little post on how a widget can use the foundation to access SAP backend Function Modules and show the data in a neat way.
You can lay your hands on the alpha/beta release of the SAP Widget Foundation as pointed out already by Eric Enterprise Widget Foundation alpha release . Also mentioned in the same post is a little detail about what this foundation is:
Foundation is a proxy for interacting with SAP. It handles authentication and remote function calls to SAP from your widgets. It currently is focused on making it easy to develop and test enterprise widgets with but by the time we’re ready to roll it out to end users it will be much more simple.
The foundation runs as a web server on your localhost and accepts XML requests and churns out XML replies. This means that we can actually have our backend calls Ajaxed, which is just great!
I’ll paste here the absolute basic code snippets that I used to get a working table data viewer. As usual, I will choose the famed RFC_READ_TABLE.The above object can be re-used to make calls to different backend function modules as and when required. An example declaration of our RFC_READ_TABLE is as follows:
+paramName = new Array(‘QUERY_TABLE’, ‘DELIMITER’, ‘NO_DATA’, ‘ROWSKIPS’, ‘ROWCOUNT’, ‘OPTIONS’);
RFCRead = new SAPWidgetFoundationCallA(paramName, ”, ‘RFC_READ_TABLE’, RFCReadStatusChange); +
paramName defines the IMPORTING, EXPORTING and TABLES paramaters that
is the function that would be called once our backend returns with the magic results.
As for the function definition and calling, all we need is:
var paramValue = new Array(
queryTable, '^', '',
'0', '0', '');
callService forms the XML query dynamically and does the POST. Now all we have to do is wait for our callback function to be called. Our XML query looks like this: