Skip to Content
avatar image
Former Member

How to send a ttachment with email.

Dear all ,

i have written the below code to send mails ..it is workiing fine

my problem is data to be shown in the mail is contained in itab

mailtxt77 .... but i want the data contained in this itab

to be sent as attachment ... how to do dat.

&----


*& Report ZTRANSPORTER_EMAIL *

*& *

&----


*& *

*& *

&----


REPORT ZTRANSPORTER_EMAIL .

data: maildata type sodocchgi1.

data: entries like sy-tabix.

data: newid like sofolenti1-object_id.

data: sent like sonv-flag.

data: BEGIN OF mailtxt OCCURS 0,

LINE(300),

END OF MAILTXT.

data: mailrec type table of SOMLRECI1 WITH HEADER LINE .

DATA : MAILREC1 type table of SOMLRECI1.

*data: mailrec type string.

data: lt_transporter like ztransporter occurs 0 with header line.

data: begin of lt_transporter2 occurs 0,

transporter(18),

end of lt_transporter2.

DATA : MAILTXT1(10),

MAILTXT2(30),

MAILTXT3(4),

MAILTXT4(18),

MAILTXT5(10),

MAILTXT6(35),

MAILTXT7(30),

MAILTXT8(40),

MAILTXT9(10),

MAILTXT10(5),

MAILTXT11(8),

MAILTXT12(10),

mail1 type string,

mail2 type string,

mail3 type string,

mail4 type string,

mail5 type string,

mail6 type string,

mail7 type string,

mail8 type string,

mail9 type string,

mail10 type string,

mail11 type string,

mail12 type string.

DATA : MAILTXT77 TYPE TABLE OF SOLISTI1 WITH HEADER LINE.

data: begin of lt_transporter1 occurs 0,

Sr_no(10),

transporter(30),

plant(4),

material(18),

VENDOR(10),

vendor_name(35),

vendor_place(30),

material_desc(40),

sched_agreement(10),

sched_line_item(5),

delivery_date(8),

delivery_qty(10),

end of lt_transporter1.

data: lt_email like ztrans_email occurs 0 with header line.

DATA: BEGIN OF MAILTXT13 OCCURS 0 ,

LINE(300),

END OF MAILTXT13.

data: var1 type i,

var2 type i,

var3 type i,

var4 type i,

var5 type i,

var6 type i,

var7 type i,

var8 type i,

var9 type i,

var10 type i,

var11 type i,

var12 type i.

start-of-selection.

clear: maildata, mailtxt, mailrec.

refresh: mailtxt. "mailrec.

select * from ztransporter into table lt_transporter.

select distinct transporter from ztransporter into table lt_transporter2

.

loop at lt_transporter.

move-corresponding lt_transporter to lt_transporter1.

append lt_transporter1.

clear lt_transporter1.

endloop.

if not lt_transporter[] is initial.

select * from ztrans_email into table lt_email

for all entries in lt_transporter

where transporter = lt_transporter-transporter.

endif.

loop at lt_transporter2.

maildata-obj_name = 'TEST'.

maildata-obj_descr = 'Test'.

maildata-obj_langu = sy-langu.

MAIL1 = ' SR NO -'.

MAIL2 = '-- -TRANSPORTER --


'.

mail3 = 'plant'.

mail4 = '-- -material ---'.

mail5 = ' -vendor '.

mail6 = '--


vendor_name--


'.

mail7 = '--


vendor_place--


'.

mail8 = '--


material_desc--


'.

mail9 = 'sched_agrt'.

mail10 = 'item-'.

mail11 = 'del. date'.

mail12 = '-del. qty-'.

concatenate mail1 ',' mail2 ',' mail3 ',' mail4 ',' mail5 ',' mail6 ','

mail7 ',' mail8 ',' mail9 ',' mail10 ',' mail11 ',' mail12 into

mailtxt77-line

separated by space.

*mailtxt = ' Srno Transporter plant material vendor vendorplace

*materialdesc schedagreement LINEITEM DELIVERYDATE DELIVERYQTY'.

append mailtxt77.

clear mailtxt77.

loop at lt_transporter1 where transporter = lt_transporter2-transporter.

*MOVE LT_TRANSPORTER1+(10) TO MAILTXT(10).

MAILTXT1 = LT_TRANSPORTER1+(10).

*MAILTXT33 = ' '.

var1 = strlen( mailtxt1 ).

var1 = 10 - var1.

shift mailtxt1 right by var1 places.

MAILTXT2 = LT_TRANSPORTER1+10(30).

var2 = strlen( mailtxt2 ).

