Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Following the example set by famous SDN Mentor Blag, I decided to demonstrate some of the capabilities of Blue Ruby along Blag's favourite smoke test for SAP Connectivity: the SE16 Emulator, a tool to display the content of an SAP DDIC table.

Now, Blag has already shown a version that prints the content of a table to STDOUT - check out his blog The specified item was not found.. To demonstrate some more features available in our Blue Ruby environment, I am going to extend his example by adding HTTP access to the table content and some basic HTML generation - and all of that in no more than 50 lines of code.

So, without further hesitation - let's jump right to the code:

 

 

The source code should be easy to understand - but I guess that's what developers always think about their own code, so here is a short explanation of the pieces we had to put together for this Blue Ruby SE16 Emulator:

Call an ABAP function module to retrieve DDIC table content

As you can see, we are using the Blue Ruby 'rfc' library to call function module RFC_READ_TABLE. The function takes the name of a DDIC table and returns the content of the table along with some metadata. The result of the call is not structured, so we will have to split the content of the returned rows at the delimiter character.

Generate the HTML output

We are showing two ways here:

For the input form, we just use a string that contains the HTML. We could also merge Ruby expressions into that string to make it more dynamic.

Remark: A future version of Blue Ruby might also be able to deal with the *.erb files used in Ruby on Rails.

The HTML table that shows the DDIC table content is rendered via the (standard Ruby) library 'xml_builder', which allows to generate XML (or in our case HTML) output in a pretty declarative and self-explaining way.

Make the program callable via HTTP

Blue Ruby doesn't work like the "standard" web servers known in the Ruby community. As we are getting so much for free in the ABAP environment (the web server is always running), it's even simpler. We just have to follow some naming conventions - we must use the same name for the file and the class we define in the file and we need to define a do_get (or do_post, do_put, ...) method that takes the HTTP request and response objects as parameters. Then we just drop that file into a special folder on our file system (the /Handlers folder) and we're ready to call our SE16 servlet.

 

 

 

Remark: For compatibility reasons, we are also implementing a Rack-compliant alternative - when it's finished, we can try to run these nifty web frameworks that keep on evolving in the Ruby community.

 

So what happens when we call our SE16 Emulator from the Web Browser? At first, it prompts us to enter a table name (and kindly suggests the SPFLI table).

 

 

 

We press the "Go" Button, and the browser will display the table content in a nice, yet puristic, HTML table.

 

 

Easy, wasn't it?

If you want to learn more about Blue Ruby, check out the following links:

http://www.sdn.sap.com/irj/scn/wiki?path=/display/research/blueruby

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/408a9a3b-03f9-2b10-b29c-f0a3374b1...

And if you want to see more SE16 Emulators, follow Blag's blogs:

http://www.sdn.sap.com/irj/scn/wiki?path=/display/profile/alvaro+tejada+galindo

http://atejada.blogspot.com/(search for "tasting the mix")

3 Comments