Skip to end of metadata
Go to start of metadata

Sending an email in ABAP should be done via BCS (class CL_BCS and related).

Don't use these obsolete APIs:

  • SO_OBJECT_SEND is an old function module for sending emails.
  • Etc.

This WIKI can be used as a reference for sending the report output as a screenshot in the body of the E-mail.

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
DATA: li_receivers       TYPE STANDARD TABLE OF soos1,
      li_listobject      TYPE STANDARD TABLE OF abaplist,
      li_ali             TYPE STANDARD TABLE OF soli,
      li_ali1            TYPE STANDARD TABLE OF soli,
      li_ali2            TYPE STANDARD TABLE OF soli,
      lwa_objecthdchange TYPE sood1,
      lwa_receivers      TYPE soos1,
      lwa_ali            TYPE soli.
DATA: l_lines   TYPE i,
      l_length  TYPE i.

DO 10 TIMES.
  NEW-LINE.
  ULINE (99).
  WRITE: /1 sy-vline,
          2 'column1',
         24 sy-vline,
         25 'Column2',
         49 sy-vline,
         50 'Column3',
         74 sy-vline,
         75 'Column4',
         99 sy-vline.
ENDDO.

NEW-LINE.
ULINE (99).
NEW-LINE.

CALL FUNCTION 'SAVE_LIST'
  EXPORTING
    list_index         = '0'    "Pass the list index like 0, 1, 2...
  TABLES
    listobject         = li_listobject
  EXCEPTIONS
    list_index_invalid = 1
    OTHERS             = 2.
IF sy-subrc NE 0.
  RAISE invalid_list.
ENDIF.

* Convert the list to ALI format
CALL FUNCTION 'TABLE_COMPRESS'
  TABLES
    in             = li_listobject
    out            = li_ali
  EXCEPTIONS
    compress_error = 1
    OTHERS         = 2.
IF sy-subrc NE 0.
  RAISE compress_error.
ENDIF.

CLEAR: lwa_objecthdchange.
DESCRIBE TABLE li_ali LINES l_lines.
DESCRIBE FIELD lwa_ali LENGTH l_length IN CHARACTER MODE.

lwa_objecthdchange-objlen = l_length * l_lines.
lwa_objecthdchange-objla  = sy-langu.
lwa_objecthdchange-objnam = 'List'.

MOVE sy-title TO lwa_objecthdchange-objdes.

MOVE: 1 TO lwa_objecthdchange-objpri,
      0 TO lwa_objecthdchange-objsns.

CLEAR: lwa_receivers.
MOVE: 'X'                 TO lwa_receivers-snddr,
      'X'                 TO lwa_receivers-sndex,
      'U'                 TO lwa_receivers-recesc,
      'E-MAIL' TO lwa_receivers-recextnam.          "Pass the recipient ID here.

APPEND lwa_receivers TO li_receivers.

* Send email
CALL FUNCTION 'SO_OBJECT_SEND'
 EXPORTING
*   FOLDER_ID                        = ' '
*   FORWARDER                        = ' '
*   OBJECT_FL_CHANGE                 = ' '
   object_hd_change                 = lwa_objecthdchange
*   OBJECT_ID                        = ' '
   object_type                      = 'ALI'
*   OUTBOX_FLAG                      = ' '
   owner                            = sy-uname
*   STORE_FLAG                       = ' '
*   DELETE_FLAG                      = ' '
   sender                           = sy-uname
*   CHECK_SEND_AUTHORITY             = ' '
*   CHECK_ALREADY_SENT               = ' '
*   GIVE_OBJECT_BACK                 =
*   ORIGINATOR                       = ' '
*   ORIGINATOR_TYPE                  = 'J'
*   LINK_FOLDER_ID                   = ' '
*   SEND_REQUEST_OID                 = ' '
*   IP_ENCRYPT                       = 'U'
*   IP_SIGN                          = 'U'
*   IP_REC_COUNT_ADD                 =
* IMPORTING
*   OBJECT_ID_NEW                    =
*   SENT_TO_ALL                      =
*   ALL_BINDING_DONE                 =
*   OFFICE_OBJECT_KEY                =
*   ORIGINATOR_ID                    =
*   E_SEND_REQUEST_OID               =
TABLES
   objcont                          = li_ali
*   OBJHEAD                          =
*   OBJPARA                          =
*   OBJPARB                          =
   receivers                        = li_receivers
*   PACKING_LIST                     =
*   ATT_CONT                         =
*   ATT_HEAD                         =
*   NOTE_TEXT                        =
*   LINK_LIST                        =
*   APPLICATION_OBJECT               =
 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
   originator_not_exist             = 20
   x_error                          = 21
   OTHERS                           = 22.

IF sy-subrc IS INITIAL.
  MESSAGE 'Mail has been sent successfully' TYPE 'S'.
ELSE.
  MESSAGE 'Error occured while sending the mail' TYPE 'S'.
ENDIF.

  • No labels