var2 = 30 - var2.

shift mailtxt2 right by var2 places.

*

*concatenate mailtxt1 mailtxt2 into mailtxt13-line respecting blanks.

MAILTXT3 = LT_TRANSPORTER1+40(4).

var3 = strlen( mailtxt3 ).

var3 = 4 - var3.

shift mailtxt3 right by var3 places.

MAILTXT4 = LT_TRANSPORTER1+44(18).

var4 = strlen( mailtxt4 ).

var4 = 18 - var4.

shift mailtxt4 right by var4 places.

MAILTXT5 = LT_TRANSPORTER1+62(10).

var5 = strlen( mailtxt5 ).

var5 = 10 - var5.

shift mailtxt5 right by var5 places.

MAILTXT6 = LT_TRANSPORTER1+72(35).

var6 = strlen( mailtxt6 ).

var6 = 35 - var6.

shift mailtxt6 right by var6 places.

MAILTXT7 = LT_TRANSPORTER1+107(30).

var7 = strlen( mailtxt7 ).

var7 = 30 - var7.

shift mailtxt7 right by var7 places.

MAILTXT8 = LT_TRANSPORTER1+137(40).

var8 = strlen( mailtxt8 ).

var8 = 40 - var8.

shift mailtxt8 right by var8 places.

MAILTXT9 = LT_TRANSPORTER1+177(10).

var9 = strlen( mailtxt9 ).

var9 = 10 - var9.

shift mailtxt9 right by var9 places.

MAILTXT10 = LT_TRANSPORTER1+187(5).

var10 = strlen( mailtxt10 ).

var10 = 5 - var10.

shift mailtxt10 right by var10 places.

MAILTXT11 = LT_TRANSPORTER1+192(8).

var11 = strlen( mailtxt11 ).

var11 = 8 - var11.

shift mailtxt11 right by var11 places.

MAILTXT12 = LT_TRANSPORTER1+200(10).

var12 = strlen( mailtxt12 ).

var12 = 10 - var12.

shift mailtxt12 right by var12 places.

*CONCATENATE LT_TRANSPORTER1(10) LT_TRANSPORTER112(30)

*LT_TRANSPORTER142(4) LT_TRANSPORTER148(18)

*LT_TRANSPORTER166(10) LT_TRANSPORTER178(35)

*LT_TRANSPORTER1115(30) LT_TRANSPORTER1147(40)

*LT_TRANSPORTER1189(10) LT_TRANSPORTER1201(5)

*LT_TRANSPORTER1208(10) LT_TRANSPORTER1220(10) INTO MAILTXT-LINE.

CONCATENATE MAILTXT1 ',' MAILTXT2 ',' MAILTXT3 ',' MAILTXT4 ','

MAILTXT5 ','

MAILTXT6 ',' MAILTXT7 ',' MAILTXT8 ',' MAILTXT9 ',' MAILTXT10 ','

MAILTXT11

',' MAILTXT12 INTO MAILTXT77-LINE SEPARATED BY SPACE.

  • mailtxt = lt_transporter1.

append mailtxt77.

clear mailtxt77.

endloop.

clear lt_email.

read table lt_email with key transporter = lt_transporter2-transporter.

if sy-subrc = 0.

mailrec-receiver = lt_email-main_email.

mailrec = lt_email-main_email.

mailrec-rec_type = 'U'.

mailrec-com_type = 'INT'.

mailrec-notif_del = 'X'.

mailrec-notif_ndel = 'X'.

append mailrec.

*perform email.

clear mailrec.

if not lt_email-email2 = ''.

mailrec-receiver = lt_email-email2.

mailrec-rec_type = 'U'.

mailrec-com_type = 'INT'.

mailrec-notif_del = 'X'.

mailrec-notif_ndel = 'X'.

*mailrec = lt_email-email2.

  • perform email.

append mailrec.

clear mailrec.

endif.

if not lt_email-email3 = ''.

mailrec-receiver = lt_email-email3.

mailrec-rec_type = 'U'.

mailrec-com_type = 'INT'.

mailrec-notif_del = 'X'.

mailrec-notif_ndel = 'X'.

append mailrec.

*mailrec = lt_email-email3.

  • perform email.

clear mailrec.

endif.

if not lt_email-email4 = ''.

mailrec-receiver = lt_email-email4.

mailrec-rec_type = 'U'.

mailrec-com_type = 'INT'.

mailrec-notif_del = 'X'.

mailrec-notif_ndel = 'X'.

append mailrec.

*mailrec = lt_email-email4.

  • perform email.

clear mailrec.

