Chat with SAP. Yes, we can.

Chat with SAP. Yes, we can.

Have your ever wanted to communicate with a user directly by SAP?  If your answer is YES, then take a look to learn to create a messenger program with SAP.

Author : Oscar

Author's Website | Articles from Oscar

Oscar is a SAP consultant with a large experience in SAP Netweaver technologies. With a major emphasis on logistics modules.

Many of us used to chat with our friends with the old messenger. Nowadays, there’re other tools like facebook, google+, twitter… But, what does it happen if our employer has closed the acces to these kind of tools? Perhaps at job we don’t have internet access. In these cases, can we still chat between us?

The answer:

yeswecan

We can use SAP to chat creating an easy report in four easy steps:

  • Retrieving the users online in SAP.
  • Showing the list of users by the SAP screen.
  • Sending the message.
  • Enjoy.

We’re going to create an ABAP report with transaction SE38 and
explaining the major points.

Step 1: Retrieve users online in SAP

In order to know who is logged in our SAP we must use the C function ThUsrInfo. In this first step we check the users online in our SAP server and save the information in internal table.

*&---------------------------------------------------------------------*
*&      Form  USERS_ONLINE
*&---------------------------------------------------------------------*
*       Retrieve users online by using ThUsrInfo
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM users_online .

  DATA:
    l_opcode TYPE x VALUE 2.
  CLEAR:
    t_user.
  REFRESH:
    t_user.

  CALL 'ThUsrInfo' ID 'OPCODE' FIELD l_opcode
      ID 'TAB' FIELD t_usr_tabl-*sys*.

  LOOP AT t_usr_tabl.
    t_user-mandt = t_usr_tabl-mandt.
    t_user-bname = t_usr_tabl-bname.
    APPEND t_user.
  ENDLOOP.

ENDFORM.                    " USERS_ONLINE

Step 2: Show the list of users

We show the list of users by using the function module REUSE_ALV_GRID_DISPLAY. We can use this function module or any other method to create list of data with ABAP.

*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       Display ALV of users online
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv .

  xrepid = sy-repid.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = 'SET_PF_STATUS'
      i_callback_user_command  = 'USER_COMMAND'
      is_layout                = e_layout
      it_fieldcat              = t_fieldcat
      i_save                   = 'A'
      is_print                 = e_print
    TABLES
      t_outtab                 = t_user
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
  ENDIF.

ENDFORM.                    " display_alv

Step 3: Sending message

Finally, the most important, how do we send the message from me to other users. By using the function module TH_POPUP. This function has the ability to send a message between users. By default, SAP uses it to display system messages, but we are allowed to use it to send messages to specific users with specific information.

  LOOP AT t_user WHERE box = 'X'.
    CALL FUNCTION 'TH_POPUP'
         EXPORTING
              client         = t_user-mandt
              user           = t_user-bname
              MESSAGE        = l_msg
              message_len    = l_length
         EXCEPTIONS
              user_not_found = 1
              OTHERS         = 2.
    IF sy-subrc <> 0.
      WRITE: 'User ', t_user-bname, 'not found.'.
    ENDIF.
  ENDLOOP.

Step 4: Enjoy

Just launch your program, check the person who send your message and write anything.

01.Messenger01

This person will get the message in the SAP screen. It doesn’t matter which transaction is working the receiver user, he/she will receive the message immediately.

02.Messenger02

You can get all the ABAP code of this program in the following address. Take into account that you’ll have to create the user status STANDARD to get the complete functionality.

Image by pimkie_photos.

Related Posts



Like this post? Share it!

  • Tweet
  • Facebook
  • Diggit
  • Delicious
  • Diggit
  • Diggit
  • Diggit
  • Diggit
  • Diggit

ADVERTISE HERE


User Comments


  1. saharoon
    June 30, 2012

    Really awesome……….Thank u for posting that code too….

    Reply

Leave a Reply

:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:
  Twitter Followers Email Updates