Skip to content

SO_NEW_DOCUMENT_ATT_SEND_API1

Send email with optional attachments from ABAP — the SAPoffice API for programmatic email dispatch.

Purpose

SO_NEW_DOCUMENT_ATT_SEND_API1 creates and sends a SAPoffice message (email) with body text and optional attachments. It handles both internal SAP users (SAPoffice inbox) and external recipients (SMTP via SAPconnect). Email delivery to external addresses requires SAPconnect to be configured (SCOT).

For new development consider CL_BCS (Business Communication Services) — it is the modern OO alternative.

Signature (key parameters)

Parameter Direction Type Description
DOCUMENT_DATA Importing SODOCCHGI1 Subject, priority, sensitivity
PUT_IN_OUTBOX Importing SONV-FLAG 'X' = place in sender's outbox
COMMIT_WORK Importing SONV-FLAG 'X' = commit after sending
PACKING_LIST Tables SOPCKLSTI1 Describes each part — body and attachments
CONTENTS_TXT Tables SOLISTI1 Body text lines (max 255 chars each)
CONTENTS_HEX Tables SOLIX Binary attachment data (255 bytes per line)
CONTENTS_BIN Tables SOLISTI1 Character attachment data (rarely used)
RECEIVERS Tables SOMLRECI1 Recipients list

PACKING_LIST is mandatory when sending attachments

Without PACKING_LIST entries the FM cannot distinguish the body from the attachment. Each part (body + every attachment) needs its own packing list row describing its start line, line count, and document type.

Recipient table (SOMLRECI1)

Field Description
RECEIVER Email address or SAP user ID
REC_TYPE 'U' = SAP user, 'B' = external (internet)
EXPRESS 'X' = express mail
COPY 'X' = CC recipient
BLIND_COPY 'X' = BCC recipient

Example — send email with PDF attachment

REPORT z_send_email_pdf.

START-OF-SELECTION.

  DATA: ls_doc        TYPE sodocchgi1,
        lt_packing    TYPE STANDARD TABLE OF sopcklsti1,
        lt_body       TYPE STANDARD TABLE OF solisti1,
        lt_attachment TYPE STANDARD TABLE OF solix,
        lt_receivers  TYPE STANDARD TABLE OF somlreci1,
        ls_pack       TYPE sopcklsti1.

  " Subject and document type
  ls_doc-obj_descr = 'Monthly report'.
  ls_doc-obj_name  = 'MAIL'.
  ls_doc-obj_prio  = '1'.

  " Body text — each line max 255 chars
  APPEND VALUE #( line = 'Dear team,' ) TO lt_body.
  APPEND VALUE #( line = '' ) TO lt_body.
  APPEND VALUE #( line = 'Please find attached the monthly report.' ) TO lt_body.
  APPEND VALUE #( line = 'Regards' ) TO lt_body.

  " Packing list entry 1: body
  ls_pack-transf_bin = space.
  ls_pack-head_start = 1.
  ls_pack-head_num   = 0.
  ls_pack-body_start = 1.
  ls_pack-body_num   = lines( lt_body ).
  ls_pack-doc_type   = 'RAW'.
  APPEND ls_pack TO lt_packing.

  " Binary attachment — PDF bytes in SOLIX table (255 bytes per line)
  " Replace lv_pdf with your actual xstring (e.g. from FPDF or CL_FDT_XL_SPREADSHEET)
  DATA lv_pdf TYPE xstring.
  " lv_pdf = <your PDF xstring here>

  DATA: lv_pdf_len TYPE i,
        lv_offset  TYPE i VALUE 0,
        lv_chunk   TYPE i,
        ls_solix   TYPE solix.

  lv_pdf_len = xstrlen( lv_pdf ).
  WHILE lv_offset < lv_pdf_len.
    CLEAR ls_solix.
    lv_chunk = lv_pdf_len - lv_offset.
    IF lv_chunk > 255. lv_chunk = 255. ENDIF.
    ls_solix-line = lv_pdf+lv_offset(lv_chunk).
    APPEND ls_solix TO lt_attachment.
    lv_offset = lv_offset + lv_chunk.
  ENDWHILE.

  " Packing list entry 2: PDF attachment
  CLEAR ls_pack.
  ls_pack-transf_bin = 'X'.
  ls_pack-head_start = 1.
  ls_pack-head_num   = 0.
  ls_pack-body_start = 1.
  ls_pack-body_num   = lines( lt_attachment ).
  ls_pack-doc_type   = 'PDF'.
  ls_pack-obj_descr  = 'monthly_report.pdf'.
  ls_pack-obj_name   = 'REPORT'.
  APPEND ls_pack TO lt_packing.

  ls_doc-doc_size = lv_pdf_len.

  " Recipient
  APPEND VALUE #(
    receiver = 'user@example.com'
    rec_type = 'B'
  ) TO lt_receivers.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = ls_doc
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = lt_packing
      contents_txt               = lt_body
      contents_hex               = lt_attachment
      receivers                  = lt_receivers
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      OTHERS                     = 7.

  IF sy-subrc = 0.
    WRITE: / 'Email sent'.
  ELSE.
    WRITE: / 'Send failed, sy-subrc:', sy-subrc.
    IF sy-msgid IS NOT INITIAL.
      MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.

