(This is Part 3 of a 3 part series. See Part 1 and Part 2 for the whole story.)

In the last 2 posts we paved the way to get some data out of SAP from Slack. First, we set up Slack to send out a request when a user enters a Slash Command. Then, Google App Engine handles that request and forwards it to Gateway. Now Gateway needs to respond back to Google with the RFC connection test that the Slack user asked for.

Here’s a simple OData service setup that will test an RFC connection on the ABAP system. My intention is to inspire you to do other cool solutions – I’m just setting this up to show off quick-n-dirty style to explain concepts. Take this and make something else work for you!

Go to SEGW and create a service. I called mine ZSLACK_DEMO. Here’s an example setup of the fields for an entity called RfcDestination:

segw for slack service.PNG

Then code up the RFCDESTINATIONSE_GET_ENTITY method in the generated class ZCL_ZSLACK_DEMO_DPC_EXT (assuming you kept the same names I used). Make sure you generate the project first, and then do the redefinition process for the method I mentioned. Here’s a great document on setting up class-based Gateway services that goes more in-depth.

Here’s a simple implementation of an RFC ping method that matches up with the service we created.

   METHOD rfcdestinationse_get_entity.
     DATA: lv_start TYPE i,
           lv_end TYPE i,
           lo_ex TYPE REF TO cx_root,
           lv_rfcdest TYPE rfcdest,
           ls_key_tab LIKE LINE OF it_key_tab.

     READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = ‘Destination’.
     IF sysubrc IS INITIAL.
       lv_rfcdest = ls_key_tabvalue.

     er_entitydestination = lv_rfcdest.

       GET RUN TIME FIELD lv_start.
           system_failure        = 1
           communication_failure = 2
           OTHERS                = 99.
       GET RUN TIME FIELD lv_end.

       IF sysubrc IS INITIAL.
         er_entityconnection_status = ‘OK’.
         er_entityconnection_time = ( lv_end lv_start ) / 1000.
             error           = er_entityconnection_status.

     CATCH CX_ROOT INTO lo_ex.
       er_entityconnection_status = lo_ex->get_text( ).

Maybe not production quality, but ready to do the trick. For a good connection, it will give you an OK ConnectionStatus and a number in milliseconds for the response time. For a bad connection, it will respond with the RFC error in the ConnectionStatus field. Our Google App Engine web server receives this and plugs it into a text response to Slack. When Slack receives the response it puts the text into the chat window for the user who requested it.

Wrapping Up

Assuming all the pieces of the chain have been done correctly, you can activate your slash command. Try it with something like “/ask-sap shout out a test of RFC <your_destination>”. If you’re all set, the chat window will shortly return to you with a response from SAP.

This was a very simple prototype implementation – but there are so many things you could do! I’ll leave you with a brain dump of ideas to inspire you beyond my work.

  • Set up a batch program that looks for new work items for people and send them a Slack message. Wouldn’t it be cool to get a digest of everything I need to approve in one private chat window every morning? Check out Incoming Webhooks for more possibilities here.
  • Incoming webhooks would even be a simple way to enable some basic real-time notifications. User-exits or enhancement points could be created with knowledge of the webhooks and respond right away to almost any ABAP event.
  • Plug in some of your master data creation processes (assuming they’re simple enough) to fit into a command. Imagine “/sap-create new business partner PAUL MODDERMAN <other field> <other field>”.
  • Slack is cloud-based and doesn’t require any complex VPN setup. The Slack app on your smartphone would be an easy way to enable your processes for quick response.

Go make cool stuff!

To report this post you need to login first.

Be the first to leave a comment

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

Leave a Reply