Email:CL_DOCUMENT_BCS= CREATE_DOCUMENT

Hi,
While using FM "SO_NEW_DOCUMENT_ATT_SEND_API1" we have an option to desgin email body using HTML by assiging SOPCKLSTI1-DOC_TYPE = 'HTML'   ( Packing list-Code for document class) & filing SOLISTI1-LINE = HTML tags.
How could we do the same, I mean using HTML tags to compose email body using "CL_DOCUMENT_BCS=>CREATE_DOCUMENT" ??
CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                      I_TYPE    = 'RAW'
                      I_TEXT    = IP_BODY
                      I_SUBJECT = IP_SUBJECT
                      I_IMPORTANCE = '1'
                      I_SENSITIVITY = 'P').
When I fill it with HTML tags, email body contents are HTML tag in text. Should we I_HEX (SOLIX_TAB) instead of  I_TEXT(SOLI_TAB)
Thanx

Hi,
    Use I_TYPE = 'HTM'
cl_document_bcs=>create_document(
                          i_type    = 'HTM'
                          i_text    =  html_contents
                          i_subject =  mail_subject )
Thanks & Regards
Bala Krishna

Similar Messages

  • Attaching xlsx files to email with CL_BCS and CL_DOCUMENT_BCS

    Hi
    I have made a program that can send an email with attachments from GOS (documents attached to sales orders and invoices). This program works almost perfect. It seems my program can attach any 3 letter file types like DOC, PDF, JPG, AVI, EXE, XLS, but not filetypes with more than 3 letters like XLSX.
    I creeate a document with CL_DOCUMENT_BCS->CREATE_DOCUMENT
    I attache the files with CL_DOCUMENT_BCS->add_attachment
    and finally i send the email with CL_BCS methodts.
    The problem is CL_DOCUMENT_BCS->add_attachment paramter I_ATTACHMENT_TYPE of type SOODK-OBJTP - this data type is only 3 chars.
    How can I attach XLSX files whit these methods?
    Best regards

    Hi Thomson,
    Thats true ABAP email API does not support 4 chars file types.
    Since Office 2007 is released on the market the new extensions (docx, xlsx,...) lead to several questions in the SAP DMS area. So it might happen that Office 2007 applications raise some warning messages because the local copy of an original has only the 'old' extension xls or doc. Even if they were created with Office 2007 and new file formats.
    Reason:
    Please note that SAP Document Management generally support the file format of Office 2007. But due to the fact that this change in file format is a very new one and the latest SAP Releases ERP2004 and ERP2005 were released some time before, the customizing field 'Suffix' could not be enlarged to four digits. So it is only possible to maintain suffix values like 'doc' or 'xls' and therefore the 'old' extensions were used if you display or edit an original. For further information please take a look at the SAP note 1147660, which was created by the Office Integration colleagues.
    Possible Solution:
    What can be offered to you is a possible workaround, which was sent for this behavior to achieve that the local copied files have a extension like .xlsx or .docx. For this workaround the following steps are necessary:
    1. We have to create new workstation applications for the new file extensions with the mime-types of the new office applications (XLX, WRX and PPX).
    2. We have to customize them with %AUTO% %NO-LEAVE% instead of %SAP-OFFICE-INTEGRATION.OUTPLACE% %MAXSIZE%
    3. We have to use a BADI on BEFORE_CHECKOUT event to determine if workstation application is one of the XLX or WRX or PPX. If it is, we have to set the target temporary file extension to the corresponding 4 characters of the new extensions. This means that we can display "USER01.xlsx", in the user local PC, as a real office 2007 file.
    However please note that this is just a possible solution and means to be a modification to the standard system.
    Generally, it is recommended to maintain the following settings for working with Office 2007 and the new formats.
    u2022 In transaction DC30, maintain the new file extensions (e.g. *.docx) or . as a general file format entry. This will avoid that you cannot add originals with the new file format to your document info records. This is very important if you have implemented SAP notes 948177 and 967839 which bring a tighter file format check into your system.
    u2022 Further, test the behavior if you set the 'Do not rename temporary files' flag in transaction DC30. This will lead to the behavior that the file name is not changed if you check out or display the original file. Maybe this could also help to avoid that the original file-name is changed or corrupted.
    Also, please refer to blog by Ander Fischer; [https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/12030]
    Hope it helps you.
    Thanks
    Arbind Prasad

  • Email attachment in cl_document_bcs

    Hi Folks!
    TYPES:  BEGIN OF ty_final_tab,
                guid_lclic    TYPE /sapsll/lclic-guid_lclic,
                lgreg         TYPE /sapsll/lclic-lgreg,
                lgreg_t       TYPE /sapsll/t606gt-text1, "legal text
                licty         TYPE /sapsll/lclic-licty,
                licty_t   TYPE /sapsll/t606t-text1, "licence tex
                exlic         TYPE /sapsll/lclic-exlic,
                guid_lclicv   TYPE /sapsll/lclicv-guid_lclicv,
                amnt_flt      TYPE /sapsll/lclicv-amnt_flt,
                amnt_flt_wval TYPE /sapsll/lclicv-amnt_flt,
                END OF ty_final_tab.
    DATA: gt_final_tab TYPE STANDARD TABLE OF ty_final_tab,
             wa_final_tab TYPE ty_final_tab.
    How to pass itab gt_final_tab in cl_document_bcs class as an attachment ??
    Anee

    DATA: send_request TYPE REF TO cl_bcs.
    DATA: text TYPE bcsy_text.
    DATA: att_text TYPE bcsy_text.
    DATA: document TYPE REF TO cl_document_bcs.
    DATA: sender TYPE REF TO cl_sapuser_bcs.
    DATA: recipient TYPE REF TO if_recipient_bcs.
    DATA: bcs_exception TYPE REF TO cx_bcs.
    DATA: sent_to_all TYPE os_boolean.
    DATA: lwa_receivers TYPE adr6.
    DATA:lit_receivers TYPE TABLE OF adr6 INITIAL SIZE 0 WITH HEADER LINE.
    lwa_receivers-smtp_addr = 'email1'.
    APPEND lwa_receivers TO lit_receivers.
    lwa_receivers-smtp_addr = ' email2'.
    APPEND lwa_receivers TO lit_receivers.
    TRY.
    create persistent send request
    send_request = cl_bcs=>create_persistent( ).
    create and set document with attachment
    create document from internal table with text
    APPEND p_it_error_records TO text.
    document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = text
    i_length = '12'
    i_subject = 'test mail' ).
    add attachment to document
    REFRESH text.
    APPEND p_it_error_records TO text .
    CALL METHOD document->add_attachment
    EXPORTING
    i_attachment_type = 'RAW'
    i_attachment_subject = 'My attachment'
    i_attachment_size = '21'
    i_att_content_text = text.
    add document to send request
    CALL METHOD send_request->set_document( document ).
    LOOP AT lit_receivers INTO lwa_receivers .
    recipient = cl_cam_address_bcs=>create_internet_address( lwa_receivers-smtp_addr
    ENDLOOP.
    add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
    EXPORTING
    i_recipient = recipient
    i_express = 'X'.
    try to use like this

  • Sending Email using cl_bcs from a badi implementation

    Hi,
    I have written my code to send Email, inside AFTER_SAVE method of BADI Implementation of DOCUMENT_MAIN01.
    Now this method of cl_bcs requires COMMIT WORK for the mail to be sent. And inside BADI implementation, we cannot write a COMMIT statement.
    What is a workaround for this? While going through few other posts, I came across remote enabled FMs.
    Is that the only way? Can I use some additions like STARTING NEW TASK etc. Following is the call used in case of cl_bcs:
       CALL METHOD G_REF_SEND_REQUEST->SEND(
              EXPORTING
                I_WITH_ERROR_SCREEN = 'X'
             RECEIVING
                RESULT              = G_SENT_TO_ALL ).
    I also tried using SO_NEW_DOCUMENT_SEND_API1 STARTING NEW TASK and it works fine. But the subject length is a constraint their.
    Please suggest.
    Thanks in advance.

    Hi friend.
    *& Report  ZTEST_273068_EMAIL_CL_BCS
    REPORT  ZTEST_273068_EMAIL_CL_BCS.
    CONSTANTS:
        gc_subject TYPE so_obj_des VALUE 'ABAP Email with CL_BCS',
        gc_raw     TYPE char03 VALUE 'RAW'.
      DATA:
        gv_mlrec         TYPE so_obj_nam,
        gv_sent_to_all   TYPE os_boolean,
        gv_email         TYPE adr6-smtp_addr,
        gv_subject       TYPE so_obj_des,
        gv_text          TYPE bcsy_text,
        gr_send_request  TYPE REF TO cl_bcs,
        gr_bcs_exception TYPE REF TO cx_bcs,
        gr_recipient     TYPE REF TO if_recipient_bcs,
        gr_sender        TYPE REF TO cl_sapuser_bcs,
        gr_document      TYPE REF TO cl_document_bcs.
      TRY.
          "Create send request
          gr_send_request = cl_bcs=>create_persistent( ).
          "Email FROM...
          gr_sender = cl_sapuser_bcs=>create( sy-uname ).
          "Add sender to send request
          CALL METHOD gr_send_request->set_sender
            EXPORTING
              i_sender = gr_sender.
          "Email TO...
          gv_email = '[email protected]'.
          gr_recipient = cl_cam_address_bcs=>create_internet_address( gv_email ).
          "Add recipient to send request
          CALL METHOD gr_send_request->add_recipient
            EXPORTING
              i_recipient = gr_recipient
              i_express   = 'X'.
          "Email BODY
          APPEND 'Hello world! My first ABAP email!' TO gv_text.
          gr_document = cl_document_bcs=>create_document(
                          i_type    = gc_raw
                          i_text    = gv_text
                          i_length  = '12'
                          i_subject = gc_subject ).
          "Add document to send request
          CALL METHOD gr_send_request->set_document( gr_document ).
          "Send email
          CALL METHOD gr_send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = gv_sent_to_all ).
          IF gv_sent_to_all = 'X'.
            WRITE 'Email sent!'.
          ENDIF.
          "Commit to send email
          COMMIT WORK.
          "Exception handling
        CATCH cx_bcs INTO gr_bcs_exception.
          WRITE:
            'Error!',
            'Error type:',
            gr_bcs_exception->error_type.
      ENDTRY.
    Just Execute it.
    Regards,
    Thrimu

  • Sending email using CL_BCS in the background with subject line 255 chars

    Hello Gurus,
           Following is the sample code,. When I run in the foreground, I am getting the mail, with proper subject line. However my output medium type is '5-'External Send#. When I am trying to run this in my output program, it is resulting in dump.
           When I keep 'COMMIT WORK',  I am getting a dump saying tText * Invalid COMMIT WORK in an update function module.*
           When I remove this 'COMMIT WORK', I am still getting the error, saying Screen output without connection to user. (The current ABAP program "SAPLSTXC" statements could not be executed.)
          Hoping for a quick solution.
    Regards,
    Shaheen
    REPORT  Z_CL_BCS_TEST.
    * Trying classes
    DATA: send_request        TYPE REF TO cl_bcs.
    DATA: li_main_text        TYPE bcsy_text,
          lw_main_text        LIKE LINE OF li_main_text.
    DATA: document            TYPE REF TO cl_document_bcs.
    DATA: recipient           TYPE REF TO if_recipient_bcs.
    DATA: sender              TYPE REF TO if_sender_bcs.
    DATA: l_mtitle            LIKE sodocchgi1-obj_descr.
    DATA: sent_to_all         TYPE os_boolean.
    DATA: bcs_exception       TYPE REF TO cx_bcs.
    DATA: lv_sub TYPE string.
    TRY.
    *     -------- create persistent send request ------------------------
        send_request = cl_bcs=>create_persistent( ).
    *     -------- create and set document---------------
    *     Email title
        l_mtitle = 'attachment'.
        lv_sub = 'Email Title : I want to try for a subject which is more than 50 chars. will this work?'.
        CALL METHOD send_request->set_message_subject
          EXPORTING
            ip_subject = lv_sub.
    *     Fill the body of the mail
        REFRESH li_main_text.
        lw_main_text = 'This is test email'.
        APPEND lw_main_text TO li_main_text.
        CLEAR: lw_main_text.
        lw_main_text = 'Regards'.
        APPEND lw_main_text TO li_main_text.
        CLEAR: lw_main_text.
    *     Create Email Object
        document = cl_document_bcs=>create_document(
          i_type    = 'RAW'
          i_text    = li_main_text
          i_subject = l_mtitle ).
    *     Add document object to send request
        send_request->set_document( document ).
    *     add recipient (e-mail address)
        recipient =
            cl_cam_address_bcs=>create_internet_address(
                  'Shaheen.Taori at solvay.com' ).           " changed the email id purposefully
    *     Add recipient object to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient = recipient
            i_express   = 'X'.
    *     ---------- send document ---------------------------------------
    *    sent_to_all = send_request->SEND_WITHOUT_DIALOG( I_WITH_ERROR_SCREEN = ' ').
        CALL METHOD send_request->SEND_WITHOUT_DIALOG.
    *      EXPORTING
    *        e_sent_to_all = 'X'.
    *    IF sent_to_all IS INITIAL.
    *      MESSAGE 'Erorr while sending email ' TYPE 'E'.
    *      EXIT.
    *    ENDIF.
          COMMIT WORK.
    *   exception handling
      CATCH cx_bcs INTO bcs_exception.
        MESSAGE i865(so) WITH bcs_exception->error_type.
    ENDTRY.

    Try using method SEND instead of SEND_WITHOUT_DIALOG.
    Also try calling method SET_SEND_IMMEDIATELY before calling method SEND.
    Use below code lines,
    send_request->set_send_immediately( i_send_immediately = 'X' ).
    sent_to_all = send_request->send( i_with_error_screen = 'X' ).   " Instead of CALL METHOD send_request->SEND_WITHOUT_DIALOG.

  • How to send Email to customer when clicked on hyperlink on SAP CRM web UI

    Hi all,
    I am working with SAP CRM 7.0 EHP1. I have one field named Email on Complaint description page on Web client UI. I have made the field a hyperlink by using the setter getter methods of attribute in component workbench for the component -BT120H_CPL. Now I want to send one mail to customer who have raised the complaint when clicked on the hyperlink Email through SAP CRM if possible or by using Microsoft  outlook(Microsoft outlook is default mailing server on the system).
    Please help !
    Thanks and regards,
    Kavita Chaudhary
    Mobile: 8800222151

    Hi kavitha Chaudhary,
    if you wan to send any details to outside mail id first you should get that person mail id. based on that you can send data to that mail id by using this code...
    just fallow this code in your event..
    DATA: send_request       TYPE REF TO cl_bcs.
    DATA: text               TYPE bcsy_text.
    DATA: document           TYPE REF TO cl_document_bcs.
    DATA: sender             TYPE REF TO cl_sapuser_bcs.
    DATA: recipient          TYPE REF TO if_recipient_bcs.
    DATA: bcs_exception      TYPE REF TO cx_bcs.
    DATA: sent_to_all        TYPE os_boolean.
    TRY.
    *     -------- create persistent send request ------------------------
           send_request = cl_bcs=>create_persistent( ).
    *     -------- create and set document -------------------------------
    *     create document from internal table with text
           APPEND 'Hi to all' TO text.
           document = cl_document_bcs=>create_document(
                           i_type    = 'RAW'
                           i_text    = text
                           i_length  = '12'
                           i_subject = 'test created by srinivas' ).
    *     add document to send request
           CALL METHOD send_request->set_document( document ).
            sender = cl_sapuser_bcs=>create( sy-uname ).
           CALL METHOD send_request->set_sender
             EXPORTING
               i_sender = sender.
    * hardcoded value im passing here u should capture customer mail id here..
    data : lv_email type string.
    lv_email = '[email protected]'.
    *     --------- add recipient (e-mail address) -----------------------
    *     create recipient - please replace e-mail address !!!
           recipient = cl_cam_address_bcs=>create_internet_address(
                                             lv_email ).
    *     add recipient with its respective attributes to send request
           CALL METHOD send_request->add_recipient
             EXPORTING
               i_recipient = recipient
               i_express   = 'X'.
    *     ---------- send document ---------------------------------------
           CALL METHOD send_request->send(
             EXPORTING
               i_with_error_screen = 'X'
             RECEIVING
               result              = sent_to_all ).
           IF sent_to_all = 'X'.
             WRITE text-003.
           ENDIF.
           COMMIT WORK.
    * *                     exception handling
    * * replace this very rudimentary exception handling
    * * with your own one !!!
         CATCH cx_bcs INTO bcs_exception.
           WRITE: text-001.
           WRITE: text-002, bcs_exception->error_type.
           EXIT.
       ENDTRY.
    after this go to sost transaction.
    first you can see first mail.. select your recent mail id execute then you will get email..
    try this and let me know..
    if this is not working then see this link too this might be help full to you.
    Hyperlink in Email using Send Mail Activity
    Thanks & Regards,
    Srinivask.

  • Sending An email from BSP

    Hi All
    i need to send an email  from BSP application when check box is clicked .
    I have the details such as pernr of an employeee by using this i need to retrieve email id of that employee and have to send an email to that employee with some text
    1. How  to retireve email id of an employee using pernr 
    2.How to send email from bsp application
    Thanks

    Hi ,
    <b>To get the Email for the given PERNR:</b>
    * Get the Communication detail from Infotype 0105
          SELECT
           USRID_LONG
           FROM PA0105 INTO
             RECEIVER_EMAIL
           WHERE PERNR = PERNR AND
                 BEGDA <= SY-DATLO     AND
                 ENDDA >= SY-DATLO     AND
                 SUBTY = '0010'
    <b>Look at this code which will send a email from BSP..</b>
    DATA:
       SEND_REQUEST       TYPE REF TO CL_BCS,
       DOCUMENT           TYPE REF TO CL_DOCUMENT_BCS,
       SENDER             TYPE REF TO CL_SAPUSER_BCS,
       RECIPIENT          TYPE REF TO IF_RECIPIENT_BCS,
       EXCEPTION_INFO     TYPE REF TO IF_OS_EXCEPTION_INFO,
       BCS_EXCEPTION      TYPE REF TO CX_BCS,
       WA_MESSAGE TYPE BAPIRET2.
      DATA:
       LEN   TYPE I,
       TEXTLENGTH TYPE SO_OBJ_LEN,
       ITAB_MESSAGE TYPE SOLI_TAB,
       WA_SOLI TYPE SOLI.
    *Load class defnitions
      CLASS CL_CAM_ADDRESS_BCS DEFINITION LOAD.
      CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
    * Create persistent send request
      TRY.
          SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
    * Format the message content to be sent into internal table
          IF NOT MESSAGE IS INITIAL.
            WA_SOLI-LINE = MESSAGE.
            APPEND WA_SOLI TO ITAB_MESSAGE.
          ELSE.
            WA_MESSAGE-MESSAGE = `Enter some Message and then Click "Send Your Message" button.`.
            APPEND WA_MESSAGE TO RETURN.
            ERROR = 'X'.
            RETURN.
          ENDIF.
          LEN = STRLEN( MESSAGE ).
          TEXTLENGTH = LEN.
    * Create document
          CALL METHOD CL_DOCUMENT_BCS=>CREATE_DOCUMENT
            EXPORTING
              I_TYPE    = 'RAW'
              I_SUBJECT = SUBJECT
              I_LENGTH  = TEXTLENGTH
              I_TEXT    = ITAB_MESSAGE
            RECEIVING
              RESULT    = DOCUMENT.
    * Add document to send request
          CALL METHOD SEND_REQUEST->SET_DOCUMENT
            EXPORTING
              I_DOCUMENT = DOCUMENT.
    * Get sender object
          CALL METHOD CL_SAPUSER_BCS=>CREATE
            EXPORTING
              I_USER = SY-UNAME
            RECEIVING
              RESULT = SENDER.
    * Add sender
          CALL METHOD SEND_REQUEST->SET_SENDER
            EXPORTING
              I_SENDER = SENDER.
    * Create recipient
          CALL METHOD CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS
            EXPORTING
              I_ADDRESS_STRING = RECEIVER
            RECEIVING
              RESULT           = RECIPIENT.
    * Add recipient with its respective attributes to send request
          CALL METHOD SEND_REQUEST->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT  = RECIPIENT
              I_EXPRESS    = ' '
              I_COPY       = ' '
              I_BLIND_COPY = ' '.
          SEND_REQUEST->SET_SEND_IMMEDIATELY( 'X' ).
    * Send document
          CALL METHOD SEND_REQUEST->SEND
            RECEIVING
              RESULT = SENT.
          IF SENT IS NOT INITIAL.
            COMMIT WORK.
            WA_MESSAGE-MESSAGE = 'Your Message sent Successfully!!!'.
            APPEND WA_MESSAGE TO RETURN.
          ELSE.
            ERROR = 'X'.
            WA_MESSAGE-MESSAGE = 'Your Message could not be sent. Please try again later'.
            APPEND WA_MESSAGE TO RETURN.
          ENDIF.
        CATCH CX_ADDRESS_BCS .
        CATCH CX_SEND_REQ_BCS.
        CATCH CX_DOCUMENT_BCS.
          WA_MESSAGE-MESSAGE = 'Your Message could not be sent. Please try again later'.
          APPEND WA_MESSAGE TO RETURN.
          ERROR = 'X'.
      ENDTRY.
    Raja T

  • Sending an email, containing an adobe interactive form, as a step in a gp

    I'm trying to create a process in gp.
    the first step is an interactive form that is submitted to netweaver and starts the gp process.
    second should be another interactive form that the system sends out to an email account.
    wstarting the process by interactive form is not a problem, but sending out emails seems impossible to me :-P...
    i tried by myself, but couldn't work anything out.
    then i searched for a while in the sdn and found the following article by ginger gatling:
    Guided Procedures:  Passing email address for Interactive Form step
    it doesnt help either. dunno what version of netWeaver she was using, but at least in version 7.0 it's not working like she describes. also it's not possible to insert an email adress via predefining the appropriate field in the attributes tab.
    i would be very glad if someone could provide me a hint to solve this problem.

    This is the way how to send the form through mail.
    Generate and Send the Form
    The next step is to write the ABAP program which will create the form and email it to the vendor so that it can be filled offline.
    The program will have the following steps:
    u2022 Data retrieval and processing : A select statement for the pre-populated information
    u2022 Obtain the name of the Generated Function Module of the form
    u2022 Start the form processing
    u2022 Call the Generated Function Module
    u2022 End form processing
    u2022 Send the form to the vendor using Business communication services (BCS)
    Data Retrieval and Processing
    This can be as simple as a select statement to complex data selection. In this example we select the vendor number, name and company code from the vendor table LFA1 based on the vendor from the selection screen
    Get vendor data
    select single lifnr name1 bukrs from lfa1 into wa_vndbnk where lifnr = p_lifnr.
    Get the Generated Function Module
    The next step is to get the generated function module. Call function module FP_FUNCTION_MODULE_NAME and pass the form name to it. The parameter e_funcname will contain the name of the generated function module name.
    First get name of the generated function module
    call function 'FP_FUNCTION_MODULE_NAME'
    exporting
    i_name = 'ZVK_TESTHD'
    importing
    e_funcname = fm_name.
    Start the Form Processing
    Form printing needs to be explicitly opened and closed. Use the function FP_JOB_OPEN to open the form for printing. The parameter ie_outputparams determines printer settings. This parameter is also where we ask the generated function module to return a PDF file back. Since this is an offline scenario and there is no printing involved we need to suppress the printer dialog popup as well. Optionally there is a parameter connection which can be used to determine the RFC destination for ADS.
    Set output parameters and open spool job
    fp_outputparams-nodialog = 'X'. " suppress printer dialog popup
    fp_outputparams-GETPDF = 'X'. " launch print preview
    call function 'FP_JOB_OPEN'
    changing
    ie_outputparams = fp_outputparams
    exceptions
    cancel = 1
    usage_error = 2
    system_error = 3
    internal_error = 4
    others = 5.
    Call the Generated Function Module
    This is similar to the generated function module in Smart Forms. Since the parameters of the function module are defined in the interface, this will vary from form to form. However, /1bcdwb/docparams is a standard parameter. This is used to set the forms locale. This is also where we tell the form that it is fillable. Once this parameter is set - if the ADS is configured correctly (including the credential) - a fillable savable form will be returned when the function module is executed.
    Set form language and country (->form locale)
    fp_docparams-langu = 'E'.
    fp_docparams-country = 'US'.
    fp_docparams-FILLABLE = 'X'.
    Now call the generated function module
    call function fm_name
    exporting
    /1bcdwb/docparams = fp_docparams
    Z_VNDBNK = wa_vndbnk
    importing
    /1BCDWB/FORMOUTPUT = fp_formoutput
    exceptions
    usage_error = 1
    system_error = 2
    internal_error = 3
    others = 4.
    End Form Processing
    Use the function FP_JOB_CLOSE to close the form for printing.
    Close spool job
    call function 'FP_JOB_CLOSE'
    exceptions
    usage_error = 1
    system_error = 2
    internal_error = 3
    others = 4.
    Send the Form to the Vendor
    The PDF file generated is available in the parameter fp_result which is returned by the generated function module. The next step would be to extract this PDF and send it to the vendor using BCS.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
    buffer = fp_formoutput-PDF "PDF file from function module
    TABLES
    binary_tab = lt_att_content_hex.
    CLASS cl_bcs DEFINITION LOAD.
    DATA:
    lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
    lo_send_request = cl_bcs=>create_persistent( ).
    Message body and subject
    DATA:
    lt_message_body TYPE bcsy_text VALUE IS INITIAL,
    lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
    APPEND 'Dear Vendor,' TO lt_message_body.
    append ' ' to lt_message_body.
    APPEND 'Please fill the attached form and send it back to us.'
    TO lt_message_body.
    append ' ' to lt_message_body.
    APPEND 'Thank You,' TO lt_message_body.
    lo_document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = lt_message_body
    i_subject = 'Vendor Payment Form' ).
    DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
    TRY.
    lo_document->add_attachment(
    EXPORTING
    i_attachment_type = 'PDF'
    i_attachment_subject = 'Vendor Payment Form'
    I_ATTACHMENT_SIZE =
    I_ATTACHMENT_LANGUAGE = SPACE
    I_ATT_CONTENT_TEXT =
    I_ATTACHMENT_HEADER =
    i_att_content_hex = lt_att_content_hex ).
    CATCH cx_document_bcs INTO lx_document_bcs.
    ENDTRY.
    Add attachment
    Pass the document to send request
    lo_send_request->set_document( lo_document ).
    Create sender
    DATA:
    lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
    l_send type ADR6-SMTP_ADDR value 'email address',
    lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).
    Set sender
    lo_send_request->set_sender(
    EXPORTING
    i_sender = lo_sender ).
    Create recipient
    *DATA:
    lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
    lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
    Set recipient
    lo_send_request->add_recipient(
    EXPORTING
    i_recipient = lo_recipient
    i_express = 'X' ).
    lo_send_request->add_recipient(
    EXPORTING
    i_recipient = lo_recipient
    i_express = 'X' ).
    Send email
    DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
    lo_send_request->send(
    EXPORTING
    i_with_error_screen = 'X'
    RECEIVING
    result = lv_sent_to_all ).
    COMMIT WORK.
    message 'The payment form has been emailed to the Vendor' type 'I'.

  • Problem by  Sending an Email with attached Adobe Interactive Form (Code)

    Thanks. I have written Programm, but it does not work as i want it to do. I will send an Email with attached Adobe Interactive Firm to [email protected]. I tried it with "*lo_recipient = cl_sapuser_bcs=>create( sy-uname )" at the marked(bold, fat) position. It worked but the Email was send to my SAP-Account, but i want to send to [email protected], so I tried this (see at code in bold, fat):
    lo_rec TYPE adr6-smtp_addr VALUE '[email protected]'. " Empfänger Receiver
    lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).
    But it doens`t send the email.
    Can anybody help me please???
    Kevin
    Here my Code:
    Report FP_EXAMPLE_01
    Printing of documents using PDF based forms
    REPORT z_example_02.
    Data declaration
    DATA: carr_id TYPE sbook-carrid,
    customer TYPE scustom,
    bookings TYPE ty_bookings,
    connections TYPE ty_connections,
    fm_name TYPE rs38l_fnam,
    fp_docparams TYPE sfpdocparams,
    fp_outputparams TYPE sfpoutputparams,
    error_string TYPE string,
    l_booking TYPE sbook,
    t_sums TYPE TABLE OF sbook,
    l_sums LIKE LINE OF t_sums,
    fp_formoutput TYPE fpformoutput.
    PARAMETER: p_custid TYPE scustom-id DEFAULT 38.
    SELECT-OPTIONS: s_carrid FOR carr_id DEFAULT 'AA' TO 'ZZ'.
    PARAMETER: p_form TYPE tdsfname DEFAULT 'FP_EXAMPLE_01'.
    PARAMETER: language TYPE sfpdocparams-langu DEFAULT 'E'.
    PARAMETER: country TYPE sfpdocparams-country DEFAULT 'US'.
    Get data from the following tables: scustom(Flight customer)
    sbook (Single flight reservation)
    spfli (Flight plan)
    SELECT SINGLE * FROM scustom INTO customer WHERE id = p_custid.
    CHECK sy-subrc = 0.
    SELECT * FROM sbook INTO TABLE bookings
    WHERE customid = p_custid
    AND carrid IN s_carrid
    ORDER BY PRIMARY KEY.
    SELECT * FROM spfli INTO TABLE connections
    FOR ALL ENTRIES IN bookings
    WHERE carrid = bookings-carrid
    AND connid = bookings-connid
    ORDER BY PRIMARY KEY.
    Print data:
    First get name of the generated function module
    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
    EXPORTING
    i_name = p_form
    IMPORTING
    e_funcname = fm_name.
    IF sy-subrc <> 0.
    MESSAGE e001(fp_example).
    ENDIF.
    Set output parameters and open spool job
    fp_outputparams-nodialog = 'X'. " suppress printer dialog popup
    fp_outputparams-getpdf = 'X'. " launch print preview
    CALL FUNCTION 'FP_JOB_OPEN'
    CHANGING
    ie_outputparams = fp_outputparams
    EXCEPTIONS
    cancel = 1
    usage_error = 2
    system_error = 3
    internal_error = 4
    OTHERS = 5.
    Set form language and country (->form locale)
    fp_docparams-langu = language.
    fp_docparams-country = country.
    *fp_docparams-fillable = 'X'.
    *fp_docparams-langu = 'E'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden
    *fp_docparams-country = 'GB'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden
    currency key dependant summing
    LOOP AT bookings INTO l_booking.
    l_sums-forcuram = l_booking-forcuram.
    l_sums-forcurkey = l_booking-forcurkey.
    COLLECT l_sums INTO t_sums.
    ENDLOOP.
    Now call the generated function module
    CALL FUNCTION fm_name
    EXPORTING
    /1bcdwb/docparams = fp_docparams
    customer = customer
    bookings = bookings
    connections = connections
    t_sums = t_sums
    IMPORTING
    /1bcdwb/formoutput = fp_formoutput
    EXCEPTIONS
    usage_error = 1
    system_error = 2
    internal_error = 3
    OTHERS = 4.
    IF sy-subrc <> 0.
    CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
    IMPORTING
    e_adserrstr = error_string.
    IF NOT error_string IS INITIAL.
    we received a detailed error description
    WRITE:/ error_string.
    EXIT.
    ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    ENDIF.
    Close spool job
    CALL FUNCTION 'FP_JOB_CLOSE'
    EXCEPTIONS
    usage_error = 1
    system_error = 2
    internal_error = 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.
    *********************Send the form*******************
    *********************to the Customer*****************
    *********************via Email***********************
    *IF i_down = abap_true.
    DATA: filename TYPE string,
    path TYPE string,
    fullpath TYPE string,
    default_extension TYPE string VALUE 'PDF'.
    Data:
    lt_att_content_hex TYPE solix_tab.
    *DATA: data_tab TYPE TABLE OF x255.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
    buffer = fp_formoutput-pdf
    TABLES
    binary_tab = lt_att_content_hex.
    CLASS cl_bcs DEFINITION LOAD.
    DATA:
    lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
    lo_send_request = cl_bcs=>create_persistent( ).
    DATA:
    lt_message_body TYPE bcsy_text VALUE IS INITIAL.
    DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
    APPEND 'Dear Vendor,' TO lt_message_body.
    APPEND ' ' TO lt_message_body.
    APPEND 'Please fill the attached form and send it back to us.'
    TO lt_message_body.
    APPEND ' ' TO lt_message_body.
    APPEND 'Thank You,' TO lt_message_body.
    lo_document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = lt_message_body
    i_subject = 'Vendor Payment Form' ).
    DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
    TRY.
    lo_document->add_attachment(
    EXPORTING
    i_attachment_type = 'PDF'
    i_attachment_subject = 'Vendor Payment Form'
    i_att_content_hex = lt_att_content_hex ).
    CATCH cx_document_bcs INTO lx_document_bcs.
    ENDTRY.
    lo_send_request->set_document( lo_document ).
    DATA:
    lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
    lo_send TYPE adr6-smtp_addr VALUE '[email protected]'. "Absender SENDER
    lo_sender = cl_cam_address_bcs=>create_internet_address( lo_send ).
    Set sender
    lo_send_request->set_sender(
    EXPORTING
    i_sender = lo_sender ).
    Create recipient
    DATA:
    lo_recipient type ref to if_recipient_bcs value is initial.
    Data:
    lo_rec TYPE adr6-smtp_addr VALUE '[email protected]'. " Empfänger Receiver
    lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).
    *lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
    Set recipient
    lo_send_request->add_recipient(
    EXPORTING
    i_recipient = lo_recipient
    i_express = 'X' ).
    *lo_send_request->add_recipient(
    *EXPORTING
    *i_recipient = lo_recipient
    *i_express = 'X' ).
    Send email
    DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
    lo_send_request->send(
    EXPORTING
    i_with_error_screen = 'X'
    RECEIVING
    result = lv_sent_to_all ).
    COMMIT WORK.
    MESSAGE 'The payment form has been emailed to the Vendor' TYPE 'I'.

    Hi Kevin,
    Please try this code to send your mail, i wrote it and works well in many system.
    Take care if in your profile you got an e-mail adress define .
    Take care also of trnasaction SCOT customizing, are you able to send mail to e-mail adress ?
    Let me know if it's works.
    Best regards.
    <i>**----
    CLASS-DEFINITIONS
    DATA: send_request       TYPE REF TO cl_bcs.
    DATA: document           TYPE REF TO cl_document_bcs.
    DATA: sender             TYPE REF TO cl_sapuser_bcs.
    DATA: recipient          TYPE REF TO if_recipient_bcs.
    INTERNAL TABLES
    DATA: l_mailtext TYPE soli_tab.
    DATA: iaddsmtp   TYPE TABLE OF bapiadsmtp.
    DATA: ireturn    TYPE TABLE OF bapiret2.
    VARIABLES
    DATA: mail_line  LIKE LINE OF l_mailtext.
    DATA: bapiadsmtp         TYPE bapiadsmtp.
    DATA: subject    TYPE so_obj_des.
    DATA : att_subject TYPE so_obj_des.
    DATA : w_except TYPE REF TO cx_root .
    CONSTANTS : c_defmail TYPE ad_smtpadr VALUE
                     '[email protected]' .
    FIELD-SYMBOLS : <smtp> TYPE bapiadsmtp.
    *Convert the pdf given by function module into Binary .
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = output-pdf "PDF file from function module
      TABLES
        binary_tab = hexa.
    *Set subject of the mail
    subject = 'Exemple de PDF interactif'.
    Set text of the mail
    mail_line = 'Merci de remplir le formulaire et nous le retourner'.
    APPEND mail_line TO l_mailtext .
    Set the name of the attached document
    att_subject = 'Template du PDF'.
    TRY.
    Create persistent send request
        send_request = cl_bcs=>create_persistent( ).
    Get sender object
        sender = cl_sapuser_bcs=>create( sy-uname ).
    Add sender
        CALL METHOD send_request->set_sender
          EXPORTING
            i_sender = sender.
    Read the E-Mail address for the user
        CALL FUNCTION 'BAPI_USER_GET_DETAIL'
          EXPORTING
            username = sy-uname
          TABLES
            return   = ireturn
            addsmtp  = iaddsmtp.
        LOOP AT iaddsmtp ASSIGNING <smtp> WHERE std_no = 'X'.
          CLEAR bapiadsmtp.
          MOVE <smtp> TO bapiadsmtp.
        ENDLOOP.
        CASE bapiadsmtp-e_mail.
          WHEN space.
    No adress main for user, so send it to the default mail adress
            recipient =
         cl_cam_address_bcs=>create_internet_address( c_defmail ).
          WHEN OTHERS.
            recipient =
         cl_cam_address_bcs=>create_internet_address( bapiadsmtp-e_mail ).
        ENDCASE.
    Add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient  = recipient
            i_express    = 'X'
            i_copy       = space
            i_blind_copy = space
            i_no_forward = space.
    Set that you don't need a Return Status E-mail
        CALL METHOD send_request->set_status_attributes
          EXPORTING
            i_requested_status = 'E'
            i_status_mail      = 'E'.
    set send immediately flag
        send_request->set_send_immediately( 'X' ).
    *Build Document
        document = cl_document_bcs=>create_document(
                            i_type    = 'RAW'
                            i_text    = l_mailtext
                            i_subject = subject ).
        add attachment to document
        CALL METHOD document->add_attachment
          EXPORTING
            i_attachment_type    = 'PDF'
            i_attachment_subject = att_subject
            i_att_content_hex    = hexa.
    Add document to send request
        CALL METHOD send_request->set_document( document ).
    Send document
        CALL METHOD send_request->send( ).
        COMMIT WORK.
      CATCH cx_send_req_bcs INTO w_except.
      CATCH cx_address_bcs INTO w_except.
      CATCH cx_document_bcs INTO w_except.
    ENDTRY.</i>

  • Problem in sending the smartform as an email in a country specific language

    Hi,
    I am facing a problem in sending a smartform as a email for all other Languages except english and another problem is its sending the email but the output status is still in RED in the messages tab.
    the program is working fine for english.
    Please do find the below code using which i would be sending the smartform as an email for a PO along with the line item attachments.
    Please help.
    Arun.
    Determine smartform function module for purchase document
      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.
        IF sy-subrc = 1.
          MESSAGE e001(/smb40/ssfcomposer).
        ENDIF.
        IF sy-subrc = 2.
          MESSAGE e002(/smb40/ssfcomposer) WITH tnapr-sform.
        ENDIF.
        PERFORM protocol_update_i.
      ENDIF.
    *Start of changes <Arun K Singarapu> C082493 <04/28/2008>
    *for print preview
      IF sy-ucomm = 'PREVOUTPUT' OR sy-ucomm = 'VIEW'.
        CALL FUNCTION lf_fm_name                  "'/1BCDWB/SF00000197'
          EXPORTING
            control_parameters = wa_ctrlop
            output_options     = wa_compop
            user_settings      = 'X'
            is_ekko            = l_doc-xekko
            is_pekko           = l_doc-xpekko
            is_nast            = l_nast
            iv_from_mem        = l_from_memory
            iv_druvo           = iv_druvo
            iv_xfz             = iv_xfz
          IMPORTING
            job_output_info    = wa_return
          TABLES
            it_ekpo            = l_doc-xekpo[]
            it_ekpa            = l_doc-xekpa[]
            it_pekpo           = l_doc-xpekpo[]
            it_eket            = l_doc-xeket[]
            it_tkomv           = l_doc-xtkomv[]
            it_ekkn            = l_doc-xekkn[]
            it_ekek            = l_doc-xekek[]
            it_komk            = 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
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        EXIT.
      ELSE.
        wa_ctrlop-LANGU = nast-spras.
        wa_ctrlop-getotf = 'X'.
        wa_ctrlop-no_dialog = 'X'.
        wa_compop-tdnoprev = 'X'.
        CALL FUNCTION lf_fm_name                  "'/1BCDWB/SF00000197'
          EXPORTING
            control_parameters = wa_ctrlop
            output_options     = wa_compop
            user_settings      = 'X'
            is_ekko            = l_doc-xekko
            is_pekko           = l_doc-xpekko
            is_nast            = l_nast
            iv_from_mem        = l_from_memory
            iv_druvo           = iv_druvo
            iv_xfz             = iv_xfz
          IMPORTING
            job_output_info    = wa_return
          TABLES
            it_ekpo            = l_doc-xekpo[]
            it_ekpa            = l_doc-xekpa[]
            it_pekpo           = l_doc-xpekpo[]
            it_eket            = l_doc-xeket[]
            it_tkomv           = l_doc-xtkomv[]
            it_ekkn            = l_doc-xekkn[]
            it_ekek            = l_doc-xekek[]
            it_komk            = 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
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    *Convert the data from OTF to PDF format
        it_otf[] = wa_return-otfdata[].
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
            max_linewidth         = 132
          IMPORTING
            bin_filesize          = l_len_in
            bin_file              = lp_xcontent
          TABLES
            otf                   = it_otf
            lines                 = it_tline
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 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.
        TRY.
      ---------- create persistent send request ----------------------
            send_request = cl_bcs=>create_persistent( ).
            len = XSTRLEN( lp_xcontent ).
    transform to solix tab
            lt_solix =
              cl_document_bcs=>xstring_to_solix(
                ip_xstring = lp_xcontent ).
    Create Body to the E-mail.
            APPEND Text-005 TO l_text.
    Attachment Name
            l_ponumber = text-004.
            CONCATENATE l_ponumber l_doc-xekko-ebeln INTO l_ponumber.
    Subject for the E-Mail.
            l_subject = text-001.
            CONCATENATE l_subject l_doc-xekko-ebeln INTO l_subject.
    *create document E-Mail.
            CALL METHOD cl_document_bcs=>create_document
              EXPORTING
                i_type    = 'RAW'
                i_subject = l_subject
                i_length  = '13'
                i_text    = l_text
              RECEIVING
                result    = l_email_object.
    *Create PDF Document
            bcs_doc =  cl_document_bcs=>create_document(
                                            i_type     = 'PDF'
                                            i_subject  = l_ponumber
                                            i_length   = len
                                            i_language = nast-spras
                                            i_hex     = lt_solix
    *Type casting
            obj_pdf_file ?= bcs_doc.
    Add PDF document as an attachment
            CALL METHOD l_email_object->add_document_as_attachment
              EXPORTING
                im_document = obj_pdf_file.
    get the attachments of the PO for each line item
            SELECT ebeln
                   ebelp
                   FROM ekpo
                   INTO TABLE it_ekpo
                   WHERE ebeln = l_doc-xekko-ebeln.
    concatenate PO and the Line Item Numebr to get the Object key
            LOOP AT it_ekpo INTO wa_ekpo.
              CONCATENATE wa_ekpo-ebeln wa_ekpo-ebelp INTO wa_temp-objky.
              APPEND wa_temp TO it_temp.
              CLEAR: wa_temp,wa_ekpo.
            ENDLOOP.
    *Get data from table DRAD
            IF it_temp[] IS NOT INITIAL.
              SELECT dokar
                     doknr
                     dokvr
                     doktl
                     objky
                     FROM drad
                     client specified
                     INTO TABLE it_drad
                     FOR ALL ENTRIES IN it_temp
                     WHERE mandt = sy-mandt
                     AND objky = it_temp-objky.
            ENDIF.
            IF NOT it_drad IS INITIAL.
              SELECT * FROM dms_doc2loio
                       INTO TABLE it_dms_doc2loio
                       FOR ALL ENTRIES IN it_drad
                       WHERE dokar = 'SRM'
                         AND doknr = it_drad-doknr
                         AND dokvr = it_drad-dokvr
                         AND doktl = it_drad-doktl.
            ENDIF.
    Get the Physical object class and Object ID of the attachment
            IF NOT it_dms_doc2loio IS INITIAL.
              SELECT * FROM dms_ph_cd1
                       INTO TABLE it_dms_ph_cd1
                       FOR ALL ENTRIES IN it_dms_doc2loio
                       WHERE loio_id = it_dms_doc2loio-lo_objid.
            ENDIF.
    Get the file from the DMS server using the below function module.
            LOOP AT it_dms_ph_cd1 INTO wa_dms_ph_cd1.
              wa_object_id-class = wa_dms_ph_cd1-ph_class.
              wa_object_id-objid = wa_dms_ph_cd1-phio_id.
              CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
                EXPORTING
                  object_id           = wa_object_id
                  client              = sy-mandt
                TABLES
                  file_access_info    = it_file_access_info
                  file_content_binary = it_sdokcntbin
                EXCEPTIONS
                  not_existing        = 1
                  not_authorized      = 2
                  no_content          = 3
                  bad_storage_type    = 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.
              READ TABLE it_file_access_info INTO wa_file_access_info INDEX 1.
              IF wa_file_access_info-mimetype = 'application/msword'.
                l_doc_type = 'DOC'.
                CLEAR: a_xstring,len.
                LOOP AT it_sdokcntbin INTO wa_sdokcntbin.
                  CONCATENATE a_xstring wa_sdokcntbin-line
                         INTO a_xstring IN BYTE MODE.
                ENDLOOP.
                len = XSTRLEN( a_xstring ).
        transform to solix tab - adding additional attachments
                REFRESH lt_solix.
                lt_solix =
                  cl_document_bcs=>xstring_to_solix(
                    ip_xstring = a_xstring ).
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_solix
    *Type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for PDF document
              ELSEIF wa_file_access_info-mimetype = 'application/pdf'.
                l_doc_type = 'PDF'.
                file_size = wa_file_access_info-file_size.
    Convert the 1022 binary data to xstring
                CLEAR a_xstring.
                CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
                  EXPORTING
                    input_length = file_size
                  IMPORTING
                    buffer       = a_xstring
                  TABLES
                    binary_tab   = it_sdokcntbin
                  EXCEPTIONS
                    failed       = 1
                    OTHERS       = 2.
                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: w_output_length TYPE i.
    Convert Xstring to 255 RAW
                CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
                  EXPORTING
                    buffer        = a_xstring
                  IMPORTING
                    output_length = w_output_length
                  TABLES
                    binary_tab    = lt_content_bin.
                len = w_output_length.
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_content_bin
           type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for Excel Document
              ELSEIF wa_file_access_info-mimetype = 'application/msexcel'.
                l_doc_type = 'XLS'.
                CLEAR: a_xstring,len.
                LOOP AT it_sdokcntbin INTO wa_sdokcntbin.
                  CONCATENATE a_xstring wa_sdokcntbin-line
                         INTO a_xstring IN BYTE MODE.
                ENDLOOP.
                len = XSTRLEN( a_xstring ).
        transform to solix tab - adding additional attachments
                REFRESH lt_solix.
                lt_solix =
                  cl_document_bcs=>xstring_to_solix(
                    ip_xstring = a_xstring ).
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_solix
    *Type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for text doxument
              ELSEIF wa_file_access_info-mimetype = 'plain/text'.
                l_doc_type = 'TXT'.
                file_size = wa_file_access_info-file_size.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
                  EXPORTING
                    input_length = file_size
                  TABLES
                    binary_tab   = it_sdokcntbin
                    text_tab     = file_data
                  EXCEPTIONS
                    failed       = 1
                    OTHERS       = 2.
                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 METHOD cl_document_bcs=>create_document
                  EXPORTING
                    i_type    = l_doc_type
                    i_subject = l_filename
                    i_text    = file_data
                  RECEIVING
                    result    = bcs_doc1.
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
              ENDIF.
              CLEAR:it_file_access_info,it_sdokcntbin.
              CLEAR:wa_object_id,wa_file_access_info,file_size.
            ENDLOOP.
            CALL METHOD send_request->set_document( l_email_object ).
    *Get the address number for the vendor
            SELECT SINGLE adrnr
                          FROM lfa1
                          INTO l_adrnr
                          WHERE lifnr = l_doc-xekko-lifnr.
            MOVE l_adrnr TO l_addrno.
    Get the Email Address for the vendor using address number
            CALL FUNCTION 'ADDR_GET_REMOTE'
              EXPORTING
                addrnumber        = l_addrno
              TABLES
                adsmtp            = it_adsmtp
              EXCEPTIONS
                parameter_error   = 1
                address_not_exist = 2
                internal_error    = 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.
            sender = cl_sapuser_bcs=>create( sy-uname ).
            CALL METHOD send_request->set_sender
              EXPORTING
                i_sender = sender.
            READ TABLE it_adsmtp INTO wa_adsmtp WITH KEY flg_nouse = 'X'.
            IF sy-subrc = 0.
              LOOP AT it_adsmtp INTO wa_adsmtp WHERE flg_nouse = 'X'.
                CALL METHOD cl_cam_address_bcs=>create_internet_address
                  EXPORTING
                    i_address_string = wa_adsmtp-smtp_addr
                  RECEIVING
                    result           = recipient.
                CALL METHOD send_request->add_recipient
                  EXPORTING
                    i_recipient = recipient
                    i_express   = 'X'.
              ENDLOOP.
            ELSE.
              READ TABLE it_adsmtp INTO wa_adsmtp WITH KEY flgdefault = 'X'.
              IF sy-subrc = 0.
                CALL METHOD cl_cam_address_bcs=>create_internet_address
                  EXPORTING
                    i_address_string = wa_adsmtp-smtp_addr
                  RECEIVING
                    result           = recipient.
                CALL METHOD send_request->add_recipient
                  EXPORTING
                    i_recipient = recipient
                    i_express   = 'X'.
              ENDIF.
            ENDIF.
            CALL METHOD send_request->send(
             EXPORTING
               i_with_error_screen = 'X'
              RECEIVING
                result              = l_sent_to_all ).
          CATCH cx_bcs INTO bcs_exception.
            WRITE: 'Fehler aufgetreten.'(001).
            WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
            EXIT.
        ENDTRY.
      ENDIF.

    Hi,
    I am facing a problem in sending a smartform as a email for all other Languages except english and another problem is its sending the email but the output status is still in RED in the messages tab.
    the program is working fine for english.
    Please do find the below code using which i would be sending the smartform as an email for a PO along with the line item attachments.
    Please help.
    Arun.
    Determine smartform function module for purchase document
      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.
        IF sy-subrc = 1.
          MESSAGE e001(/smb40/ssfcomposer).
        ENDIF.
        IF sy-subrc = 2.
          MESSAGE e002(/smb40/ssfcomposer) WITH tnapr-sform.
        ENDIF.
        PERFORM protocol_update_i.
      ENDIF.
    *Start of changes <Arun K Singarapu> C082493 <04/28/2008>
    *for print preview
      IF sy-ucomm = 'PREVOUTPUT' OR sy-ucomm = 'VIEW'.
        CALL FUNCTION lf_fm_name                  "'/1BCDWB/SF00000197'
          EXPORTING
            control_parameters = wa_ctrlop
            output_options     = wa_compop
            user_settings      = 'X'
            is_ekko            = l_doc-xekko
            is_pekko           = l_doc-xpekko
            is_nast            = l_nast
            iv_from_mem        = l_from_memory
            iv_druvo           = iv_druvo
            iv_xfz             = iv_xfz
          IMPORTING
            job_output_info    = wa_return
          TABLES
            it_ekpo            = l_doc-xekpo[]
            it_ekpa            = l_doc-xekpa[]
            it_pekpo           = l_doc-xpekpo[]
            it_eket            = l_doc-xeket[]
            it_tkomv           = l_doc-xtkomv[]
            it_ekkn            = l_doc-xekkn[]
            it_ekek            = l_doc-xekek[]
            it_komk            = 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
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
        EXIT.
      ELSE.
        wa_ctrlop-LANGU = nast-spras.
        wa_ctrlop-getotf = 'X'.
        wa_ctrlop-no_dialog = 'X'.
        wa_compop-tdnoprev = 'X'.
        CALL FUNCTION lf_fm_name                  "'/1BCDWB/SF00000197'
          EXPORTING
            control_parameters = wa_ctrlop
            output_options     = wa_compop
            user_settings      = 'X'
            is_ekko            = l_doc-xekko
            is_pekko           = l_doc-xpekko
            is_nast            = l_nast
            iv_from_mem        = l_from_memory
            iv_druvo           = iv_druvo
            iv_xfz             = iv_xfz
          IMPORTING
            job_output_info    = wa_return
          TABLES
            it_ekpo            = l_doc-xekpo[]
            it_ekpa            = l_doc-xekpa[]
            it_pekpo           = l_doc-xpekpo[]
            it_eket            = l_doc-xeket[]
            it_tkomv           = l_doc-xtkomv[]
            it_ekkn            = l_doc-xekkn[]
            it_ekek            = l_doc-xekek[]
            it_komk            = 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
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    *Convert the data from OTF to PDF format
        it_otf[] = wa_return-otfdata[].
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
            max_linewidth         = 132
          IMPORTING
            bin_filesize          = l_len_in
            bin_file              = lp_xcontent
          TABLES
            otf                   = it_otf
            lines                 = it_tline
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 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.
        TRY.
      ---------- create persistent send request ----------------------
            send_request = cl_bcs=>create_persistent( ).
            len = XSTRLEN( lp_xcontent ).
    transform to solix tab
            lt_solix =
              cl_document_bcs=>xstring_to_solix(
                ip_xstring = lp_xcontent ).
    Create Body to the E-mail.
            APPEND Text-005 TO l_text.
    Attachment Name
            l_ponumber = text-004.
            CONCATENATE l_ponumber l_doc-xekko-ebeln INTO l_ponumber.
    Subject for the E-Mail.
            l_subject = text-001.
            CONCATENATE l_subject l_doc-xekko-ebeln INTO l_subject.
    *create document E-Mail.
            CALL METHOD cl_document_bcs=>create_document
              EXPORTING
                i_type    = 'RAW'
                i_subject = l_subject
                i_length  = '13'
                i_text    = l_text
              RECEIVING
                result    = l_email_object.
    *Create PDF Document
            bcs_doc =  cl_document_bcs=>create_document(
                                            i_type     = 'PDF'
                                            i_subject  = l_ponumber
                                            i_length   = len
                                            i_language = nast-spras
                                            i_hex     = lt_solix
    *Type casting
            obj_pdf_file ?= bcs_doc.
    Add PDF document as an attachment
            CALL METHOD l_email_object->add_document_as_attachment
              EXPORTING
                im_document = obj_pdf_file.
    get the attachments of the PO for each line item
            SELECT ebeln
                   ebelp
                   FROM ekpo
                   INTO TABLE it_ekpo
                   WHERE ebeln = l_doc-xekko-ebeln.
    concatenate PO and the Line Item Numebr to get the Object key
            LOOP AT it_ekpo INTO wa_ekpo.
              CONCATENATE wa_ekpo-ebeln wa_ekpo-ebelp INTO wa_temp-objky.
              APPEND wa_temp TO it_temp.
              CLEAR: wa_temp,wa_ekpo.
            ENDLOOP.
    *Get data from table DRAD
            IF it_temp[] IS NOT INITIAL.
              SELECT dokar
                     doknr
                     dokvr
                     doktl
                     objky
                     FROM drad
                     client specified
                     INTO TABLE it_drad
                     FOR ALL ENTRIES IN it_temp
                     WHERE mandt = sy-mandt
                     AND objky = it_temp-objky.
            ENDIF.
            IF NOT it_drad IS INITIAL.
              SELECT * FROM dms_doc2loio
                       INTO TABLE it_dms_doc2loio
                       FOR ALL ENTRIES IN it_drad
                       WHERE dokar = 'SRM'
                         AND doknr = it_drad-doknr
                         AND dokvr = it_drad-dokvr
                         AND doktl = it_drad-doktl.
            ENDIF.
    Get the Physical object class and Object ID of the attachment
            IF NOT it_dms_doc2loio IS INITIAL.
              SELECT * FROM dms_ph_cd1
                       INTO TABLE it_dms_ph_cd1
                       FOR ALL ENTRIES IN it_dms_doc2loio
                       WHERE loio_id = it_dms_doc2loio-lo_objid.
            ENDIF.
    Get the file from the DMS server using the below function module.
            LOOP AT it_dms_ph_cd1 INTO wa_dms_ph_cd1.
              wa_object_id-class = wa_dms_ph_cd1-ph_class.
              wa_object_id-objid = wa_dms_ph_cd1-phio_id.
              CALL FUNCTION 'SDOK_PHIO_LOAD_CONTENT'
                EXPORTING
                  object_id           = wa_object_id
                  client              = sy-mandt
                TABLES
                  file_access_info    = it_file_access_info
                  file_content_binary = it_sdokcntbin
                EXCEPTIONS
                  not_existing        = 1
                  not_authorized      = 2
                  no_content          = 3
                  bad_storage_type    = 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.
              READ TABLE it_file_access_info INTO wa_file_access_info INDEX 1.
              IF wa_file_access_info-mimetype = 'application/msword'.
                l_doc_type = 'DOC'.
                CLEAR: a_xstring,len.
                LOOP AT it_sdokcntbin INTO wa_sdokcntbin.
                  CONCATENATE a_xstring wa_sdokcntbin-line
                         INTO a_xstring IN BYTE MODE.
                ENDLOOP.
                len = XSTRLEN( a_xstring ).
        transform to solix tab - adding additional attachments
                REFRESH lt_solix.
                lt_solix =
                  cl_document_bcs=>xstring_to_solix(
                    ip_xstring = a_xstring ).
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_solix
    *Type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for PDF document
              ELSEIF wa_file_access_info-mimetype = 'application/pdf'.
                l_doc_type = 'PDF'.
                file_size = wa_file_access_info-file_size.
    Convert the 1022 binary data to xstring
                CLEAR a_xstring.
                CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
                  EXPORTING
                    input_length = file_size
                  IMPORTING
                    buffer       = a_xstring
                  TABLES
                    binary_tab   = it_sdokcntbin
                  EXCEPTIONS
                    failed       = 1
                    OTHERS       = 2.
                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: w_output_length TYPE i.
    Convert Xstring to 255 RAW
                CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
                  EXPORTING
                    buffer        = a_xstring
                  IMPORTING
                    output_length = w_output_length
                  TABLES
                    binary_tab    = lt_content_bin.
                len = w_output_length.
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_content_bin
           type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for Excel Document
              ELSEIF wa_file_access_info-mimetype = 'application/msexcel'.
                l_doc_type = 'XLS'.
                CLEAR: a_xstring,len.
                LOOP AT it_sdokcntbin INTO wa_sdokcntbin.
                  CONCATENATE a_xstring wa_sdokcntbin-line
                         INTO a_xstring IN BYTE MODE.
                ENDLOOP.
                len = XSTRLEN( a_xstring ).
        transform to solix tab - adding additional attachments
                REFRESH lt_solix.
                lt_solix =
                  cl_document_bcs=>xstring_to_solix(
                    ip_xstring = a_xstring ).
                CLEAR l_filename.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                bcs_doc1 =  cl_document_bcs=>create_document(
                                                i_type     = l_doc_type
                                                i_subject  = l_filename
                                                i_length   = len
                                                i_language = sy-langu
                                                i_hex     = lt_solix
    *Type casting
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
    for text doxument
              ELSEIF wa_file_access_info-mimetype = 'plain/text'.
                l_doc_type = 'TXT'.
                file_size = wa_file_access_info-file_size.
            Get the file name
                l_filename = wa_file_access_info-file_name.
                CALL FUNCTION 'SCMS_BINARY_TO_TEXT'
                  EXPORTING
                    input_length = file_size
                  TABLES
                    binary_tab   = it_sdokcntbin
                    text_tab     = file_data
                  EXCEPTIONS
                    failed       = 1
                    OTHERS       = 2.
                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 METHOD cl_document_bcs=>create_document
                  EXPORTING
                    i_type    = l_doc_type
                    i_subject = l_filename
                    i_text    = file_data
                  RECEIVING
                    result    = bcs_doc1.
                obj_file ?= bcs_doc1.
    Add Attachment as a document to the email object
                CALL METHOD l_email_object->add_document_as_attachment
                  EXPORTING
                    im_document = obj_file.
              ENDIF.
              CLEAR:it_file_access_info,it_sdokcntbin.
              CLEAR:wa_object_id,wa_file_access_info,file_size.
            ENDLOOP.
            CALL METHOD send_request->set_document( l_email_object ).
    *Get the address number for the vendor
            SELECT SINGLE adrnr
                          FROM lfa1
                          INTO l_adrnr
                          WHERE lifnr = l_doc-xekko-lifnr.
            MOVE l_adrnr TO l_addrno.
    Get the Email Address for the vendor using address number
            CALL FUNCTION 'ADDR_GET_REMOTE'
              EXPORTING
                addrnumber        = l_addrno
              TABLES
                adsmtp            = it_adsmtp
              EXCEPTIONS
                parameter_error   = 1
                address_not_exist = 2
                internal_error    = 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.
            sender = cl_sapuser_bcs=>create( sy-uname ).
            CALL METHOD send_request->set_sender
              EXPORTING
                i_sender = sender.
            READ TABLE it_adsmtp INTO wa_adsmtp WITH KEY flg_nouse = 'X'.
            IF sy-subrc = 0.
              LOOP AT it_adsmtp INTO wa_adsmtp WHERE flg_nouse = 'X'.
                CALL METHOD cl_cam_address_bcs=>create_internet_address
                  EXPORTING
                    i_address_string = wa_adsmtp-smtp_addr
                  RECEIVING
                    result           = recipient.
                CALL METHOD send_request->add_recipient
                  EXPORTING
                    i_recipient = recipient
                    i_express   = 'X'.
              ENDLOOP.
            ELSE.
              READ TABLE it_adsmtp INTO wa_adsmtp WITH KEY flgdefault = 'X'.
              IF sy-subrc = 0.
                CALL METHOD cl_cam_address_bcs=>create_internet_address
                  EXPORTING
                    i_address_string = wa_adsmtp-smtp_addr
                  RECEIVING
                    result           = recipient.
                CALL METHOD send_request->add_recipient
                  EXPORTING
                    i_recipient = recipient
                    i_express   = 'X'.
              ENDIF.
            ENDIF.
            CALL METHOD send_request->send(
             EXPORTING
               i_with_error_screen = 'X'
              RECEIVING
                result              = l_sent_to_all ).
          CATCH cx_bcs INTO bcs_exception.
            WRITE: 'Fehler aufgetreten.'(001).
            WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
            EXIT.
        ENDTRY.
      ENDIF.

  • Format issue in opening an XLS attachment sent through email by ABAP2XLSX

    I have downloaded the ABAP2XLSX nuggets and tried to send an attachment in the email using the SAP. But when opening the attachment it is giving up an format issue and not able to view the content. I am able to save the XLSX file on the PC and able to read it but when I  send it to email it doesn't open correctly and it is in a non readable format. Please find the code that I have been using. Can someone help me on this.
    TYPES: BEGIN OF tp_zzrule,
             zzprog     TYPE zzfunc,
             zzdata     TYPE zzcri1,
             zzseq      TYPE zzseq,
             zzkey1     TYPE zzkey1,
             zzkey2     TYPE zzkey2,
         END OF tp_zzrule.
    DATA: w_zzrule   TYPE tp_zzrule,
          t_zzrule   TYPE TABLE OF zzourule.
    TYPE-POOLS: abap.
    DATA:   v_document            TYPE REF TO cl_document_bcs,
            v_recipient           TYPE REF TO if_recipient_bcs,
            v_main_text           TYPE bcsy_text,
            v_send_request        TYPE REF TO cl_bcs,
            v_msub                TYPE so_obj_des,
             v_size               TYPE so_obj_len,
            v_string2             TYPE string,
            v_attsub              TYPE sood-objdes,
            v_mailid              TYPE ad_smtpadr,
            v_sent(1)             type c,
            v_sent_to_all         TYPE os_boolean,
            v_string              TYPE string,
            v_repid               TYPE sy-repid,
            v_title               TYPE so_text255,
            v_dochead             TYPE so_text255.
    DATA lt_test TYPE TABLE OF sflight.
    DATA: lo_excel                TYPE REF TO zcl_excel,
          lo_excel_writer         TYPE REF TO zif_excel_writer,
          lo_worksheet            TYPE REF TO zcl_excel_worksheet,
          column_dimension        TYPE REF TO zcl_excel_worksheet_columndime.
    DATA: ls_table_settings       TYPE zexcel_s_table_settings.
    DATA: lv_file                 TYPE xstring,
          lv_bytecount            TYPE i,
          lt_file_tab             TYPE solix_tab,
          t_objtxt  like solisti1   occurs 0 with header line,
          t_objbin  like solisti1   occurs 0 with header line,
          t_objpack like sopcklsti1 occurs 0 with header line,
          t_reclist like table of somlreci1 with header line.
    DATA: lv_full_path      TYPE string,
          lv_workdir        TYPE string,
          lv_file_separator TYPE c.
    CONSTANTS: lv_default_file_name TYPE string VALUE 'multi sheet test.xlsx'.
    PARAMETERS: p_path  TYPE zexcel_export_dir,
                p_empty TYPE flag.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
      lv_workdir = p_path.
      cl_gui_frontend_services=>directory_browse( EXPORTING initial_folder  = lv_workdir
                                                  CHANGING  selected_folder = lv_workdir ).
      p_path = lv_workdir.
    INITIALIZATION.
      cl_gui_frontend_services=>get_sapgui_workdir( CHANGING sapworkdir = lv_workdir ).
      cl_gui_cfw=>flush( ).
      p_path = lv_workdir.
    START-OF-SELECTION.
      IF p_path IS INITIAL.
        p_path = lv_workdir.
      ENDIF.
      cl_gui_frontend_services=>get_file_separator( CHANGING file_separator = lv_file_separator ).
      CONCATENATE p_path lv_file_separator lv_default_file_name INTO lv_full_path.
    SELECT *
        INTO TABLE t_zzrule
       FROM zzourule
      WHERE zzprog  = 'RV63A999'.
        SELECT * FROM sflight INTO TABLE lt_test.
      " Creates active sheet
      CREATE OBJECT lo_excel.
    For first Sheet in the excel workbook
      " Get active sheet
      lo_worksheet = lo_excel->get_active_worksheet( ).
      lo_worksheet->set_title( ip_title = 'Test sheet one').
      ls_table_settings-table_style  = zcl_excel_table=>builtinstyle_medium2.
      ls_table_settings-show_row_stripes = abap_true.
      lo_worksheet->bind_table( ip_table          = lt_test
                                is_table_settings = ls_table_settings ).
      lo_worksheet->freeze_panes( ip_num_rows = 3 ). "freeze column headers when scrolling
      column_dimension = lo_worksheet->get_column_dimension( ip_column = 'E' ). "make date field a bit wider
      column_dimension->set_width( ip_width = 20 ).
    For second Sheet in the excel workbook
      lo_worksheet = lo_excel->add_new_worksheet( ).
      lo_worksheet->set_title( ip_title = 'Second sheet' ).
      lo_worksheet->set_cell( ip_column = 'B' ip_row = 2
               ip_value = 'This is the test for second sheet by Pavan' ).
      ls_table_settings-table_style  = zcl_excel_table=>builtinstyle_medium2.
      ls_table_settings-show_row_stripes = abap_true.
      lo_worksheet->bind_table( ip_table          = t_zzrule
                                is_table_settings = ls_table_settings ).
    This will create excel.
    CREATE OBJECT lo_excel_writer TYPE zcl_excel_writer_2007.
      lv_file = lo_excel_writer->write_file( lo_excel ).
    " Convert to binary
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = lv_file
        IMPORTING
          output_length = lv_bytecount
        TABLES
          binary_tab    = lt_file_tab.
    Save the file on to the PC
      cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = lv_bytecount
                                                        filename     = lv_full_path
                                                        filetype     = 'BIN'
                                               CHANGING data_tab     = lt_file_tab ).
    *--Create and set document with attachment.
    v_main_text-line  = 'This is the main text not sure where this would print'.
    append v_main_text.
      TRY.
        v_send_request = cl_bcs=>create_persistent( ).      "#EC .., bzw.
        CATCH cx_send_req_bcs . "#EC NO_HANDLER
      ENDTRY.
      v_msub       = 'Test excel with multi sheets.XLS'.
      TRY.
          v_document = cl_document_bcs=>create_document(
          i_type     = 'RAW'
          i_text     = v_main_text
          i_subject  = v_msub ).
        CATCH cx_document_bcs . "#EC NO_HANDLER
      ENDTRY.
        v_size = lv_bytecount.
    *--Add the attachment.
      TRY.
          v_document->add_attachment(                          "#EC .., bzw
                i_attachment_type    = 'EXT'
               i_attachment_type    = 'XLS'
               i_attachment_type    = 'RAW'
                i_attachment_subject = v_attsub
                i_attachment_size    = v_size
               i_att_content_hex    = lt_file_tab ).    "#EC .., bzw.
               i_att_content_hex    = lt_file_tab ).    "#EC .., bzw.
        CATCH cx_document_bcs . "#EC NO_HANDLER
      ENDTRY.
    *--Add document object to send request.
      TRY.
          v_send_request->set_document( v_document ).         "#EC .., bzw.
        CATCH cx_send_req_bcs . "#EC NO_HANDLER
      ENDTRY.
    *--E-mail recipent list
      t_reclist-rec_type = 'U'.
      t_reclist-receiver = <email Id here>.
      APPEND t_reclist.
      CLEAR t_reclist.
      LOOP AT t_reclist.
        CLEAR v_mailid.
        v_mailid = t_reclist-receiver.
    *--Create mail recipient object.
        TRY.
          v_recipient = cl_cam_address_bcs=>create_internet_address( v_mailid ). "#EC .., bzw.
           CATCH cx_address_bcs . "#EC NO_HANDLER
          ENDTRY.
    *--Add recipient object to send request.
        TRY.
            v_send_request->add_recipient( v_recipient ).     "#EC .., bzw.
          CATCH cx_send_req_bcs . "#EC NO_HANDLER
        ENDTRY.
      ENDLOOP.
    **--Add recipient object to send request.
      TRY.
        v_sent_to_all = v_send_request->send( i_with_error_screen = 'X' ).
    CATCH cx_send_req_bcs . "#EC NO_HANDLER
      ENDTRY.
    *--Send document.
      COMMIT WORK.
      IF sy-subrc = 0.
       MESSAGE s999(zou01) WITH text-020.
        v_sent = 'X'.
      ENDIF.

    I realize this is an old post, but am wondering if you ever resolved this.  I'm having the same issue.  Download an xlsx file locally opens fine, but attaching the seemingly exact same file throw errors/warnings when trying to open via an email attachment.

  • Internal Table attached as Excel file to an eMail - BCS_EXAMPLE_7 for UC

    Hi forums,
    SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
    report bcs_example_7.
    This report provides an example for sending an Excel
    attachment in Unicode Systems
    constants:
      gc_tab  type c value cl_bcs_convert=>gc_tab,
      gc_crlf type c value cl_bcs_convert=>gc_crlf.
    parameters:
      mailto type ad_smtpadr
       default 'john.doe(a)crazy-company.com'.                    "#EC *
    data send_request   type ref to cl_bcs.
    data document       type ref to cl_document_bcs.
    data recipient      type ref to if_recipient_bcs.
    data bcs_exception  type ref to cx_bcs.
    data main_text      type bcsy_text.
    data binary_content type solix_tab.
    data size           type so_obj_len.
    data sent_to_all    type os_boolean.
    start-of-selection.
      perform create_content.
      perform send.
    *&      Form  send
    form send.
      try.
        -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
        -------- create and set document with attachment ---------------
        create document object from internal table with text
          append 'Hello world!' to main_text.                   "#EC NOTEXT
          document = cl_document_bcs=>create_document(
            i_type    = 'RAW'
            i_text    = main_text
            i_subject = 'Test Created By BCS_EXAMPLE_7' ).      "#EC NOTEXT
        add the spread sheet as attachment to document object
          document->add_attachment(
            i_attachment_type    = 'xls'                        "#EC NOTEXT
            i_attachment_subject = 'ExampleSpreadSheet'         "#EC NOTEXT
            i_attachment_size    = size
            i_att_content_hex    = binary_content ).
        add document object to send request
          send_request->set_document( document ).
        --------- add recipient (e-mail address) -----------------------
        create recipient object
          recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
        add recipient object to send request
          send_request->add_recipient( recipient ).
        ---------- send document ---------------------------------------
          sent_to_all = send_request->send( i_with_error_screen = 'X' ).
          commit work.
          if sent_to_all is initial.
            message i500(sbcoms) with mailto.
          else.
            message s022(so).
          endif.
      ------------ exception handling ----------------------------------
      replace this rudimentary exception handling with your own one !!!
        catch cx_bcs into bcs_exception.
          message i865(so) with bcs_exception->error_type.
      endtry.
    endform.                    "send
    *&      Form  create_content
    Create Example Content
    1) Write example text into a string
    2) convert this string to solix_tab
    form create_content.
      data lv_string type string.
      data ls_t100 type t100.
    as example content we use some system messages out of t100
    get them for all installed languages from db
    and write one line for each language into the spread sheet
    columns are separated by TAB and each line ends with CRLF
      concatenate 'This Is Just Example Text!'                  "#EC NOTEXT
                  gc_crlf gc_crlf
                  into lv_string.
    header line
      concatenate lv_string
                  'MSGID'    gc_tab
                  'MSGNO'    gc_tab
                  'Language' gc_tab                             "#EC NOTEXT
                  'Text'     gc_crlf                            "#EC NOTEXT
                  into lv_string.
    data lines
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '182'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '316'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
    convert the text string into UTF-16LE binary data including
    byte-order-mark. Mircosoft Excel prefers these settings
    all this is done by new class cl_bcs_convert (see note 1151257)
      try.
          cl_bcs_convert=>string_to_solix(
            exporting
              iv_string   = lv_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
              iv_add_bom  = 'X'     "for other doc types
            importing
              et_solix  = binary_content
              ev_size   = size ).
        catch cx_bcs.
          message e445(so).
      endtry.
    endform.                    "create_content
    NOTES:
    UTF-16LE including the BOM (Byte order mark)
    is preferred by Microsoft Excel. If you want to create
    other binary content you may choose another codepage (e.g.
    '4110' (UTF-8) which is standard for e-mails).
    Find SAP codepage names in the drop down list
    for the codepage setting of node SMTP in transaction SCOT.
    Or: leave iv_codepage and iv_add_bom empty. Then the target
    codepage is set according to SAPconnect settings
    Important:
    SAP neither guarantees that the attachment created
    by this report can be opened by all Excel Versions nor
    that it can be opened by any 3rd party software at all
    Best regards to you
    Thorsten Hüser
    SAP CRM Senior consultant
    arvato / Bertelsmann

    Hi forums,
    SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
    report bcs_example_7.
    This report provides an example for sending an Excel
    attachment in Unicode Systems
    constants:
      gc_tab  type c value cl_bcs_convert=>gc_tab,
      gc_crlf type c value cl_bcs_convert=>gc_crlf.
    parameters:
      mailto type ad_smtpadr
       default 'john.doe(a)crazy-company.com'.                    "#EC *
    data send_request   type ref to cl_bcs.
    data document       type ref to cl_document_bcs.
    data recipient      type ref to if_recipient_bcs.
    data bcs_exception  type ref to cx_bcs.
    data main_text      type bcsy_text.
    data binary_content type solix_tab.
    data size           type so_obj_len.
    data sent_to_all    type os_boolean.
    start-of-selection.
      perform create_content.
      perform send.
    *&      Form  send
    form send.
      try.
        -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
        -------- create and set document with attachment ---------------
        create document object from internal table with text
          append 'Hello world!' to main_text.                   "#EC NOTEXT
          document = cl_document_bcs=>create_document(
            i_type    = 'RAW'
            i_text    = main_text
            i_subject = 'Test Created By BCS_EXAMPLE_7' ).      "#EC NOTEXT
        add the spread sheet as attachment to document object
          document->add_attachment(
            i_attachment_type    = 'xls'                        "#EC NOTEXT
            i_attachment_subject = 'ExampleSpreadSheet'         "#EC NOTEXT
            i_attachment_size    = size
            i_att_content_hex    = binary_content ).
        add document object to send request
          send_request->set_document( document ).
        --------- add recipient (e-mail address) -----------------------
        create recipient object
          recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
        add recipient object to send request
          send_request->add_recipient( recipient ).
        ---------- send document ---------------------------------------
          sent_to_all = send_request->send( i_with_error_screen = 'X' ).
          commit work.
          if sent_to_all is initial.
            message i500(sbcoms) with mailto.
          else.
            message s022(so).
          endif.
      ------------ exception handling ----------------------------------
      replace this rudimentary exception handling with your own one !!!
        catch cx_bcs into bcs_exception.
          message i865(so) with bcs_exception->error_type.
      endtry.
    endform.                    "send
    *&      Form  create_content
    Create Example Content
    1) Write example text into a string
    2) convert this string to solix_tab
    form create_content.
      data lv_string type string.
      data ls_t100 type t100.
    as example content we use some system messages out of t100
    get them for all installed languages from db
    and write one line for each language into the spread sheet
    columns are separated by TAB and each line ends with CRLF
      concatenate 'This Is Just Example Text!'                  "#EC NOTEXT
                  gc_crlf gc_crlf
                  into lv_string.
    header line
      concatenate lv_string
                  'MSGID'    gc_tab
                  'MSGNO'    gc_tab
                  'Language' gc_tab                             "#EC NOTEXT
                  'Text'     gc_crlf                            "#EC NOTEXT
                  into lv_string.
    data lines
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '182'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '316'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
    convert the text string into UTF-16LE binary data including
    byte-order-mark. Mircosoft Excel prefers these settings
    all this is done by new class cl_bcs_convert (see note 1151257)
      try.
          cl_bcs_convert=>string_to_solix(
            exporting
              iv_string   = lv_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
              iv_add_bom  = 'X'     "for other doc types
            importing
              et_solix  = binary_content
              ev_size   = size ).
        catch cx_bcs.
          message e445(so).
      endtry.
    endform.                    "create_content
    NOTES:
    UTF-16LE including the BOM (Byte order mark)
    is preferred by Microsoft Excel. If you want to create
    other binary content you may choose another codepage (e.g.
    '4110' (UTF-8) which is standard for e-mails).
    Find SAP codepage names in the drop down list
    for the codepage setting of node SMTP in transaction SCOT.
    Or: leave iv_codepage and iv_add_bom empty. Then the target
    codepage is set according to SAPconnect settings
    Important:
    SAP neither guarantees that the attachment created
    by this report can be opened by all Excel Versions nor
    that it can be opened by any 3rd party software at all
    Best regards to you
    Thorsten Hüser
    SAP CRM Senior consultant
    arvato / Bertelsmann

  • Abap spool to pdf  as email

    Hi Gurus
    I have to send output of report as pdf attachment of the email.
    I have used Fm CONVERT_ABAPSPOOLJOB_2_PDF to convet spool request to pdf format.
    and SO_DOCUMENT_SEND_API1 Fm to send email. Its working Fine.
    But Now i need to send email by using Methods,My code is as below
    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.
    DATA: it_pdf_output2 type SOLIX_TAB occurs 0.
    DATA: BEGIN OF it_pdf_output OCCURS 0.
           INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    DATA:
    *it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att_wa TYPE solisti1,
          gti_documents TYPE zsti_email_documents,
          g_documents_wa TYPE LINE OF zsti_email_documents,
          gti_recipients TYPE zsti_email_recipients,
          g_recipients_wa TYPE LINE OF zsti_email_recipients,
          gti_contents_hex TYPE solix_tab,
          gti_contents_text TYPE soli_tab.
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid              = gd_spool_nr
          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.
    <b>it_pdf_output is to be converted into gti_contents_hex.</b>
    LOOP AT it_pdf_output INTO mess_att_wa.
        MOVE mess_att_wa-line TO contents_hex_wa-line.
        APPEND contents_hex_wa TO gti_contents_hex.
      ENDLOOP.
      g_documents_wa-type = 'RAW'.
      g_documents_wa-subject = 'KUMAR TEST '.
      g_documents_wa-content_hex = xcontent_hex.
      APPEND g_documents_wa TO gti_documents.
      DATA:email TYPE so_name.
      email = '[email protected]'.
      g_recipients_wa-uname = 'KUMAR'.
      g_recipients_wa-c_address = email.
      APPEND g_recipients_wa TO gti_recipients.
    TRY.
    -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
          APPEND 'hello world' TO text.
          APPEND '20/09/2007' TO text.
          document = cl_document_bcs=>create_document(
          i_type = 'RAW'
          i_text = text
          i_length = '12'
          i_subject = 'subject' ).
          CALL METHOD document->add_attachment
          EXPORTING
          i_attachment_type = 'PDF'
          i_attachment_subject = gd_subject
          <b>i_att_content_hex = gti_contents_hex.</b>
    add document to send request
          CALL METHOD send_request->set_document( document ).
    --------- set sender -------------------------------------------
    note: this is necessary only if you want to set the sender
    different from actual user (SY-UNAME). Otherwise sender is
    set automatically with actual user.
          sender = cl_sapuser_bcs=>create( sy-uname ).
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
    --------- add recipient (e-mail address) -----------------------
    create recipient - please replace e-mail address !!!
          recipient = cl_cam_address_bcs=>create_internet_address( email ).
    add recipient with its respective attributes to send request
          CALL METHOD send_request->add_recipient
            EXPORTING
              i_recipient = recipient
              i_express   = 'X'.
    set send immediately flag
          send_request->set_send_immediately( 'X' ).
    ---------- send document ----------------------------------
          CALL METHOD send_request->send(
          EXPORTING
          i_with_error_screen = 'X'
          RECEIVING
          result = sent_to_all ).
          COMMIT WORK.
    exception handling
        CATCH cx_bcs INTO bcs_exception.
          WRITE: bcs_exception->error_type.
          EXIT.
      ENDTRY.
    MY problem is:
    Iam receiving  'hello world' and '20/09/2007' as a pdf file in mail.But the actual data
    from CONVERT_ABAPSPOOLJOB_2_PDF (it_pdf_output) is not getting in the pdf file.
    Iam receiving the email properly with pdf attached, but no data in pdf.
    Can any one please help me,its very ugrent
    The Bold line above is the problem here ,the data from Fm it_pdf_output is of type tline and the method takes data as HEX. How to convert  ?

    Sudheer,
    Refer to this link... https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&

  • PDF email

    Hi Gurus
    I have to send output of report as pdf attachment of the email.
    I have used Fm CONVERT_ABAPSPOOLJOB_2_PDF to convet spool request to pdf format.
    and SO_DOCUMENT_SEND_API1 Fm to send email. Its working Fine.
    But Now i need to send email by using Methods,My code is as below
    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.
    DATA: it_pdf_output2 type SOLIX_TAB occurs 0.
    DATA: BEGIN OF it_pdf_output OCCURS 0.
    INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    DATA:
    *it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    it_mess_att_wa TYPE solisti1,
    gti_documents TYPE zsti_email_documents,
    g_documents_wa TYPE LINE OF zsti_email_documents,
    gti_recipients TYPE zsti_email_recipients,
    g_recipients_wa TYPE LINE OF zsti_email_recipients,
    gti_contents_hex TYPE solix_tab,
    gti_contents_text TYPE soli_tab.
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
    src_spoolid = gd_spool_nr
    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.
    <b>it_pdf_output is to be converted into gti_contents_hex.</b>
    LOOP AT it_pdf_output INTO mess_att_wa.
    MOVE mess_att_wa-line TO contents_hex_wa-line.
    APPEND contents_hex_wa TO gti_contents_hex.
    ENDLOOP.
    g_documents_wa-type = 'RAW'.
    g_documents_wa-subject = 'KUMAR TEST '.
    g_documents_wa-content_hex = xcontent_hex.
    APPEND g_documents_wa TO gti_documents.
    DATA:email TYPE so_name.
    email = '[email protected]'.
    g_recipients_wa-uname = 'KUMAR'.
    g_recipients_wa-c_address = email.
    APPEND g_recipients_wa TO gti_recipients.
    TRY.
    -------- create persistent send request ------------------------
    send_request = cl_bcs=>create_persistent( ).
    APPEND 'hello world' TO text.
    APPEND '20/09/2007' TO text.
    document = cl_document_bcs=>create_document(
    i_type = 'RAW'
    i_text = text
    i_length = '12'
    i_subject = 'subject' ).
    CALL METHOD document->add_attachment
    EXPORTING
    i_attachment_type = 'PDF'
    i_attachment_subject = gd_subject
    <b>i_att_content_hex = gti_contents_hex.</b>
    add document to send request
    CALL METHOD send_request->set_document( document ).
    --------- set sender -------------------------------------------
    note: this is necessary only if you want to set the sender
    different from actual user (SY-UNAME). Otherwise sender is
    set automatically with actual user.
    sender = cl_sapuser_bcs=>create( sy-uname ).
    CALL METHOD send_request->set_sender
    EXPORTING
    i_sender = sender.
    --------- add recipient (e-mail address) -----------------------
    create recipient - please replace e-mail address !!!
    recipient = cl_cam_address_bcs=>create_internet_address( email ).
    add recipient with its respective attributes to send request
    CALL METHOD send_request->add_recipient
    EXPORTING
    i_recipient = recipient
    i_express = 'X'.
    set send immediately flag
    send_request->set_send_immediately( 'X' ).
    ---------- send document ----------------------------------
    CALL METHOD send_request->send(
    EXPORTING
    i_with_error_screen = 'X'
    RECEIVING
    result = sent_to_all ).
    COMMIT WORK.
    exception handling
    CATCH cx_bcs INTO bcs_exception.
    WRITE: bcs_exception->error_type.
    EXIT.
    ENDTRY.
    MY problem is:
    Iam receiving 'hello world' and '20/09/2007' as a pdf file in mail.But the actual data
    from CONVERT_ABAPSPOOLJOB_2_PDF (it_pdf_output) is not getting in the pdf file.
    Iam receiving the email properly with pdf attached, but no data in pdf.
    Can any one please help me,its very ugrent
    The Bold line above is the problem here ,the data from Fm it_pdf_output is of type tline and the method takes data as HEX. How to convert ?

    Hi,
    after  calling the FM .U HAVE TO CALL ONE peform.In order to get the PDF. ..please check the below code.
    CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
    EXPORTING
    src_spoolid = gd_spool_nr
    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.
    Declaration of local variables
      DATA : lv_bytecount  TYPE i,
             lv_cancel(1)  TYPE c,
             lv_filename1  LIKE rlgrap-filename.    "File name
    Declaration of local constants
      CONSTANTS: lc_pdf(4) TYPE c VALUE '.PDF'.
      CONCATENATE c_c
                  sy-repid
                  lc_pdf
          INTO lv_filename1.
    To  Download to PDF format
        PERFORM download_w_ext(rstxpdft) TABLES i_pdf
                                          USING lv_filename1
                                                lc_pdf
                                                'BIN'
                                                lv_bytecount
                                                lv_cancel.
    Regards,
    Nagaraj

  • Email issue in ECC 6.0

    Hi,
    I have written a program to send emails as shown in SAP example programs, I am not able to send the emails.
    I have ran some of the SAP example programs
    BCS_EXAMPLE_1
    BCS_EXAMPLE_2
    BCS_EXAMPLE_3
    BCS_EXAMPLE_4
    BCS_EXAMPLE_5
    BCS_EXAMPLE_6
    I still don't see email in SOST. Is there any thing apart from this code we need to do in the settings to send the email then please let me know.
    Regards
    Sandeep

    Hi Sandeep,
    You can refer this code:
    FORM mail_pdf .
    *&--Send PDF Form by E-Mail
      TRY.
          send_request = cl_bcs=>create_persistent( ).
    *get PDF xstring and convert it to BCS format
          lp_pdf_size = XSTRLEN( ls_formoutput-pdf ).
          pdf_content = cl_document_bcs=>xstring_to_solix(
              ip_xstring = ls_formoutput-pdf ).
          IF  nast-kschl = c_zhpl.
            w_subject = text-001.
          ELSEIF nast-kschl = c_zhcs.
            w_subject = text-002.
          ENDIF.
          document = cl_document_bcs=>create_document(
                i_type    = c_pdf
                i_hex     = pdf_content
                i_length  = lp_pdf_size
                i_subject = w_subject ).
    *add document to send request
          send_request->set_document( document ).
          CALL FUNCTION 'BAPI_USER_GET_DETAIL'
            EXPORTING
              username = sy-uname
            TABLES
              return   = t_return
              addsmtp  = t_addr.
          CLEAR w_addr.
          READ TABLE t_addr INTO w_addr INDEX 1.
          recipient = cl_cam_address_bcs=>create_internet_address(
              i_address_string = w_addr-e_mail ).
    *add recipient to send request
          send_request->add_recipient( i_recipient = recipient ).
          sent_to_all = send_request->send(
              i_with_error_screen = c_x ).
          IF sent_to_all = c_x.
            MESSAGE i022(so).
          ENDIF.
          COMMIT WORK.
        CATCH cx_bcs INTO bcs_exception.
    *Exception Handing
          MESSAGE ID bcs_exception->msgid TYPE bcs_exception->msgty
          NUMBER bcs_exception->msgno
            WITH bcs_exception->msgv1 bcs_exception->msgv2
                 bcs_exception->msgv3 bcs_exception->msgv4.
          EXIT.
      ENDTRY.
    ENDFORM.                    " MAIL_PDF
    Regards,
    Hemant
    Edited by: Hemant Goyal on Sep 5, 2008 8:22 AM
    Edited by: Hemant Goyal on Sep 5, 2008 8:23 AM

Maybe you are looking for