Skip to Content
avatar image
Former Member

sending mails from SAP with Report Attachment

Hi experts,

I have a requirement to send the mails with attachment

I have searched in the forum .

Now i am able to send mail with attachment but it is working for only TEXT display .

i need to send the report attachment

the attachment should be same as the report

in forum i have searched but for the attachment everyone is using compress but the TABLE_COMPRESS is giving runtime error

I am using below FM

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
exporting
document_data = lv_docchng
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = li_objpack
object_header = li_objhead
contents_bin = objbin
contents_txt = li_objtxt
receivers = li_reclist

Please tell me how to attach my report to this

Note: My report has 10 pages.

regards,

Sri

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Sep 02, 2008 at 06:08 AM

    HI ,

    check the code below.

    DATA:

    *v_spono LIKE tsp01-rqident,

    v_type LIKE soodk-objtp,

    i_pdflist LIKE tline OCCURS 0,

    • t_print TYPE slis_print_alv,

    jobname LIKE tbtcjob-jobname,

    jobcount LIKE tbtcjob-jobcount,

    numbytes TYPE i,

    pdfspoolid LIKE tsp01-rqident,

    jobname2 LIKE tbtcjob-jobname,

    jobcount2 LIKE tbtcjob-jobcount,

    i_compresslist LIKE soli OCCURS 0.

    DATA: pdf LIKE tline OCCURS 100 WITH HEADER LINE,

    objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

    *--convert into PDF

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    src_spoolid = v_spno

    no_dialog = ' '

    IMPORTING

    pdf_bytecount = numbytes

    pdf_spoolid = pdfspoolid

    btc_jobname = jobname2

    btc_jobcount = jobcount2

    TABLES

    pdf = pdf

    EXCEPTIONS

    err_no_abap_spooljob = 1

    err_no_spooljob = 2

    err_no_permission = 3

    err_conv_not_possible = 4

    err_bad_destdevice = 5

    user_cancelled = 6

    err_spoolerror = 7

    err_temseerror = 8

    err_btcjob_open_failed = 9

    err_btcjob_submit_failed = 10

    err_btcjob_close_failed = 11.

    IF sy-subrc <> 0.

    ENDIF.

    *-- change the width of the pdf table --

    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

    EXPORTING

    line_width_src = 134

    line_width_dst = 255

    TABLES

    content_in = pdf

    content_out = objbin

    EXCEPTIONS

    err_line_width_src_too_long = 1

    err_line_width_dst_too_long = 2

    err_conv_failed = 3

    OTHERS = 4.

    IF sy-subrc <> 0.

    ENDIF.

    *--declare the internal table for sending of mail

    data: li_objpack like sopcklsti1 occurs 2 with header line,

    li_objhead like solisti1 occurs 1 with header line,

    li_objbin like solisti1 occurs 0 with header line,

    li_objtxt like solisti1 occurs 10 with header line,

    li_reclist like somlreci1 occurs 10 with header line.

    data: lv_docchng like sodocchgi1,

    lv_tablines like sy-tabix.

    data: lv_report like trdir-name value 'RSCONN01',

    lv_text like solisti1-line.

    lv_docchng-obj_name = 'LIST'(l01).

    li_objtxt-line = 'Dear Sir / Madam,'.

    append li_objtxt.

    clear li_objtxt.

    append li_objtxt.

    li_objtxt-line = 'Please find attached Report '.

    append li_objtxt.

    clear li_objtxt.

    append li_objtxt.

    li_objtxt-line = 'Regards'.

    append li_objtxt.

    clear li_objtxt.

    append li_objtxt.

    describe table li_objtxt lines lv_tablines.

    read table li_objtxt index lv_tablines transporting all fields.

    lv_docchng-doc_size = ( lv_tablines - 1 ) * 255 + strlen( li_objtxt ).

    *---Object Pack

    • text content

    clear li_objpack-transf_bin.

    li_objpack-head_start = 1.

    li_objpack-head_num = 0.

    li_objpack-body_start = 1.

    li_objpack-body_num = lv_tablines.

    li_objpack-doc_type = 'RAW'.

    append li_objpack.

    • attachement

    describe table objbin lines lv_tablines.

    li_objpack-transf_bin = 'X'.

    li_objpack-head_start = 1.

    li_objpack-head_num = 0.

    li_objpack-body_start = 1.

    li_objpack-body_num = lv_tablines.

    li_objpack-doc_type = 'PDF'.

    li_objpack-obj_name = 'ATTACHMENT'(a01).

    li_objpack-obj_descr = SY-TITLE.

    li_objpack-doc_size = lv_tablines * 255 .

    append li_objpack.

    lv_docchng-obj_descr = sy-title.

    li_reclist-receiver = sy-uname.

    li_reclist-rec_type = 'B'.

    li_reclist-express = 'X'.

    append li_reclist.

    clear li_reclist.

    if li_reclist[] is initial.

    message i030(zgso).

    leave list-processing.

    endif. " IF li_reclist[] IS INITIAL

    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    exporting

    document_data = lv_docchng

    put_in_outbox = 'X'

    commit_work = 'X'

    tables

    packing_list = li_objpack

    object_header = li_objhead

    contents_bin = objbin

    contents_txt = li_objtxt

    receivers = li_reclist

    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 is initial.

    submit (lv_report) with mode = 'INT' and return .

    message 'Alert Sent' type 'S'.

    else.

    message id sy-msgid type sy-msgty number sy-msgno

    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    endif. " IF sy-subrc IS INITIAL

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 02, 2008 at 06:11 AM

    Hi...

    checkout this link...

    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

    regards

    vivek

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 02, 2008 at 06:57 AM

    Hi,

    Check below sample code.

      DATA: OBJECTHDCHANGE LIKE SOOD1    OCCURS 0 WITH HEADER LINE.
    
      DATA: LISTOBJECT LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.
      DATA  SO_ALI LIKE SOLI OCCURS 100 WITH HEADER LINE.
    
      DATA: LINENO TYPE I,
            LENGTH TYPE I,
            SIZE   TYPE I.
    
    * Get the current list into internal table
      CALL FUNCTION 'SAVE_LIST'
           EXPORTING
                LIST_INDEX         = 0
           TABLES
                LISTOBJECT         = 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             = LISTOBJECT
                OUT            = SO_ALI
           EXCEPTIONS
                COMPRESS_ERROR = 1
                OTHERS         = 2.
      IF SY-SUBRC NE 0.
        RAISE COMPRESS_ERROR.
      ENDIF.
    
      CLEAR OBJECTHDCHANGE.    
      DESCRIBE TABLE SO_ALI LINES LINENO.
      DESCRIBE FIELD SO_ALI LENGTH LENGTH.
      SIZE = LENGTH * LINENO.
      OBJECTHDCHANGE-OBJLEN = SIZE.
      OBJECTHDCHANGE-OBJLA  = SY-LANGU.
      OBJECTHDCHANGE-OBJNAM = 'List'.
    
     IF description IS INITIAL. 
      OBJECTHDCHANGE-OBJDES = SY-TITLE.
     ELSE.
      OBJECTHDCHANGE-OBJDES = description.
     ENDIF.
    
      OBJECTHDCHANGE-OBJPRI = '1'.
      OBJECTHDCHANGE-OBJSNS = 'O'.
    
    * Send email
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                OWNER            = SY-UNAME
                OBJECT_TYPE      = 'ALI'
                OBJECT_HD_CHANGE = OBJECTHDCHANGE
           TABLES
                OBJCONT          = SO_ALI
                RECEIVERS        = RECEIVERS
           EXCEPTIONS
                OTHERS           = 1.
      IF SY-SUBRC <> 0.
        RAISE EMAIL_ERROR.
      ENDIF.
    
       SUBMIT RSCONN01 USING SELECTION-SET 'INT' AND   ENDIF.
    
      CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.
    

    Thanks,

    Vinod.

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 02, 2008 at 07:08 AM

    Sai,

    No coding required.

    Just on report output screen list>send/save>office>give the recipient adress>recipitent type should be internet address>Press Shift+F8.this will send as attachement as it is as report shown in output.

    Amit.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Sai,

      To generate the spool id for your report....

      SUBMIT (p_repid) VIA SELECTION-SCREEN TO SAP-SPOOL WITHOUT SPOOL DYNPRO

      SPOOL PARAMETERS mstr_print_parms

      USING SELECTION-SET p_slset

      AND RETURN.

      report output to send the email , mention the attachment type as mentioned below...

      I_ATTACHMENT_TYPE = 'ALI'.

      For email code is as followed

      CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

      EXPORTING

      rqident = p_spoolno

      • FIRST_LINE = 1

      • LAST_LINE =

      • DESIRED_TYPE =

      • IMPORTING

      • REAL_TYPE =

      • SP_LANG =

      TABLES

      buffer = l_contents

      • BUFFER_PDF =

      • EXCEPTIONS

      • NO_SUCH_JOB = 1

      • JOB_CONTAINS_NO_DATA = 2

      • SELECTION_EMPTY = 3

      • NO_PERMISSION = 4

      • CAN_NOT_ACCESS = 5

      • READ_ERROR = 6

      • TYPE_NO_MATCH = 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.

      IF l_contents IS NOT INITIAL.

      CALL FUNCTION 'SO_SOLITAB_TO_SOLIXTAB'

      EXPORTING

      ip_solitab = l_contents

      IMPORTING

      ep_solixtab = contents_hex.

      • Create the send request

      TRY.

      l_send_request = cl_bcs=>create_persistent( ).

      • Create the main document

      l_doc = cl_document_bcs=>create_document(

      i_type = 'RAW'

      i_text = l_text

      i_subject = p_sub ).

      • Add attachment to document

      l_doc->add_attachment( i_attachment_type = I_ATTACHMENT_TYPE

      i_attachment_subject = p_doc

      • i_att_content_text = contents_text ).

      i_att_content_hex = contents_hex ).

      • Add document to send request

      l_send_request->set_document( l_doc ).

      • Add recipients to send request

      • LOOP AT s_to.

      l_recipient = cl_cam_address_bcs=>create_internet_address(

      p_email1-low ).

      l_send_request->add_recipient( i_recipient = l_recipient ).

      • Send email

      l_sent_all = l_send_request->send( ).

      IF sy-subrc NE 0.

      • MESSAGE e070.

      ELSE.

      • MESSAGE s074.

      ENDIF.

      CATCH cx_bcs INTO l_err.

      • MESSAGE e071 WITH l_err->error_type.

      ENDTRY.

      *

      • ENDIF.

      ENDIF.

      *ENDIF.

      commit work.

      hope this works, i have already implemented this , it is working fine.

      Thanks,

      Madhavi