Example — send plain text email (no attachment)

REPORT z_send_email_text.

START-OF-SELECTION.

  DATA: ls_doc     TYPE sodocchgi1,
        lt_packing TYPE STANDARD TABLE OF sopcklsti1,
        lt_body    TYPE STANDARD TABLE OF solisti1,
        lt_recv    TYPE STANDARD TABLE OF somlreci1.

  ls_doc-obj_descr = 'Hello from ABAP'.
  ls_doc-obj_name  = 'MAIL'.

  APPEND VALUE #( line = 'This is an automated message from SAP.' ) TO lt_body.

  " Single packing list entry for the body
  APPEND VALUE #(
    transf_bin = space
    head_start = 1
    head_num   = 0
    body_start = 1
    body_num   = lines( lt_body )
    doc_type   = 'RAW'
  ) TO lt_packing.

  APPEND VALUE #(
    receiver = 'user@example.com'
    rec_type = 'B'
  ) TO lt_recv.

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data = ls_doc
      put_in_outbox = 'X'
      commit_work   = 'X'
    TABLES
      packing_list  = lt_packing
      contents_txt  = lt_body
      receivers     = lt_recv
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      OTHERS                     = 7.

  IF sy-subrc = 0.
    WRITE: / 'Email sent'.
  ELSE.
    WRITE: / 'Send failed, sy-subrc:', sy-subrc.
    IF sy-msgid IS NOT INITIAL.
      MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.

Common pitfalls

Virus scan profile not active

If the FM raises "Virus scan profile /SCMS/KPRO_CREATE is not active", the system's virus scan interface is enabled but the profile hasn't been activated. Go to transaction VSI → select profile /SCMS/KPRO_CREATE → activate. If you don't have access, ask your Basis team.

SAPconnect must be configured for external email

Internal SAP user messages work without SAPconnect. External (internet) email requires SMTP configuration in SCOT. Test with SBWP → send test message.

COMMIT_WORK = 'X' commits the entire LUW

Setting COMMIT_WORK issues a COMMIT WORK that affects all open database changes in the current work process, not just the email. Omit it if you need to control the commit yourself.

  • Binary vs character attachments: Binary data (PDF, ZIP, XLS) goes in CONTENTS_HEX (SOLIX — 255 bytes/line). Character data goes in CONTENTS_BIN or CONTENTS_TXT (SOLISTI1 — 255 chars/line).
  • Body line length: Each line in CONTENTS_TXT is limited to 255 characters. Long lines must be split manually.
  • Document type: DOCUMENT_DATA-OBJ_NAME = 'MAIL' for plain email.

See also

  • Transaction SCOT — SAPconnect configuration for outbound SMTP
  • Transaction SBWP — SAP Business Workplace, test outbox
  • Transaction SOST — outbound message monitor (check send status)

Comments