Skip to Content
author's profile photo Former Member
Former Member

send internal table data to an aexternal email like gmail,yahoo.....

Hi,

can any one help me how to send the internal table data in a report to

external EMAIL like yahoo,gmail and ............. waiting for ur reply

thanks raja reddy.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 18, 2008 at 05:53 AM

    check the following sample program and also its easy to understand.

    REPORT zvenkat_mail_xls_attach.

    ----


    " Data retrieval related declarations

    ----


    TYPES:

    BEGIN OF t_emp_dat,

    pernr TYPE pa0001-pernr,

    persg TYPE pa0001-persg,

    persk TYPE pa0001-persk,

    plans TYPE pa0001-plans,

    stell TYPE pa0001-stell,

    END OF t_emp_dat.

    DATA:

    w_emp_data TYPE t_emp_dat.

    DATA:

    i_emp_data TYPE STANDARD TABLE OF t_emp_dat.

    ----


    " Mail related declarations

    ----


    "Variables

    DATA :

    g_sent_to_all TYPE sonv-flag,

    g_tab_lines TYPE i.

    "Types

    TYPES:

    t_document_data TYPE sodocchgi1,

    t_packing_list TYPE sopcklsti1,

    t_attachment TYPE solisti1,

    t_body_msg TYPE solisti1,

    t_receivers TYPE somlreci1.

    "Workareas

    DATA :

    w_document_data TYPE t_document_data,

    w_packing_list TYPE t_packing_list,

    w_attachment TYPE t_attachment,

    w_body_msg TYPE t_body_msg,

    w_receivers TYPE t_receivers.

    "Internal Tables

    DATA :

    i_document_data TYPE STANDARD TABLE OF t_document_data,

    i_packing_list TYPE STANDARD TABLE OF t_packing_list,

    i_attachment TYPE STANDARD TABLE OF t_attachment,

    i_body_msg TYPE STANDARD TABLE OF t_body_msg,

    i_receivers TYPE STANDARD TABLE OF t_receivers.

    ----


    "Start-of-selection.

    ----


    START-OF-SELECTION.

    PERFORM get_data.

    PERFORM build_xls_data_table.

    ----


    "End-of-selection.

    ----


    END-OF-SELECTION.

    PERFORM send_mail.

    &----


    "Form get_data from PA0001

    &----


    FORM get_data.

    SELECT pernr

    persg

    persk

    plans

    stell

    FROM pa0001

    INTO CORRESPONDING FIELDS OF TABLE i_emp_data

    UP TO 4 ROWS.

    ENDFORM. " get_data

    &----


    "Form build_xls_data_table

    &----


    FORM build_xls_data_table.

    "If you have Unicode check active in program attributes then

    "you will need to declare constants as follows.

    CLASS cl_abap_char_utilities DEFINITION LOAD.

    CONSTANTS:

    con_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,

    con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.

    CONCATENATE 'PERNR' 'PERSG' 'PERSK' 'PLANS' 'STELL'

    INTO w_attachment

    SEPARATED BY con_tab.

    CONCATENATE con_cret

    w_attachment

    INTO w_attachment.

    APPEND w_attachment TO i_attachment.

    CLEAR w_attachment.

    LOOP AT i_emp_data INTO w_emp_data.

    CONCATENATE w_emp_data-pernr

    w_emp_data-persg

    w_emp_data-persk

    w_emp_data-plans

    w_emp_data-stell

    INTO w_attachment

    SEPARATED BY con_tab.

    CONCATENATE con_cret w_attachment

    INTO w_attachment.

    APPEND w_attachment TO i_attachment.

    CLEAR w_attachment.

    ENDLOOP.

    ENDFORM. "build_xls_data_table

    &----


    "Form send_mail

    "----


    "PACKING LIST

    "This table requires information about how the data in the

    "tables OBJECT_HEADER, CONTENTS_BIN and CONTENTS_TXT are to

    "be distributed to the documents and its attachments.The first

    "row is for the document, the following rows are each for one

    "attachment.

    &----


    FORM send_mail .

    "Subject of the mail.

    w_document_data-obj_name = 'MAIL_TO_HEAD'.

    w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

    "Body of the mail

    PERFORM build_body_of_mail

    USING:space,

    'Hi,',

    'I am fine. How are you? How are you doing ? ',

    'This program has been created to send simple mail',

    'with Subject,Body with Address of the sender. ',

    'Regards,',

    'Venkat.O,',

    'SAP HR Technical Consultant.'.

    "Write Packing List for Body

    DESCRIBE TABLE i_body_msg LINES g_tab_lines.

    w_packing_list-head_start = 1.

    w_packing_list-head_num = 0.

    w_packing_list-body_start = 1.

    w_packing_list-body_num = g_tab_lines.

    w_packing_list-doc_type = 'RAW'.

    APPEND w_packing_list TO i_packing_list.

    CLEAR w_packing_list.

    "Write Packing List for Attachment

    w_packing_list-transf_bin = 'X'.

    w_packing_list-head_start = 1.

    w_packing_list-head_num = 1.

    w_packing_list-body_start = 1.

    DESCRIBE TABLE i_attachment LINES w_packing_list-body_num.

    w_packing_list-doc_type = 'XLS'.

    w_packing_list-obj_descr = 'Excell Attachment'.

    w_packing_list-obj_name = 'XLS_ATTACHMENT'.

    w_packing_list-doc_size = w_packing_list-body_num * 255.

    APPEND w_packing_list TO i_packing_list.

    CLEAR w_packing_list.

    "Fill the document data and get size of attachment

    w_document_data-obj_langu = sy-langu.

    READ TABLE i_attachment INTO w_attachment INDEX g_tab_lines.

    w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN(

    w_attachment ).

    "Receivers List.

    w_receivers-rec_type = 'U'. "Internet address

    w_receivers-receiver = 'enter the email id'.

    w_receivers-com_type = 'INT'.

    w_receivers-notif_del = 'X'.

    w_receivers-notif_ndel = 'X'.

    APPEND w_receivers TO i_receivers .

    CLEAR:w_receivers.

    "Function module to send mail to Recipients

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = w_document_data

    put_in_outbox = 'X'

    commit_work = 'X'

    IMPORTING

    sent_to_all = g_sent_to_all

    TABLES

    packing_list = i_packing_list

    contents_bin = i_attachment

    contents_txt = i_body_msg

    receivers = i_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.

    IF sy-subrc = 0 .

    MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.

    ELSE.

    WAIT UP TO 2 SECONDS.

    "This program starts the SAPconnect send process.

    SUBMIT rsconn01 WITH mode = 'INT'

    WITH output = 'X'

    AND RETURN.

    ENDIF.

    ENDFORM. " send_mail

    &----


    " Form build_body_of_mail

    &----


    FORM build_body_of_mail USING l_message.

    w_body_msg = l_message.

    APPEND w_body_msg TO i_body_msg.

    CLEAR w_body_msg.

    ENDFORM. " build_body_of_mail

    In this field in this program write ur mail id----


    w_receivers-receiver

    Thanks,

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Raja,

      Did u check the sy-subrc after calling the FM. If it is 0 then go to transaction SOST. It must be under waiting(With yellow icon). If not zero then there is some problem with code.

      If yes then put below code to send the mail immediately.

          SUBMIT rsconn01 USING SELECTION-SET lc_mode AND RETURN.
          CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.
      

      From SOST do like this to send the mails

      Menu=>Utilities=>Start send process. Give INT in transaction method.and enter. It will send all the mails.

      Thanks,

      Vinod.

      Edited by: Vinod Reddy Vemuru on Jul 24, 2008 3:14 PM

  • author's profile photo Former Member
    Former Member
    Posted on Jul 18, 2008 at 05:58 AM

    data: p_email type somlreci1-receiver

    value 'MAIL ID'.

    data: tmara type mara occurs 0 with header line.

    data: imessage type standard table of solisti1 with header line,

    iattach type standard table of solisti1 with header line,

    ipacking_list like sopcklsti1 occurs 0 with header line,

    ireceivers like somlreci1 occurs 0 with header line,

    iattachment like solisti1 occurs 0 with header line.

    start-of-selection.

    select * into table tmara from mara up to 50 rows.

    • Populate table with detaisl to be entered into .xls file

    perform build_xls_data .

    • Populate message body text

    clear imessage. refresh imessage.

    imessage = 'Please find attached excel file'.

    append imessage.

    • Send file by email as .xls speadsheet

    perform send_email_with_xls tables imessage

    iattach

    using p_email

    'Example Excel Attachment'

    'XLS'

    'TestFileName'

    'CompanyCodes'.

    ************************************************************************

    • Form BUILD_XLS_DATA

    ************************************************************************

    form build_xls_data .

    • constants: con_cret type x value '0D', "OK for non Unicode

    • con_tab type x value '09'. "OK for non Unicode

    *If you have Unicode check active in program attributes thnen you will

    *need to declare constants as follows

    *class cl_abap_char_utilities definition load.

    constants:

    con_tab type c value cl_abap_char_utilities=>horizontal_tab,

    con_cret type c value cl_abap_char_utilities=>cr_lf.

    concatenate 'MATNR'

    'ERSDA'

    'ERNAM'

    'LAEDA'

    'AENAM'

    'VPSTA'

    'PSTAT'

    'LVORM'

    'MTART'

    'MBRSH'

    'MATKL'

    'BISMT'

    'MEINS'

    'BSTME'

    'ZEINR'

    'ZEIAR'

    'ZEIVR'

    'ZEIFO'

    'AESZN'

    'BLATT'

    'BLANZ'

    'FERTH'

    'FORMT'

    'GROES'

    'WRKST'

    'NORMT'

    'LABOR'

    'EKWSL'

    *'BRGEW'

    *'NTGEW'

    'GEWEI'

    *'VOLUM'

    'VOLEH'

    'BEHVO'

    'RAUBE'

    'TEMPB'

    'DISST'

    'TRAGR'

    'STOFF'

    'SPART'

    'KUNNR'

    'EANNR'

    *'WESCH'

    'BWVOR'

    'BWSCL'

    'SAISO'

    'ETIAR'

    'ETIFO'

    'ENTAR'

    'EAN11'

    'NUMTP'

    *'LAENG'

    into iattach separated by con_tab.

    concatenate con_cret iattach into iattach.

    append iattach.

    loop at tmara .

    concatenate tmara-matnr tmara-ersda

    tmara-ernam

    tmara-laeda

    tmara-aenam

    tmara-vpsta

    tmara-pstat

    tmara-lvorm

    tmara-mtart

    tmara-mbrsh

    tmara-matkl

    tmara-bismt

    tmara-meins

    tmara-bstme

    tmara-zeinr

    tmara-zeiar

    tmara-zeivr

    tmara-zeifo

    tmara-aeszn

    tmara-blatt

    tmara-blanz

    tmara-ferth

    tmara-formt

    tmara-groes

    tmara-wrkst

    tmara-normt

    tmara-labor

    tmara-ekwsl

    *tmara-BRGEW

    *tmara-NTGEW

    tmara-gewei

    *tmara-VOLUM

    tmara-voleh

    tmara-behvo

    tmara-raube

    tmara-tempb

    tmara-disst

    tmara-tragr

    tmara-stoff

    tmara-spart

    tmara-kunnr

    tmara-eannr

    *tmara-WESCH

    tmara-bwvor

    tmara-bwscl

    tmara-saiso

    tmara-etiar

    tmara-etifo

    tmara-entar

    tmara-ean11

    tmara-numtp

    *tmara-LAENG

    into iattach separated by con_tab.

    concatenate con_cret iattach into iattach.

    append iattach.

    endloop .

    endform.

    ************************************************************************

    • Form SEND_EMAIL_WITH_XLS

    ************************************************************************

    form send_email_with_xls tables pit_message

    pit_attach

    using p_email

    p_mtitle

    p_format

    p_filename

    p_attdescription.

    data: xdocdata like sodocchgi1,

    xcnt type i.

    • Fill the document data.

    xdocdata-doc_size = 1.

    • Populate the subject/generic message attributes

    xdocdata-obj_langu = sy-langu .

    xdocdata-obj_name = 'SAPRPT' .

    xdocdata-obj_descr = p_mtitle .

    • Fill the document data and get size of attachment

    clear xdocdata.

    read table iattach index xcnt.

    xdocdata-doc_size =

    ( xcnt - 1 ) * 255 + strlen( iattach ).

    xdocdata-obj_langu = sy-langu.

    xdocdata-obj_name = 'SAPRPT'.

    xdocdata-obj_descr = p_mtitle.

    clear iattachment. refresh iattachment.

    iattachment[] = pit_attach[].

    • Describe the body of the message

    clear ipacking_list. refresh ipacking_list.

    ipacking_list-transf_bin = space.

    ipacking_list-head_start = 1.

    ipacking_list-head_num = 0.

    ipacking_list-body_start = 1.

    describe table imessage lines ipacking_list-body_num.

    ipacking_list-doc_type = 'RAW'.

    append ipacking_list.

    • Create attachment notification

    ipacking_list-transf_bin = 'X'.

    ipacking_list-head_start = 1.

    ipacking_list-head_num = 1.

    ipacking_list-body_start = 1.

    describe table iattachment lines ipacking_list-body_num.

    ipacking_list-doc_type = p_format.

    ipacking_list-obj_descr = p_attdescription.

    ipacking_list-obj_name = p_filename.

    ipacking_list-doc_size = ipacking_list-body_num * 255.

    append ipacking_list.

    • Add the recipients email address

    clear ireceivers. refresh ireceivers.

    ireceivers-receiver = p_email.

    ireceivers-rec_type = 'U'.

    ireceivers-com_type = 'INT'.

    ireceivers-notif_del = 'X'.

    ireceivers-notif_ndel = 'X'.

    append ireceivers.

    ireceivers-receiver = 'xxxMAILID(GMAIL)'.

    ireceivers-rec_type = 'U'.

    ireceivers-com_type = 'INT'.

    ireceivers-notif_del = 'X'.

    ireceivers-notif_ndel = 'X'.

    append ireceivers.

    call function 'SO_DOCUMENT_SEND_API1'

    exporting

    document_data = xdocdata

    put_in_outbox = 'X'

    commit_work = 'X'

    tables

    packing_list = ipacking_list

    contents_bin = iattachment

    contents_txt = imessage

    receivers = ireceivers

    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.

    endform.

    this report will help u...........

    Before posting PlZ search in forums

    Regards

    Anbu

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 18, 2008 at 06:02 AM

    Use SO_NEW_DOCUMENT_ATT_SEND_API1

    for code

    http://www.sap-img.com/fu016.htm

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 24, 2008 at 10:04 AM

    Hello Raja,

    Please try the following code..

    After executing it, gotto tcode, SOST and clear all the previous mails which are in the queue and place your new transmission request in it.

    Continue pressing F8 until it clears from the queue.

    report yh_email1.
    data: email type somlreci1-receiver value '<email id>'.
    data: sender type SOEXTRECI1-RECEIVER value 'SAPDEV02'.
    
    data: imessage type standard table of solisti1 with header line,
    iattach type standard table of solisti1 with header line,
    ipacking_list like sopcklsti1 occurs 0 with header line,
    ireceivers like somlreci1 occurs 0 with header line.
    
    start-of-selection.
    
    clear imessage. refresh imessage.
    imessage = 'This is a mail from SAP ECC6'.
    append imessage.
    imessage = 'Thanks and Regards'.
    append imessage.
    imessage = 'Indu'.
    append imessage.
    
    perform send_email tables imessage
    using email
    'Mail from Indu'.
    
    ***********************************************************************
    *
    
    * Form SEND_EMAIL
    
    ***********************************************************************
    *
    form send_email tables pit_message
    using email
    p_mtitle.
    
    data: xdocdata like sodocchgi1,
    xcnt type i.
    
    * Fill the document data.
    
    xdocdata-doc_size = 1.
    
    * Populate the subject/generic message attributes
    
    xdocdata-obj_langu = sy-langu .
    xdocdata-obj_name = 'SAPRPT' .
    xdocdata-obj_descr = p_mtitle .
    
    
    clear ipacking_list. refresh ipacking_list.
    ipacking_list-transf_bin = space.
    ipacking_list-head_start = 1.
    ipacking_list-head_num = 0.
    ipacking_list-body_start = 1.
    describe table imessage lines ipacking_list-body_num.
    ipacking_list-doc_type = 'RAW'.
    append ipacking_list.
    
    
    clear ireceivers.
    refresh ireceivers.
    ireceivers-receiver = email.
    ireceivers-rec_type = 'U'.
    
    append ireceivers.
    call function 'SO_DOCUMENT_SEND_API1'
    exporting
    document_data = xdocdata
    put_in_outbox = 'X'
    SENDER_ADDRESS = SENDER
    commit_work = 'X'
    tables
    packing_list = ipacking_list
    contents_txt = imessage
    receivers = ireceivers
    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.
    
    endform.

    Hope it helps you

    Regards

    Indu.

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Can u try to send the mail to ur company ID? If it is coming then there must be something to do with configuration settings. Probably ur BASIS has access to it.

      U can check these settings in transaction SCOT.

      Also u did not tell what is the sy-subrc after calling mail FM

      Did u check transaction SOST too where all the mails are stored.

      I have checked this code and is working fine in my system.

      Copy paste my code, Debug and see what is happening.

      Thanks,

      Vinod.

  • author's profile photo Former Member
    Former Member
    Posted on Jul 24, 2008 at 10:26 AM
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.