Quantcast
Channel: ABAP Development
Viewing all articles
Browse latest Browse all 948

Vesna Hello World Application

$
0
0

A working example is worth hundreds pages of documentation. Hence, let me entertain you today with a simple yet powerful Vesna Hello World application, demonstrating basic Vesna application composition capabilities. I don't want to keep you waiting so let's just install and run it.

First Steps

If you do not have Vesna Framework installed yet, it's high time to do it. You can find an awfully long manual here - please do not read the whole of it, the short version will do just fine.

The installation procedure for this Vesna Hello World application can hardly be made any easier:

  1. Download source code file ZVESNA_HELLO_WORLD.txt attached to this blog post
  2. Create report ZVESNA_HELLO_WORLD in your ABAP NW system where you have Vesna installed:
    ActionImage
    Create Programscreenshot041.png
    Defaults will do just finescreenshot042.png
    Save locallyscreenshot043.png
    Copy-paste the contents from attached source code filescreenshot044.png
  3. Activate the report
  4. Enjoy your Vesna Hello World application:

screenshot045.png

That's it. No classes to install, nothing. The demo uses two classes present in any system running Vesna, being:

  • CL_OS_SYSTEM
  • CL_ABAP_OBJECTDESCR

Vesna Application Composition

The application instantiates an object of type CL_OS_SYSTEM (under bean name of sys) and passes this instance to a factory method CL_ABAP_TYPEDESCR=>DESCRIBE_BY_OBJ_REF( ), obtaining a reference to an object of type CL_ABAP_OBJECTDESCR as rtts bean. This concludes the application composition part of the application.

Application Logic

This part has nothing to do with presenting Vesna Framework and merely proves that we actually have obtained a fully configured object. What we do is list methods of our sys bean. Easy-peasy.

More detail, please!

Let's jump straight to the point where we find some action: method application=>handle_sapevent. If you have copy-pasted the report ZVESNA_HELLO_WORLD, this will be line 212 of the code. As soon as you press the button (or more precisely, The Button as there is only one), that's where you land.

The first thing is to bring your Vesna application container to life. You will do that by feeding the constructor of the /ARCONA1/APPLICATION_CONTEXT class with an iXML input stream (IF_IXML_ISTREAM). iXML library offers us a few wonderful options to do this by the means of loading XML from file, text string, binary string, internal table and so on. The example in line 225 of the ZVESNA_HELLO_WORLD shows one of many possibilities. You can learn how to do it in a different way by the means of consutling SAP iXML library documentation in the SAP Help portal. I'm not providing the link since they usually don't work. Just google for it. Anyway, in most usable scenarios reading an XML input of any sort and converting it to an iXML input stream is a matter of a nice one-liner.

 

Where were we? Ah yes, getting hold of the application container. And in fact, that's just about it. Unless you want to register any objects existing already in this pre-context of your application, you can go and request your business logic handle right away. You'll do that by the means of querying the GET_BEAN method of the Vesna application container with the bean name that is of interest to you. This should be something like a single point of entry to your application so that you don't have to refer to Vesna bindings any more. This is what happens in the line 230 of the ZVESNA_HELLO_WORLD report. Beyond this line, the application is all yours: do with it whatever you like.

 

Side Effects

Now, let's hold on for a moment and consider the collateral damage;) that will be inflicted by the use of Vesna application composition as compared to static coding.

 

Great Testability

The application we're accessing knows only one thing: all the dependencies are simply there. It does neither know or care what exactly types they are or what their internal logic is. This means, we can very easily test any given object in full isolation but retaining its functionality as long as we provide (via Vesna configuration) some compatible dependencies so that tested object "thinks" that it works in a true environment. In other words, mock testing is at hand.

Native Extensibility

Just in the same way we can pick & mix standard and custom implementations for any given application without changing a single line of the original code. This is the ultimate technology for customer extensions, allowing you to plug in just about anywhere in the code and yet change nothing.

 

Transparent Application Structure

Have you ever wondered, looking at your SE80 package structure, what the application really needs and where? Well, the days of such pondering are over with Vesna. The beans are laid out in front of you, nicely interlinked via ref tokens. In a typical code you would also have some runtime variables preconfigured as well and passed to the application via value tokens. Also, you'd probably make good use of setter methods apart from constructor arguments.

 

Really Good OO Code

Vesna will very quickly start changing your way of thinking about code and suggest you excellent OO design, without any effort from your side. Especially in ABAP OO with its extraordinarily elaborate code, you'll be no longer tempted to create monster classes in order to avoid lots and lots of coding just in order to provide for plumbing & welding for your application. Vesna will do that all for you, out the box and you can only concentrate on the functionality at hand.

 

Zero Footprint

Basic Vesna usage has barely measurable footprint as it does not generate anything and relies solely on runtime object properties. Therefore it is lightning fast and absolutely safe to use in any environment.

 

No Strings Attached

This very demo applications shows that Vesna works just fine with any plain old ABAP Objects, not implementing any special interfaces or inheriting from any special classes. Feel free to use it the way you like.

 

Summary

This is but a trivial and completely unproductive sample of a Vesna application. It is solely up to you to venture something more challenging. However, real adventure begins with AOP coding in ABAP OO which I'll show to you next time.

Stay tuned!


Viewing all articles
Browse latest Browse all 948

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>