Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Steps for Mailing a Report

Hi,

How can i e-mail a list generated by the report?

Kindly explain me all de steps bcoz i am trying it and i am not recieving any mail ......

Cheers n regards,

Will.

Tags:
Former Member
Former Member replied

Hi Will

This is the sample code I used for the same purpose.

Hope this can be useful and give better idea for you.

TABLES: tsp01.

TYPES: BEGIN OF t_spool,

rqident TYPE tsp01-rqident,

END OF t_spool.

DATA: i_spool TYPE STANDARD TABLE OF t_spool,

wa_spool TYPE t_spool.

SELECT rqident FROM tsp01

INTO TABLE i_spool

WHERE rqowner = sy-uname.

SORT i_spool DESCENDING BY rqident.

LOOP AT i_spool INTO wa_spool.

ENDLOOP.

  • data: l_rqident type tsp01-rqident.

*

  • SELECT SINGLE rqident FROM tsp01 INTO l_rqident

  • WHERE rqowner = sy-uname.

  • DATA: l_spoolno LIKE tsp01-rqident VALUE '0000024884'.

TYPES: l_ty_tab_pdf TYPE tline OCCURS 0.

DATA: l_pdf TYPE l_ty_tab_pdf,

l_spool TYPE tsp01-rqident.

  • Type for binary attachment table.

TYPES: l_ty_tab_objbin TYPE solisti1 OCCURS 0.

DATA: l_objbin TYPE l_ty_tab_objbin.

  • l_spool = l_spoolno.

  • l_spool = l_rqident.

l_spool = wa_spool-rqident.

**/ Call the standard function

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF' "#EC ARGCHECKED

EXPORTING

src_spoolid = l_spool

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

  • IMPORTING

  • pdf_bytecount = numbytes

  • pdf_spoolid = pdfspoolid

    • LIST_PAGECOUNT =

  • btc_jobname = jobname

  • btc_jobcount = jobcount

TABLES

pdf = l_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

OTHERS = 12.

IF sy-subrc <> 0.

WRITE: / 'error', sy-subrc.

ENDIF.

**/ Convert the PDF format to the table type required for the

*attachment.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = l_pdf

t_target_tab = l_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

IF sy-subrc <> 0.

WRITE: / 'error', sy-subrc.

ENDIF.

TABLES : soli.

TABLES : zpsdsalrep.

DATA: v_email TYPE soli-line.

DATA: v_email1 TYPE soli-line.

DATA: l_adrnr LIKE kna1-adrnr.

DATA: l_objky TYPE nast-objky.

DATA: l_zzterrmg TYPE zpsdsalrep-zzterrmg.

DATA: l_zsupervisor TYPE zpsdsalrep-zsupervisor.

DATA: l_kunnr TYPE kna1-kunnr.

DATA: l_kunnr1 TYPE vbak-kunnr.

SELECT SINGLE kunnr FROM vbak INTO l_kunnr1

WHERE vbeln = nast-objky.

SELECT SINGLE adrnr FROM kna1 INTO l_adrnr

WHERE kunnr = l_kunnr1.

CHECK sy-subrc IS INITIAL.

SELECT SINGLE smtp_addr FROM adr6 INTO v_email

WHERE addrnumber = l_adrnr.

SELECT SINGLE zzterrmg FROM zpsdsalrep INTO l_zzterrmg

WHERE zzsalesrep = l_kunnr1.

SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor

WHERE zzterrmg = l_zzterrmg.

SELECT SINGLE kunnr FROM kna1 INTO l_kunnr

WHERE sortl = l_zsupervisor.

SELECT SINGLE adrnr FROM kna1 INTO l_adrnr

WHERE kunnr = l_kunnr.

CHECK sy-subrc IS INITIAL.

SELECT SINGLE smtp_addr FROM adr6 INTO v_email1

WHERE addrnumber = l_adrnr.

DATA: l_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE.

DATA: l_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: l_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.

DATA: l_doc_chng LIKE sodocchgi1.

DATA: l_objhead LIKE solisti1 OCCURS 0 WITH HEADER LINE.

DATA: l_tab_lines LIKE sy-tabix.

CONSTANTS: k_true TYPE boolean_flg VALUE 'X'.

DATA: l_mail TYPE somlreci1-receiver.

DATA: l_mail1 TYPE somlreci1-receiver.

DATA: k_mail2 TYPE somlreci1-receiver.

DATA: k_mail TYPE somlreci1-receiver.

l_mail = v_email.

l_mail1 = v_email1.

k_mail2 = text-006.

k_mail = text-007.

  • Creation of the document to be sent

  • File Name

l_doc_chng-obj_name = 'SENDFILE'.

  • Mail Subject

l_doc_chng-obj_descr = text-001.

  • Completing the recipient list

l_reclist-receiver = l_mail.

l_reclist-rec_type = 'U'.

APPEND l_reclist.

l_reclist-receiver = l_mail1.

l_reclist-rec_type = 'U'.

APPEND l_reclist.

l_reclist-receiver = k_mail.

l_reclist-rec_type = 'U'.

APPEND l_reclist.

l_reclist-receiver = k_mail2.

l_reclist-rec_type = 'U'.

APPEND l_reclist.

  • Mail Contents

l_objtxt = text-002.

APPEND l_objtxt.

CLEAR l_objtxt. " put in a blank line

APPEND l_objtxt.

l_objtxt = text-003.

APPEND l_objtxt.

l_objtxt = text-004 .

APPEND l_objtxt.

  • Calculate email size in bytes

DESCRIBE TABLE l_objtxt LINES l_tab_lines.

READ TABLE l_objtxt INDEX l_tab_lines.

l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_objtxt ).

  • Creation of the entry for the compressed document

  • for the email text

CLEAR l_objpack-transf_bin.

l_objpack-head_start = 1.

l_objpack-head_num = 0.

l_objpack-body_start = 1.

l_objpack-body_num = l_tab_lines.

l_objpack-doc_type = 'RAW'.

APPEND l_objpack.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

DESCRIBE TABLE l_objbin LINES l_tab_lines.

l_objhead = text-001 .

APPEND l_objhead.

CLEAR l_objpack.

**/ Creation of the entry for the compressed/attached document

l_objpack-transf_bin = k_true.

l_objpack-head_start = 1.

l_objpack-head_num = 1.

l_objpack-body_start = 1.

l_objpack-body_num = l_tab_lines.

l_objpack-doc_type = 'PDF'.

l_objpack-obj_name = text-005.

l_objpack-obj_descr = text-001.

l_objpack-doc_size = l_tab_lines * 255.

APPEND l_objpack. "/ .

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' "/ .

EXPORTING

document_data = l_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = l_objpack

object_header = l_objhead

contents_bin = l_objbin

contents_txt = l_objtxt

receivers = l_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc <> 0.

WRITE: / 'unsuccessful', sy-subrc.

ELSE.

WRITE: / 'successful'.

ENDIF.

**/Take_note it is a requirement to do a commit work for the

  • email to go into transaction SOST.

COMMIT WORK. "/Take_note .

Regards,

Sree

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question