Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Sending mail with 2 attachments

Former Member
0 Kudos

Hi All,

I have a requirement where I have to send a mail with 2 attachments. Both attachments should be excel sheets.

Iam using the function module

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = gd_doc_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = gd_sent_all

TABLES

packing_list = it_packing_list

contents_txt = it_message

contents_bin = it_attachment

receivers = it_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

enqueue_error = 7

OTHERS = 8.

I don't know where to pass another attachment.

How can it be done?

Kindly help me.

Regards,

Krithika

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Just populate the it_attachement itab with the data for both the excel attachements with all the parameters.

Cheers

VJ

7 REPLIES 7

Former Member
0 Kudos

Just populate the it_attachement itab with the data for both the excel attachements with all the parameters.

Cheers

VJ

0 Kudos

I want it as 2 separate attachments. If I populate all the contents to it_attachment it will be with one attachment.

0 Kudos

U need to populate the data in it_attachment table and also insert a record in the packing list internal table. Basically the packlist table would indicate from which line is the second attachment(body_num)

CLEAR OBJPACK.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = Lines_1. (Number of lines in objbin table for first attachment)

OBJPACK-DOC_TYPE = 'XLS'.

OBJPACK-OBJ_NAME = 'Attachment'.

OBJPACK-OBJ_DESCR = 'File1'.

DOC_SIZE = ( LINES_1 - 1 ) * 255 + STRLEN( OBJBIN ).

OBJPACK-DOC_SIZE = DOC_SIZE.

APPEND OBJPACK.

CLEAR OBJPACK.

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = Lines_1 + 1.

OBJPACK-BODY_NUM = Lines_2. (Number of lines in objbin table for first attachment)

OBJPACK-DOC_TYPE = 'XLS'.

OBJPACK-OBJ_NAME = 'Attachment'.

OBJPACK-OBJ_DESCR = 'File2'.

DOC_SIZE = ( LINES_2 - Lines_1 ) * 255 + STRLEN( OBJBIN ).

OBJPACK-DOC_SIZE = DOC_SIZE.

APPEND OBJPACK.

Regards

Anurag

Message was edited by: Anurag Bankley

Former Member
0 Kudos

/people/sravya.talanki2/blog/2006/01/12/xi-triggering-e-mails-with-multiple-attachments--problems

regards

srikanth

Former Member
0 Kudos

Check this thread ..

Regards,

Santosh

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

You have to fill the packing_list parameter of the FM for each and every attachment.

PACKING_LIST

This table requires information on how the data from tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT should be distributed to the document and its attachments. The first line stands for the document and each of the following lines for one attachment.

sample code :

  • Write Packing List (Attachment)



Data : objpack    like sopcklsti1 occurs  1 with header line.
    att_type = 'ALI'.

    describe table objbin lines tab_lines.

    read     table objbin index tab_lines.

    objpack-doc_size = ( tab_lines - 1 ) * 255 + strlen( objbin ).

    objpack-transf_bin = 'X'.

    objpack-head_start = 1.

    objpack-head_num   = 0.

    objpack-body_start = 1.

    objpack-body_num   = tab_lines.

    objpack-doc_type   = att_type.

    objpack-obj_name   = 'ATTACHMENT'.

    objpack-obj_descr  = 'Attached Document'.

    append objpack.

Regards

Appana

Former Member
0 Kudos

Hi,

Try this code.

you have to populate both packing_list and contents_bin internal tables before passing to the fm SO_NEW_DOCUMENT_ATT_SEND_API1

FORM CONVERT_OTF_TO_PDF TABLES OTFTAB STRUCTURE OTF.
  CLEAR: SOOD, W_LINES, CONTENT_IN, CONTENT_OUT.
  REFRESH: CONTENT_IN, CONTENT_OUT.

  DESCRIBE TABLE OTFTAB LINES W_LINES.
  SOOD-OBJLEN = W_LINES.
  REFRESH: CONTENT_IN, CONTENT_OUT.
  CLEAR: CONTENT_IN, CONTENT_OUT.
   CONTENT_IN[] = OTFTAB[].

    CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
         EXPORTING
              FORMAT_SRC      = 'OTF'
              FORMAT_DST      = 'PDF'
              DEVTYPE         = 'HPLJ5SI'
