Actionscript Libraries for SAP Widget Foundation…

29 May

Introduction

I had blogged about how one can use the SAP Widget Foundation with Adobe Flex/Air in this Blog : Enterprise Widget Foundation & Adobe Flex : Awesome Twosome ? (Video) .

That was just an example or a Proof of Concept. What I have here is something that makes the whole deal a lot more easier for everyone. The Actionscript Libraries for SAP Widget Foundation lets anyone using Adobe technologies consume services from the Widget foundation at ease without having to wonder about the nitty gritties of the REST services exposed by SAPWF.

Acknowledgement

  • Jaideep Srinivasan of EDS for constantly prodding me and helping me with this initiative. It’s would definitely have slipped my mind if not for him.
  • Daniel Mcweeney for reviewing the code and providing pertinent feedback. He’s awesome to talk to and always willing to help. A greate motivator and guide.
  • Durairaj Athavan Raja who has been my F1 key for any problems related to RIAs or ABAP, for lending a patient ear to me.
  • Craig Cmehil for the support as always. This would not have been possible without him.
  • Mrinal Wadhwa, a warehouse of knowledge on RIAs, Flex and Air for being there for my help whenever I needed him and also for his cool ideas.

Documentation

The helper class is located in the package com.sap and is called SAPWFHelper.

Calling the helper class is as easy as instanciating it and calling the helper methods.
As we all know we can pass Parameters, Structures and Tables to ABAP RFCs. The helper class gives you helper methods to do just tha.

  • Add Input Parameters : The method addParamInput(paramName:String, paramValue:String) allows you to add an input parameter to the request. ParamName is the name of the Input parameter and the value is the parameter value you want to pass.
  • Add Input Structures : The method addParamStructure(structName:String, fieldName:String, value:String) lets you add a structure to the Input. structName is the name of the Structure, fieldName is the field in the structure that you want to pass and value is the value of the field.
  • Add Table : Since passing a table is not that simple it has been broken down into 5 methods to help use of use.
    • createParamTable(tabName:String) : Creates a Table Parameter with the given tabname.
      Note:
      this does not automatically add the Table parameter to the parameter list as it does for addParamInput and addParamStructure. You need to call the addTableToParams method to do that.
    • createRow(rowName:String) : Creates a Row to be added to the table with the rowName.
      Note:
      The rowName should be unique across all tables defined in the parameters. This means if you have created a row named row1 for table tab1, you cannot create a row with the same name row1 for table tab2. It is advised you use names like tab1row1, tab1row2 for rowNames.
    • addRowField(rowName:String, fieldName:String, value:String) : Adds a field to the table row. rowName is the name of the row, fieldName is the name of the field in the row and value is the value of the field.
    • addRowToTable(tabName:String, rowName:String) : Adds the row to a table. tabName is the name of the Table to add the row named rowName to.
      Note: You should have created a Table Parameter using createParamTable for this to work.
    • addTableToParams(tabName:String) : Adds the table with the tabName to the SAPWF parameters list.
  • Create and send the request : The method sendRequestToSAPWF(BAPIName:String, serviceProvider:String=null):void takes in the BAPIName (the BAPI/RFC you want to call and optionally a serviceProvider name that you have created in the SAP Widget foundation. If this parameter is ommitted it takes the default service. This method creates a HTTPService object and sends the request to the SAP Widget Foundation. It dispatches two events SAPWFResultEvent.RESULT in case data is returned and SAPWFFaultEvent.FAULT in case an error occurs. You need to add event handlers to listen to the events mentioned above and handle them according to your need.

If you think these methods are a little too daunting for you let me give you a small example on how to make them work :

****************************************************

BAPI_MATERIAL_GETLIST Example

****************************************************

var WfHelper:SAPWFHelper = new SAPWFHelper();
WfHelper.addParamInput(“MAXROWS”,”4″);
WfHelper.createParamTable(“MATNRSELECTION”);
WfHelper.createRow(“MATNRSELECTIONrow1”);
WfHelper.addRowField(“row1″,”SIGN”, “I”);
WfHelper.addRowField(“row1″,”OPTION”, “EQ”);
WfHelper.addRowField(“row1″,”MATNR_LOW”, “Y-300”);
WfHelper.addRowToTable(“MATNRSELECTION”, “MATNRSELECTIONrow1”);
WfHelper.createRow(“MATNRSELECTIONrow2”);
WfHelper.addRowField(“MATNRSELECTIONrow2″,”SIGN”, “I”);
WfHelper.addRowField(“MATNRSELECTIONrow2″,”OPTION”, “EQ”);
WfHelper.addRowField(“MATNRSELECTIONrow2″,”MATNR_LOW”, “Y-500”);
WfHelper.addRowToTable(“MATNRSELECTION”, “MATNRSELECTIONrow2”);
WfHelper.addTableToParams(“MATNRSELECTION”);
WfHelper.createParamTable(“MATERIALSHORTDESCSEL”);
WfHelper.createRow(“MATERIALSHORTDESCSELrow1”);
WfHelper.addRowField(“MATERIALSHORTDESCSELrow1″,”SIGN”, “I”);
WfHelper.addRowField(“MATERIALSHORTDESCSELrow1″,”OPTION”, “EQ”);
WfHelper.addRowField(“MATERIALSHORTDESCSELrow1″,”DESCR_LOW”, “”);
WfHelper.addRowToTable(“MATERIALSHORTDESCSEL”,”MATERIALSHORTDESCSELrow3″);
WfHelper.addTableToParams(“MATERIALSHORTDESCSEL”);
WfHelper.addEventListener(SAPWFResultEvent.RESULT, populateGrid);
WfHelper.addEventListener(SAPWFFaultEvent.FAULT, raiseAlert);
WfHelper.sendRequestToSAPWF(“BAPI_MATERIAL_GETLIST”);

private function populateGrid(event:SAPWFResultEvent):void{
myGrid.dataProvider = event.result.root.BAPI_FLIGHT_GETLIST.FLIGHT_LIST.item;
}
private function raiseAlert(event:SAPWFFaultEvent):void{
Alert.show(event.fault.faultString);
}

****************************************************

End of Example

****************************************************

Download

You can download the library and the sample project here…