Skip to Content
avatar image
Former Member

sending SAP script output to email/

Hi all,

Had any one come accross a requirement like when ever a print button is clicked after giving the output type it has trigger a email with the output as a attachment.

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Jul 29, 2009 at 11:10 AM

    Hi,

    Refer to the code to send the pdf output as attachment.

    DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

    WITH HEADER LINE.

    DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

    WITH HEADER LINE.

    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,

    gd_error TYPE sy-subrc,

    gd_reciever TYPE sy-subrc.

    • Populate message body text

    perform populate_email_message_body.

    • Send file by email as .xls speadsheet

    PERFORM send_file_as_email_attachment

    tables it_message

    it_attach

    using p_email

    'Example .xls documnet attachment'

    'XLS'

    'filename'

    ' '

    ' '

    ' '

    changing gd_error

    gd_reciever.

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

    PERFORM initiate_mail_execute_program.

    FORM build_xls_data_table.

    CONSTANTS: con_cret TYPE c VALUE '0D', "OK for non Unicode

    con_tab TYPE c VALUE '09'. "OK for non Unicode

    CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'

    INTO it_attach SEPARATED BY con_tab.

    CONCATENATE con_cret it_attach INTO it_attach.

    APPEND it_attach.

    LOOP AT it_ekpo INTO wa_charekpo.

    CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp

    wa_charekpo-aedat wa_charekpo-matnr

    INTO it_attach SEPARATED BY con_tab.

    CONCATENATE con_cret it_attach INTO it_attach.

    APPEND it_attach.

    ENDLOOP.

    ENDFORM. " BUILD_XLS_DATA_TABLE

    &----


    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT

    &----


    • Send email

    ----


    FORM send_file_as_email_attachment tables pit_message

    pit_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.

    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 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 ).

    CLEAR t_attachment.

    REFRESH t_attachment.

    t_attachment[] = pit_attach[].

    DESCRIBE TABLE it_message LINES t_packing_list-body_num.

    t_packing_list-doc_type = 'RAW'.

    APPEND t_packing_list.

    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.

    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

    Hope it helps.

    Regards,

    Rajesh Kumar

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      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[] = pit_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-com_type = 'INT'.

      t_receivers-notif_del = 'X'.

      t_receivers-notif_ndel = '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.

      Regards,

      Rajesh Kumar

  • avatar image
    Former Member
    Jul 29, 2009 at 10:04 AM

    Hi,

    Transaction SOST will be holding the emails/Fax.

    chech d link, u will surely get the answer of ur query. This is very useful link,

    Sending SAP Script Output to Mail & Fax

    with regards,

    Mamta Kumari

    Edited by: Mamta Kumari on Jul 29, 2009 12:06 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 29, 2009 at 10:55 AM

    Hi,

    First you need to convert the script as PDF document as shown below.

    Hi,

    Refer to the following program.

    TABLES: likp, lips,itcpo.

    DATA: pdftab type standard TABLE OF tline,

    datab TYPE standard TABLE OF itcoo.

    itcpo-tdgetotf = 'X'.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    DEVICE = 'PRINTER'

    DIALOG = 'X'

    FORM = 'Z1989_PRAC'

    LANGUAGE = SY-LANGU

    OPTIONS = itcpo

    // call script using start_form and write_form.

    CALL FUNCTION 'END_FORM'

    IMPORTING

    RESULT = gi_ofc

    CALL FUNCTION 'CLOSE_FORM'

    TABLES

    OTFDATA = datab

    EXCEPTIONS

    UNOPENED = 1

    BAD_PAGEFORMAT_FOR_PRINT = 2

    SEND_ERROR = 3

    SPOOL_ERROR = 4

    CODEPAGE = 5

    OTHERS = 6

    .

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    FORMAT = 'PDF'

    IMPORTING

    BIN_FILESIZE = BINFILE

    TABLES

    otf = datab

    lines = pdftab

    *use if you want to see pdf output on front end i.e. in your desktop.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    BIN_FILESIZE = binfile

    filename = 'D:\MYFILE.PDF' //give the address where u want output.

    FILETYPE = 'BIN'

    tables

    data_tab = pdftab

    Regards

    Rajesh Kumar

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello dude,

      I dont want to c this in my front end i want to send this an attachment through email when the user opts the print button.

      Tnx,

      Joe