Skip to Content
Following up on the PHP ABAP console from PHP ABAP console I updated my little PHP ABAP console (PHP ABAP console) to use the RFC_ABAP_INSTALL_AND_RUN function deprecating my own ZSTOYAN_RFC_EVAL. I also added syntax checking for the code typed into the console.

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:

  1. Call RFC_ABAP_INSTALL_AND_RUN.
  2. 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.

Evaluated and highlighted code Code with 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 🙂

To report this post you need to login first.

9 Comments

You must be Logged on to comment or reply to a post.

  1. Alvaro Tejada Galindo
    Hi Stoyan! Thanx for the comments -:) I’m glad to be helpfull…And gotta say, you new app looks better that ever…and that error highlighting is really great! -:D

    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.

    (0) 
  2. Ankan Banerjee
    Very good work here!

    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 😉

    (0) 
      1. Stoyan Stefanov Post author
        strange…

        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?

        (0) 
        1. Alvaro Tejada Galindo
          Hehehe….Sorry Stoyan…I was actually talking about my SE38 Emulator -:P Haven’t have the time to test your’s -:'(…I read the code of course…But haven’t test it…But you’re right…Your including the “REPORT” statement…So maybe the problem is with the web browser or something…

          Greetings,

          Blag.

          (0) 
    1. Stoyan Stefanov Post author
      Hi Ankan,

      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.

      (0) 
  3. Michael Nicholls
    Before implementing this type of functionality, it might be worth adding some logic that checks there are no dangerous commands in the ABAP code being passed. Without saying too much, a “select” statement is probably OK, but I’m sure people could think of some other statements that might not be appropriate…

    Cheers

    (0) 
    1. Stoyan Stefanov Post author
      Absolutelly true, Mike. That’s why I strongly emphasized in the previous post about not using this  on a live server. It’s mainly for training and testing purposes for a developer’s use.

      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

      (0) 

Leave a Reply