PHP ABAP console v.2
What is it?
In case you’ve missed the previous post, this little piece of code that I did is a web interace for you to type in some ABAP code and watch it execute. I did it with the idea that it could be useful for learning ABAP of just quickly trying out little code snippets.
How it’s done?
Using PHP with SAPRFC to connect to an SAP system and call RFCs on it. Using AJAX to avoid page reloads and using Yahoo UI library to help with the JavaScript part (animations, async requests, events).
What’s new?
In the previous version I’ve created an RFC function that takes an internal table containing ABAP code, executes it as a report and returns the screen result. Thanks to Blag, who pointed out in his comment that such an RFC already exists, I deprecated mine and used RFC_ABAP_INSTALL_AND_RUN instead. It’s definitelly better, because it does auth checks on the user executing it, also a syntax check on the ABAP code passed to it and finally it cleans up the temp report created to execute the code.
The only problem with this RFC is that when it does the syntax check, it returns only a cut-off error message (50 chars) and no details on the line of code that contained an error and the string (word) that causes the error. So I went ahead and created a very simple RFC that only calls SYNTAX-CHECK FOR statement and returns everything this statement gives – full text of the error message, line of code and word. So now the way the console works is:
- Call RFC_ABAP_INSTALL_AND_RUN.
- If there is an error message, call ZSTOYAN_RFC_SYNTAX_CHECK to get the full details of the syntax error, then highlight the error.
Screenshots and code download
Here are two screenshot, one with code executed OK and one with code with a syntax error.
The code is here (the custom RFC’s source can be found in the _extras/ folder).
If you want to try the console out, you need to create the ZSTOYAN_RFC_SYNTAX_CHECK function module and then to edit /model/business.php changing the credentials to access your SAP system.
Thanks!
Thanks for reading, any comments are appreciated. And thanks again to Blag, please give this guy all SDN points he deserves 🙂
Regards
Kathirvel
Hope to see more of you work soon! -;) I'm going to start writting my new blog tonight, so please stay tuned -:)
And, about the points...hehehe...I hope Craig hears you -:P
Greetings,
Blag.
I kept trying the scripts at our systems here and after debugging a bit I seem to be getting the error: "REPORT/PROGRAM statement missing, or program type".
I guess we have to write the REPORT statement if its
going to be executed as a report/program.
I guess it's something specific to our systems here, but the idea is just great 😉
Greetings,
Blag.
In my case if I put REPORT statement, I get the error "Each ABAP program can contain only one "REPORT" or "PROGRAM" or "FUNCTION-POOL" statement." which makes sense, since I'm adding one behind the scenes.
Blag, did you have the same issue with the first version? There I was adding a new line after the automatically included REPORT statement?
Greetings,
Blag.
It's weird that you should get this message, because my idea was not to have to write the REPORT statement, for this purpose I add it to the source you pass to be executed. Let's say you want to execute:
WRITE: / 'Hello!'.
I take this and make it (in the function evaluate() found in business.php):
REPORT zabap_console.WRITE: / 'Hello!'.
This code is syntax checked and executed by RFC_ABAP_INSTALL_AND_RUN.
I kept REPORT statement on the same line, so that when the syntax check gives me a line number that contains an error, I don't have to substract one from it.
The other thing that might be causing a problem is the program type, RFC_ABAP_INSTALL_AND_RUN accepts the parameter MODE which I set to F, I don't know if that has anything to do with it.
Cheers
Otherwise stripping out all potentially dangerous code sounds like a pretty big task. "Cleaning up" code, even written in a less powerful language such as HTML is a task many people have failed in 🙂 Take that MySpace XSS from last year for example, it's very funny - http://namb.la/popular/tech.html