endif.

if not lt_email-email5 = ''.

mailrec-receiver = lt_email-email5.

mailrec-rec_type = 'U'.

append mailrec.

mailrec = lt_email-email5.

  • perform email.

clear mailrec.

endif.

endif.

call function 'SO_NEW_DOCUMENT_SEND_API1'

exporting

document_data = maildata

document_type = 'RAW'

put_in_outbox = 'X'

commit_work = 'X'

importing

sent_to_all = sent

new_object_id = newid

tables

object_content = mailtxt77

receivers = mailrec

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.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    May 14, 2007 at 09:28 AM

    Hi Tarang Shah,

    <b>Check out the following examples and documentation - very useful

    FORM SEND_MAIL.

    DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

    DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

    DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

    DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

    DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

    DATA: DOC_CHNG LIKE SODOCCHGI1.

    DATA: TAB_LINES LIKE SY-TABIX.

    DATA L_NUM(3).

    • Creation of the document to be sent

    • File Name

    DOC_CHNG-OBJ_NAME = 'SENDFILE'.

    • Mail Subject

    DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.

    • Mail Contents

    OBJTXT = 'Object text'.

    APPEND OBJTXT.

    DESCRIBE TABLE OBJTXT LINES TAB_LINES.

    READ TABLE OBJTXT INDEX TAB_LINES.

    DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

    • Creation of the entry for the compressed document

    CLEAR OBJPACK-TRANSF_BIN.

    OBJPACK-HEAD_START = 1.

    OBJPACK-HEAD_NUM = 0.

    OBJPACK-BODY_START = 1.

    OBJPACK-BODY_NUM = TAB_LINES.

    OBJPACK-DOC_TYPE = 'RAW'.

    APPEND OBJPACK.

    • Creation of the document attachment

    LOOP AT ITAB_DATA.

    CONCATENATE ITAB_DATA-PRODUCTOR

    ITAB_DATA-VBELN

    ITAB_DATA-POSNR

    ITAB_DATA-MATNR INTO OBJBIN.

    APPEND OBJBIN.

    ENDLOOP.

    DESCRIBE TABLE OBJBIN LINES TAB_LINES.

    OBJHEAD = 'ORDERS'.

    APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

    OBJPACK-TRANSF_BIN = 'X'.

    OBJPACK-HEAD_START = 1.

    OBJPACK-HEAD_NUM = 1.

    OBJPACK-BODY_START = 1.

    OBJPACK-BODY_NUM = TAB_LINES.

    OBJPACK-DOC_TYPE = 'TXT'.

    OBJPACK-OBJ_NAME = 'WEBSITE'.

    OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.

    OBJPACK-DOC_SIZE = TAB_LINES * 255.

    APPEND OBJPACK.

    • Completing the recipient list

    • target recipent

    clear RECLIST.

    RECLIST-RECEIVER = 'test@here.com'.

    RECLIST-EXPRESS = 'X'.

    RECLIST-REC_TYPE = 'U'.

    APPEND RECLIST.

    • copy recipents

    clear RECLIST.

    RECLIST-RECEIVER = 'secondtest@here.com'.

    RECLIST-EXPRESS = 'X'.

    RECLIST-REC_TYPE = 'U'.

    RECLIST-COPY = 'X'.

    APPEND RECLIST.

    • Sending the document

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    DOCUMENT_DATA = DOC_CHNG

    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.

    ENDFORM. " SEND_MAIL

    Example 2:

    Check ut the following code for sending emails:

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    formname = 'Z_TEST'

    IMPORTING

    fm_name = v_fname.

    CALL FUNCTION v_fname

    EXPORTING

    control_parameters = x_ctrl_p

    IMPORTING

    job_output_info = x_output_data.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    format = 'PDF'

    max_linewidth = 134

    IMPORTING

    bin_filesize = v_size

    TABLES

    otf = x_output_data-otfdata

    lines = it_lines

    EXCEPTIONS

    err_max_linewidth = 1

    err_format = 2

    err_conv_not_possible = 3

    OTHERS = 4.

    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

    EXPORTING

    line_width_dst = 255

    TABLES

    content_in = it_lines

    content_out = it_soli

    EXCEPTIONS

    err_line_width_src_too_long = 1

    err_line_width_dst_too_long = 2

    err_conv_failed = 3

    OTHERS = 4.

    CALL FUNCTION 'FUNC_CONVERT_DATA_ODC01'

    EXPORTING

    iv_byte_mode = 'X'

    TABLES

    it_data = it_lines

    et_data = it_table.

    *-----To caluculate total number of lines of internal table

    DESCRIBE TABLE it_table LINES v_lines.

    *-----Create Message Body and Title and Description

    it_mess =

    'i have successfully converted smartform from otf format to pdf' .

    " and i have attached that in mail'.

    APPEND it_mess.

    wa_doc_data-obj_name = 'smartform'.

    wa_doc_data-expiry_dat = sy-datum + 10.

    wa_doc_data-obj_descr = 'smartform'.

    wa_doc_data-sensitivty = 'F'.

    wa_doc_data-doc_size = v_lines * 255.

    APPEND it_pcklist.

    *-----PDF Attachment

    it_pcklist-transf_bin = 'X'.

    it_pcklist-head_start = 1.

    it_pcklist-head_num = 0.

    it_pcklist-body_start = 1.

    it_pcklist-doc_size = v_lines_bin * 255 .

    it_pcklist-body_num = v_lines.

    it_pcklist-doc_type = 'PDF'.

    it_pcklist-obj_name = 'smartform'.

    it_pcklist-obj_descr = 'smart_desc'.

    it_pcklist-obj_langu = 'E'.

    it_pcklist-doc_size = v_lines * 255.

    APPEND it_pcklist.

    *-----Giving the receiver email-id

    CLEAR it_receivers.

    it_receivers-receiver = abcd@yahoo.com'.

    it_receivers-rec_type = 'U'.

    APPEND it_receivers.

    *-----Calling the function module to sending email

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = wa_doc_data

    put_in_outbox = 'X'

    commit_work = 'X'

    TABLES

    packing_list = it_pcklist

    contents_txt = it_mess

    contents_hex = it_table

    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.

    Check out these links for more information:

    http://www.geocities.com/mpioud/Z_EMAIL_ABAP_REPORT.html

    http://www.thespot4sap.com/Articles/SAP_Mail_SO_Object_Send.asp

    http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm>

    Good Luck and thanks

    AK

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 14, 2007 at 09:30 AM

    Hi

    See this

    Mailing with Attachment by ABAP Coding

    Refer this link:

    mail-with-attachment

    FORM send_list_to_basis .

    DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,

    lt_index TYPE sy-tabix,

    doc_type(3) TYPE c,

    descr LIKE it_objpack_basis-obj_descr,

    temp_data LIKE w_path,

    temp1 TYPE string,

    tab_lines TYPE i,

    langu(15) TYPE c,

    expirydate TYPE so_obj_edt,

    L_FILE1(100).

    CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.

    W_PATH-FILENAME = L_FILE1.

    APPEND w_path.

    CLEAR w_path.

    wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.

    wa_doc_chng-obj_langu = 'E'.

    wa_doc_chng-obj_expdat = sy-datum.

    CLEAR w_subject.

    CONCATENATE 'Please find attached document with list of users'

    'not logged on for 180 days for client' sy-mandt

    INTO w_subject SEPARATED BY space.

    it_objtxt_basis-line = w_subject.

    APPEND it_objtxt_basis.

    CLEAR it_objtxt_basis.

    it_objtxt_basis-line = text-004.

    APPEND it_objtxt_basis.

    CLEAR it_objtxt_basis.

    CLEAR w_tab_line.

    DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.

    READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.

    wa_doc_chng-doc_size =

    ( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).

    CLEAR it_objpack_basis-transf_bin.

    it_objpack_basis-head_start = 1.

    it_objpack_basis-head_num = 0.

    it_objpack_basis-body_start = 1.

    it_objpack_basis-body_num = w_tab_line.

    it_objpack_basis-doc_type = 'RAW'.

    APPEND it_objpack_basis.

    CLEAR it_objpack_basis.

    LOOP AT w_path.

    temp1 = w_path.

    descr = w_path.

    CALL FUNCTION 'STRING_REVERSE'

    EXPORTING

    string = descr

    lang = 'E'

    IMPORTING

    rstring = descr.

    CALL FUNCTION 'STRING_SPLIT'

    EXPORTING

    delimiter = '\'

    string = descr

    IMPORTING

    head = descr

    tail = temp_data.

    CALL FUNCTION 'STRING_REVERSE'

    EXPORTING

    string = descr

    lang = 'E'

    IMPORTING

    rstring = descr.

    CALL FUNCTION 'STRING_SPLIT'

    EXPORTING

    delimiter = '.'

    string = descr

    IMPORTING

    head = temp_data

    tail = doc_type.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = temp1

    filetype = 'BIN'

    header_length = 0

    read_by_line = 'X'

    replacement = '#'

    TABLES

    data_tab = it_upload.

    DESCRIBE TABLE it_upload LINES tab_lines.

    DESCRIBE TABLE it_objbin_basis LINES lt_index.

    lt_index = lt_index + 1.

    LOOP AT it_upload.

    wa_objbin_basis-line = it_upload-line.

    APPEND wa_objbin_basis TO it_objbin_basis.

    CLEAR wa_objbin_basis.

    ENDLOOP.

    it_objpack_basis-transf_bin = 'X'.

    it_objpack_basis-head_start = 0.

    it_objpack_basis-head_num = 0.

    it_objpack_basis-body_start = lt_index.

    it_objpack_basis-body_num = tab_lines.

    it_objpack_basis-doc_type = doc_type.

    it_objpack_basis-obj_descr = descr.

    it_objpack_basis-doc_size = tab_lines * 255.

    APPEND it_objpack_basis.

    CLEAR it_objpack_basis.

    ENDLOOP.

    it_reclist_basis-receiver = 'XXX@.com'.

    it_reclist_basis-rec_type = 'U'.

    APPEND it_reclist_basis.

    CLEAR it_reclist_basis.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = wa_doc_chng

    put_in_outbox = 'X'

    commit_work = 'X'

    TABLES

    packing_list = it_objpack_basis

    contents_txt = it_objtxt_basis

    contents_bin = it_objbin_basis

    receivers = it_reclist_basis

    EXCEPTIONS

    too_many_receivers = 1

    document_not_sent = 2

    operation_no_authorization = 4

    OTHERS = 99.

    IF sy-subrc EQ 0.

    SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

    ENDIF.

    ENDFORM. " send_list_to_basis

    Reward points if useful

    Regards

    Anji

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 14, 2007 at 09:31 AM

    Hi Tarang,

    Check this sample program

    REPORT zsendemail .

    PARAMETERS: psubject(40) type c default 'Hello',

    p_email(40) type c default 'test@sapdev.co.uk' .

    data: it_packing_list like sopcklsti1 occurs 0 with header line,

    it_contents like solisti1 occurs 0 with header line,

    it_receivers like somlreci1 occurs 0 with header line,

    it_attachment like solisti1 occurs 0 with header line,

    gd_cnt type i,

    gd_sent_all(1) type c,

    gd_doc_data like sodocchgi1,

    gd_error type sy-subrc.

    data: it_message type standard table of SOLISTI1 initial size 0

    with header line.

    START-OF-SELECTION.

    Perform populate_message_table.

    *Send email message, although is not sent from SAP until mail send

    *program has been executed(rsconn01)

    PERFORM send_email_message.

    *Instructs mail send program for SAPCONNECT to send email(rsconn01)

    perform initiate_mail_execute_program.

    form populate_message_table.

    Append 'Email line 1' to it_message.

    Append 'Email line 2' to it_message.

    Append 'Email line 3' to it_message.

    Append 'Email line 4' to it_message.

    endform. " POPULATE_MESSAGE_TABLE

    form send_email_message.

    • Fill the document data.

    gd_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    gd_doc_data-obj_langu = sy-langu.

    gd_doc_data-obj_name = 'SAPRPT'.

    gd_doc_data-obj_descr = psubject.

    gd_doc_data-sensitivty = 'F'.

    • Describe the body of the message

    clear it_packing_list.

    refresh it_packing_list.

    it_packing_list-transf_bin = space.

    it_packing_list-head_start = 1.

    it_packing_list-head_num = 0.

    it_packing_list-body_start = 1.

    describe table it_message lines it_packing_list-body_num.

    it_packing_list-doc_type = 'RAW'.

    append it_packing_list.

    • Add the recipients email address

    clear it_receivers.

    refresh it_receivers.

    it_receivers-receiver = p_email.

    it_receivers-rec_type = 'U'.

    it_receivers-com_type = 'INT'.

    it_receivers-notif_del = 'X'.

    it_receivers-notif_ndel = 'X'.

    append it_receivers.

    • Call the FM to post the message to SAPMAIL

    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

    document_data = gd_doc_data

    put_in_outbox = 'X'

    importing

    sent_to_all = gd_sent_all

    tables

    packing_list = it_packing_list

    contents_txt = it_message

    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.

    • Store function module return code

    gd_error = sy-subrc.

    • Get it_receivers return code

    loop at it_receivers.

    endloop.

    endform. " SEND_EMAIL_MESSAGE

    form initiate_mail_execute_program.

    wait up to 2 seconds.

    if gd_error eq 0.

    submit rsconn01 with mode = 'INT'

    with output = 'X'

    and return.

    endif.

    endform.

    Thanks,

    Vinay

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 14, 2007 at 02:02 PM

    dear all,

    i am now able to get attachments with the mail

    but there are 2 attachments

    1. . raw

    2. .ali - this attachment shows junk characters

    i need only one .html file as attachement

    if you can kindly find the fault in this code

    &----


    *& Report ZTRANSPORTER_EMAIL *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT ZTRANSPORTER_EMAIL .

    data: maildata type sodocchgi1.

    DATA:

    l_datum(10),

    ls_docdata TYPE sodocchgi1,

    lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

    lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

    lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

    lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,

    lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,

    lt_listobject TYPE TABLE OF abaplist WITH HEADER LINE,

    l_tab_lines TYPE i,

    l_att_type LIKE soodk-objtp.

    data: entries like sy-tabix.

    data: newid like sofolenti1-object_id.

    data: sent like sonv-flag.

    data: BEGIN OF mailtxt OCCURS 0,

    LINE(300),

    END OF MAILTXT.

    data: mailrec type table of SOMLRECI1 WITH HEADER LINE .

    DATA : MAILREC1 type table of SOMLRECI1.

    *data: mailrec type string.

    data: lt_transporter like ztransporter occurs 0 with header line.

    data: begin of lt_transporter2 occurs 0,

    transporter(18),

    end of lt_transporter2.

    DATA : MAILTXT1(10),

    MAILTXT2(30),

    MAILTXT3(4),

    MAILTXT4(18),

    MAILTXT5(10),

    MAILTXT6(35),

    MAILTXT7(30),

    MAILTXT8(40),

    MAILTXT9(10),

    MAILTXT10(5),

    MAILTXT11(8),

    MAILTXT12(10),

    mail1 type string,

    mail2 type string,

    mail3 type string,

    mail4 type string,

    mail5 type string,

    mail6 type string,

    mail7 type string,

    mail8 type string,

    mail9 type string,

    mail10 type string,

    mail11 type string,

    mail12 type string.

    DATA : MAILTXT77 TYPE TABLE OF SOLISTI1 WITH HEADER LINE.

    data: begin of lt_transporter1 occurs 0,

    Sr_no(10),

    transporter(30),

    plant(4),

    material(18),

    VENDOR(10),

    vendor_name(35),

    vendor_place(30),

    material_desc(40),

    sched_agreement(10),

    sched_line_item(5),

    delivery_date(8),

    delivery_qty(10),

    end of lt_transporter1.

    data: lt_email like ztrans_email occurs 0 with header line.

    DATA: BEGIN OF MAILTXT13 OCCURS 0 ,

    LINE(300),

    END OF MAILTXT13.

    data: var1 type i,

    var2 type i,

    var3 type i,

    var4 type i,

    var5 type i,

    var6 type i,

    var7 type i,

    var8 type i,

    var9 type i,

    var10 type i,

    var11 type i,

    var12 type i.

    start-of-selection.

    clear: maildata, mailtxt, mailrec.

    refresh: mailtxt. "mailrec.

    select * from ztransporter into table lt_transporter.

    select distinct transporter from ztransporter into table lt_transporter2

    .

    loop at lt_transporter.

    move-corresponding lt_transporter to lt_transporter1.

    append lt_transporter1.

    clear lt_transporter1.

    endloop.

    if not lt_transporter[] is initial.

    select * from ztrans_email into table lt_email

    for all entries in lt_transporter

    where transporter = lt_transporter-transporter.

    endif.

    loop at lt_transporter2.

    maildata-obj_name = 'TEST'.

    maildata-obj_descr = 'Test'.

    maildata-obj_langu = sy-langu.

    MAIL1 = ' SR NO -'.

    MAIL2 = '-- -TRANSPORTER --


    '.

    mail3 = 'plant'.

    mail4 = '-- -material ---'.

    mail5 = ' -vendor '.

    mail6 = '--


    vendor_name--


    '.

    mail7 = '--


    vendor_place--


    '.

    mail8 = '--


    material_desc--


    '.

    mail9 = 'sched_agrt'.

    mail10 = 'item-'.

    mail11 = 'del. date'.

    mail12 = '-del. qty-'.

    concatenate mail1 ',' mail2 ',' mail3 ',' mail4 ',' mail5 ',' mail6 ','

    mail7 ',' mail8 ',' mail9 ',' mail10 ',' mail11 ',' mail12 into

    mailtxt77-line

    separated by space.

    *mailtxt = ' Srno Transporter plant material vendor vendorplace

    *materialdesc schedagreement LINEITEM DELIVERYDATE DELIVERYQTY'.

    append mailtxt77.

    clear mailtxt77.

    loop at lt_transporter1 where transporter = lt_transporter2-transporter.

    *MOVE LT_TRANSPORTER1+(10) TO MAILTXT(10).

    MAILTXT1 = LT_TRANSPORTER1+(10).

    *MAILTXT33 = ' '.

    var1 = strlen( mailtxt1 ).

    var1 = 10 - var1.

    shift mailtxt1 right by var1 places.

    MAILTXT2 = LT_TRANSPORTER1+10(30).

    var2 = strlen( mailtxt2 ).

    var2 = 30 - var2.

    shift mailtxt2 right by var2 places.

    *

    *concatenate mailtxt1 mailtxt2 into mailtxt13-line respecting blanks.

    MAILTXT3 = LT_TRANSPORTER1+40(4).

    var3 = strlen( mailtxt3 ).

    var3 = 4 - var3.

    shift mailtxt3 right by var3 places.

    MAILTXT4 = LT_TRANSPORTER1+44(18).

    var4 = strlen( mailtxt4 ).

    var4 = 18 - var4.

    shift mailtxt4 right by var4 places.

    MAILTXT5 = LT_TRANSPORTER1+62(10).

    var5 = strlen( mailtxt5 ).

    var5 = 10 - var5.

    shift mailtxt5 right by var5 places.

    MAILTXT6 = LT_TRANSPORTER1+72(35).

    var6 = strlen( mailtxt6 ).

    var6 = 35 - var6.

    shift mailtxt6 right by var6 places.

    MAILTXT7 = LT_TRANSPORTER1+107(30).

    var7 = strlen( mailtxt7 ).

    var7 = 30 - var7.

    shift mailtxt7 right by var7 places.

    MAILTXT8 = LT_TRANSPORTER1+137(40).

    var8 = strlen( mailtxt8 ).

    var8 = 40 - var8.

    shift mailtxt8 right by var8 places.

    MAILTXT9 = LT_TRANSPORTER1+177(10).

    var9 = strlen( mailtxt9 ).

    var9 = 10 - var9.

    shift mailtxt9 right by var9 places.

    MAILTXT10 = LT_TRANSPORTER1+187(5).

    var10 = strlen( mailtxt10 ).

    var10 = 5 - var10.

    shift mailtxt10 right by var10 places.

    MAILTXT11 = LT_TRANSPORTER1+192(8).

    var11 = strlen( mailtxt11 ).

    var11 = 8 - var11.

    shift mailtxt11 right by var11 places.

    MAILTXT12 = LT_TRANSPORTER1+200(10).

    var12 = strlen( mailtxt12 ).

    var12 = 10 - var12.

    shift mailtxt12 right by var12 places.

    *CONCATENATE LT_TRANSPORTER1(10) LT_TRANSPORTER112(30)

    *LT_TRANSPORTER142(4) LT_TRANSPORTER148(18)

    *LT_TRANSPORTER166(10) LT_TRANSPORTER178(35)

    *LT_TRANSPORTER1115(30) LT_TRANSPORTER1147(40)

    *LT_TRANSPORTER1189(10) LT_TRANSPORTER1201(5)

    *LT_TRANSPORTER1208(10) LT_TRANSPORTER1220(10) INTO MAILTXT-LINE.

    CONCATENATE MAILTXT1 ',' MAILTXT2 ',' MAILTXT3 ',' MAILTXT4 ','

    MAILTXT5 ','

    MAILTXT6 ',' MAILTXT7 ',' MAILTXT8 ',' MAILTXT9 ',' MAILTXT10 ','

    MAILTXT11

    ',' MAILTXT12 INTO MAILTXT77-LINE SEPARATED BY SPACE.

    • mailtxt = lt_transporter1.

    append mailtxt77.

    clear mailtxt77.

    • Create receiver list

    **LOOP AT s_name.

    *lt_reclist-receiver = s_name-low.

    **lt_reclist-rec_type = 'B'.

    **APPEND lt_reclist.

    **ENDLOOP.

    • Send Message

    endloop.

    submit zreport with transporter = lt_transporter2-transporter

    exporting list to memory and return.

    *REFRESH LT_LISTOBJECT.

    CALL FUNCTION 'LIST_FROM_MEMORY'

    TABLES

    listobject = lt_listobject

    EXCEPTIONS

    not_found = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    • Error in function module &1

    MESSAGE ID '61' TYPE 'E' NUMBER '731'

    WITH 'LIST_FROM_MEMORY'.

    ENDIF.

    • Because listobject is of size RAW(1000)

    • and objbin is of size CHAR(255) we make this table copy

    CALL FUNCTION 'TABLE_COMPRESS'

    TABLES

    in = lt_listobject

    out = lt_objbin

    EXCEPTIONS

    compress_error = 1

    OTHERS = 2.

    IF sy-subrc <> 0.

    • Error in function module &1

    MESSAGE ID '61' TYPE 'E' NUMBER '731'

    WITH 'TABLE_COMPRESS'.

    ENDIF.

    ls_docdata-obj_name = 'USERS_LIST'.

    CONCATENATE 'List of Users' sy-sysid '-' l_datum "#EC *

    INTO ls_docdata-obj_descr SEPARATED BY space.

    • Main Text

    lt_objtxt = 'List of Users According to Logon Date' &

    ' and Password Change'. "#EC *

    APPEND lt_objtxt.

    • Write Packing List (Main)

    DESCRIBE TABLE lt_objtxt LINES l_tab_lines.

    READ TABLE lt_objtxt INDEX l_tab_lines.

    ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).

    CLEAR lt_objpack-transf_bin.

    lt_objpack-head_start = 1.

    lt_objpack-head_num = 0.

    lt_objpack-body_start = 1.

    lt_objpack-body_num = l_tab_lines.

    lt_objpack-doc_type = 'RAW'.

    APPEND lt_objpack.

    • Create Message Attachment

    • Write Packing List (Attachment)

    l_att_type = 'ALI'.

    DESCRIBE TABLE lt_objbin LINES l_tab_lines.

    READ TABLE lt_objbin INDEX l_tab_lines.

    lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).

    lt_objpack-transf_bin = 'X'.

    lt_objpack-head_start = 1.

    lt_objpack-head_num = 0.

    lt_objpack-body_start = 1.

    lt_objpack-body_num = l_tab_lines.

    lt_objpack-doc_type = l_att_type.

    lt_objpack-obj_name = 'ATTACHMENT'.

    lt_objpack-obj_descr = 'List_of_Users'. "#EC *

    APPEND lt_objpack.

    clear lt_email.

    read table lt_email with key transporter = lt_transporter2-transporter.

    if sy-subrc = 0.

    mailrec-receiver = lt_email-main_email.

    mailrec = lt_email-main_email.

    mailrec-rec_type = 'U'.

    • mailrec-com_type = 'INT'.

    • mailrec-notif_del = 'X'.

    • mailrec-notif_ndel = 'X'.

    append mailrec.

    *perform email.

    clear mailrec.

    if not lt_email-email2 = ''.

    mailrec-receiver = lt_email-email2.

    mailrec-rec_type = 'U'.

    mailrec-com_type = 'INT'.

    mailrec-notif_del = 'X'.

    mailrec-notif_ndel = 'X'.

    *mailrec = lt_email-email2.

    • perform email.

    append mailrec.

    clear mailrec.

    endif.

    if not lt_email-email3 = ''.

    mailrec-receiver = lt_email-email3.

    mailrec-rec_type = 'U'.

    mailrec-com_type = 'INT'.

    mailrec-notif_del = 'X'.

    mailrec-notif_ndel = 'X'.

    append mailrec.

    *mailrec = lt_email-email3.

    • perform email.

    clear mailrec.

    endif.

    if not lt_email-email4 = ''.

    mailrec-receiver = lt_email-email4.

    mailrec-rec_type = 'U'.

    mailrec-com_type = 'INT'.

    mailrec-notif_del = 'X'.

    mailrec-notif_ndel = 'X'.

    append mailrec.

    *mailrec = lt_email-email4.

    • perform email.

    clear mailrec.

    endif.

    if not lt_email-email5 = ''.

    mailrec-receiver = lt_email-email5.

    mailrec-rec_type = 'U'.

    append mailrec.

    mailrec = lt_email-email5.

    • perform email.

    clear mailrec.

    endif.

    endif.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = ls_docdata

    put_in_outbox = ''

    commit_work = 'X'

    TABLES

    packing_list = lt_objpack

    object_header = lt_objhead

    contents_bin = lt_objbin

    contents_txt = lt_objtxt

    receivers = MAILREC

    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.

    IF sy-subrc = 0.

    • Document sent

    MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.

    ELSE.

    • Document <&> could not be sent

    MESSAGE ID 'SO' TYPE 'S' NUMBER '023'

    WITH ls_docdata-obj_name.

    ENDIF.

    kindly help..

    APT POINTS WILL BE GIVEN..

    Add comment
    10|10000 characters needed characters exceeded