Skip to Content
avatar image
Former Member

Send Email with pdf as attachment

Hi,

We have a requirement where we need to send email to an external xyz@abc.com address with a pdf as an attachment.

I have following queries with regard to this requirement:

1. After converting spool to pdf is it required to store pdf document at some location on application/presentation server so that it can be attached to the outgoing email, Or it is can be attached to an outgoing email without saving it.

2. I need some more info on how to use the function module SO_NEW_DOCUMENT_SEND_API1 to send email. ( I hope I have identified the correct Function Module to send email).

Note: Please do not copy paste any code from the net in your answer. I need to understand on how to use the FM.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 25, 2008 at 07:09 AM

    Hi

    The code below demonstrates how to send an email to an external email address

    where the data is stored within a .xls attachment.

    &----


    *& Report ZEMAIL_ATTACH *

    *& *

    &----


    *& Example of sending external email via SAPCONNECT *

    *& *

    &----


    REPORT ZEMAIL_ATTACH .

    TABLES: ekko.

    PARAMETERS: p_email TYPE somlreci1-receiver

    DEFAULT 'test@sapdev.co.uk'.

    TYPES: BEGIN OF t_ekpo,

    ebeln TYPE ekpo-ebeln,

    ebelp TYPE ekpo-ebelp,

    aedat TYPE ekpo-aedat,

    matnr TYPE ekpo-matnr,

    END OF t_ekpo.

    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,

    wa_ekpo TYPE t_ekpo.

    TYPES: BEGIN OF t_charekpo,

    ebeln(10) TYPE c,

    ebelp(5) TYPE c,

    aedat(8) TYPE c,

    matnr(18) TYPE c,

    END OF t_charekpo.

    DATA: wa_charekpo TYPE t_charekpo.

    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.

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

    *START_OF_SELECTION

    START-OF-SELECTION.

    • Retrieve sample data from table ekpo

    PERFORM data_retrieval.

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

    PERFORM build_xls_data_table.

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

    *END-OF-SELECTION

    END-OF-SELECTION.

    • 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 DATA_RETRIEVAL

    &----


    • Retrieve data form EKPO table and populate itab it_ekko

    ----


    FORM data_retrieval.

    SELECT ebeln ebelp aedat matnr

    UP TO 10 ROWS

    FROM ekpo

    INTO TABLE it_ekpo.

    ENDFORM. " DATA_RETRIEVAL

    &----


    *& Form BUILD_XLS_DATA_TABLE

    &----


    • Build data table for .xls document

    ----


    FORM build_xls_data_table.

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

    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[] = 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.

    • Populate zerror return code

    ld_error = sy-subrc.

    • Populate zreceiver return code

    LOOP AT t_receivers.

    ld_receiver = t_receivers-retrn_code.

    ENDLOOP.

    ENDFORM.

    &----


    *& Form INITIATE_MAIL_EXECUTE_PROGRAM

    &----


    • Instructs mail send program for SAPCONNECT to send email.

    ----


    FORM initiate_mail_execute_program.

    WAIT UP TO 2 SECONDS.

    SUBMIT rsconn01 WITH mode = 'INT'

    WITH output = 'X'

    AND RETURN.

    ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

    &----


    *& Form POPULATE_EMAIL_MESSAGE_BODY

    &----


    • Populate message body text

    ----


    form populate_email_message_body.

    REFRESH it_message.

    it_message = 'Please find attached a list test ekpo records'.

    APPEND it_message.

    endform. " POPULATE_EMAIL_MESSAGE_BODY

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:20 AM

    Once you have a spool, you can convert it to PDF by using function module

    "CONVERT_ABAPSPOOLJOB_2_PDF"

    For sending emails with attachments use:

    "SO_NEW_DOCUMENT_ATT_SEND_API1"

    here you need to pass

    1) DOCUMENT_DATA - For Document Attributes. Here you mainly specifies your list title, description

    2) PUT_IN_OUTBOX = SPACE -> If you do not want to save an email.

    3) CONTENTS_TXT -> text to be written in email

    4) CONTENTS_BIN - > for attachment

    5) RECEIVERS -> Recepients of Mail

    Read the function module definition for better understanding.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:04 AM

    You are correct. Using FM SO_NEW_DOCUMENT_SEND_API1 you can send the pdf as email attachment.

    visit here:

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

    DATA: maildata TYPE sodocchgi1.

    DATA: BEGIN OF mailpack OCCURS 0.

    INCLUDE STRUCTURE sopcklsti1.

    DATA: END OF mailpack.

    DATA: BEGIN OF mailhead OCCURS 0.

    INCLUDE STRUCTURE solisti1.

    DATA: END OF mailhead.

    DATA: BEGIN OF mailbin OCCURS 0.

    INCLUDE STRUCTURE solisti1.

    DATA: END OF mailbin.

    DATA: BEGIN OF mailtext OCCURS 0.

    INCLUDE STRUCTURE solisti1.

    DATA: END OF mailtext.

    DATA: BEGIN OF mailrec OCCURS 0.

    INCLUDE STRUCTURE somlreci1.

    DATA: END OF mailrec.

    CLEAR: i_bultos_error_conta.

    Rellenamos el campo fecha.

    LOOP AT i_bultos_error_conta.

    READ TABLE i_bultos WITH KEY cod_bulto = i_bultos_error_conta-cod_bulto.

    i_bultos_error_conta-fecha = i_bultos-fecha.

    MODIFY i_bultos_error_conta.

    CONCATENATE i_bultos_error_conta-cod_bulto i_bultos_error_conta-fecha INTO mailbin-line.

    mailbin+253(2) = cl_abap_char_utilities=>cr_lf.

    APPEND mailbin. CLEAR mailbin.

    ENDLOOP.

    datos de "cabecera del correo

    READ TABLE mailbin INDEX maildata-doc_size.

    maildata-doc_size = ( maildata-doc_size - 1 ) * 255 + STRLEN( mailbin ). "255

    maildata-obj_langu = sy-langu.

    maildata-obj_name = 'CORREO'.

    CONCATENATE 'SHIPPING_OUT: BULTOS CON ERROR EN LA CONTABILIZACION' hub

    INTO maildata-obj_descr SEPARATED BY space..

    CLEAR mailpack.

    REFRESH mailpack.

    TEXTO DEL CORREO

    CONCATENATE 'Códigos de bulto con error en la contabilización de'

    'la entrega para el HUB' hub 'ejecutado el' sy-datum '.'

    INTO mailtext-line SEPARATED BY space.

    mailtext-line = 'Fichero con el log de la ejecucion del SHIPPING_OUT'.

    APPEND mailtext.

    DESCRIPCIÓN DEL TEXTO DEL MENSAJE

    mailpack-transf_bin = ' '.

    mailpack-head_start = 1.

    mailpack-head_num = 0.

    mailpack-body_start = 1.

    DESCRIBE TABLE mailtext LINES mailpack-body_num.

    mailpack-doc_type = 'RAW'.

    APPEND mailpack.

    CREACIÓN DE ARCHIVOS ADJUNTOS

    mailpack-transf_bin = 'X'.

    mailpack-head_start = 1.

    mailpack-head_num = 0.

    mailpack-body_start = 1.

    DESCRIBE TABLE mailbin LINES mailpack-body_num.

    mailpack-doc_type = 'txt'.

    mailpack-obj_descr = 'BULTOS_ERROR_CONTABILIZACION'.

    mailpack-obj_name = 'Texto'.

    mailpack-doc_size = mailpack-body_num * 255.

    APPEND mailpack.

    DESTINATARIOS

    IF sy-mandt = '400'.

    mailrec-receiver = 'user1@company.com'.

    mailrec-receiver = 'user2@company.com'.

    mailrec-rec_type = 'U'.

    APPEND mailrec.

    ELSEIF sy-mandt = '300'.

    mailrec-receiver = 'user3@company.com'.

    mailrec-rec_type = 'U'.

    APPEND mailrec.

    ENDIF.

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = maildata

    put_in_outbox = 'X'

    commit_work = 'X'

    IMPORTING

    SENT_TO_ALL =

    NEW_OBJECT_ID =

    TABLES

    packing_list = mailpack

    OBJECT_HEADER = MAILHEAD

    contents_bin = mailbin

    contents_txt = mailtext

    CONTENTS_HEX =

    OBJECT_PARA =

    OBJECT_PARB =

    receivers = mailrec

    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.

    NADA

    ENDIF.

    Message was edited by: Matthew Billingham - removed email addresses

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:06 AM

    Check this link.

    http://www.sap-basis-abap.com/abap011.htm

    Regards,

    Maha

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:11 AM

    Also check this thread..

    SO_NEW_DOCUMENT_SEND_API1

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:13 AM

    Hi,

    u can use the same logic.

    REPORT ytest_01 .

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

    DATA DECLARATION

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

    TYPE-POOLS: meein.

    TABLES: toa_dara,

    nast,

    tnapr,

    arc_params.

    DATA: ent_retco TYPE sy-subrc,

    ent_screen TYPE c,

    l_xkomk LIKE TABLE OF komk WITH HEADER LINE,

    xscreen. "Kz. Probeausgabe

    DATA: i_texto_cuerpo LIKE solisti1 OCCURS 0 WITH HEADER LINE.

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

    SELECT OPTIONS / PARAMETERS

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

    PARAMETERS:

    p_kappl LIKE nast-kappl OBLIGATORY DEFAULT 'EF',

    p_objky LIKE nast-objky OBLIGATORY DEFAULT '0010001125',

    p_kschl LIKE nast-kschl OBLIGATORY DEFAULT 'NEU',

    p_spras LIKE nast-spras OBLIGATORY DEFAULT 'EN',

    p_parnr LIKE nast-parnr OBLIGATORY DEFAULT '50009123',

    p_parvw LIKE nast-parvw OBLIGATORY DEFAULT 'BA',

    p_erdat LIKE nast-erdat OBLIGATORY DEFAULT '20050908',

    p_eruhr LIKE nast-eruhr OBLIGATORY DEFAULT '130105',

    p_aende LIKE nast-aende DEFAULT 'X',

    p_nacha LIKE nast-nacha DEFAULT '1',

    p_ndialo TYPE tdsfflag DEFAULT ' ',

    p_telfx LIKE nast-telfx DEFAULT '1-920-721-0284',

    p_tland LIKE nast-tland DEFAULT 'US',

    p_sform TYPE tdsfname DEFAULT 'ZMMNABPR3PFMMPO_L3' OBLIGATORY.

    *PDF TABLES

    DATA: tb_pdf LIKE tline OCCURS 0.

    DATA: tb_pdf255 TYPE so_text255 OCCURS 0.

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

    MAIN PROCESSING SECTION

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

    START-OF-SELECTION.

    SELECT SINGLE *

    INTO nast

    FROM nast

    WHERE kappl = p_kappl

    AND objky = p_objky

    AND kschl = p_kschl

    AND spras = p_spras

    AND parnr = p_parnr

    AND parvw = p_parvw

    AND erdat = p_erdat

    AND eruhr = p_eruhr.

    *

    IF sy-subrc 0.

    MESSAGE s000(00) WITH 'Record in NAST not found.'.

    nast-kappl = p_kappl.

    nast-objky = p_objky.

    nast-kschl = p_kschl.

    nast-spras = p_spras.

    nast-parnr = p_parnr.

    nast-parvw = p_parvw.

    nast-erdat = p_erdat.

    nast-eruhr = p_eruhr.

    nast-nacha = p_nacha.

    nast-telfx = p_telfx.

    nast-tland = p_tland.

    ENDIF.

    nast-aende = p_aende.

    tnapr-sform = p_sform.

    PERFORM entry_neu

    USING

    ent_retco

    ent_screen.

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

    FORMS

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

    &----


    *& Form entry_neu

    &----


    text

    -


    -->ENT_RETCO text

    -->ENT_SCREEN text

    -


    FORM entry_neu

    USING

    ent_retco

    ent_screen.

    DATA: l_druvo LIKE t166k-druvo,

    l_nast LIKE nast,

    l_from_memory,

    l_doc TYPE meein_purchase_doc_print.

    DATA: ls_print_data_to_read TYPE lbbil_print_data_to_read.

    DATA: ls_bil_invoice TYPE lbbil_invoice.

    DATA: lf_fm_name TYPE rs38l_fnam.

    DATA: ls_control_param TYPE ssfctrlop.

    DATA: ls_composer_param TYPE ssfcompop.

    DATA: ls_recipient TYPE swotobjid.

    DATA: ls_sender TYPE swotobjid.

    DATA: lf_formname TYPE tdsfname.

    DATA: ls_addr_key LIKE addr_key.

    xscreen = ent_screen.

    clear ent_retco.

    IF nast-aende EQ space.

    l_druvo = '1'.

    ELSE.

    l_druvo = '2'.

    ENDIF.

    CALL FUNCTION 'ME_READ_PO_FOR_PRINTING'

    EXPORTING

    ix_nast = nast

    ix_screen = ent_screen

    IMPORTING

    ex_retco = ent_retco

    ex_nast = l_nast

    doc = l_doc

    CHANGING

    cx_druvo = l_druvo

    cx_from_memory = l_from_memory.

    CHECK ent_retco EQ 0.

    IF nast-adrnr IS INITIAL.

    PERFORM get_addr_key

    CHANGING ls_addr_key.

    ELSE.

    ls_addr_key = nast-adrnr.

    ENDIF.

    *Set the print Parameters

    PERFORM set_print_param USING ls_addr_key

    CHANGING ls_control_param

    ls_composer_param

    ls_recipient

    ls_sender

    ent_retco.

    *Get the Smart Form name.

    IF NOT tnapr-sform IS INITIAL.

    lf_formname = tnapr-sform.

    ELSE.

    lf_formname = tnapr-fonam.

    ENDIF.

    determine smartform function module for invoice

    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

    EXPORTING

    formname = lf_formname

    IMPORTING

    fm_name = lf_fm_name

    EXCEPTIONS

    no_form = 1

    no_function_module = 2

    OTHERS = 3.

    IF sy-subrc 0.

    error handling

    ent_retco = sy-subrc.

    perform protocol_update_i.

    ENDIF.

    ls_control_param-getotf = 'X'.

    DATA: l_document_output_info TYPE ssfcrespd,

    l_job_output_info TYPE ssfcrescl,

    l_job_output_options TYPE ssfcresop.

    CALL FUNCTION lf_fm_name

    EXPORTING

    archive_index = toa_dara

    archive_parameters = arc_params

    control_parameters = ls_control_param

    mail_recipient = ls_recipient

    mail_sender = ls_sender

    output_options = ls_composer_param

    user_settings = ' '

    zxekko = l_doc-xekko

    zxpekko = l_doc-xpekko

    zxaend = l_doc-xaend

    IMPORTING

    document_output_info = l_document_output_info

    job_output_info = l_job_output_info

    job_output_options = l_job_output_options

    TABLES

    l_xekpo = l_doc-xekpo[]

    l_xekpa = l_doc-xekpa[]

    l_xpekpo = l_doc-xpekpo[]

    l_xeket = l_doc-xeket[]

    l_xtkomv = l_doc-xtkomv[]

    l_xekkn = l_doc-xekkn[]

    l_xekek = l_doc-xekek[]

    l_xaend = l_doc-xaend[]

    l_xkomk = l_xkomk

    EXCEPTIONS

    formatting_error = 1

    internal_error = 2

    send_error = 3

    user_canceled = 4

    OTHERS = 5.

    IF sy-subrc 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.

    BREAK-POINT.

    ENDIF.

    Converts OTF to PDF

    DATA: v_len_in TYPE i.

    CALL FUNCTION 'CONVERT_OTF'

    EXPORTING

    format = 'PDF'

    max_linewidth = 132

    IMPORTING

    bin_filesize = v_len_in

    TABLES

    otf = l_job_output_info-otfdata

    lines = tb_pdf

    EXCEPTIONS

    err_max_linewidth = 0

    err_format = 1

    err_conv_not_possible = 2

    OTHERS = 3.

    IF sy-subrc 0.

    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

    ENDIF.

    Change the PDF format from 132 to 255.

    CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

    EXPORTING

    line_width_src =

    line_width_dst =

    transfer_bin = 'X'

    TABLES

    content_in = tb_pdf

    content_out = tb_pdf255

    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.

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

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

    ENDIF.

    DATA: lw_subject TYPE so_obj_des.

    DATA: lwa_body TYPE solisti1.

    DATA: ltb_body TYPE TABLE OF solisti1.

    DATA: lw_filename TYPE char100.

    DATA: ltb_recipients TYPE TABLE OF somlreci1.

    DATA: lwa_recipients TYPE somlreci1.

    lw_subject = 'This is the email subject'.

    lwa_body-line = 'This is the email body - Line1'.

    APPEND lwa_body TO ltb_body.

    lwa_body-line = 'This is the email body - Line2'.

    APPEND lwa_body TO ltb_body.

    lwa_body-line = 'This is the email body - Line3'.

    APPEND lwa_body TO ltb_body.

    lwa_body-line = 'This is the email body - Line4'.

    APPEND lwa_body TO ltb_body.

    lw_filename = 'Contract'.

    *RECIPIENTS

    lwa_recipients-rec_type = 'U'.

    lwa_recipients-express = 'X'.

    lwa_recipients-receiver = sy-uname.

    lwa_recipients-copy = ''.

    APPEND lwa_recipients TO ltb_recipients.

    RECIPIENTS

    lwa_recipients-rec_type = 'U'.

    lwa_recipients-express = 'X'.

    lwa_recipients-receiver = 'john.doe@abc.com'.

    lwa_recipients-copy = ''.

    APPEND lwa_recipients TO ltb_recipients.

    RECIPIENTS

    lwa_recipients-rec_type = 'U'.

    lwa_recipients-express = 'X'.

    lwa_recipients-receiver = 'john.doe@gmail.com'.

    lwa_recipients-copy = ''.

    APPEND lwa_recipients TO ltb_recipients.

    Sends the PDF by email.

    PERFORM f_send_pdf_by_email

    TABLES

    tb_pdf255

    ltb_body

    ltb_recipients

    USING

    lw_subject

    lw_filename.

    ENDFORM. "entry_neu

    &----


    *& Form ZCA_MAIL_BIN

    &----


    text

    -


    FORM f_send_pdf_by_email

    TABLES

    ptb_pdf255 STRUCTURE solisti1

    ptb_body STRUCTURE solisti1

    ptb_recipients STRUCTURE somlreci1

    USING

    pw_subject TYPE so_obj_des

    pw_filename TYPE char100.

    *-DATA DECLARATION----


    Variables y tablas internas.

    DATA: BEGIN OF ltb_objbin OCCURS 0.

    INCLUDE STRUCTURE solisti1.

    DATA: END OF ltb_objbin.

    DATA: lwa_doc_chng LIKE sodocchgi1,

    lw_tab_lines LIKE sy-tabix,

    ltb_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

    ltb_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

    *-MAIN PROCESSING SECTION----


    clear: ltb_objbin, ltb_objtxt, ltb_objpack, lwa_doc_chng.

    refresh: ltb_objbin, ltb_objtxt, ltb_objpack.

    Control Data

    lwa_doc_chng-obj_name = 'URGENT'.

    lwa_doc_chng-sensitivty = 'P'.

    lwa_doc_chng-no_change = 'X'.

    lwa_doc_chng-priority = '1'.

    lwa_doc_chng-obj_prio = '1'.

    lwa_doc_chng-obj_langu = sy-langu.

    lwa_doc_chng-no_change = 'X'.

    Email Subject

    lwa_doc_chng-obj_descr = pw_subject.

    Email Body

    ltb_objtxt] = ptb_body[.

    CLEAR ltb_objtxt.

    DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines.

    IF lw_tab_lines GT 0.

    READ TABLE ltb_objtxt INDEX lw_tab_lines.

    lwa_doc_chng-doc_size =

    ( lw_tab_lines - 1 ) * 255 + STRLEN( ltb_objtxt ).

    CLEAR ltb_objpack-transf_bin.

    ltb_objpack-body_start = 1.

    ltb_objpack-body_num = lw_tab_lines.

    ltb_objpack-doc_type = 'RAW'.

    APPEND ltb_objpack.

    ENDIF.

    Attachment

    Move the binary attachment to other internal table.

    ltb_objbin] = ptb_pdf255[.

    ltb_objpack-transf_bin = 'X'.

    ltb_objpack-body_start = 1.

    Get the number of lines in the Attachment (PDF FILE)

    DESCRIBE TABLE ltb_objbin LINES lw_tab_lines.

    ltb_objpack-body_num = lw_tab_lines.

    ltb_objpack-doc_type = 'PDF'.

    ltb_objpack-obj_descr = pw_filename.

    ltb_objpack-obj_name = pw_filename.

    ltb_objpack-doc_size = lw_tab_lines * 255.

    APPEND ltb_objpack.

    Call the function to send the PDF file by email

    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

    document_data = lwa_doc_chng

    put_in_outbox = 'X'

    TABLES

    packing_list = ltb_objpack

    contents_bin = ltb_objbin

    contents_txt = ltb_objtxt

    receivers = ptb_recipients

    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.

    CASE sy-subrc.

    WHEN 0.

    WHEN 1. RAISE too_many_receivers.

    WHEN 2. RAISE document_not_sent .

    WHEN 3. RAISE document_type_not_exist.

    WHEN 4. RAISE operation_no_authorization.

    WHEN 5. RAISE parameter_error.

    WHEN 7. RAISE enqueue_error .

    WHEN OTHERS. RAISE x_error.

    ENDCASE.

    COMMIT WORK.

    ENDFORM. "ZCA_MAIL_BIN

    &----


    *& Form get_addr_key

    &----


    text

    -


    -->P_CS_BIL_INVOICE_HD_ADR text

    <--P_CS_ADDR_KEY text

    -


    FORM get_addr_key

    CHANGING l_addr_key LIKE addr_key.

    DATA: l_lfa1 LIKE lfa1.

    SELECT SINGLE * FROM lfa1 INTO l_lfa1

    WHERE lifnr = nast-parnr.

    IF sy-subrc = 0.

    MOVE l_lfa1-adrnr TO l_addr_key.

    ENDIF.

    ENDFORM. " get_addr_key

    &----


    *& Form set_print_param

    &----


    text

    -


    -->P_LS_ADDR_KEY text

    <--P_LS_CONTROL_PARAM text

    <--P_LS_COMPOSER_PARAM text

    <--P_LS_RECIPIENT text

    <--P_LS_SENDER text

    <--P_CF_RETCODE text

    -


    FORM set_print_param USING is_addr_key LIKE addr_key

    CHANGING cs_control_param TYPE ssfctrlop

    cs_composer_param TYPE ssfcompop

    cs_recipient TYPE swotobjid

    cs_sender TYPE swotobjid

    cf_retcode TYPE sy-subrc.

    DATA: ls_itcpo TYPE itcpo.

    DATA: lf_repid TYPE sy-repid.

    DATA: lf_device TYPE tddevice.

    DATA: ls_recipient TYPE swotobjid.

    DATA: ls_sender TYPE swotobjid.

    lf_repid = sy-repid.

    CALL FUNCTION 'WFMC_PREPARE_SMART_FORM'

    CALL FUNCTION 'Z_MMNA_WFMC_PREPARE_SMART_FORM'

    EXPORTING

    pi_nast = nast

    pi_addr_key = is_addr_key

    pi_repid = lf_repid

    IMPORTING

    pe_returncode = cf_retcode

    pe_itcpo = ls_itcpo

    pe_device = lf_device

    pe_recipient = cs_recipient

    pe_sender = cs_sender.

    IF cf_retcode = 0.

    MOVE-CORRESPONDING ls_itcpo TO cs_composer_param.

    cs_composer_param-tdimmed = ' '.

    cs_control_param-device = lf_device.

    cs_control_param-no_dialog = 'X'.

    cs_control_param-no_dialog = p_ndialo.

    cs_control_param-preview = xscreen.

    cs_control_param-getotf = ls_itcpo-tdgetotf.

    cs_control_param-langu = nast-spras.

    ENDIF.

    ENDFORM. "set_print_param

    Regards,

    Satish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 07:45 AM

    hai... plz use this function module & c ... it will work...

    after spooling it...

    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

    SRC_SPOOLID = MI_RQIDENT

    NO_DIALOG = C_NO

    DST_DEVICE = C_DEVICE

    IMPORTING

    PDF_BYTECOUNT = GD_BYTECOUNT

    TABLES

    PDF = IT_PDF_OUTPUT

    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 it works.. plz reply...

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 25, 2008 at 09:31 AM

    Thanks a lot to everyone for their answers especially Richa..

    Add comment
    10|10000 characters needed characters exceeded