Archive for the ‘ABAP’ Category

SAP Web Services in Flex Builder

Wednesday, November 14th, 2007

SAP web services are really complex, tables inside rows inside tables inside structures.  I’ve been fielding an increasing number of questions about using these in the forum so, instead of answering everyone separately here are a few examples from simple to complex.

Let’s start off with one of the simpler examples just to get the hang of it.  Use SAPLink and install this function group and generate a web service from the one function in it.  Now, lets write some Flex code to call this.

Import Statements

A few people have asked me to add the import statements to this.  For reference if you go to the object that has the error, move your cursor to the end of the word hold control and press space the import will be added for you automatically, welcome to the wonderful world of a good IDE.  But the following in a <mx:Script> block between the <mx:Application> tags.

import mx.rpc.AbstractOperation; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.soap.LoadEvent; import mx.rpc.soap.WebService;

Simplest Example

Step 1 - Get your WSDL

1 private function callWebService():void{ 2 fooService = new WebService(); 3 fooService.wsdl = "http://localhost/sap/bc/srt/rfc/sap/Z_TEST_CHANGING_PARAM?sap-client=300&wsdl=1.1"; 4 fooService.addEventListener(LoadEvent.LOAD, loadListener); 5 fooService.addEventListener(ResultEvent.RESULT, resultTrigger); 6 fooService.addEventListener(FaultEvent.FAULT,fault); 7 fooService.loadWSDL(); 8 }

Line by Line:

  1. Declare a function that will start the whole process
  2. Create a WebService object, this should be global or at least visible to the other methods ( you’ll need it later )
  3. Point the WS to the location of the WSDL
  4. Add an EventListener for when the Loading of the WSDL is complete
  5. Add an EventListener for the results coming back from the call
  6. Add an EventListener for any errors that occur
  7. Tell the WS to load the WSDL

Step 2 - Set Some Parameters

1 private function loadListener(event:LoadEvent):void{ 2 var op:AbstractOperation = fooService.getOperation("Z_DOUBLE_ROWS"); 3 var input:Object = new Object(); 4 input.TEST = new Array(); 5 input.TEST.push("foo"); 6 input.TEST.push("bar"); 7 op.arguments = input; 8 op.send(); 9 }

Line by Line:

  1. Declare a function who handles the event you subscribed to in the Step 1 line 4.
  2. Get the Operation from the WSDL file.  This is one of those “standard” ways of doing things.  If you look at your WSDL file you will see that it could have more then one operation in it, this gets the particular operation you want to call.
  3. Create a dynamic object that will hold the inbound parameters to your WS.  In this case the parameter TEST is a table of strings.
  4. Here we create what Flex builder thinks is how to hold  a table, an Array.
  5. Then we push each “row” of the table into the array again, in this case it’s just one string at a time.
  6. See Line 5
  7. We then map the input object to the arguments of the WS.
  8. Send our request including all the input data to the server

Step 3 - Look at the Output

1 private function resultTrigger(event:ResultEvent):void{ 2 var item:String; 3 for each(item in event.result){ 4 trace(item); 5 } 6 }

Line by Line

  1. Define a function to handle the event from section 1 line 5
  2. Declare on object to hold each result
  3. Loop at each item in the result list, which happen to be strings.
  4. Print them out to the debug console

I will talk about more advanced parsing of the result set later on.

Inbound Table Parameter

First, get your WSDL, in this case I will be using the FM BAPI_FLIGHT_GETLIST from the SFLIGHTS example we are all so fond of.  You should run this FM a few times to make sure you have data on the ABAP side, I will be passing in a date range to this FM so, you might want to find two dates that return some data for you. ( I named my WebService “Z_GET_FLIGHT_LIST” )

Step 1 - Get Your WSDL

This is the same exact thing you did before, just with a different WSDL.

Step 2 - Set some Parameters

There is a strange behavior with ABAP WebServices where if you have a table that is both Input and Output you must pass it as part request to get it filled.  You’ll see in a second:

1 private function loadListener(event:LoadEvent):void{ 2 var op:AbstractOperation = fooService.getOperation("BAPI_FLIGHT_GETLIST"); 3 var input:Object = new Object(); 4 input.FLIGHT_LIST = new Array(); 5 input.RETURN = new Array(); 6 op.arguments = input; 7 op.send(); 8 }

Line by Line

  1. Define a function that handles the event
  2. Get the right operation
  3. Dynamic input object
  4. You have to pass blank parameters to the WS so that the Web Application Server will fill them
  5. See line 4
  6. Same as last time
  7. Same here

