Send Popup Message to SAP Users with LSMW

Jimbo's picture

Popup mountain goatsHidden deep in SAP is a way to send a popup messages to users who are logged on. This can be a convenient way to reach out to a user who has open an object that needs to be updated--especially if that user is in another country.

An easy way to send a popup message to another user is by launching the SE37 transaction and running the TH_POPUP function. An even easier way that does not require access to SE37 and lists the users who are currently logged on is by using an LSMW object as a user-friendly wrapper for the TH_POPUP function.

This LSMW object is used as a framework to create a report and relies on the drop down menu to provide a list of users who are logged in. Start by adding the parameters and variables that will be used to provide the list of online users to the GLOBAL_DATA section of Field Mapping and Conversion Rules.

data: it_Users type standard table of UINFO with header line.
TYPE-POOLS: vrm.
DATA: gt_list     TYPE vrm_values.
DATA: gwa_list    TYPE vrm_value.
DATA: gt_values   TYPE TABLE OF dynpread,
      gwa_values  TYPE dynpread.
DATA: gv_selected_value(10) TYPE c.
data: lUSR21 like USR21, lADRP like ADRP.
parameters: p_user like USR01-BNAME AS LISTBOX visible length 20
             obligatory,
            p_messag like SM04DIC-POPUPMSG obligatory.

Next, use the THUSRINFO function to populate the it_Users internal table with the list of online users and then use those values to populate the gt_list internal table that will then be used populate the drop down menu. The VRM_SET_VALUES function associates the values in the gt_list internal table with the parameter P_USER.

"Get list of users currently logged in . . .
call function 'THUSRINFO'
  tables
    USR_TABL = it_Users.
loop at it_Users where BNAME ne ''.
  gwa_list-key = it_Users-BNAME.
  select * from USR21 into lUSR21 where BNAME eq it_Users-BNAME.
    select * from ADRP into lADRP
     where PERSNUMBER eq lUSR21-PERSNUMBER.
      concatenate it_Users-BNAME ':' lADRP-NAME_FIRST lADRP-NAME_LAST
       into gwa_list-text separated by space.
    endselect.
  endselect.
  append gwa_list to gt_list.
endloop.

  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      id              = 'P_USER'
      values          = gt_list
    EXCEPTIONS
      id_illegal_name = 1
      OTHERS          = 2.

Finally, call the TH_POP using the values from the initial screen to send the popup message. Because the user ID comes from a list of users that are logged on, this will go through unless the user has logged off while typing the message--hence the error catching code.

call function 'TH_POPUP'
  exporting
    client  = sy-mandt
    user    = p_user
    message = p_Messag
  exceptions
    USER_NOT_FOUND = 1.
if sy-subrc eq 0.
  write: / 'Message sent' color col_positive.
else.
  write: / 'User not found' color col_negative.
endif.

That is all it takes to send a popup message in SAP. This LSMW object is included as part of Jimbo's LSMW Toolbox along with several other useful tools.

Programming Language: 
ABAP