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

SAP internal mail from buffer internal table

Hi All,

I want to send SAP internal mail with PDF attachment wherein, i take the data not from file in application server. I want to pass the data from internal table into PDF and then into mail as attachment.

Kindly advise.

Regards

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Feb 13, 2008 at 09:37 AM

    Hi,

    Pls follow the code below.

    REPORT ztest_vasu_main .

    PARAMETER: p_email1 LIKE usr02-bname

    DEFAULT 'CONRCD',

    p_sender LIKE usr02-bname

    DEFAULT 'CONRCD',

    p_delspl AS CHECKBOX.

    *DATA DECLARATION

    DATA: gd_recsize TYPE i.

    • Spool IDs

    TYPES: BEGIN OF t_tbtcp.

    INCLUDE STRUCTURE tbtcp.

    TYPES: END OF t_tbtcp.

    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,

    wa_tbtcp TYPE t_tbtcp.

    • Job Runtime Parameters

    DATA: gd_eventid LIKE tbtcm-eventid,

    gd_eventparm LIKE tbtcm-eventparm,

    gd_external_program_active LIKE tbtcm-xpgactive,

    gd_jobcount LIKE tbtcm-jobcount,

    gd_jobname LIKE tbtcm-jobname,

    gd_stepcount LIKE tbtcm-stepcount,

    gd_error TYPE sy-subrc,

    gd_reciever TYPE sy-subrc.

    DATA: w_recsize TYPE i.

    DATA: gd_subject LIKE sodocchgi1-obj_descr,

    it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    gd_sender_type LIKE soextreci1-adr_typ,

    gd_attachment_desc TYPE so_obj_nam,

    gd_attachment_name TYPE so_obj_des.

    • Spool to PDF conversions

    DATA: gd_spool_nr LIKE tsp01-rqident,

    gd_destination LIKE rlgrap-filename,

    gd_bytecount LIKE tst01-dsize,

    gd_buffer TYPE string.

    • Binary store for PDF

    DATA: BEGIN OF it_pdf_output OCCURS 0.

    INCLUDE STRUCTURE tline.

    DATA: END OF it_pdf_output.

    CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',

    c_no(1) TYPE c VALUE ' ',

    c_device(4) TYPE c VALUE 'LOCL'.

    DATA :wa_makt TYPE makt,

    it_makt TYPE TABLE OF makt.

    DATA :wa_tsp01 TYPE tsp01,

    it_tsp01 TYPE TABLE OF tsp01.

    DATA : it_pdf TYPE TABLE OF tline WITH HEADER LINE.

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

    *START-OF-SELECTION.

    START-OF-SELECTION.

    SELECT * UP TO 100 ROWS FROM makt INTO TABLE it_makt.

    PERFORM convert_pdf.

    PERFORM process_email.

    ----


    • FORM convert_pdf *

    ----


    • ........ *

    ----


    FORM convert_pdf.

    • NEW-PAGE PRINT ON.

    WRITE : 'Put the heading here' , /.

    LOOP AT it_makt INTO wa_makt.

    WRITE : / wa_makt-matnr , 10 wa_makt-maktx.

    ENDLOOP.

    NEW-PAGE PRINT OFF.

    SELECT rqident FROM tsp01 INTO TABLE it_tsp01

    WHERE rqclient = sy-mandt AND

    rqowner = sy-uname.

    SORT it_tsp01 BY rqident DESCENDING.

    READ TABLE it_tsp01 INTO wa_tsp01 INDEX 1.

    DATA size TYPE i.

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    src_spoolid = wa_tsp01-rqident

    no_dialog = 'X'

    • DST_DEVICE =

    • PDF_DESTINATION =

    IMPORTING

    pdf_bytecount = size

    • PDF_SPOOLID =

    • LIST_PAGECOUNT =

    • BTC_JOBNAME =

    • BTC_JOBCOUNT =

    TABLES

    pdf = it_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.

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

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

    ENDIF.

    • CALL FUNCTION 'GUI_DOWNLOAD'

    • EXPORTING

    • bin_filesize = size

    • filename = 'C:\try.pdf'

    • filetype = 'BIN'

    • APPEND = ' '

    • WRITE_FIELD_SEPARATOR = ' '

    • HEADER = '00'

    • TRUNC_TRAILING_BLANKS = ' '

    • WRITE_LF = 'X'

    • COL_SELECT = ' '

    • COL_SELECT_MASK = ' '

    • DAT_MODE = ' '

    • IMPORTING

    • FILELENGTH =

    • TABLES

    • data_tab = it_pdf

    • EXCEPTIONS

    • FILE_WRITE_ERROR = 1

    • NO_BATCH = 2

    • GUI_REFUSE_FILETRANSFER = 3

    • INVALID_TYPE = 4

    • NO_AUTHORITY = 5

    • UNKNOWN_ERROR = 6

    • HEADER_NOT_ALLOWED = 7

    • SEPARATOR_NOT_ALLOWED = 8

    • FILESIZE_NOT_ALLOWED = 9

    • HEADER_TOO_LONG = 10

    • DP_ERROR_CREATE = 11

    • DP_ERROR_SEND = 12

    • DP_ERROR_WRITE = 13

    • UNKNOWN_DP_ERROR = 14

    • ACCESS_DENIED = 15

    • DP_OUT_OF_MEMORY = 16

    • DISK_FULL = 17

    • DP_TIMEOUT = 18

    • FILE_NOT_FOUND = 19

    • DATAPROVIDER_EXCEPTION = 20

    • CONTROL_FLUSH_ERROR = 21

    • OTHERS = 22

    .

    • IF sy-subrc <> 0.

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

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

    • ENDIF.

    ENDFORM.

    ----


    • FORM process_email *

    ----


    FORM process_email.

    • DESCRIBE TABLE it_mess_att LINES gd_recsize.

    • CHECK gd_recsize > 0.

    PERFORM send_email USING p_email1.

    • perform send_email using p_email2.

    ENDFORM.

    ----


    • FORM send_email *

    ----


    • --> p_email *

    ----


    FORM send_email USING p_email.

    CHECK NOT ( p_email IS INITIAL ).

    REFRESH it_mess_bod.

    • Default subject matter

    gd_subject = 'Subject'.

    gd_attachment_desc = 'Attachname'.

    • CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.

    it_mess_bod = 'Message Body text, line 1'.

    APPEND it_mess_bod.

    it_mess_bod = 'Message Body text, line 2...'.

    APPEND it_mess_bod.

    • If no sender specified - default blank

    IF p_sender EQ space.

    gd_sender_type = space.

    ELSE.

    gd_sender_type = 'INT'.

    ENDIF.

    • Send file by email as .xls speadsheet

    PERFORM send_file_as_email_attachment

    TABLES it_mess_bod

    it_pdf

    USING p_email1

    'Example .xls documnet attachment'

    'PDF'

    gd_attachment_name

    gd_attachment_desc

    p_sender

    gd_sender_type

    CHANGING gd_error

    gd_reciever.

    ENDFORM.

    &----


    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT

    &----


    • Send email

    ----


    FORM send_file_as_email_attachment TABLES it_message

    it_attach

    USING p_email

    p_mtitle

    p_format

    p_filename

    p_attdescription

    p_sender_address

    p_sender_addres_type

    CHANGING p_error

    p_reciever.

    DATA: ld_error TYPE sy-subrc,

    ld_reciever TYPE sy-subrc,

    ld_mtitle LIKE sodocchgi1-obj_descr,

    ld_email LIKE somlreci1-receiver,

    ld_format TYPE so_obj_tp ,

    ld_attdescription TYPE so_obj_nam ,

    ld_attfilename TYPE so_obj_des ,

    ld_sender_address LIKE soextreci1-receiver,

    ld_sender_address_type LIKE soextreci1-adr_typ,

    ld_receiver LIKE sy-subrc.

    DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

    t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

    t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,

    w_cnt TYPE i,

    w_sent_all(1) TYPE c,

    w_doc_data LIKE sodocchgi1.

    ld_email = p_email.

    ld_mtitle = p_mtitle.

    ld_format = p_format.

    ld_attdescription = p_attdescription.

    ld_attfilename = p_filename.

    ld_sender_address = p_sender_address.

    ld_sender_address_type = p_sender_addres_type.

    • Fill the document data.

    w_doc_data-doc_size = 1.

    • Populate the subject/generic message attributes

    w_doc_data-obj_langu = sy-langu.

    w_doc_data-obj_name = 'SAPRPT'.

    w_doc_data-obj_descr = ld_mtitle .

    w_doc_data-sensitivty = 'F'.

    • Fill the document data and get size of attachment

    CLEAR w_doc_data.

    READ TABLE it_attach INDEX w_cnt.

    w_doc_data-doc_size =

    ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).

    w_doc_data-obj_langu = sy-langu.

    w_doc_data-obj_name = 'SAPRPT'.

    w_doc_data-obj_descr = ld_mtitle.

    w_doc_data-sensitivty = 'F'.

    CLEAR t_attachment.

    REFRESH t_attachment.

    t_attachment[] = it_attach[].

    • Describe the body of the message

    CLEAR t_packing_list.

    REFRESH t_packing_list.

    t_packing_list-transf_bin = space.

    t_packing_list-head_start = 1.

    t_packing_list-head_num = 0.

    t_packing_list-body_start = 1.

    DESCRIBE TABLE it_message LINES t_packing_list-body_num.

    t_packing_list-doc_type = 'RAW'.

    APPEND t_packing_list.

    • Create attachment notification

    t_packing_list-transf_bin = 'X'.

    t_packing_list-head_start = 1.

    t_packing_list-head_num = 1.

    t_packing_list-body_start = 1.

    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

    t_packing_list-doc_type = ld_format.

    t_packing_list-obj_descr = ld_attdescription.

    t_packing_list-obj_name = ld_attfilename.

    t_packing_list-doc_size = t_packing_list-body_num * 255.

    APPEND t_packing_list.

    • Add the recipients email address

    CLEAR t_receivers.

    REFRESH t_receivers.

    t_receivers-receiver = ld_email.

    t_receivers-rec_type = 'U'.

    • t_receivers-rec_type = 'B'.

    t_receivers-com_type = 'INT'.

    t_receivers-notif_del = 'X'.

    t_receivers-notif_ndel = 'X'.

    • T_receivers-sndex = 'X'.

    APPEND t_receivers.

    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

    EXPORTING

    document_data = w_doc_data

    put_in_outbox = 'X'

    sender_address = ld_sender_address

    sender_address_type = ld_sender_address_type

    commit_work = 'X'

    IMPORTING

    sent_to_all = w_sent_all

    TABLES

    packing_list = t_packing_list

    contents_bin = t_attachment

    contents_txt = it_message

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

    • Populate zerror return code

    ld_error = sy-subrc.

    • Populate zreceiver return code

    LOOP AT t_receivers.

    ld_receiver = t_receivers-retrn_code.

    ENDLOOP.

    ENDFORM.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 13, 2008 at 09:40 AM

    Hi,

    its only for background spooling. Execute the program in background.

    Pls let me know if you need foreground process.

    Regards

    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.