- Here’s a screenshot to see it in action. And another one.
- Here’s the code if you want to install and play with it
How does it work
The web interface part is written in PHP, using the open-source SAPRFC extension to be able to connect to an SAP system, where the ABAP code you type will be executed. I’m also using some AJAX calls to execute the code and display results, without reloading the page. There is also a bit of animation, done using Yahoo UI libraries, just to change the color of the result area, signaling to the user, that the code is executed. The overall code/directory structure is built upon this little AXAJ MVC idea, I came up with not so long ago.
In addition to executing the code, it’s also displayed highlighted (different colors for keywords and so on). This part was done by another AJAX call using the PEAR::Text_Highlighter package plus my additions to it – JSON renderer and ABAP language definition.
JSON is used for both server-client data transfters done after the AJAX calls.
The actual execution of the ABAP code is handled by a new ABAP function module I created and RFC-enabled, so that it’s accessible by PHP. This function module creates an ABAP report on the fly, using the code you typed, executes the report and scraps the output of this report. This means you can type in the ABAP console anything you would normally execute in a report. The result you get is whatever you decided to
write: /. Since I’m new to ABAP (that’s why I came up with this console idea in the first place), the ABAP part is probably not the best solution to the problem at hand, but hey, it worked.
As you can see from the paragraph above, this code scratches quite a few programming itches – PHP+SAPRFC, PEAR, AJAX, YUI, JSON, ABAP, so there are a quite some pre-requisites. To make it easier, I took the liberty of including the YUI and PEAR libs I need, as part of the download. The only thing you need to make sure is that your PHP environment includes the SAPRFC extension. If you’re using Craig Cmehil‘s Scripting In A Box army of tools, you’re good to go.
One important security reminder:
Be careful with my ABAP function module (ZSTOYAN_RFC_EVAL), I mean be careful on which system you install it. Having an RFC module is a security concern in itself, but having an RFC module that executes arbitrary code, passed to it, that’s no different than having a Trojan Horse in your system. So be aware of that and probably just install it locally or on a training system, no production servers!
- Unzip the package into your web folder (httpd), so that it’s for example in http://localhost/abap_console
- Install ZSTOYAN_RFC_EVAL on the (non-production!) SAP system. This means create a function group and a function module with this name and paste the code you’ll find in
_extras/ZSTOYAN_RFC_EVAL.abap. The function module works with two tables – SOURCE and RESULT. Don’t forget to Remote-enable the module.
- Open the script
model/business.phpand edit the SAP connection information – username, password, etc.
- Point your browser to the little app, ex. http://localhost/abap_console
- Code away
- Implement user log-in, so that the username/pass are not hardcoded
- Improve the ABAP part, the RFC module that executes the code
- Implement syntax check for the typed-in code (I know I saw somewhere that such functions exist in ABAP)
Thanks for reading, any comments are appreciated.