Skip to end of metadata
Go to start of metadata

Author: Steffen Fröhlich
Submitted: 04/13/2010

This small program triggers FM: SM02_ADD_MESSAGE which generates system message. With this report it is possible to call it via background job (Tcode: SM36). Thus you'll be able to implement the system message, which will not be executed immediately. It will show up for all users when the background job starts.

To view the correct message on errors it is necessary to create a message class (Tcode: SE91) and add 7 messages.
In this example I used Z_ADD_MESSAGE for message class name.

*&---------------------------------------------------------------------*
*& Report  Z_ADD_MESSAGE
*&
*&---------------------------------------------------------------------*
REPORT  z_add_message MESSAGE-ID z_add_message.



"Selection Screen
PARAMETERS:  sp_msg1  TYPE emetext OBLIGATORY
            ,sp_msg2  TYPE emetext
            ,sp_msg3  TYPE emetext
            ,sp_servn TYPE msname     OBLIGATORY
            ,sp_expda TYPE emedatdel  OBLIGATORY
            ,sp_expti TYPE emetimdel  OBLIGATORY
            ,sp_delda TYPE emedatrem  OBLIGATORY
            ,sp_delti TYPE emetimrem  OBLIGATORY
            ,sp_clnt  TYPE mandt      OBLIGATORY  DEFAULT sy-mandt
            ,sp_langu TYPE emelangu   OBLIGATORY  DEFAULT sy-langu
            .



INITIALIZATION.

  IF sy-uzeit > '230000'.
    sp_expda = sy-datlo + 1.
    sp_expti = '230000'.
  ELSE.
    sp_expda = sy-datlo.
    sp_expti = '230000'.
  ENDIF.


  sp_delda = sp_expda.
  sp_delti = sp_expti + 30.



AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_servn.
  TYPES: BEGIN OF ls_server
        ,name TYPE msname2
        ,host	TYPE mshost2
        ,END OF ls_server.


  DATA:  lt_server_out TYPE STANDARD TABLE OF ls_server
        ,wa_server_out TYPE ls_server
        ,lt_server TYPE STANDARD TABLE OF msxxlist
        ,len       TYPE i
        .

  FIELD-SYMBOLS: <fs_server> TYPE msxxlist.

  CLEAR   lt_server[].

  "get list for all servers
  CALL FUNCTION 'TH_SERVER_LIST'
    TABLES
      list   = lt_server
    EXCEPTIONS
      OTHERS = 99.

  IF sy-subrc <> 0.
    MESSAGE e000. "Could not get server list
    EXIT.
  ENDIF.

  len = LINES( lt_server ).

  IF len = 0.
    MESSAGE e001. "Get zero entries for server list
    EXIT.
  ENDIF.

  SORT lt_server BY name ASCENDING.

  LOOP AT lt_server ASSIGNING <fs_server>.
    wa_server_out-name = <fs_server>-name.
    wa_server_out-host = <fs_server>-host.
    APPEND wa_server_out TO lt_server_out.
  ENDLOOP.


  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield    = 'NAME'
      dynpprog    = sy-repid
      dynpnr      = sy-dynnr
      dynprofield = 'SP_SERVN'
      value_org   = 'S'
    TABLES
      value_tab   = lt_server_out.




AT SELECTION-SCREEN ON VALUE-REQUEST FOR sp_clnt.
  TYPES: BEGIN OF ls_clients
        ,mandt TYPE mandt
        ,mtext TYPE mtext_d
        ,END OF ls_clients.

  DATA: lt_clients TYPE STANDARD TABLE OF ls_clients.


  SELECT mandt mtext
    FROM t000
    INTO CORRESPONDING FIELDS OF TABLE lt_clients
    .
  IF sy-subrc <> 0.
    MESSAGE e006. "Could not get client list
    EXIT.
  ENDIF.
  SORT lt_clients BY mandt ASCENDING.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield    = 'MANDT'
      dynpprog    = sy-repid
      dynpnr      = sy-dynnr
      dynprofield = 'SP_CLNT'
      value_org   = 'S'
    TABLES
      value_tab   = lt_clients.





START-OF-SELECTION.

  CALL FUNCTION 'SM02_ADD_MESSAGE'
       EXPORTING
            message              = sp_msg1
            message2             = sp_msg2
            message3             = sp_msg3
            servername           = sp_servn
            client               = sp_clnt
            langu                = sp_langu
            expiration_date      = sp_expda
            expiration_time      = sp_expti
            delete_date          = sp_delda
            delete_time          = sp_delti
*    IMPORTING
*         MESSAGE_ID           =
       EXCEPTIONS
            empty_message        = 1
            server_not_available = 2
            client_not_available = 3
            langu_not_available  = 4.

  CASE sy-subrc.
    WHEN 1.
      MESSAGE i005.  "Messagetext is empty
    WHEN 2.
      MESSAGE e002 WITH sp_servn.  "Application server &1 is not available
    WHEN 3.
      MESSAGE e003 WITH sp_clnt.   "Mandant &1 is not available
    WHEN 4.
      MESSAGE e004 WITH sp_langu.  "Languagekey &1 is not available
  ENDCASE.