Tips and Tricks for the ABAP® Programming Language

ZMESSAGE – Sending a SAPOffice message

This reports does send a message SapOffice.

Parameters:
p_line1(70) type c obligatory,
p_line2(70) type c,
p_line3(70) type c,
p_title like sood1-objdes,
p_user like sy-uname obligatory.

Output:
message SapOffice

ABAP-Source-Code

You can copy and paste the source code directly into the ABAP-Workbench.

REPORT ZMESSAGE LINE-SIZE 250.      "yyyymmdd, Release x.x
*
**********************         HEADER                    **************
*
* Copyright (c) 2001 by Angell, 44318 Anywhere, http://xxxxx
* or: Copyright (c) 2001 by A.L. from I.
*
*     You can use or modify this report for your own work as long
*               as you don't try to sell or republish it.
*      In no event will the author be liable for indirect, special,
*        Incidental, or consequental damages (if any) arising out of
*                       the use of this report.
*//////////////////////////////////////////////////////////////////////*
* Append your coding here ...
parameters: p_line1(70) type c obligatory,
            p_line2(70) type c,
            p_line3(70) type c,
            p_title like sood1-objdes,
            p_user like sy-uname obligatory.

START-OF-SELECTION.

DATA: I_RECEIVERS LIKE SOOS1 OCCURS   0 WITH HEADER LINE,
      I_OBJCONT LIKE SOLI OCCURS   0 WITH HEADER LINE,
      I_OBJHEAD LIKE SOLI OCCURS   0 WITH HEADER LINE,
      R_OBJECT_HD_CHANGE LIKE SOOD1 OCCURS   0 WITH HEADER LINE.

  R_OBJECT_HD_CHANGE-OBJDES = p_title.    "Title
  R_OBJECT_HD_CHANGE-OBJNAM = TEXT-000.   "Document name
  R_OBJECT_HD_CHANGE-OBJLA = sy-langu.    "Lenguaje
  R_OBJECT_HD_CHANGE-OBJSNS = 'P'.        "Atributos del objeto, Privado
  R_OBJECT_HD_CHANGE-VMTYP = 'F'.         "Tipe
  R_OBJECT_HD_CHANGE-SKIPS = ' '.         "Procesar 1º dynpro no visible
  R_OBJECT_HD_CHANGE-ACNAM = SY-UNAME.

  I_RECEIVERS-RECESC = 'B'.               "Sap User
  I_RECEIVERS-RECNAM = p_user.            "Destiny user
  I_RECEIVERS-SNDEX = 'X'.
  APPEND I_RECEIVERS.

  I_OBJCONT-LINE = p_line1.
  APPEND I_OBJCONT.
  CLEAR I_OBJCONT.
  I_OBJHEAD-LINE = I_OBJHEAD-LINE  + 1.

  IF NOT P_LINE2 IS INITIAL.
    I_OBJCONT-LINE = p_line2.
    APPEND I_OBJCONT.
    CLEAR I_OBJCONT.
    I_OBJHEAD-LINE = I_OBJHEAD-LINE  + 1.
  ENDIF.
  IF NOT P_LINE3 IS INITIAL.
    I_OBJCONT-LINE = p_line3.
    APPEND I_OBJCONT.
    CLEAR I_OBJCONT.
    I_OBJHEAD-LINE = I_OBJHEAD-LINE  + 1.
  ENDIF.
  APPEND I_OBJHEAD.
  CALL FUNCTION 'SO_OBJECT_SEND'
       EXPORTING
            OBJECT_HD_CHANGE           =  R_OBJECT_HD_CHANGE
            OBJECT_TYPE                = 'RAW'
            OWNER                      = SY-UNAME
       TABLES
            OBJCONT                    = I_OBJCONT
            OBJHEAD                    = I_OBJHEAD
            RECEIVERS                  = I_RECEIVERS
       EXCEPTIONS
            ACTIVE_USER_NOT_EXIST      = 1
            COMMUNICATION_FAILURE      = 2
            COMPONENT_NOT_AVAILABLE    = 3
            FOLDER_NOT_EXIST           = 4
            FOLDER_NO_AUTHORIZATION    = 5
            FORWARDER_NOT_EXIST        = 6
            NOTE_NOT_EXIST             = 7
            OBJECT_NOT_EXIST           = 8
            OBJECT_NOT_SENT            = 9
            OBJECT_NO_AUTHORIZATION    = 10
            OBJECT_TYPE_NOT_EXIST      = 11
            OPERATION_NO_AUTHORIZATION = 12
            OWNER_NOT_EXIST            = 13
            PARAMETER_ERROR            = 14
            SUBSTITUTE_NOT_ACTIVE      = 15
            SUBSTITUTE_NOT_DEFINED     = 16
            SYSTEM_FAILURE             = 17
            TOO_MUCH_RECEIVERS         = 18
            USER_NOT_EXIST             = 19
            X_ERROR                    = 20
            OTHERS                     = 21.

  IF SY-SUBRC <> 0.
*    MESSAGE I000.  "Error en el envío de mensaje al responsable
    WRITE: /1  'Error en el envío de mensaje al responsable'.
    LEAVE SCREEN.
  ENDIF.
************************************************************************
******************* END OF PROGRAM *************************************