*         FUNCPARA        =
              LEN_IN          = SOOD-OBJLEN
*    IMPORTING
*         LEN_OUT         =
         TABLES
              CONTENT_IN      = CONTENT_IN
              CONTENT_OUT     = CONTENT_OUT
         EXCEPTIONS
              ERR_CONV_FAILED = 1
              OTHERS          = 2.
  REFRESH OBJBIN. CLEAR OBJBIN.
  IF GV_SUMMARY <> 'X'.
    OBJBIN[] = CONTENT_OUT[].
  ELSE.
    REFRESH CONTENT_OUT.
    CLEAR CONTENT_OUT.
  ENDIF.
  REFRESH: CONTENT_IN, OBJPACK.
  CLEAR: CONTENT_IN, OBJPACK.

  DOC_CHNG-OBJ_NAME = TEXT-003.
  IF SY-SYSID NE 'S4P'.
   IF DOC_CHNG-OBJ_DESCR IS  INITIAL.
      DOC_CHNG-OBJ_DESCR = TEXT-004.
    ELSE.
      IF GV_SUMMARY = 'X'.
       DOC_CHNG-OBJ_DESCR = TEXT-012.
      ENDIF.
    ENDIF.
  ENDIF.

  DESCRIBE TABLE OBJTXT LINES TAB_LINES.
  READ TABLE OBJTXT INDEX TAB_LINES.
  DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

* Fill the fields of the packing_list for the main document:

    CLEAR  OBJPACK.
    DESCRIBE TABLE OBJBIN LINES TAB_LINES.
   OBJPACK-TRANSF_BIN = 'X'.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM = 0.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM = TAB_LINES.
    OBJPACK-DOC_TYPE = 'XLS'.
    OBJPACK-OBJ_NAME = 'Attachment'.
    OBJPACK-OBJ_DESCR = C_PAYER.
    READ TABLE OBJBIN INDEX TAB_LINES.
    DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJBIN ).
    OBJPACK-DOC_SIZE = DOC_SIZE.
    APPEND OBJPACK.


    CLEAR  OBJPACK.
    DESCRIBE TABLE OBJBIN LINES TAB_LINES.
   OBJPACK-TRANSF_BIN = 'X'.
    OBJPACK-HEAD_START = 1.
    OBJPACK-HEAD_NUM = 0.
    OBJPACK-BODY_START = 1.
    OBJPACK-BODY_NUM = TAB_LINES.
    OBJPACK-DOC_TYPE = 'XLS'.
    OBJPACK-OBJ_NAME = 'Attachment'.
    OBJPACK-OBJ_DESCR = C_PAYER.
    READ TABLE OBJBIN INDEX TAB_LINES.
    DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJBIN ).
    OBJPACK-DOC_SIZE = DOC_SIZE.
    APPEND OBJPACK.


    REFRESH RECLIST.
    CLEAR RECLIST.
** get E-mail address
      IF NOT P_EMAIL IS INITIAL.
        RECIPIENT_INT-ADDRESS = P_EMAIL.
      ENDIF.
        RECLIST-RECEIVER = RECIPIENT_INT.
        RECLIST-REC_TYPE = 'U'.
        APPEND RECLIST.
*******************************************************************
* SEND THE DOCUMENT BY CALLING THE SAPOFFICE API1 MODULE
* FOR SENDING DOCUMENTS WITH ATTACHMENTS
******************************************************************

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       EXPORTING
            DOCUMENT_DATA              = DOC_CHNG
            PUT_IN_OUTBOX              = 'X'
       IMPORTING
            SENT_TO_ALL                = SENT_TO_ALL
       TABLES
            PACKING_LIST               = OBJPACK
            OBJECT_HEADER              = OBJHEAD
            CONTENTS_BIN               = OBJBIN
            CONTENTS_TXT               = OBJTXT
            RECEIVERS                  = RECLIST
       EXCEPTIONS
            TOO_MANY_RECEIVERS         = 1
            DOCUMENT_NOT_SENT          = 2
            OPERATION_NO_AUTHORIZATION = 4
           OTHERS                     = 99.

Regards,

Sailaja.