Send email in html format with pdf attachment

I am trying to send an email out of SAP using an abap program in the html format with a pdf attachment. I am using the function module -SO_DOCUMENT_SEND_API1. I noticed that when i specify the body type of the message as 'RAW' I get to see the pdf attachments however when i switch it to 'HTM' I loose the attachment in the email generated. Can anyone please help me in solving this problem. Thanks!

  ld_email                 = p_email. "All email IDs
  ld_mtitle                 = 'Bank Statement'.
  ld_format                = 'PDF'. "Attachment Format
  ld_attdescription      = 'Statement'.
  ld_attfilename          = p_filename. "Name of file
  ld_sender_address      = p_sender_address. "Sender mail address
  ld_sender_address_type = p_sender_addres_type. "INT - Internet
* 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 . "Description
  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. "Description
  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 = 'HTM'. " THis is for BODY of mail 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.

Similar Messages

  • Send Email in HTML Format with Javamail.

    GOD BE BLESSED!
    Hello dudes,
    i create a jsp page let me send emails from a database using the API Javamail.
    But these emails when i send then, goes in text format only, and i want to send emails in HTML format too. Anyone can help me?
    I think the Javamail API can send in HTML format.
    thanks and sorry, my english is basic but i think you understand. ;)
    Adler Medrado

    I was trying to do the same thing...I found this on the java.sun.com website somewhere. Hope it works out for you.
    try {
    String host = "";
    String from = "";
    String to = "";
    String fileAttachment = fileName;
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session1 =
    Session.getInstance(props, null);
    // Define message
    MimeMessage message =
    new MimeMessage(session1);
    message.setFrom(
    new InternetAddress(from));
    message.addRecipient(
    Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject("");
    // create the message part
    MimeBodyPart messageBodyPart =
    new MimeBodyPart();
    //fill message
    messageBodyPart.setText("");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source =
    new FileDataSource(fileAttachment);
    messageBodyPart.setDataHandler(
    new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send( message );
    }catch (Exception e){
    System.err.print("Mailing error:");
    System.err.println(e);

  • Send email in HTML format with attachment.

    I want to send out email in HTML fromat and attach a file to it. I know how to send HTML email but I cant attach a file to it.
    Can anybody help me with that?

    What kind of attachment?
    1) A file not related to the HTML
    or 2) a file used by the HTML (i.e. a GIF)?
    If 1) see here http://developer.java.sun.com/developer/onlineTraining/JavaMail/contents.html#SendingAttachments
    If 2) see here http://forum.java.sun.com/thread.jsp?forum=43&thread=242791
    (make sure you read all the thread as inline attachments are mentioned at the end)
    SH

  • Sending email in html format.

    i am trying to send email in html format. the following is my sample code. it's just sending plain text. how should i send html file in email?
    String message_body = "<a href=\"test.html\">click here</a>";
    MimeMessage msg = new MimeMessage( session );
    // From Address
    msg.setFrom( new InternetAddress( fromAddress ) );
    // TO Address
    InternetAddress recipient_Address = new InternetAddress( toAddress );
    msg.addRecipient(Message.RecipientType.TO, recipient_Address);
    // Subject
    msg.setSubject( subject );
    // MimeBodyPart object for message body part
    MimeBodyPart mbp1 = new MimeBodyPart();
    mbp1.setText( message_body );
    // MimeBodyPart object for file to attach
    MimeBodyPart mbp2 = new MimeBodyPart();
    Multipart mp = new MimeMultipart();
    // create the Multipart and add message body and file to attach.
    mp.addBodyPart(mbp1);
    // add the Multipart to the message
    msg.setContent(mp);
    msg.setSentDate(new Date());
    // send the message
    Transport.send(msg);
    i'd appreciated it...

    msg.setContent(mp, "text/html");Have I put this in the right place? You need to apply it to your body text, at any rate.

  • Java.mail sending email in html format

    I trying to send emails from my java program, I ve managd to send text mails, I want to send email in html format is there a way of doing that and how
    thanks for your help

    Thanks a lot it is working now but I think that sending mails in text format is the best way since there isn't a way of knowing whether the recepient can handel html mails

  • Send emails in html format

    Hi All,
    My requirement is to send emails. I am using javamail and it works fine. But the body of the email should be in table format.
    I am planning to use Html as below. But don't know how to combine html in java. Is there any other way of achieving it ? Please let me know if I am not clear.
    <htm>
    <table border="1">
    <tr>
    <td bgcolor="red">Header</td>
    </tr>
    <tr>
    <td bgcolor="yellow">Sub Header1</td>
    <td bgcolor="yellow">Sub Header1</td>
    </tr>
    <tr>
    <td bgcolor="green">Values</td>
    <td bgcolor="green">Values</td>
    </tr>
    </html>

    so, do I need another method which tells Java whereto output the HTML Tags ?
    The method writes to a PrintWriter defined somewhere,
    you can also pass the PrintWriter as third argument
    to the method.
    To generate a String containg the whole HTML Dokument
    you would write something like:
    StringWriter stringWriter = new StringWriter();
    PrintWriter printWriter = new
    PrintWriter(stringWriter);
    writeStartTable();
    writeStartRow();
    writeCell("BlaBla", "green");
    printEndTable();
    printWriter.flush();
    printWriter.close();
    stringWriter.close();
    String content = stringWriter().toString();
    BodyPart mailBody = new MimeBodyPart();
    mailBody.setContent(content, "text/html");
    I was succesful in sending mail using HTML format. Thanks for ur reply.
    But if I try send the mail in HTML format along with an attachment, the MIME type defaults to "text/plain".
    Is there a way to set the MIME type to "text/html" when I send mail with an attachment.
    Please help . Let me know if I am not clear

  • Send email in html format

    Hello everybody,
    First of all:
    I already searched via internet but couldn´t found an example which helped me to solve my problem. Anyway I believe it must be very simple what I want to do.
    My Problem: I want to send an email in html format, but until now everything I tried didn´t worked. Please help me. What do I have to do?
    I already tried a lot of code typing. For example this one:
    this.resolveNode("#event").submit.target="mailto:"+email_adressen+"subject="+subject+"&Body="+body+"&MessageFormat=HTML";
    But nothing is working, you always see the html tags in the text - they have no effect at all :-( .
    Best regards,
    Paolo

    I was trying to do the same thing...I found this on the java.sun.com website somewhere. Hope it works out for you.
    try {
    String host = "";
    String from = "";
    String to = "";
    String fileAttachment = fileName;
    // Get system properties
    Properties props = new Properties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session1 =
    Session.getInstance(props, null);
    // Define message
    MimeMessage message =
    new MimeMessage(session1);
    message.setFrom(
    new InternetAddress(from));
    message.addRecipient(
    Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject("");
    // create the message part
    MimeBodyPart messageBodyPart =
    new MimeBodyPart();
    //fill message
    messageBodyPart.setText("");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    DataSource source =
    new FileDataSource(fileAttachment);
    messageBodyPart.setDataHandler(
    new DataHandler(source));
                   messageBodyPart.setFileName(fileAttachment);
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send( message );
    }catch (Exception e){
    System.err.print("Mailing error:");
    System.err.println(e);

  • Error occured when sending mail with PDF attachment

    Dear Experts
    When i trigger email through SMTP server with PDF attachment using application server 10g , i got following error :
    REP-50159: Executed successfully but there were some errors when distribute the output
    i am using web.show_document utility
    str1:='http://erp.ruchi.com:7777/reports/rwservlet?destype=mail'||'&desname='||c1rec.hist_email||'&from=[email protected]'||'&subject=Your Payslip for Month '||to_char(c1rec.tran_month,'Mon-YYYY')||'&desformat=PDF&server=rep_erp_bi&report=/asdeploy/webutil/pay/reports/payslip.rdf&userid=qwqwqw/aasasas@DIAMOND'||'&COMPANY='||:parameter.para_comp_code||'&LOCATION='||:parameter.para_loc_code||'&MONTH='||to_char(:sdate,'MM/YYYY')||'&ECODE='||c1rec.tran_ecode;
    WEB.SHOW_DOCUMENT(str1,'_SELF');
    previously i had successfully using this utility but now i am facing above error
    Pl suggest
    regards
    shailesh

    Dear Experts
    I already configured application server configuration file with specifying SMTP mail server IP in pluginParam parameter
    <pluginParam name="mailServer">202.157.161.76</pluginParam>
    <property name="enableSSL" value="no"/>
    <property name="mailUserName" value="%[email protected]%"/>
    <property name="mailPassword" value="%soyacl#123%"/>
    what is the issue
    Pl clarify
    Please reply it's urgent

  • Send mail in HTML Format in Service Desk

    Dear Friends,
    We want to send email in html format to every user in service desk, how can we figure it?
    Thanks in advance
    Regards,

    Hello Eray,
    You will want to have a look at this document and hopefully it will assist you accomplish what you need.
    http://service.sap.com/~sapidb/011000358700001903822008E
    Regards,
    Paul

  • Send Invoice email with pdf attachement through DI?

    Hi all,
    is it possible to send an Invoice email with pdf attachement through DI as it can be done through UI?
    Best Regards,
    Vangelis

    Hi Vangelis,
    I Don't think that the DI API has that functionality (but I am not sure).
    However with .Net's System.Net.Mail it should be quite easy to build.
    Good luck,
    Johan

  • Sending an email with pdf attachment in Ecc6

    we were in 4.6 c and recentely upgraded to ECC6. we have a program which we are sending email with pdf attachments. now it is breaking, we are able to display the pdf in the screen, but once it became the attachment , it is not going.
    we are running the program in forground and not reading the spool and sending it. any idea

    http://www.sap-img.com/abap/sending-email-with-attachment.htm
    Sending mail to an external maild with PDF attachment.
    Creating a PDF attachment and send it via Email
    Sending E-Mail from ABAP - Version 610 and Higher - BCS Interface
    How to send a ttachment with email.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/abap-Sendthespooldatatoanemail+address.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSpoolrequesttoPDFandsendase-mail
    Friend just have a look in the forum itself, there are many posts for ur query, you definetly get exact solution no need to wait for answers/solutions.
    All the best

  • External Send PO as email with PDF attachment not working

    hi,
    we are using ECC6, and in txn NACT, Processing routine we can use Sapscript External send > SAPFM06P > ENTRY_NEU > MEDRUCK > PDF and in MN04/5 i create Output record, and in SCOT my PO is ready for transmission from either ME21N/2 and ME9F - works well - email sent with pdf PO attached.
    <b>HOWEVER,</b> we have just created a SMARTFORM PO, and with similar settings, i cannot create External send OUTPUT!!! (Output failed in ME9F/ME23N) NACT settings External Send > /SMB40/FM06P > Z_MMPO_A > PDF
    In SCOT > SMTP > Internet X > Sapscript/SmartForm = PDF.
    Does special code need to be entered into Smartform to generate PDF email similar to Sapscript? Any code would be appreciated.
    regards Adam

    Hi,
    You need to build a code to create the Spool OTF output into PDF.
    This can be done in Print program, which converts the spool into PDF & sends a mail with PDF attachment.
    Please refer this sample program:
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm
    Best regards,
    Prashant

  • Send Mail with PDF Attachment in ABAP

    Hi Experts,
    I have a requirement where I need to convert internal table data into PDF format and send it as an E-Mail with PDF attachment to Outlook mail using ABAP.
    How do I achieve this .
    Can anyone send me example code for doing this.
    Thanks
    Kumar

    hiii
    check following code for PDF attachment and mail
    ** Check for any ATTACHMENTS...
    IF d_desired_type = 'RAW'.           " Set to RAW?
    *    PERFORM convert_to_abaplist.       " YES - convert it
      ENDIF.                               " end...
      IF d_desired_type = 'ALI'.           " Set to ALI?
        PERFORM convert_to_alilist.        " YES - convert it
      ENDIF.                               " end...
    * Check for any ATTACHMENTS...
      IF NOT t_soli[] IS INITIAL.          " attachment?
        h_real_type = d_desired_type.      " ENABLE
        h_transf_type = 'X'.               " Transfer type BINARY...
    *   Write PDF/ALI formatted data to BINARY table...
        t_con_bin[] = t_soli[].
    *   Add Packing List (attachment) for PDF...
        DESCRIBE TABLE t_con_bin LINES h_tab_cntr.
        READ TABLE t_con_bin INDEX h_tab_cntr.
        h_doc_data-doc_size = h_doc_data-doc_size
                            + ( ( h_tab_cntr - 1 )
                            * 255 + STRLEN( t_con_bin ) ).
        h_doc_data-obj_descr  = mail_subject.
        h_body_start = 1.
        h_body_num = h_tab_cntr.
    *   Write RAW data if that's what it is (adds to TEXT)...
        IF h_real_type = 'RAW'.
          DESCRIBE TABLE t_con_text LINES h_body_start.
          h_body_start = h_body_start + 1.
          h_transf_type = space.           " Transfer type TEXT...
          LOOP AT t_con_bin.               " Zip thru TEXT stuff
            t_con_text = t_con_bin.        " set TEXT table header..
            APPEND t_con_text.             " add to what's there!
          ENDLOOP.
          CLEAR: t_con_bin.                " clear BINARY header..
          REFRESH: t_con_bin.              " reset BINARY table...
        ENDIF.
        CLEAR t_pak_list.
        IF h_transf_type = 'X'.            " Binary=PDF/ALI?
          t_pak_list-transf_bin = 'X'.
          t_pak_list-head_start = 1.
          t_pak_list-head_num   = 0.
          t_pak_list-body_start = 1.
          t_pak_list-body_num   = h_tab_cntr.
          t_pak_list-doc_type   = h_real_type.
          t_pak_list-obj_name   = 'ATTACHMENT'.
          t_pak_list-obj_descr  = 'Document'(001).
          t_pak_list-doc_size   = ( h_tab_cntr - 1 )
                                * 255 + STRLEN( t_con_bin ).
        ELSE.
          DESCRIBE TABLE t_con_text LINES h_tab_cntr.
          READ TABLE t_con_text INDEX h_tab_cntr.
          t_pak_list-transf_bin = ' '.     " Binary=RAW
          t_pak_list-head_start = 1.
          t_pak_list-head_num   = 0.
          t_pak_list-body_start = h_body_start.
          t_pak_list-body_num   = h_tab_cntr.
          t_pak_list-doc_type   = h_real_type.
          t_pak_list-obj_name   = 'ATTACHMENT'(002).
          t_pak_list-obj_descr  = 'Report'(003).
          t_pak_list-doc_size   = ( h_body_num - 1 )
                                * 255 + STRLEN( t_con_text ).
        ENDIF.
        APPEND t_pak_list.
      ENDIF.
    * Send the EMAIL out with SAP function...
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = h_doc_data
          put_in_outbox              = 'X'
    *      commit_work                = 'X'
        TABLES
          packing_list               = t_pak_list
          contents_bin               = t_con_bin
          contents_txt               = t_con_text
          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.
      IF syst-subrc NE 0.
    *    RAISE send_failed.
        CALL FUNCTION 'NAST_PROTOCOL_UPDATE'
          EXPORTING
            msg_arbgb = '00'
            msg_nr    = '001'
            msg_ty    = 'E'
            msg_v1    = 'O/P Could not be issued '(001)
            msg_v2    = ' Due to No Mail ID'(002)
            msg_v3    = syst-msgv3
            msg_v4    = syst-msgv4
          EXCEPTIONS
            OTHERS    = 1.
    * Check General incompletion status of the header
        IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ELSE.
          WRITE : 'SENT'.
        ENDIF.
      ELSE.
    *    commit work.
      ENDIF.
    ENDFORM.                               " SEND_MAIL_FAX
    *&      Form  convert_otf_2_pdf
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM convert_otf_2_pdf .
      DATA: "t_line            LIKE tline OCCURS 0 WITH HEADER LINE,
            t_objcont         LIKE soli  OCCURS 0 WITH HEADER LINE,
            d_doc_size(12)    TYPE c,
            d_fle1(2)         TYPE p,
            d_fle2(2)         TYPE p,
            d_off1            TYPE p,
            d_hltlines        TYPE i,
            d_hfeld(500)      TYPE c,
            w_indx            LIKE sy-tabix.
      CLEAR: t_line, t_objcont, d_off1.
      REFRESH: t_line, t_objcont.
    * Check/set DEFAULT Desired-type attachment...
      IF d_desired_type IS INITIAL.        " Entered Desired type?
        d_desired_type = 'PDF'.            " NO  - default to PDF
      ENDIF.                               "
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = d_desired_type
        IMPORTING
          bin_filesize          = d_doc_size
        TABLES
          otf                   = t_itcoo
          lines                 = t_line
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          OTHERS                = 4.
      IF sy-subrc > 0.
        RAISE otf_convert_failed.
      ENDIF.
    ENDFORM.                               " convert_otf_2_pdf
    *&      Form  convert_otf_2_pdf_sx
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM convert_otf_2_pdf_sx .
      DATA:
        t_otf          LIKE solisti1 OCCURS 0 WITH HEADER LINE,"ENABLE
        t_pdf          LIKE tline    OCCURS 0 WITH HEADER LINE,"ENABLE
        doc_size(12)   TYPE n,
        len_out        TYPE i,
        x_real         LIKE  soodk-objtp,
        x_idx_b        LIKE sy-tabix,
        x_idx_e        LIKE sy-tabix.
      IF d_desired_type = 'PDF'.
        d_desired_type = 'OTF'.
      ENDIF.
      CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
        EXPORTING
          rqident              = d_spool_id
          desired_type         = d_desired_type
        IMPORTING
          real_type            = x_real
        TABLES
          buffer               = t_otf
          buffer_pdf           = t_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.
        IF sy-subrc = 1.
          RAISE invalid_spool_id.
        ELSE.
          RAISE otf_convert_failed.
        ENDIF.
      ENDIF.
    * Check Desired-Type vs. Real-Type (if any)...
      IF d_desired_type IS INITIAL.
        IF x_real = 'OTF'.
          d_desired_type = 'PDF'.
        ELSE.
          d_desired_type = x_real.
        ENDIF.
      ELSE.
        IF ( d_desired_type = 'PDF' OR
             d_desired_type = 'OTF' ) AND
           ( x_real = 'OTF' OR
             x_real = 'PDF' ).
          d_desired_type = 'PDF'.
        ELSE.
          IF d_desired_type <> x_real.
            RAISE type_no_match.
          ENDIF.
        ENDIF.
        IF ( d_desired_type = 'ALI' OR
             d_desired_type = 'RAW' ) AND
             x_real = 'OTF'.
          RAISE type_no_match.
        ENDIF.
      ENDIF.
    * Check if ABAP-LIST and not SapScript...
      IF d_desired_type = 'ALI' OR
         d_desired_type = 'RAW'.
        t_soli[] = t_otf[].
        EXIT.
      ENDIF.
    * Load OTF data gotten from spool...
      LOOP AT t_otf.
        t_itcoo = t_otf.
        APPEND t_itcoo.
    *   if Vendor P/O (SapScript = Z_MEDRUCK) then
    *      trap INDEX for "Terms & Conditions" on BACK...
        IF t_itcoo-tdprintcom =  'IN' AND
           t_itcoo-tdprintpar =  '01EZ_MEDRUCK       BACK'.
          x_idx_b = sy-tabix.
        ENDIF.
        IF t_itcoo-tdprintcom =  'IN' AND
           t_itcoo-tdprintpar =  '01EZ_MEDRUCK       NEXT'.
          x_idx_e = ( sy-tabix - 1 ).
        ENDIF.
      ENDLOOP.
    * Drop from table if INDEX'S are set (see above)...
      IF ( x_idx_b > 0 AND
         ( x_idx_e > x_idx_b ) ) .
        DELETE t_itcoo FROM x_idx_b
                     TO x_idx_e.
      ENDIF.
      PERFORM convert_otf_2_pdf.
    ENDFORM.                               " convert_otf_2_pdf_sx
    *&      Form  CONVERSION_OF_SIZE                                       *
    * *"Converting the file to get a 255 char single line internal table   *
    * The PDF file that is generated out of the above function module     *
    * cannot be transported as it needs to be of 255 chars. Hence         *
    * converting the file to get a 255 char single line,internal table.   *
    FORM conversion_of_size .
    "Declaring Local Constants............................................
      CONSTANTS:
         cnv_hexconst_zero TYPE x VALUE '00'.
    * Internal table to hold 255 Char's Single Line.                      *
      DATA:
        lv_big_lines(268) TYPE c
                          OCCURS 0 WITH HEADER LINE.
    *"Local Work Variables.................................................
      DATA:
        lfl_flag          TYPE c,
        lv_left_t(268)    TYPE c,
        lv_left_i         TYPE i,
        tv_left_i         TYPE i,
        lv_curr_i         TYPE i.
      FIELD-SYMBOLS: <f>.
    * Get the lines into a table of 268 char as the first step to put it in
    * the pdf file of 255 chars
      CLEAR lfl_flag.
      LOOP AT t_line.
        IF lfl_flag EQ ' '.
          CLEAR lv_big_lines.
          ASSIGN lv_big_lines(134) TO <f>.
          <f> = t_line.
          lfl_flag = 'X'.
        ELSE.
          lv_big_lines+134 = t_line.
          APPEND lv_big_lines.
          CLEAR: lfl_flag.
        ENDIF.                             " If lfl_flag = ''..
      ENDLOOP.                             " Loop at t_pdf
      IF lfl_flag EQ 'X'.
        APPEND lv_big_lines.
      ENDIF.                               " If lflf_flag eq 'X'..
    * Next fill it into a 255 char table
      CLEAR: lv_left_t, lv_left_i, tv_left_i.
      lv_curr_i = 255.
      LOOP AT lv_big_lines.
        IF lv_left_i NE 0.
          IF lv_curr_i NE 0.
            wa_objcont(lv_left_i)           = lv_left_t(lv_left_i).
            wa_objcont+lv_left_i(lv_curr_i) = lv_big_lines(lv_curr_i).
          ELSE.
            wa_objcont = lv_left_t(lv_left_i).
          ENDIF.                           " IF lv_curr_i NE 0
        ELSE.
          wa_objcont = lv_big_lines(lv_curr_i).
        ENDIF.                             " IF lv_left_i NE 0
        APPEND wa_objcont TO t_objcont.
        tv_left_i = 268 - lv_curr_i.
        IF tv_left_i > 255.
          wa_objcont = lv_big_lines+lv_curr_i(255).
          APPEND wa_objcont TO t_objcont.
          lv_left_i = tv_left_i - 255.
          tv_left_i = 255 + lv_curr_i.
          lv_curr_i = 255 - lv_left_i.
          lv_left_t = lv_big_lines+tv_left_i.
        ELSE.
          lv_left_t = lv_big_lines+lv_curr_i.
          lv_left_i = 268 - lv_curr_i.
          lv_curr_i = 255 - lv_left_i.
        ENDIF.                             " IF tv_left_i > 255
      ENDLOOP.                             " LOOP AT lv_big_lines.
      CLEAR wa_objcont .
      ASSIGN wa_objcont(lv_left_i) TO <f>.
      <f> = lv_left_t(lv_left_i).
      APPEND wa_objcont TO t_objcont.
        h_transf_type = 'X'.                 " Transfer type BINARY...
      IF NOT t_objcont[] IS INITIAL.
        t_soli[]     = t_objcont[].        " SapScript doc to Objects...
      ENDIF.
    regards
    twinkal

  • Custome FM to create Email with PDF attachment

    Hi Experts,
    I am working in Smart form.  my requriment is to create a Custom Function module , for sending  email  with PDF attachment  to the customer. PDF is nothing but which ever I create smart form.
    How can I approach , please give me a suggestion or send me a sample code, if any one create.
    1. This FM should work like : convert form to PDF and send Email to particular customer.

    Hi,
    Steps to convert Smartform to PDF,
    1 Call smartform through FM SSF_FUNCTION_MODULE_NAME.
       CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    2  Converting Smartform to OTF and in turn to PDF
       Set Following parameter in order to convert Smartform into OTF.
      gs_cparam-no_dialog = 'X'.   " Suppressing the dialog box
      gs_cparam-preview = 'X'.     " for print preview
      gs_cparam-getotf = 'X'.     " To get Output in OTF
        CALL FUNCTION g_fmodule
          EXPORTING
            control_parameters = gs_cparam
            output_options     = gs_outoptions
          IMPORTING
            job_output_info    = gt_otf_from_fm
          TABLES
            gt_final           = gt_final
         gt_otf[] = gt_otf_from_fm-otfdata [].
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
            max_linewidth         = 132
          IMPORTING
            bin_filesize          = g_bin_filesize
          TABLES
            otf                   = gt_otf
            lines                 = gt_pdf_tab
        CHECK sy-subrc = 0.
        g_bin_filesize = g_bin_filesize + 1.
    Transfer the 132-long strings to 255-long strings
        LOOP AT gt_pdf_tab into gs_pdf_tab.
          TRANSLATE gs_pdf_tab USING ' ~'.
          CONCATENATE g_buffer gs_pdf_tab INTO g_buffer.
        ENDLOOP.
        TRANSLATE g_buffer USING '~ '.
        DO.
          gs_mess_att = g_buffer.
          APPEND gs_mess_att to gt_mess_att.
          SHIFT g_buffer LEFT BY 255 PLACES.
          IF g_buffer IS INITIAL.
            EXIT.
          ENDIF.
        ENDDO.
    3 For Sending Mail use following mail,
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = ls_doc_data
          put_in_outbox              = 'X'
          sender_address             = l_sender_address
          sender_address_type        = l_sender_address_type
          commit_work                = 'X'
        TABLES
          packing_list               = lt_packing_list
          contents_bin               = lt_attachment
          contents_txt               = lt_message
          receivers                  = lt_receivers
    I hope this could help you,
    Please let me know if any issue.
    Thanks & regards,
    ShreeMohan
    Edited by: ShreeMohan Pugalia on Jul 18, 2009 8:02 AM
    Edited by: ShreeMohan Pugalia on Jul 18, 2009 8:03 AM
    Edited by: ShreeMohan Pugalia on Jul 18, 2009 8:05 AM

  • Problem in sending mail with PDF attachment

    Hi all,
    Kindly check this code..
    I neeed to send the smartform as a PDF attachment..
    PDF generated form of smartform is generated successfully..
    <b>but PDF  going as attachment is showing errors in opening</b> .
    Please help me to solve this issue as soon as possible
          DESCRIBE TABLE objtxt LINES tab_lines.
          READ TABLE objtxt INDEX tab_lines.
          doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
         doc_chng-doc_size = tab_lines * 255.
    Creation of the entry for the compressed document
          CLEAR objpack-transf_bin.
          objpack-head_start = 1.
          objpack-head_num = 0.
          objpack-body_start = 1.
          objpack-body_num = tab_lines.
          objpack-doc_type = 'RAW'.
          APPEND objpack.
    Creation of the document attachment
          DESCRIBE TABLE objbin LINES tab_lines.
    Creation of the entry for the compressed document
          CLEAR objpack-transf_bin.
          objpack-transf_bin = 'X'.
          objpack-head_start = 1.
          objpack-head_num = 0.
          objpack-body_start = 1.
          READ TABLE objbin INDEX tab_lines.
          objpack-doc_size =  tab_lines * 255 .
          objpack-body_num = tab_lines.
          objpack-doc_type = 'PDF'.
          objpack-obj_name = 'SMART'.
          objpack-obj_descr = 'test'.
          APPEND objpack.
    Completing the recipient list
    target recipent
          CLEAR reclist.
          reclist-receiver = '[email protected]'.
          reclist-express  = 'X'.
          reclist-rec_type = 'U'.
          APPEND reclist.
    Sending the document
          CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
            EXPORTING
              document_data              = doc_chng
              put_in_outbox              = 'X'
            TABLES
              packing_list               = objpack
              object_header              = objhead
              contents_bin               = objbin
              contents_txt               = objtxt
              receivers                  = 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                     = 99.
          IF sy-subrc <> 0.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
    Regards,
    ajith

    Hello Ajith,
    Use this Code.
    Internal Table declarations
    DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
    i_tline TYPE TABLE OF tline WITH HEADER LINE,
    i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
    i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    Objects to send mail.
    i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
    i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
    Work Area declarations
    wa_objhead TYPE soli_tab,
    w_ctrlop TYPE ssfctrlop,
    w_compop TYPE ssfcompop,
    w_return TYPE ssfcrescl,
    wa_doc_chng typE sodocchgi1,
    w_data TYPE sodocchgi1,
    wa_buffer TYPE string,"To convert from 132 to 255
    Variables declarations
    v_form_name TYPE rs38l_fnam,
    v_len_in LIKE sood-objlen,
    v_len_out LIKE sood-objlen,
    v_len_outn TYPE i,
    v_lines_txt TYPE i,
    v_lines_bin TYPE i.
    call function 'SSF_FUNCTION_MODULE_NAME'
    exporting
    formname = 'ZZZ_TEST1'
    importing
    fm_name = v_form_name
    exceptions
    no_form = 1
    no_function_module = 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.
    w_ctrlop-getotf = 'X'.
    w_ctrlop-no_dialog = 'X'.
    w_compop-tdnoprev = 'X'.
    CALL FUNCTION v_form_name
    EXPORTING
    control_parameters = w_ctrlop
    output_options = w_compop
    user_settings = 'X'
    IMPORTING
    job_output_info = w_return
    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
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    i_otf[] = w_return-otfdata[].
    call function 'CONVERT_OTF'
    EXPORTING
    format = 'PDF'
    max_linewidth = 132
    IMPORTING
    bin_filesize = v_len_in
    TABLES
    otf = i_otf
    lines = i_tline
    EXCEPTIONS
    err_max_linewidth = 1
    err_format = 2
    err_conv_not_possible = 3
    others = 4.
    Fehlerhandling
    if sy-subrc <> 0.
    endif.
    loop at i_tline.
    translate i_tline using '~'.
    concatenate wa_buffer i_tline into wa_buffer.
    endloop.
    translate wa_buffer using '~'.
    do.
    i_record = wa_buffer.
    append i_record.
    shift wa_buffer left by 255 places.
    if wa_buffer is initial.
    exit.
    endif.
    enddo.
    Attachment
    refresh:
    i_reclist,
    i_objtxt,
    i_objbin,
    i_objpack.
    clear wa_objhead.
    i_objbin[] = i_record[].
    Create Message Body
    Title and Description
    i_objtxt = 'test with pdf-Attachment!'.
    append i_objtxt.
    describe table i_objtxt lines v_lines_txt.
    read table i_objtxt index v_lines_txt.
    wa_doc_chng-obj_name = 'smartform'.
    wa_doc_chng-expiry_dat = sy-datum + 10.
    wa_doc_chng-obj_descr = 'smartform'.
    wa_doc_chng-sensitivty = 'F'.
    wa_doc_chng-doc_size = v_lines_txt * 255.
    Main Text
    wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )
    clear i_objpack-transf_bin.
    i_objpack-head_start = 1.
    i_objpack-head_num = 0.
    i_objpack-body_start = 1.
    i_objpack-body_num = v_lines_txt.
    i_objpack-doc_type = 'RAW'.
    append i_objpack.
    Attachment
    (pdf-Attachment)
    i_objpack-transf_bin = 'X'.
    i_objpack-head_start = 1.
    i_objpack-head_num = 0.
    i_objpack-body_start = 1.
    Länge des Attachment ermitteln
    describe table i_objbin lines v_lines_bin.
    read table i_objbin index v_lines_bin.
    i_objpack-doc_size = v_lines_bin * 255 .
    i_objpack-body_num = v_lines_bin.
    i_objpack-doc_type = 'PDF'.
    i_objpack-obj_name = 'smart'.
    i_objpack-obj_descr = 'test'.
    append i_objpack.
    clear i_reclist.
    i_reclist-receiver = '[email protected]'.
    i_reclist-rec_type = 'U'.
    append i_reclist.
    call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = wa_doc_chng
    put_in_outbox = 'X'
    TABLES
    packing_list = i_objpack
    object_header = wa_objhead
    CONTENTS_BIN = i_objbin
    contents_txt = i_objtxt
    receivers = i_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 helped reward points
    Vasanth

Maybe you are looking for

  • Hot Synch Problems with Centro and Computer

    Transfered phone numbers from old phone and added three  months of dates on the calendar.  Hot Synched and it transferred to my laptop.  Went back to Verizon and they beamed my PalmVx info into phone.  Got all the addresses and phone numbers, but it

  • PDF will not print correctly from any app

    I seem to keep on getting the same error everywhere I print on SL (from safari/firefox/preview etc etc) It will usually print any lines or logos but miss all text?? I did have the dreaded adobe reader installed but have since removed it? I am in urge

  • Vision builder AI shared variable sudenly damaged

    Dear Ni users. Description of aplication. We use NI vision builder AI together with siemens WINCC software. We use shared variables acros NI shared variable engine, so read and write some parameters over WiNCC. The  aplication witch was working for m

  • Delete and restore scheduling of reports

    Hi I have BO 4.0 installed on Linux Platform Is there any way i can 1) Backup all the scheduling information for all my reports 2) Restore only few of them at a time All i want to achieve is as we are migrating from 3.1 to 4.0 we want to schedule onl

  • Display Preferences

    The instructions for my 20" Cinema display indicate that I can set the power button on the display to function as a sleep switch. The instructions say to go to Click Options in Displays preferences. But I don't have an options tab in the displays pre