Set Table Parameters

1 var dateRangeRow:Object = new Object(); 2 input.DATE_RANGE = new Array(); 3 dateRangeRow.SIGN = "I"; 4 dateRangeRow.OPTION = "EQ"; 5 dateRangeRow.LOW = "2002-12-20"; 6 dateRangeRow.HIGH = ""; 7 input.DATE_RANGE.push(dateRangeRow);

Line by Line ( add this between lines 5 and 6 from the prior example )

  1. Create a new dynamic object that holds a Row of the DATE_RANGE table
  2. Create an array called DATE_RANGE which will map to the DATE_RANGE input parameter
  3. Set each field dynamically
  4. More fields
  5. More fields
  6. More fields ( don’t need to pass this one because it’s blank )
  7. Push this row into the array

Step 3 - Look at the Output

1 private function resultTrigger(event:ResultEvent):void{ 2 var row:Object; 3 for each (row in event.result.FLIGHT_LIST){ 4 trace(row.AIRLINE + " " + row.CITYFROM); 5 } 6 }

Line by Line

  1. Function, again.
  2. Use a place holder dynamic object
  3. Loop at the table called FLIGHT_LIST ( looks like ABAP doesn’t it? )
  4. Print to the console the fields you want ( looks like ABAP doesn’t it? )

Disclaimer: There are a number of ways to call WebServices in Flex, I believe this is the most complete and “standard” way to call them, if not someone please point me to Adobe docs that show the most correct way.

Secrets of the Subscription EULA

Wednesday, October 17th, 2007

I was able to ask Zia Yusuf this morning about some of the restrictions around the SAP Subscription License.  paraphrasing his answer a bit:

The license you are granted is a development license if you intend to resell or license any of your solutions you create you need to get a different license from SAP

So what this means is that if you develop something on the subscription program you cannot resell it.  The EULA is pretty clear in this regard:

If You wish to use an Add-On or Consuming Product Application created by You in a production environment, or to otherwise commercialize and/or distribute that Add-On or Consuming Product Application, You must first enter into a separate agreement with SAP.  Under this Agreement You are not entitled to: … license sell, offer to sell, transfer, rent, lease, distribute and/or otherwise make available the SAP Software and/or any Add-On to third parties. [source: EULA]

Thanks to Eddie for the link to the EULA.

Basically this means if you want to sell something you need a new license and probably any open source work would also meet with a cease and desist from the SAP legal team. 

To compare this to another player in the industry the EULA associated with the MSDN subscription appears to not make any distinctions like this.  Granted the pricing for the MSDN subscription is a bit higher, New $10,939, then $3,499 / year thereafter.  Compared to the SDN Subscription cost which is $2,300 / year.  I wonder how the MSDN numbers compare with the cost of the SAP license to resell your solutions.

I think the subscription is a great idea and a big step forward for SAP but, to become a “platform company” they need to make it easier(cheaper being part of this) to get started in the ISV market.

ABAP Magic Models

Sunday, November 26th, 2006

After reading a lot about Rails and it’s former inclusion (thanks to Tom and Ryan) of a bunch of REST functionality into the next release and a blog by Dr. Nic feed about his Magic Models project I’ve decided to embark on a new project.

Simply put I want Dr. Nic’s magic models for ABAP. The basic idea behind the project is that RoR developers should be able to easily consume ABAP objects. Current solutions only create the ability to call RFCs, which if you are not an ABAP person are totally procedural elements so, this removes any of the beauty of OOP from systems you can build that interact with ABAP. With this project I hope to put it back. In the end what you should be able to do on the RoR side is create a config file to point to your SAP instance and then make calls like this:

@abapObject = Zcl_foobar.new

@abapObject.callMethod( with, some, params )

Where Zcl_foobar is the name of class that resides only on the ABAP system. What this will allow a RoR developer to do is simply and quickly access classes from ABAP without having to have an ABAP person wrap every method call in a function module. In the background Ruby is using the const_missing method to generate a generic class for Zcl_foobar. When a method is called the call is converted into a specially formatted REST call to an ICF Node ( basically a servlet ) on the ABAP side and ABAP responds to the message with another XML document that the newly generated class understand and unpacks into more Ruby data objects.

For now I am only building a “connector” to the Ruby programming language but, there is nothing to prevent the addition of other scripting languages from using this method and the base ICF node to accomplish similar feats. Over the next month or two I will be focusing almost all my time in taking this from it’s current stage, simply a proof of concept to a fully working system.