ALV send AS EMAIL in pdf ofrmat

hi all
my problem is
i made one alv report ............
now i want to send this in pdf format to particuler email address.......
can any body tell....
it is emergency....
if helpful then rewarded......

Hi
The code below demonstrates how to retrieve a spool request and email it as a PDF document. Please note
for the below program to process a spool request the program must be executed in background otherwise no
spool request will be created. Once you have had a look at this there is an modified version of the program
which works in both background and foreground. Also see transaction SCOT for SAPConnect administration.
*& Report  ZSPOOLTOPDF                                                 *
*& Converts spool request into PDF document and emails it to           *
*& recipicant.                                                         *
*& Execution                                                           *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on      *
*& screen                                                              *
REPORT  zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
                                    DEFAULT '[email protected]',
           p_sender LIKE somlreci1-receiver
                                    DEFAULT '[email protected]',
           p_delspl  AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
* Spool IDs
TYPES: BEGIN OF t_tbtcp.
        INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
      wa_tbtcp TYPE t_tbtcp.
* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
      gd_eventparm LIKE tbtcm-eventparm,
      gd_external_program_active LIKE tbtcm-xpgactive,
      gd_jobcount LIKE tbtcm-jobcount,
      gd_jobname LIKE tbtcm-jobname,
      gd_stepcount LIKE tbtcm-stepcount,
      gd_error    TYPE sy-subrc,
      gd_reciever TYPE sy-subrc.
DATA:  w_recsize TYPE i.
DATA: gd_subject   LIKE sodocchgi1-obj_descr,
      it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
      gd_sender_type     LIKE soextreci1-adr_typ,
      gd_attachment_desc TYPE so_obj_nam,
      gd_attachment_name TYPE so_obj_des.
* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
      gd_destination LIKE rlgrap-filename,
      gd_bytecount LIKE tst01-dsize,
      gd_buffer TYPE string.
* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
        INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
           c_no(1)     TYPE c   VALUE ' ',
           c_device(4) TYPE c   VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
  WRITE 'Hello World'.
  new-page.
  commit work.
  new-page print off.
  IF sy-batch EQ 'X'.
    PERFORM get_job_details.
    PERFORM obtain_spool_id.
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
*        to sap-spool
*        spool parameters   %_print
*        archive parameters %_print
*        without spool dynpro
*        and return.
* Get spool id from program called above
*  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
    PERFORM convert_spool_to_pdf.
    PERFORM process_email.
    if p_delspl EQ 'X'.
      PERFORM delete_spool.
    endif.
    IF sy-sysid = c_dev.
      wait up to 5 seconds.
      SUBMIT rsconn01 WITH mode   = 'INT'
                      WITH output = 'X'
                      AND RETURN.
    ENDIF.
  ELSE.
    SKIP.
    WRITE:/ 'Program must be executed in background in-order for spool',
            'request to be created.'.
  ENDIF.
*       FORM obtain_spool_id                                          *
FORM obtain_spool_id.
  CHECK NOT ( gd_jobname IS INITIAL ).
  CHECK NOT ( gd_jobcount IS INITIAL ).
  SELECT * FROM  tbtcp
                 INTO TABLE it_tbtcp
                 WHERE      jobname     = gd_jobname
                 AND        jobcount    = gd_jobcount
                 AND        stepcount   = gd_stepcount
                 AND        listident   <> '0000000000'
                 ORDER BY   jobname
                            jobcount
                            stepcount.
  READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
  IF sy-subrc = 0.
    message s004(zdd) with gd_spool_nr.
    gd_spool_nr = wa_tbtcp-listident.
    MESSAGE s004(zdd) WITH gd_spool_nr.
  ELSE.
    MESSAGE s005(zdd).
  ENDIF.
ENDFORM.
*       FORM get_job_details                                          *
FORM get_job_details.
* Get current job details
  CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
       IMPORTING
            eventid                 = gd_eventid
            eventparm               = gd_eventparm
            external_program_active = gd_external_program_active
            jobcount                = gd_jobcount
            jobname                 = gd_jobname
            stepcount               = gd_stepcount
       EXCEPTIONS
            no_runtime_info         = 1
            OTHERS                  = 2.
ENDFORM.
*       FORM convert_spool_to_pdf                                     *
FORM convert_spool_to_pdf.
  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.
  CHECK sy-subrc = 0.
* Transfer the 132-long strings to 255-long strings
  LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
  ENDLOOP.
  TRANSLATE gd_buffer USING '~ '.
  DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
      EXIT.
    ENDIF.
  ENDDO.
ENDFORM.
*       FORM process_email                                            *
FORM process_email.
  DESCRIBE TABLE it_mess_att LINES gd_recsize.
  CHECK gd_recsize > 0.
  PERFORM send_email USING p_email1.
*  perform send_email using p_email2.
ENDFORM.
*       FORM send_email                                               *
*  -->  p_email                                                       *
FORM send_email USING p_email.
  CHECK NOT ( p_email IS INITIAL ).
  REFRESH it_mess_bod.
* Default subject matter
  gd_subject         = 'Subject'.
  gd_attachment_desc = 'Attachname'.
*  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
  it_mess_bod        = 'Message Body text, line 1'.
  APPEND it_mess_bod.
  it_mess_bod        = 'Message Body text, line 2...'.
  APPEND it_mess_bod.
* If no sender specified - default blank
  IF p_sender EQ space.
    gd_sender_type  = space.
  ELSE.
    gd_sender_type  = 'INT'.
  ENDIF.
* Send file by email as .xls speadsheet
  PERFORM send_file_as_email_attachment
                               tables it_mess_bod
                                      it_mess_att
                                using p_email
                                      'Example .xls documnet attachment'
                                      'PDF'
                                      gd_attachment_name
                                      gd_attachment_desc
                                      p_sender
                                      gd_sender_type
                             changing gd_error
                                      gd_reciever.
ENDFORM.
*       FORM delete_spool                                             *
FORM delete_spool.
  DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
  ld_spool_nr = gd_spool_nr.
  CHECK p_delspl <> c_no.
  CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
       EXPORTING
            spoolid = ld_spool_nr.
ENDFORM.
*&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
*       Send email
FORM send_file_as_email_attachment tables it_message
                                          it_attach
                                    using p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 changing p_error
                                          p_reciever.
  DATA: ld_error    TYPE sy-subrc,
        ld_reciever TYPE sy-subrc,
        ld_mtitle LIKE sodocchgi1-obj_descr,
        ld_email LIKE  somlreci1-receiver,
        ld_format TYPE  so_obj_tp ,
        ld_attdescription TYPE  so_obj_nam ,
        ld_attfilename TYPE  so_obj_des ,
        ld_sender_address LIKE  soextreci1-receiver,
        ld_sender_address_type LIKE  soextreci1-adr_typ,
        ld_receiver LIKE  sy-subrc.
data:   t_packing_list like sopcklsti1 occurs 0 with header line,
        t_contents like solisti1 occurs 0 with header line,
        t_receivers like somlreci1 occurs 0 with header line,
        t_attachment like solisti1 occurs 0 with header line,
        t_object_header like solisti1 occurs 0 with header line,
        w_cnt type i,
        w_sent_all(1) type c,
        w_doc_data like sodocchgi1.
  ld_email   = p_email.
  ld_mtitle = p_mtitle.
  ld_format              = p_format.
  ld_attdescription      = p_attdescription.
  ld_attfilename         = p_filename.
  ld_sender_address      = p_sender_address.
  ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
  w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
  w_doc_data-obj_langu = sy-langu.
  w_doc_data-obj_name  = 'SAPRPT'.
  w_doc_data-obj_descr = ld_mtitle .
  w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
  CLEAR w_doc_data.
  READ TABLE it_attach INDEX w_cnt.
  w_doc_data-doc_size =
     ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
  w_doc_data-obj_langu  = sy-langu.
  w_doc_data-obj_name   = 'SAPRPT'.
  w_doc_data-obj_descr  = ld_mtitle.
  w_doc_data-sensitivty = 'F'.
  CLEAR t_attachment.
  REFRESH t_attachment.
  t_attachment[] = it_attach[].
* Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 0.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE it_message LINES t_packing_list-body_num.
  t_packing_list-doc_type = 'RAW'.
  APPEND t_packing_list.
* Create attachment notification
  t_packing_list-transf_bin = 'X'.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 1.
  t_packing_list-body_start = 1.
  DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
  t_packing_list-doc_type   =  ld_format.
  t_packing_list-obj_descr  =  ld_attdescription.
  t_packing_list-obj_name   =  ld_attfilename.
  t_packing_list-doc_size   =  t_packing_list-body_num * 255.
  APPEND t_packing_list.
* Add the recipients email address
  CLEAR t_receivers.
  REFRESH t_receivers.
  t_receivers-receiver = ld_email.
  t_receivers-rec_type = 'U'.
  t_receivers-com_type = 'INT'.
  t_receivers-notif_del = 'X'.
  t_receivers-notif_ndel = 'X'.
  APPEND t_receivers.
  CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
       EXPORTING
            document_data              = w_doc_data
            put_in_outbox              = 'X'
            sender_address             = ld_sender_address
            sender_address_type        = ld_sender_address_type
            commit_work                = 'X'
       IMPORTING
            sent_to_all                = w_sent_all
       TABLES
            packing_list               = t_packing_list
            contents_bin               = t_attachment
            contents_txt               = it_message
            receivers                  = t_receivers
       EXCEPTIONS
            too_many_receivers         = 1
            document_not_sent          = 2
            document_type_not_exist    = 3
            operation_no_authorization = 4
            parameter_error            = 5
            x_error                    = 6
            enqueue_error              = 7
            OTHERS                     = 8.
* Populate zerror return code
  ld_error = sy-subrc.
* Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.

Similar Messages

  • CRM ONLINE 2013: On Approval Of Quotation, Run Report, Generate PDF and Send an Email With PDF as attachment

    Hi,
    I am using CRM ONLINE 2013.
    How to automate below process?
    1. On Approval Of Quotation, Run Report.
    2. Generate PDF.
    3. Send an Email With PDF as attachment.
    As i have gone through many forums for this topic, but creating a plugin code for generating Report PDF is not possible in CRM ONLINE.
    So, What is the alternate way to do this..?
    Thanks.

    This is my entire code mentioned below:-
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title></title>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script type="text/javascript">
            if (typeof (SDK) == "undefined")
            { SDK = { __namespace: true }; }
            SDK.JScriptRESTDataOperations = {
                _context: function () {
                    if (typeof GetGlobalContext != "undefined")
                    { return GetGlobalContext(); }
                    else {
                        if (typeof Xrm != "undefined") {
                            return Xrm.Page.context;
                        else { return new Error("Context is not available."); }
                _getServerUrl: function () {
                    var serverUrl = this._context().getServerUrl()
                    if (serverUrl.match(/\/$/)) {
                        serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                    return serverUrl;
                _ODataPath: function () {
                    return this._getServerUrl() + "/XRMServices/2011/OrganizationData.svc/";
                _errorHandler: function (req) {
                    return new Error("Error : " +
      req.status + ": " +
      req.statusText + ": " +
      JSON.parse(req.responseText).error.message.value);
                _dateReviver: function (key, value) {
                    var a;
                    if (typeof value === 'string') {
                        a = /Date\(([-+]?\d+)\)/.exec(value);
                        if (a) {
                            return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
                    return value;
                Create: function (object, type, successCallback, errorCallback) {
                    var req = new XMLHttpRequest();
                    req.open("POST", this._ODataPath() + type + "Set", true);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    req.onreadystatechange = function () {
                        if (this.readyState == 4 /* complete */) {
                            if (this.status == 201) {
                                successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
                            else {
                                errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
                    req.send(JSON.stringify(object));
                Retrieve: function (id, type, successCallback, errorCallback) {
                    var req = new XMLHttpRequest();
                    req.open("GET", this._ODataPath() + type + "Set(guid'" + id + "')", true);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    req.onreadystatechange = function () {
                        if (this.readyState == 4 /* complete */) {
                            if (this.status == 200) {
                                successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d);
                            else {
                                errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
                    req.send();
                Update: function (id, object, type, successCallback, errorCallback) {
                    var req = new XMLHttpRequest();
                    req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    req.setRequestHeader("X-HTTP-Method", "MERGE");
                    req.onreadystatechange = function () {
                        if (this.readyState == 4 /* complete */) {
                            if (this.status == 204 || this.status == 1223) {
                                successCallback();
                            else {
                                errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
                    req.send(JSON.stringify(object));
                Delete: function (id, type, successCallback, errorCallback) {
                    var req = new XMLHttpRequest();
                    req.open("POST", this._ODataPath() + type + "Set(guid'" + id + "')", true);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    req.setRequestHeader("X-HTTP-Method", "DELETE");
                    req.onreadystatechange = function () {
                        if (this.readyState == 4 /* complete */) {
                            if (this.status == 204 || this.status == 1223) {
                                successCallback();
                            else {
                                errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
                    req.send();
                RetrieveMultiple: function (type, filter, successCallback, errorCallback) {
                    if (filter != null) {
                        filter = "?" + filter;
                    else { filter = ""; }
                    var req = new XMLHttpRequest();
                    req.open("GET", this._ODataPath() + type + "Set" + filter, true);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                    req.onreadystatechange = function () {
                        if (this.readyState == 4 /* complete */) {
                            if (this.status == 200) {
                                successCallback(JSON.parse(this.responseText, SDK.JScriptRESTDataOperations._dateReviver).d.results);
                            else {
                                errorCallback(SDK.JScriptRESTDataOperations._errorHandler(this));
                    req.send();
                __namespace: true
        </script>
        <script type="text/javascript">
            //Create Email and link it with Order as Regarding field
            var Xrm;
            var email = new Object();
            var ownerID = "";
            var CustomerId = "";
            if (window.opener) { Xrm = window.opener.Xrm; }
            else if (window.parent) { Xrm = window.parent.Xrm; }
            //Get ownerid who send email of quotation to customer
            function GetOwnerID() {
                var owner = Xrm.Page.getAttribute("ownerid").getValue();
                ownerID = owner[0].id;
                var ownerName = owner[0].name;
                var entityType = owner[0].entityType;
                GetToEmailGUID();
            //Get customerid who receive email of quotation from owner
            function GetToEmailGUID() {
                var Customer = Xrm.Page.getAttribute('customerid').getValue();
                CustomerId = Customer[0].id;
                var CustomerName = Customer[0].name;
                var entityType = Customer[0].entityType;
                //if CustomerId is type of "Account" then get Primary Contact id of that account
                if (entityType == "account") {
                    var contact = Xrm.Page.getAttribute("customerid").getValue();
                    if (contact === null) return;
                    var serverUrl = Xrm.Page.context.getClientUrl();
                    var oDataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc/AccountSet(guid'" + contact[0].id + "')?$select=PrimaryContactId";
                    var req = new XMLHttpRequest();
                    req.open("GET", oDataSelect, false);
                    req.setRequestHeader("Accept", "application/json");
                    req.setRequestHeader("Content-Type", "application/json;charset=utf-8");
                    req.onreadystatechange = function () {
                        if (req.readyState === 4) {
                            if (req.status === 200) {
                                var retrieved = JSON.parse(req.responseText).d;
                                CustomerId = retrieved.PrimaryContactId.Id;
                            else {
                                alert(this.statusText);
                    req.send();
            function CreateEmail() {
                GetOwnerID();
                email.Subject = "Email with Report Attachment";
                //Set The current order as the Regarding object
                email.RegardingObjectId = {
                    Id: Xrm.Page.data.entity.getId(),    //Get the current entity Id , here OrderId
                    LogicalName: Xrm.Page.data.entity.getEntityName()//Get the current entity name, here it will be “salesOrder”
                //Create Email Activity
                SDK.JScriptRESTDataOperations.Create(email, "Email", EmailCallBack, function (error) { alert(error.message); });
            // Email Call Back function
            function EmailCallBack(result) {
                email = result; // Set the email to result to use it later in email attachment for retrieving activity Id
                var activityPartyFrom = new Object();
                // Set the From party of the ActivityParty to relate an entity with Email From field
                activityPartyFrom.PartyId = {
                    Id: CustomerId, //"79EBDD26-FDBE-E311-8986-D89D6765B238",  // id of entity you want to associate this activity with.        
                    LogicalName: "contact"
                // Set the "activity" of the ActivityParty
                activityPartyFrom.ActivityId = {
                    Id: result.ActivityId,
                    LogicalName: "email"
                // Now set the participation type that describes the role of the party on the activity).
                activityPartyFrom.ParticipationTypeMask = { Value: 2 }; // 2 means ToRecipients
                // Create the from ActivityParty for the email
                SDK.JScriptRESTDataOperations.Create(activityPartyFrom, "ActivityParty", ActivityPartyFromCallBack, function (error) { alert(error.message); });
                var activityPartyTo = new Object();
                // Set the From party of the ActivityParty to relate an entity with Email From field
                activityPartyTo.PartyId = {
                    Id: ownerID, //"79EBDD26-FDBE-E311-8986-D89D6765B238",  // id of entity you want to associate this activity with.        
                    LogicalName: "systemuser"
                // Set the "activity" of the ActivityParty  
                activityPartyTo.ActivityId = {
                    Id: result.ActivityId,
                    LogicalName: "email"
                // Now set the participation type that describes the role of the party on the activity).    
                activityPartyTo.ParticipationTypeMask = { Value: 1 }; // 1 means Sender
                // Create the from ActivityParty
                SDK.JScriptRESTDataOperations.Create(activityPartyTo, "ActivityParty", ActivityPartyToCallBack, function (error) { alert(error.message); });
            //ActivityParty From Callback
            function ActivityPartyFromCallBack(result) {
            //ActivityParty To Callback
            function ActivityPartyToCallBack(result) {
                GetReportId('ABM_Infotech_SalesQuote');
            //Create attachment for the created email
            function CreateEmailAttachment() {
                //get reporting session and use the params to convert a report in PDF
                var params = getReportingSession();
                //Email attachment parameters
                var activitymimeattachment = Object();
                activitymimeattachment.ObjectId = Object();
                activitymimeattachment.ObjectId.LogicalName = "email";
                activitymimeattachment.ObjectId.Id = email.ActivityId;
                activitymimeattachment.ObjectTypeCode = "email",
                    activitymimeattachment.Subject = "File Attachment";
                activitymimeattachment.Body = encodePdf(params);
                activitymimeattachment.FileName = "Report1.pdf";
                activitymimeattachment.MimeType = "application/pdf";
                //Attachment call
                SDK.JScriptRESTDataOperations.Create(activitymimeattachment, "ActivityMimeAttachment", ActivityMimeAttachmentCallBack, function (error) { alert(error.message); });
            //ActivityMimeAttachment CallBack function
            function ActivityMimeAttachmentCallBack(result) {
                var features = "location=no,menubar=no,status=no,toolbar=no,resizable=yes";
                var width = "800px";
                var height = "600px";
                window.open(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", features);
                // To open window which works in outlook and IE both
                //openStdWin(Xrm.Page.context.getServerUrl() + "main.aspx?etc=" + 4202 + "&pagetype=entityrecord&id=" + email.ActivityId, "_blank", width,
    height, features);
            //This method will get the reportId based on a report name that will be used in            getReportingSession() function
            function GetReportId(reportName) {
                var oDataSetName = "ReportSet";
                var columns = "ReportId";
                var filter = "Name eq '" + reportName + "'";
                retrieveMultiple(oDataSetName, columns, filter, onSuccess);
            function retrieveMultiple(odataSetName, select, filter, successCallback) {
                var serverUrl = Xrm.Page.context.getServerUrl();
                var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
                var odataUri = serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "?";
                if (select) {
                    odataUri += "$select=" + select + "&";
                if (filter) {
                    odataUri += "$filter=" + filter;
                $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    url: odataUri,
                    beforeSend: function (XMLHttpRequest) {
                        XMLHttpRequest.setRequestHeader("Accept", "application/json");
                    success: function (data) {
                        if (successCallback) {
                            if (data && data.d && data.d.results) {
                                successCallback(data.d.results);
                            else if (data && data.d) {
                                successCallback(data.d);
                            else {
                                successCallback(data);
                    error: function (XmlHttpRequest, errorThrown) {
                        if (XmlHttpRequest && XmlHttpRequest.responseText) {
                            alert("Error while retrieval ; Error – " + XmlHttpRequest.responseText);
            function onSuccess(data) {
                reportId = data[0].ReportId.replace('{', ").replace('}', ");
                CreateEmailAttachment(); // Create Email Attachment
            //Gets the report contents
            function getReportingSession() {
                var pth = Xrm.Page.context.getServerUrl() + "/CRMReports/rsviewer/reportviewer.aspx";
                var retrieveEntityReq = new XMLHttpRequest();
                var Id = Xrm.Page.data.entity.getId();
                var quotationGUID = Id.replace('{', ""); //set this to selected quotation GUID
                quotationGUID = quotationGUID.replace('}', "");
                var reportName = "ABM_Infotech_SalesQuote"; //set this to the report you are trying to download
                var reportID = "751089AA-74B8-E211-B52F-D8D3855B253B"; //set this to the guid of the report you are trying to download
                var rptPathString = ""; //set this to the CRMF_Filtered parameter
                var strParameterXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'><entity name='quote'><all-attributes /><filter type='and'><condition
    attribute='quoteid' operator='eq' uitype='quote' value='" + quotationGUID + "' /> </filter></entity></fetch>";
                retrieveEntityReq.open("POST", pth, false);
                retrieveEntityReq.setRequestHeader("Accept", "*/*");
                retrieveEntityReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                rptPathString = "id=%7B" + reportID + "%7D&uniquename=" + Xrm.Page.context.getOrgUniqueName() + "&iscustomreport=true&reportnameonsrs=&reportName="
    +
                                reportName + "&isScheduledReport=false&p:ABMFilteredQuote=" + strParameterXML;
                //remove the part starting from &p:salesorderid if your report has no parameters
                retrieveEntityReq.send(rptPathString);
                var x = retrieveEntityReq.responseText.indexOf("ReportSession=");
                var ret = new Array();
                ret[0] = retrieveEntityReq.responseText.substr(x + 14, retrieveEntityReq.responseText.indexOf("&", x) - x - 14); //the session id
                x = retrieveEntityReq.responseText.indexOf("ControlID=");
                ret[1] = retrieveEntityReq.responseText.substr(x + 10, retrieveEntityReq.responseText.indexOf("&", x) - x - 10); //the control id
                return ret;
            var bdy = new Array();
            var bdyLen = 0;
            function concat2Bdy(x) {
                bdy[bdyLen] = x;
                bdyLen++;
            function encodePdf(params) {
                bdy = new Array();
                bdyLen = 0;
                var retrieveEntityReq = new XMLHttpRequest();
                var pth = Xrm.Page.context.getServerUrl() + "/Reserved.ReportViewerWebControl.axd?ReportSession=" + params[0] +
                "&Culture=1033&CultureOverrides=True&UICulture=1033&UICultureOverrides=True&ReportStack=1&ControlID=" + params[1] +
                "&OpType=Export&FileName=Public&ContentDisposition=OnlyHtmlInline&Format=PDF";
                retrieveEntityReq.open("GET", pth, false);
                retrieveEntityReq.setRequestHeader("Accept", "*/*");
                retrieveEntityReq.send();
                BinaryToArray(retrieveEntityReq.responseBody);
                return encode64(bdy);
            var StringMaker = function () {
                this.parts = [];
                this.length = 0;
                this.append = function (s) {
                    this.parts.push(s);
                    this.length += s.length;
                this.prepend = function (s) {
                    this.parts.unshift(s);
                    this.length += s.length;
                this.toString = function () {
                    return this.parts.join('');
            var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
            function encode64(input) {
                var output = new StringMaker();
                var chr1, chr2, chr3;
                var enc1, enc2, enc3, enc4;
                var i = 0;
                while (i < input.length) {
                    chr1 = input[i++];
                    chr2 = input[i++];
                    chr3 = input[i++];
                    enc1 = chr1 >> 2;
                    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                    enc4 = chr3 & 63;
                    if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                    } else if (isNaN(chr3)) {
                        enc4 = 64;
                    output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
                return output.toString();
        </script>
        <script type="text/vbscript">
        Function BinaryToArray(Binary)
               Dim i
               ReDim byteArray(LenB(Binary))
               For i = 1 To LenB(Binary)
                     byteArray(i-1) = AscB(MidB(Binary, i, 1))
                     concat2Bdy(AscB(MidB(Binary, i, 1)))
             Next
              BinaryToArray = byteArray
       End Function     
        </script>
    </head>
    <body>
        <input type="button" onclick="CreateEmail();" value="Attach Report" />
    </body>
    </html>

  • Send Invoice email with pdf attachement through DI?

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

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

  • Sending an email with pdf attachment in Ecc6

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

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

  • ALV send AS EMAIL

    hi all
    can any body tell me how can i send the alv report in pdf format to particuler email?
    Message was edited by:
            patel paresh

    Hi
    The code below demonstrates how to retrieve a spool request and email it as a PDF document. Please note
    for the below program to process a spool request the program must be executed in background otherwise no
    spool request will be created. Once you have had a look at this there is an modified version of the program
    which works in both background and foreground. Also see transaction SCOT for SAPConnect administration.
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    * Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    * Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    * Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    * Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    * Write statement to represent report output. Spool request is created
    * if write statement is executed in background. This could also be an
    * ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    *** Alternative way could be to submit another program and store spool
    *** id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
    *        to sap-spool
    *        spool parameters   %_print
    *        archive parameters %_print
    *        without spool dynpro
    *        and return.
    * Get spool id from program called above
    *  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
    *       FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
    *       FORM get_job_details                                          *
    FORM get_job_details.
    * Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
    *       FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      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.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
    *       FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    *  perform send_email using p_email2.
    ENDFORM.
    *       FORM send_email                                               *
    *  -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    *  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
    *       FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.

  • Error while sending by email a PDF from SMARTFORM

    Hi all.
    Wer'e upgrading to EP4 and I can send smartform PDF by email but get an error message while trying to open it.
    *FORM convert_otf_2_pdf.
      call function 'CONVERT_OTF_2_PDF'
        importing
          bin_filesize           = lv_len_in  
        tables
          otf                    = gs_return-otfdata[]
          doctab_archive         = it_docs[]
          lines                  = lt_tline[]
        exceptions
          err_conv_not_possible  = 1
          err_otf_mc_noendmarker = 2
          others                 = 3.
      if sy-subrc ne 0.
         MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    *then to send it as Email attachemnt we need to format the PDF data
      call function 'SX_TABLE_LINE_WIDTH_CHANGE'
        exporting
          line_width_dst              = '255'
        tables
          content_in                  = lt_tline
          content_out                 = lt_objbin
        exceptions
          err_line_width_src_too_long = 1
          err_line_width_dst_too_long = 2
          err_conv_failed             = 3
          others                      = 4.
      clear ls_solisti.
      ls_solisti = 'Payment Notification'.
      append ls_solisti to lt_objtxt.
    DESCRIBE TABLE lt_objtxt LINES lv_lines.
    READ TABLE lt_objtxt INDEX lv_lines.
      ls_doc_chg-obj_name = 'Payment Notification'.
      ls_doc_chg-expiry_dat = sy-datum + 10.
      ls_doc_chg-obj_descr =  'Payment Notification'.
      ls_doc_chg-sensitivty = 'F'.
      ls_doc_chg-doc_size = 255.
      ls_objpack-head_start = 1.
      ls_objpack-head_num = 0.
      ls_objpack-body_start = 1.
      ls_objpack-body_num = 1. "lv_lines.
      ls_objpack-doc_type = 'RAW'.
      append ls_objpack to lt_objpack.
    (pdf-Attachment)
      ls_objpack-transf_bin = 'X'.
      ls_objpack-head_start = 1.
      ls_objpack-head_num = 0.
      ls_objpack-body_start = 1.
      describe table lt_objbin lines lv_lines.
      "READ TABLE lt_objbin INDEX lv_lines.
      ls_objpack-doc_size = lv_lines * 255 .
      ls_objpack-body_num = lv_lines.
      ls_objpack-doc_type = 'PDF'.
      ls_objpack-obj_name = 'NOTIF'.
      ls_objpack-obj_descr = 'Payment Notif.'.
      append ls_objpack to lt_objpack.
      clear lt_dli[].
      lv_name = p_list.
      call function 'SO_DLI_READ_API1'
        exporting
          dli_name                   = lv_name
          dli_id                     = '000000000001'
          shared_dli                 = 'X'
        tables
          dli_entries                = lt_dli
        exceptions
          dli_not_exist              = 1
          operation_no_authorization = 2
          parameter_error            = 3
          x_error                    = 4
          others                     = 5.
      if sy-subrc eq 0 and
        lt_dli[] is not initial.
    clear ls_reclist.
        ls_reclist-receiver = p_list.
        ls_reclist-rec_type = 'C'.
        append ls_reclist to lt_reclist.
      endif.
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        exporting
          document_data              = ls_doc_chg
          put_in_outbox              = ''
        tables
          packing_list               = lt_objpack
          object_header              = ls_objhead
          contents_bin               = lt_objbin
          contents_txt               = lt_objtxt
          receivers                  = lt_reclist
        exceptions
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          others                     = 8.
    What's wrong ??
    Thanks all,
    Rebeka

    Hello,
    Try below code
    LOOP AT gt_check_data INTO gw_inc_payment.
              CLEAR wa_pa0105.
              READ TABLE gt_pa0105 INTO wa_pa0105
                                   WITH KEY pernr = gw_inc_payment-pernr.
              IF sy-subrc = 0.      ELSE.             CONDENSE  wa_pa0105-usrid_long NO-GAPS.
                TRANSLATE wa_pa0105-usrid_long TO LOWER CASE.
              ENDIF.
              CALL FUNCTION 'ZHR_ITA_MAIL_PDF'
                EXPORTING
                  im_incentive       = gw_ita_inc
                  im_flag            = 'X'
                IMPORTING
                  ls_job_output_info = ls_op_info
                EXCEPTIONS
                  cntl_error_ctrl    = 1
                  cntl_error_cont    = 2
                  cntl_error_load    = 3
                  cntl_error_show    = 4
                  OTHERS             = 5.
              IF sy-subrc <> 0.
                MESSAGE text-024 TYPE 'E'.
              ELSE.
                CLEAR gt_tline[].
                CALL FUNCTION 'CONVERT_OTF'
                  EXPORTING
                    format                = 'PDF'
                  IMPORTING
                    bin_filesize          = g_pdfsize
                  TABLES
                    otf                   = ls_op_info-otfdata
                    lines                 = gt_tline
                  EXCEPTIONS
                    err_max_linewidth     = 1
                    err_format            = 2
                    err_conv_not_possible = 3
                    err_bad_otf           = 4
                    OTHERS                = 5.
                IF sy-subrc <> 0.
                  IF gt_tline IS INITIAL.
                    MESSAGE text-023 TYPE 'E'.
                  ENDIF.
                ELSE.
          Data handling with required length
                  LOOP AT gt_tline INTO gw_tline.
                    lv_pos = 255 - lv_len.
                    IF lv_pos > 134.                          "length of pdf_table
                      lv_pos = 134.
                    ENDIF.
                    gw_objbin+lv_len = gw_tline(lv_pos).
                    lv_len = lv_len + lv_pos.
                    IF lv_len = 255.                          "length of out (contents_bin)
                      APPEND gw_objbin TO gt_objbin.
                      CLEAR: gw_objbin, lv_len.
                      IF lv_pos < 134.
                        gw_objbin = gw_tline+lv_pos.
                        lv_len = 134 - lv_pos.
                      ENDIF.
                    ENDIF.
                  ENDLOOP.
                  IF lv_len > 0.
                    APPEND gw_objbin TO gt_objbin.
                  ENDIF.
                  CLEAR gw_objbin.
            Mail process with the PDF attachment
                  PERFORM mail_process_attach USING wa_pa0105-usrid_long.
                ENDIF.
              ENDIF.
            ENDLOOP.
    FORM mail_process_attach USING lv_receive TYPE comm_id_long.
    **//--- For Sending eMail
      DATA :  it_packing_list TYPE TABLE OF  sopcklsti1,
              wa_packing_list TYPE sopcklsti1,
              it_receivers    TYPE TABLE OF somlreci1,
              wa_receivers    TYPE somlreci1,
              it_message      TYPE  TABLE OF solisti1,
              wa_message      TYPE  solisti1,
              it_line         TYPE STANDARD TABLE OF tline,
              wa_line         TYPE tline,
              it_attachment   TYPE TABLE OF solisti1,
              wa_attachment   TYPE solisti1,
              wa_doc_data     TYPE sodocchgi1,
              lv_cnt          TYPE  i,
              lv_tablines     TYPE i,
              lv_subject      TYPE so_obj_des,
              lv_incref       TYPE string.
    *--Populating Mail Recepients
      wa_receivers-rec_type   = 'U'.
      wa_receivers-com_type   = 'INT'.
      wa_receivers-notif_del  = 'X'.
      wa_receivers-notif_ndel = 'X'.
      wa_receivers-express    = 'X'.
    assgining a receiver's mail id
      wa_receivers-receiver   = lv_receive.
      APPEND wa_receivers TO it_receivers.
      CLEAR wa_receivers.
    *--Populating the body
      CALL FUNCTION 'READ_TEXT'
        EXPORTING
          client                  = sy-mandt
          id                      = 'ST'
          language                = sy-langu
          name                    = gc_so10_name
          object                  = 'TEXT'
        TABLES
          lines                   = it_line
        EXCEPTIONS
          id                      = 1
          language                = 2
          name                    = 3
          not_found               = 4
          object                  = 5
          reference_check         = 6
          wrong_access_to_archive = 7
          OTHERS                  = 8.
      IF sy-subrc = 0.
        LOOP AT it_line INTO wa_line.
          wa_message-line = wa_line-tdline.
          APPEND wa_message TO it_message.
          CLEAR : wa_line, wa_message.
        ENDLOOP.
      ENDIF.
    *//---  Populate the subject/generic message attributes
      wa_doc_data-obj_langu  = sy-langu.
      READ TABLE it_attachment INTO wa_attachment INDEX lv_cnt.
      wa_doc_data-doc_size   = ( lv_cnt - 1 ) * 255 + STRLEN( wa_attachment ).
      wa_doc_data-obj_name   = 'SAPRPT'.
    *//--- Subject Begin
      CLEAR : lv_subject.
      lv_subject = gw_inc_payment-pernr.
      SHIFT  lv_subject LEFT DELETING LEADING '0'.
      CONCATENATE text-009 '(' lv_subject ')'
                  INTO  wa_doc_data-obj_descr
                  SEPARATED BY space.
    *//--- Subject End
      wa_doc_data-sensitivty = 'F'.
    *--Describe the body of the message
      CLEAR : wa_packing_list, it_packing_list[].
      wa_packing_list-transf_bin  = space.
      wa_packing_list-head_start  = 1.
      wa_packing_list-head_num    = 0.
      wa_packing_list-body_start  = 1.
      DESCRIBE TABLE it_message LINES wa_packing_list-body_num.
      wa_packing_list-doc_type    = 'RAW'.
      APPEND wa_packing_list TO it_packing_list.
    Filling the attachment table
      DESCRIBE TABLE gt_objbin LINES lv_tablines.
      wa_packing_list-transf_bin  = 'X'.
      wa_packing_list-head_start  = 1.
      wa_packing_list-head_num    = 0.
      wa_packing_list-body_start  = 1.
      wa_packing_list-body_num    = lv_tablines.
      wa_packing_list-doc_type    = 'PDF'.
      wa_packing_list-obj_name    = 'ATTACHMENT'(a01).
    *//--- Attachment File Name - Begin
      CLEAR : lv_subject.
      lv_subject = gw_inc_payment-pernr.
      lv_incref  = gw_inc_payment-incref.
      SHIFT lv_subject LEFT DELETING LEADING '0'.
      SHIFT lv_incref  LEFT DELETING LEADING '0'.
      CONCATENATE text-011
                  lv_subject
                  gw_inc_payment-itafy
                  lv_incref
                  INTO wa_packing_list-obj_descr
                  SEPARATED BY '_'.
    *//--- Attachment File Name - End
      wa_packing_list-doc_size    = lv_tablines * 255.
      APPEND wa_packing_list TO it_packing_list.
      CLEAR wa_packing_list.
    calling the function module to send the mail
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data              = wa_doc_data
          put_in_outbox              = 'X'
          sender_address             = gc_sender
          sender_address_type        = 'INT'
          commit_work                = 'X'
        TABLES
          packing_list               = it_packing_list
          contents_bin               = gt_objbin[]
          contents_txt               = it_message
          receivers                  = it_receivers
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          document_type_not_exist    = 3
          operation_no_authorization = 4
          parameter_error            = 5
          x_error                    = 6
          enqueue_error              = 7
          OTHERS                     = 8.
      IF sy-subrc <> 0.
        gw_inc_payment-zmail       = '0'.
        gw_inc_payment-mail_status = text-022.
        gw_ita_inc-zmail           = '0'.
        MODIFY  gt_inc_payment  FROM gw_inc_payment
        TRANSPORTING zmail  WHERE incref = gw_inc_payment-incref
                              AND pernr = gw_inc_payment-pernr.
        MODIFY zhr_ita_inc_payk FROM gw_ita_inc.
        MESSAGE text-013 TYPE 'E'.
        CLEAR gw_ita_inc.
      ELSE.
        gw_inc_payment-zmail       = '1'.
        gw_inc_payment-mail_status = text-021.
        gw_ita_inc-zmail           = '1'.
        MODIFY  gt_inc_payment FROM gw_inc_payment
                               TRANSPORTING zmail mail_status
                               WHERE incref = gw_inc_payment-incref AND
                                     pernr = gw_inc_payment-pernr.
        IF sy-subrc = 0.
          MODIFY zhr_ita_inc_payk FROM gw_ita_inc.
          IF sy-subrc = 0.
            MESSAGE text-012 TYPE 'S'.
          ENDIF.
        ENDIF.
        CLEAR gw_ita_inc.
      ENDIF.
      CLEAR : it_packing_list,
              gt_objbin[],
              it_message[],
              it_receivers[],
              wa_doc_data.
    ENDFORM.                    " MAIL_PROCESS_ATTACH
    regards

  • When needing to send an email from Pages a new email document does not come up. PDF

    When needing to send email document from Pages when I hit Share, send via email then PDF no new email document comes up. Please advise.

    Chances are you have an "illegal" character in the file name such as a / or *.

  • Sending smartform output as PDF attachment, Error opening PDF attachment

    Hi Experts,
    I am using the code form the following link to send a smartform output as PDF attachment. I can able to see the message, but can not open PDF document.
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&
    The information should be on my smartform are some text, company logo and a barcode.
    With all of these received error: "There was an error opening this document. The file is damaged and could not be repaired."
    I tried different ways like only text, text with company logo, text with barcode. I got the following errors:
    An unrecognized token 'Td0' was found
    There was problem reading this document(16).
    There was problem reading this document(111).
    Does anyone have idea of these ? Your help is greatly appreciated.
    Thank you,
    Surya

    please see this code  ...  for sending the  Email as  PDF attach file,
    *& Report  ZSPOOLTOPDF                                                 *
    *& Converts spool request into PDF document and emails it to           *
    *& recipicant.                                                         *
    *& Execution                                                           *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on      *
    *& screen                                                              *
    REPORT  zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_sender LIKE somlreci1-receiver
                                        DEFAULT '[email protected]',
               p_delspl  AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    * Spool IDs
    TYPES: BEGIN OF t_tbtcp.
            INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
          wa_tbtcp TYPE t_tbtcp.
    * Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
          gd_eventparm LIKE tbtcm-eventparm,
          gd_external_program_active LIKE tbtcm-xpgactive,
          gd_jobcount LIKE tbtcm-jobcount,
          gd_jobname LIKE tbtcm-jobname,
          gd_stepcount LIKE tbtcm-stepcount,
          gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA:  w_recsize TYPE i.
    DATA: gd_subject   LIKE sodocchgi1-obj_descr,
          it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          gd_sender_type     LIKE soextreci1-adr_typ,
          gd_attachment_desc TYPE so_obj_nam,
          gd_attachment_name TYPE so_obj_des.
    * Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
          gd_destination LIKE rlgrap-filename,
          gd_bytecount LIKE tst01-dsize,
          gd_buffer TYPE string.
    * Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
            INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE  sy-sysid VALUE 'DEV',
               c_no(1)     TYPE c   VALUE ' ',
               c_device(4) TYPE c   VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    * Write statement to represent report output. Spool request is created
    * if write statement is executed in background. This could also be an
    * ALV grid which would be converted to PDF without any extra effort
      WRITE 'Hello World'.
      new-page.
      commit work.
      new-page print off.
      IF sy-batch EQ 'X'.
        PERFORM get_job_details.
        PERFORM obtain_spool_id.
    *** Alternative way could be to submit another program and store spool
    *** id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
    *        to sap-spool
    *        spool parameters   %_print
    *        archive parameters %_print
    *        without spool dynpro
    *        and return.
    * Get spool id from program called above
    *  IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
        PERFORM convert_spool_to_pdf.
        PERFORM process_email.
        if p_delspl EQ 'X'.
          PERFORM delete_spool.
        endif.
        IF sy-sysid = c_dev.
          wait up to 5 seconds.
          SUBMIT rsconn01 WITH mode   = 'INT'
                          WITH output = 'X'
                          AND RETURN.
        ENDIF.
      ELSE.
        SKIP.
        WRITE:/ 'Program must be executed in background in-order for spool',
                'request to be created.'.
      ENDIF.
    *       FORM obtain_spool_id                                          *
    FORM obtain_spool_id.
      CHECK NOT ( gd_jobname IS INITIAL ).
      CHECK NOT ( gd_jobcount IS INITIAL ).
      SELECT * FROM  tbtcp
                     INTO TABLE it_tbtcp
                     WHERE      jobname     = gd_jobname
                     AND        jobcount    = gd_jobcount
                     AND        stepcount   = gd_stepcount
                     AND        listident   <> '0000000000'
                     ORDER BY   jobname
                                jobcount
                                stepcount.
      READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
      IF sy-subrc = 0.
        message s004(zdd) with gd_spool_nr.
        gd_spool_nr = wa_tbtcp-listident.
        MESSAGE s004(zdd) WITH gd_spool_nr.
      ELSE.
        MESSAGE s005(zdd).
      ENDIF.
    ENDFORM.
    *       FORM get_job_details                                          *
    FORM get_job_details.
    * Get current job details
      CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
           IMPORTING
                eventid                 = gd_eventid
                eventparm               = gd_eventparm
                external_program_active = gd_external_program_active
                jobcount                = gd_jobcount
                jobname                 = gd_jobname
                stepcount               = gd_stepcount
           EXCEPTIONS
                no_runtime_info         = 1
                OTHERS                  = 2.
    ENDFORM.
    *       FORM convert_spool_to_pdf                                     *
    FORM convert_spool_to_pdf.
      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.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf_output.
        TRANSLATE it_pdf_output USING ' ~'.
        CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
      ENDLOOP.
      TRANSLATE gd_buffer USING '~ '.
      DO.
        it_mess_att = gd_buffer.
        APPEND it_mess_att.
        SHIFT gd_buffer LEFT BY 255 PLACES.
        IF gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.
    *       FORM process_email                                            *
    FORM process_email.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1.
    *  perform send_email using p_email2.
    ENDFORM.
    *       FORM send_email                                               *
    *  -->  p_email                                                       *
    FORM send_email USING p_email.
      CHECK NOT ( p_email IS INITIAL ).
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = 'Subject'.
      gd_attachment_desc = 'Attachname'.
    *  CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
      it_mess_bod        = 'Message Body text, line 1'.
      APPEND it_mess_bod.
      it_mess_bod        = 'Message Body text, line 2...'.
      APPEND it_mess_bod.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_mess_bod
                                          it_mess_att
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'PDF'
                                          gd_attachment_name
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 changing gd_error
                                          gd_reciever.
    ENDFORM.
    *       FORM delete_spool                                             *
    FORM delete_spool.
      DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
      ld_spool_nr = gd_spool_nr.
      CHECK p_delspl <> c_no.
      CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
           EXPORTING
                spoolid = ld_spool_nr.
    ENDFORM.
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment tables it_message
                                              it_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
    data:   t_packing_list like sopcklsti1 occurs 0 with header line,
            t_contents like solisti1 occurs 0 with header line,
            t_receivers like somlreci1 occurs 0 with header line,
            t_attachment like solisti1 occurs 0 with header line,
            t_object_header like solisti1 occurs 0 with header line,
            w_cnt type i,
            w_sent_all(1) type c,
            w_doc_data like sodocchgi1.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      ld_error = sy-subrc.
    * Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    reward  points  if it is usefull ....
    Girish

  • How to send ALV report by email, in the body of the email?

    Hello friends,
    I need to send a report ALV by email. First, the user wanted it attached as PDF file, but now he wants it in the body of the email.
    Does anybody have any solution?
    P.S.: I am using methods to send the email.
    Thanks in advance.
    Karla.

    Thank you Jan,
    I used the following solution to get the report in HTML code:
    I use submit to export the list to memory
    SUBMIT zsdr006_alv EXPORTING LIST TO MEMORY AND RETURN.
    Them I get the list from memory
      CALL FUNCTION 'LIST_FROM_MEMORY'
    Finaly I convert the list to HTML code
      CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
    The problem is when I send the email, it is still not going on the body of the email.
    I tried taking off the attach method, but the email goes blank in the body.
    Actually to SOST the message goes with the HMTL report in the body, just like I need, but when send to any e-mail address, it does not go on the body of the message.
    Does any body could check this out?
      TRY.
        -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
        -------- create and set document with attachment ---------------
        create document from internal table with text
          IF p_pdf EQ 'X'.
            l_type = 'RAW'.
            APPEND text-t01 TO text.
            IF NOT s_erdat-low IS INITIAL.
              CONCATENATE s_erdat-low6(2) '.' s_erdat-low4(2) '.' s_erdat-low(4) INTO ls_text-line.
              IF NOT s_erdat-high IS INITIAL.
                CONCATENATE ls_text-line 'a' INTO ls_text-line SEPARATED BY space.
                CONCATENATE ls_text-line s_erdat-high+6(2) INTO ls_text-line SEPARATED BY space.
                CONCATENATE ls_text-line '.' s_erdat-high+4(2) '.' s_erdat-high(4) INTO ls_text-line.
              ENDIF.
              CONCATENATE 'Período:' ls_text-line INTO ls_text-line SEPARATED BY space.
              APPEND ls_text TO text.
            ENDIF.
          ELSEIF p_htm EQ 'X'.
            l_type = 'HTM'.
            LOOP AT gt_ascdata INTO ls_ascdata.
              ls_text = ls_ascdata-line.
              APPEND ls_text TO text.
            ENDLOOP.
          ENDIF.
          subject = text-t01.
          document = cl_document_bcs=>create_document(
                          i_type    = l_type
                          i_text    = text
                          i_length  = '12'
                          i_subject = subject ).
        add attachment to document
        BCS expects document content here e.g. from document upload
        binary_content = ...
          IF p_pdf EQ 'X'.
            CALL METHOD document->add_attachment
              EXPORTING
                i_attachment_type    = 'PDF'
                i_attachment_subject = g_filename
                i_att_content_hex    = binary_content.
          ELSEIF p_htm EQ 'X'.
            CALL METHOD document->add_attachment
              EXPORTING
                i_attachment_type    = 'HTM'
                i_attachment_subject = g_filename
                i_att_content_text   = gt_ascdata.
          ENDIF.
        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 ).
          lv_email = g_email.
          sender = cl_cam_address_bcs=>create_internet_address( lv_email ).
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
        --------- add recipient (e-mail address) -----------------------
        create recipient - please replace e-mail address !!!
          LOOP AT s_email.
            lv_email = s_email-low.
            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'.
          ENDLOOP.
        ---------- send document ---------------------------------------
          CALL METHOD send_request->send(
            EXPORTING
              i_with_error_screen = 'X'
            RECEIVING
              result              = sent_to_all ).

  • Email in PDF format through ALV

    Hi Everybody,
    I have a query related to simple ALV report...i want to send a email of the output list of my ALV report in pdf format to a certain person's email id...
    Please can anybody suggest me how to do this?
    Its very urgent....
    With regards,
    Asish

    The code below demonstrates how to retrieve a spool request and email it as a PDF document. Please note
    for the below program to process a spool request the program must be executed in background otherwise no
    spool request will be created. Once you have had a look at this there is an modified version of the program
    which works in both background and foreground. Also see transaction SCOT for SAPConnect administration.
    *& Report ZSPOOLTOPDF *
    *& Converts spool request into PDF document and emails it to *
    *& recipicant. *
    *& Execution *
    *& This program must be run as a background job in-order for the write *
    *& commands to create a Spool request rather than be displayed on *
    *& screen *
    REPORT zspooltopdf.
    PARAMETER: p_email1 LIKE somlreci1-receiver
    DEFAULT '[email protected]',
    p_sender LIKE somlreci1-receiver
    DEFAULT '[email protected]',
    p_delspl AS CHECKBOX.
    *DATA DECLARATION
    DATA: gd_recsize TYPE i.
    Spool IDs
    TYPES: BEGIN OF t_tbtcp.
    INCLUDE STRUCTURE tbtcp.
    TYPES: END OF t_tbtcp.
    DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
    wa_tbtcp TYPE t_tbtcp.
    Job Runtime Parameters
    DATA: gd_eventid LIKE tbtcm-eventid,
    gd_eventparm LIKE tbtcm-eventparm,
    gd_external_program_active LIKE tbtcm-xpgactive,
    gd_jobcount LIKE tbtcm-jobcount,
    gd_jobname LIKE tbtcm-jobname,
    gd_stepcount LIKE tbtcm-stepcount,
    gd_error TYPE sy-subrc,
    gd_reciever TYPE sy-subrc.
    DATA: w_recsize TYPE i.
    DATA: gd_subject LIKE sodocchgi1-obj_descr,
    it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
    gd_sender_type LIKE soextreci1-adr_typ,
    gd_attachment_desc TYPE so_obj_nam,
    gd_attachment_name TYPE so_obj_des.
    Spool to PDF conversions
    DATA: gd_spool_nr LIKE tsp01-rqident,
    gd_destination LIKE rlgrap-filename,
    gd_bytecount LIKE tst01-dsize,
    gd_buffer TYPE string.
    Binary store for PDF
    DATA: BEGIN OF it_pdf_output OCCURS 0.
    INCLUDE STRUCTURE tline.
    DATA: END OF it_pdf_output.
    CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
    c_no(1) TYPE c VALUE ' ',
    c_device(4) TYPE c VALUE 'LOCL'.
    *START-OF-SELECTION.
    START-OF-SELECTION.
    Write statement to represent report output. Spool request is created
    if write statement is executed in background. This could also be an
    ALV grid which would be converted to PDF without any extra effort
    WRITE 'Hello World'.
    new-page.
    commit work.
    new-page print off.
    IF sy-batch EQ 'X'.
    PERFORM get_job_details.
    PERFORM obtain_spool_id.
    Alternative way could be to submit another program and store spool
    id into memory, will be stored in sy-spono.
    *submit ZSPOOLTOPDF2
    to sap-spool
    spool parameters %_print
    archive parameters %_print
    without spool dynpro
    and return.
    Get spool id from program called above
    IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
    PERFORM convert_spool_to_pdf.
    PERFORM process_email.
    if p_delspl EQ 'X'.
    PERFORM delete_spool.
    endif.
    IF sy-sysid = c_dev.
    wait up to 5 seconds.
    SUBMIT rsconn01 WITH mode = 'INT'
    WITH output = 'X'
    AND RETURN.
    ENDIF.
    ELSE.
    SKIP.
    WRITE:/ 'Program must be executed in background in-order for spool',
    'request to be created.'.
    ENDIF.
    FORM obtain_spool_id *
    FORM obtain_spool_id.
    CHECK NOT ( gd_jobname IS INITIAL ).
    CHECK NOT ( gd_jobcount IS INITIAL ).
    SELECT * FROM tbtcp
    INTO TABLE it_tbtcp
    WHERE jobname = gd_jobname
    AND jobcount = gd_jobcount
    AND stepcount = gd_stepcount
    AND listident '0000000000'
    ORDER BY jobname
    jobcount
    stepcount.
    READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
    IF sy-subrc = 0.
    message s004(zdd) with gd_spool_nr.
    gd_spool_nr = wa_tbtcp-listident.
    MESSAGE s004(zdd) WITH gd_spool_nr.
    ELSE.
    MESSAGE s005(zdd).
    ENDIF.
    ENDFORM.
    FORM get_job_details *
    FORM get_job_details.
    Get current job details
    CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
    IMPORTING
    eventid = gd_eventid
    eventparm = gd_eventparm
    external_program_active = gd_external_program_active
    jobcount = gd_jobcount
    jobname = gd_jobname
    stepcount = gd_stepcount
    EXCEPTIONS
    no_runtime_info = 1
    OTHERS = 2.
    ENDFORM.
    FORM convert_spool_to_pdf *
    FORM convert_spool_to_pdf.
    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.
    CHECK sy-subrc = 0.
    Transfer the 132-long strings to 255-long strings
    LOOP AT it_pdf_output.
    TRANSLATE it_pdf_output USING ' ~'.
    CONCATENATE gd_buffer it_pdf_output INTO gd_buffer.
    ENDLOOP.
    TRANSLATE gd_buffer USING '~ '.
    DO.
    it_mess_att = gd_buffer.
    APPEND it_mess_att.
    SHIFT gd_buffer LEFT BY 255 PLACES.
    IF gd_buffer IS INITIAL.
    EXIT.
    ENDIF.
    ENDDO.
    ENDFORM.
    FORM process_email *
    FORM process_email.
    DESCRIBE TABLE it_mess_att LINES gd_recsize.
    CHECK gd_recsize > 0.
    PERFORM send_email USING p_email1.
    perform send_email using p_email2.
    ENDFORM.
    FORM send_email *
    --> p_email *
    FORM send_email USING p_email.
    CHECK NOT ( p_email IS INITIAL ).
    REFRESH it_mess_bod.
    Default subject matter
    gd_subject = 'Subject'.
    gd_attachment_desc = 'Attachname'.
    CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
    it_mess_bod = 'Message Body text, line 1'.
    APPEND it_mess_bod.
    it_mess_bod = 'Message Body text, line 2...'.
    APPEND it_mess_bod.
    If no sender specified - default blank
    IF p_sender EQ space.
    gd_sender_type = space.
    ELSE.
    gd_sender_type = 'INT'.
    ENDIF.
    Send file by email as .xls speadsheet
    PERFORM send_file_as_email_attachment
    tables it_mess_bod
    it_mess_att
    using p_email
    'Example .xls documnet attachment'
    'PDF'
    gd_attachment_name
    gd_attachment_desc
    p_sender
    gd_sender_type
    changing gd_error
    gd_reciever.
    ENDFORM.
    FORM delete_spool *
    FORM delete_spool.
    DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
    ld_spool_nr = gd_spool_nr.
    CHECK p_delspl c_no.
    CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
    EXPORTING
    spoolid = ld_spool_nr.
    ENDFORM.
    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT
    Send email
    FORM send_file_as_email_attachment tables it_message
    it_attach
    using p_email
    p_mtitle
    p_format
    p_filename
    p_attdescription
    p_sender_address
    p_sender_addres_type
    changing p_error
    p_reciever.
    DATA: ld_error TYPE sy-subrc,
    ld_reciever TYPE sy-subrc,
    ld_mtitle LIKE sodocchgi1-obj_descr,
    ld_email LIKE somlreci1-receiver,
    ld_format TYPE so_obj_tp ,
    ld_attdescription TYPE so_obj_nam ,
    ld_attfilename TYPE so_obj_des ,
    ld_sender_address LIKE soextreci1-receiver,
    ld_sender_address_type LIKE soextreci1-adr_typ,
    ld_receiver LIKE sy-subrc.
    data: t_packing_list like sopcklsti1 occurs 0 with header line,
    t_contents like solisti1 occurs 0 with header line,
    t_receivers like somlreci1 occurs 0 with header line,
    t_attachment like solisti1 occurs 0 with header line,
    t_object_header like solisti1 occurs 0 with header line,
    w_cnt type i,
    w_sent_all(1) type c,
    w_doc_data like sodocchgi1.
    ld_email = p_email.
    ld_mtitle = p_mtitle.
    ld_format = p_format.
    ld_attdescription = p_attdescription.
    ld_attfilename = p_filename.
    ld_sender_address = p_sender_address.
    ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
    w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle .
    w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
    CLEAR w_doc_data.
    READ TABLE it_attach INDEX w_cnt.
    w_doc_data-doc_size =
    ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle.
    w_doc_data-sensitivty = 'F'.
    CLEAR t_attachment.
    REFRESH t_attachment.
    t_attachment] = it_attach[.
    Describe the body of the message
    CLEAR t_packing_list.
    REFRESH t_packing_list.
    t_packing_list-transf_bin = space.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 0.
    t_packing_list-body_start = 1.
    DESCRIBE TABLE it_message LINES t_packing_list-body_num.
    t_packing_list-doc_type = 'RAW'.
    APPEND t_packing_list.
    Create attachment notification
    t_packing_list-transf_bin = 'X'.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 1.
    t_packing_list-body_start = 1.
    DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
    t_packing_list-doc_type = ld_format.
    t_packing_list-obj_descr = ld_attdescription.
    t_packing_list-obj_name = ld_attfilename.
    t_packing_list-doc_size = t_packing_list-body_num * 255.
    APPEND t_packing_list.
    Add the recipients email address
    CLEAR t_receivers.
    REFRESH t_receivers.
    t_receivers-receiver = ld_email.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    APPEND t_receivers.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = w_doc_data
    put_in_outbox = 'X'
    sender_address = ld_sender_address
    sender_address_type = ld_sender_address_type
    commit_work = 'X'
    IMPORTING
    sent_to_all = w_sent_all
    TABLES
    packing_list = t_packing_list
    contents_bin = t_attachment
    contents_txt = it_message
    receivers = t_receivers
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.
    Populate zerror return code
    ld_error = sy-subrc.
    Populate zreceiver return code
    LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
    ENDLOOP.
    ENDFORM.
    Reward points if useful.

  • Block List ALV Output Send As Email Attachment

    Hi,  All The ABAP Gurus,
    I have made a block ALV Report. I want that this output should be converted into .xls with HTML format and this should be send in email as attachment. This all will be made in a background job which will be scheduled daily.
    How can I achieve this? I know that the output of classical report can be attached as pdf in email.But I want in Block ALV.
    Thanks in Advance.
    Regards,
    Bharti Jain
    Edited by: Bharti Jain on Jun 28, 2011 10:20 AM

    Hi
    Not 100 percent sure what you want to do here.  I am confused by the .xls in html format.   If you want the output in html you can submit the program and export the list to memory,  Then retrieve the list and convert it to html.  i have done this with the program 1sdbf12l/rv14akzy . see code below.  This converts the output to html, you are left with a binary itab and size at the end of the routine and this can be attached to an email.
    Submit Program and export the list to Memory
    SUBMIT /1sdbf12l/rv14akzy USING SELECTION-SCREEN '1000'
      WITH SELECTION-TABLE lt_params_new EXPORTING LIST TO MEMORY AND RETURN.
      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          listobject = lt_list
        EXCEPTIONS
          not_found  = 1
          OTHERS     = 2.
    Convert the List to html
      IF sy-subrc = 0.
        DATA: it_html TYPE TABLE OF bapihtml WITH HEADER LINE,
              it_html_out TYPE TABLE OF bapihtml WITH HEADER LINE,
              lt_html TYPE TABLE OF bapihtml WITH HEADER LINE,
              lv_html LIKE LINE OF it_html,
              lv_html_out TYPE string.
        DATA: lv_html_tab_wide(50000) TYPE c.
        DATA: lineno TYPE i, length TYPE i, size TYPE i.
        DATA: gui_codepage(4) TYPE n,        " added for message 500824
              is_unicode TYPE rststype-sel_ok.
        DATA: convert_output TYPE xstring,
              convert_buffer TYPE xstring.
        CALL FUNCTION 'LIST_FREE_MEMORY'
          TABLES
            listobject = lt_list.
        CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
             EXPORTING
                  REPORT_NAME   =
                  template_name = 'WEBREPORTING_REPORT'
             TABLES
                  html          =  it_html
                  listobject    =  lt_list.
        DESCRIBE TABLE it_html LINES lineno .
        DESCRIBE FIELD it_html LENGTH length IN BYTE MODE.
        size = length * lineno.
        CALL 'CUR_LCL' ID 'GUICP'  FIELD gui_codepage.
        CALL FUNCTION 'SCP_GET_CODEPAGE_PROPERTIES'
          EXPORTING
            codepage         = gui_codepage
          IMPORTING
            can_unicode      = is_unicode
          EXCEPTIONS
            codepage_unknown = 1.
        IF sy-subrc <> 0.
          CLEAR gui_codepage.
        ENDIF.
        IF is_unicode EQ 'X'.         "in case of unicode, always use utf-8
          gui_codepage = '4110'.
        ENDIF.
        CLEAR: convert_output, convert_buffer.
        LOOP AT it_html INTO lv_html.
          REPLACE ALL OCCURRENCES OF c_bg_def IN lv_html WITH c_bg_white.
          CALL FUNCTION 'SCP_TRANSLATE_CHARS'
            EXPORTING
              inbuff           = lv_html
              outcode          = gui_codepage
              csubst           = 'X'
              substc_space     = 'X'
            IMPORTING
              outbuff          = convert_output
            EXCEPTIONS
              invalid_codepage = 1
              internal_error   = 2
              cannot_convert   = 3
              fields_bad_type  = 4
              OTHERS           = 5.
          IF sy-subrc <> 0.
           message i020 raising download_error.
          ENDIF.
          CONCATENATE convert_buffer convert_output INTO convert_buffer IN
          BYTE MODE.
          CONCATENATE lv_html_out lv_html INTO lv_html_out.
        ENDLOOP.
        ev_html_string = lv_html_out.
        i = 0.
        DESCRIBE FIELD html_tab_converted LENGTH tablength IN BYTE MODE.
        WHILE i < XSTRLEN( convert_buffer ).
          dummy = XSTRLEN( convert_buffer ) - i.
          IF tablength > dummy.
            html_tab_converted-line = convert_buffer+i(dummy).
          ELSE.
            html_tab_converted-line = convert_buffer+i(tablength).
          ENDIF.
          i = i + tablength.
          APPEND html_tab_converted.
        ENDWHILE.
        et_bin[] = html_tab_converted[].
        ev_bin_size = size.

  • Sending an email of the layout in PDF attachement

    Hello All,
    I have written a program to send the layout in PDF format to send in a mail to the customer.
    The email is going fne with the PDF attachement in the development box, but it is not working in Quality box.
    In the Quality box the email is going but the attachement is not opening.
    I have used CONVERT_OTF function module for converting OTF format to PDF format. As per my analysis it is returning the PDF format properly in Developement box but not the same in Quality. In Quality the the data returning in PDF format is not in proper manner. It is giving some junk data with symbols like traingle, rectange..etc..
    I am using FM SO_OBJECT_SEND for sending an email.
    Can you please suggest me what may be problem?
    Valuable answers will be rewarded.
    Thanks & Regards,
    Satish.

    Hi,
    you need to save the File in PDF format not in the text format.
    check whether the file is saved in pdf format or not.
    Regards,
    Raj.

  • Convert spool to pdf and send in email sometimes attachment duplicated.

    Hi all, I have a process that creates a spool, converts it to a pdf and then attaches it to an email. My problem is that sometimes, the same attachment is duplicated.
    The process seems to work fine in debug mode (the attachment changes for each loop) but when I run it in the background, every few emails, it will duplicate an attachment.
    I have noticed that the size of the pdf seems to change properly but that the content of the pdf does not match.  So, it is like it gets the correct size of the pdf but not the body.
    This is code that a consultant wrote and I am pretty new to abap/sap. I have changed some of the code because it was trying to handle an endless loop (I figured it should not have to handle (be in) an endless loop). I changed that code and it is working but this previous issue still exists. Thanks for your help.
    *&      Form  PROCESS_EMPLOYEE
    FORM process_employee .
    * process appraisal only
      IF it_final[] IS NOT INITIAL .
    *                READ DISTRIBUTION LIST                                *
        REFRESH : it_email, it_idlient. 
    *Sort by supervisor
        SORT it_final[] BY supervisor.
        LOOP AT it_final INTO wa_final .
          APPEND wa_final TO it_final1 .
          AT END OF supervisor .
    * Perform to create the PDF from the Output
           report = 'zhr_pm_appemail'.
           PERFORM create_pdf using report.
    ** Perform to email the PDF attachment
    ** to the supervisor and the Mailing list
            subject = 'Performance Appraisals'.
            PERFORM process_email using subject.
            REFRESH it_final1 .
            CLEAR it_final1 .
            CLEAR wa_final .
            FREE MEMORY ID 'MEM'.
          ENDAT .
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " PROCESS_EMPLOYEE
    *&      Form  CREATE_PDF
    FORM create_pdf using report.
      DATA:  spoolno TYPE tsp01-rqident.
      DATA : p_repid TYPE sy-repid .
      DATA: v_len  TYPE i , v_len1  TYPE i .
      DATA: v_temp(8) TYPE c .
      DATA: p_uname TYPE sy-uname .
      DATA: it_tsp01 TYPE STANDARD TABLE OF tsp01 WITH HEADER LINE .
    *  DATA: it_pdf TYPE tline OCCURS 0 WITH HEADER LINE .
      TABLES: tsp01.
      DATA: var  TYPE c .
    *-- STRUCTURES
      DATA:
        lc_rq2name TYPE tsp01-rq2name.
      DATA:
        mstr_print_parms TYPE pri_params,
        mc_valid(1)      TYPE c,
        mi_bytecount     TYPE i,
        mi_length        TYPE i,
        mi_rqident       TYPE tsp01-rqident.
    *-- INTERNAL TABLES
      DATA:
        mtab_pdf    TYPE tline OCCURS 0 WITH HEADER LINE,
        mc_filename TYPE rlgrap-filename.
    *-- SELECTION SCREEN
      DATA:
        p_linsz TYPE sy-linsz VALUE 80, " Line size
        p_paart TYPE sy-paart VALUE 'X_65_80'.  " Paper Format
        p_uname = sy-uname .
        var = var + 1.
        p_repid = report.
    * START-OF-SELECTION .
      concatenate p_repid+0(9)
                  p_uname+0(3)
            into mc_filename
       separated by '_'.
    translate mc_filename to upper case.
    *-- Setup the Print Parmaters
      CALL FUNCTION 'GET_PRINT_PARAMETERS'
        EXPORTING
          authority              = space
          copies                 = '1'
          cover_page             = space
          data_set               = space
          department             = space
          destination            = space
          expiration             = '1'
          immediately            = space
          new_list_id            = 'X'
          no_dialog              = 'X'
          user                   = sy-uname
        IMPORTING
          out_parameters         = mstr_print_parms
          valid                  = mc_valid
        EXCEPTIONS
          archive_info_not_found = 1
          invalid_print_params   = 2
          invalid_archive_params = 3
          OTHERS                 = 4.
    IF sy-subrc = 0 .
    *--Make sure that a printer destination has been set up. If this is not done the PDF module abends.
    *-- Explicitly set line width, and output format so that
    *-- the PDF conversion comes out OK
      mstr_print_parms-linsz = p_linsz.
      mstr_print_parms-paart = p_paart.
            EXPORT it_final1 it_email p_email1 p_sender p_date vl_nmth
            TO MEMORY ID 'MEM' .
          IF report =   'zhr_pm_appandprogemail'.
             SUBMIT zhr_pm_appandprogemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
          ENDIF.
          IF report =   'zhr_pm_appemail'.
             SUBMIT zhr_pm_appemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
          ENDIF.
    ENDIF.
    *Find out what the spool number is that was just created
      perform get_spool_number using p_repid p_uname changing mi_rqident.
    *converting the spool request into pdf
      CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
        EXPORTING
          src_spoolid              = mi_rqident
          no_dialog                = space
          dst_device               = mstr_print_parms-pdest
        IMPORTING
          pdf_bytecount            = mi_bytecount
        TABLES
          pdf                      = it_pdf
        EXCEPTIONS
          err_no_abap_spooljob     = 1
          err_no_spooljob          = 2
          err_no_permission        = 3
          err_conv_not_possible    = 4
          err_bad_destdevice       = 5
          user_cancelled           = 6
          err_spoolerror           = 7
          err_temseerror           = 8
          err_btcjob_open_failed   = 9
          err_btcjob_submit_failed = 10
          err_btcjob_close_failed  = 11
          OTHERS                   = 12.
    *  call function 'DOWNLOAD'
    *    exporting
    *      bin_filesize      = mi_bytecount
    *      filename          = mc_filename
    *      filetype          = 'BIN'
    *    importing
    *      act_filename      = mc_filename
    *    tables
    *      data_tab          = it_mess_att.
      CHECK sy-subrc = 0.
    * Transfer the 132-long strings to 255-long strings
      LOOP AT it_pdf INTO wa_pdf.
        TRANSLATE wa_pdf USING ' ~'.
        CONCATENATE v_gd_buffer wa_pdf INTO v_gd_buffer.
        CLEAR wa_pdf .
      ENDLOOP.
      TRANSLATE v_gd_buffer USING '~ '.
      DO.
        it_mess_att = v_gd_buffer.
       APPEND it_mess_att.
        SHIFT v_gd_buffer LEFT BY 255 PLACES.
        IF v_gd_buffer IS INITIAL.
          EXIT.
        ENDIF.
      ENDDO.
    ENDFORM.                    " CREATE_PDF
    * FORM get_spool_nunber *
    * Get the most recent spool created by user/report                      *
    form get_spool_number using f_repid
          f_uname changing f_rqident.
      data:
            lc_rq2name TYPE rlgrap-filename.
      concatenate f_repid+0(6)
                  f_repid+7(3)
                  f_uname+0(3)
            into lc_rq2name.
    *   separated by '_'.
    translate lc_rq2name to upper case.
      select * from tsp01 where rq2name = lc_rq2name
        order by rqcretime descending.
          f_rqident = tsp01-rqident.
          exit.
          endselect.
          if sy-subrc ne 0.
            clear f_rqident.
          endif.
    endform. " get spool number
    *&      Form  SEND_MAIL
    FORM send_email USING p_email subject.
      REFRESH it_mess_bod.
    * Default subject matter
      gd_subject         = text-019 ."'Subject'.
      gd_attachment_desc = text-020 ."'Performance Appraisal'.
      IF subject =   'Performance Appraisals and Progression I'.
        gd_attachment_desc = 'PerfAppAndProg'.
      ENDIF.
      IF subject =   'Performance Appraisals'.
        gd_attachment_desc = 'PerfAppraisal'.
      ENDIF.
    * If no sender specified - default blank
      IF p_sender EQ space.
        gd_sender_type  = space.
      ELSE.
        gd_sender_type  = 'INT'.
      ENDIF.
    * Send file by email as .pdf
      PERFORM send_file_as_email_attachment
                                   TABLES it_mess_bod
                                          it_mess_att
                                    USING p_email
                                          subject
                                          'PDF'
                                          gd_attachment_desc
                                          gd_attachment_desc
                                          p_sender
                                          gd_sender_type
                                 CHANGING gd_error
                                          gd_reciever.
    ENDFORM.                    " SEND_MAIL
    *       FORM process_email                                            *
    FORM process_email using subject.
      DESCRIBE TABLE it_mess_att LINES gd_recsize.
      CHECK gd_recsize > 0.
      PERFORM send_email USING p_email1 subject.
    *  perform send_email using p_email2.
    ENDFORM.                    "process_email
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM send_file_as_email_attachment TABLES it_message
                                              it_attach
                                        USING p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     CHANGING p_error
                                              p_reciever.
      CLEAR : ld_email , ld_mtitle , ld_format , ld_attdescription  ,
        ld_attfilename , ld_sender_address , ld_sender_address_type ,
        w_doc_data.
      REFRESH: t_packing_list.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
      w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = it_attach[].
    * Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    * Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    * Add the recipients email address
      CLEAR t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      LOOP AT it_email.
    * Add the recipients email address
        t_receivers-receiver = it_email.
        t_receivers-rec_type = 'U'.
        t_receivers-com_type = 'INT'.
        t_receivers-notif_del = 'X'.
        t_receivers-notif_ndel = 'X'.
        APPEND t_receivers.
      ENDLOOP.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
    *            CONTENTS_HEX               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           EXCEPTIONS
                too_many_receivers         = 1
                document_not_sent          = 2
                document_type_not_exist    = 3
                operation_no_authorization = 4
                parameter_error            = 5
                x_error                    = 6
                enqueue_error              = 7
                OTHERS                     = 8.
      IF sy-subrc = 0.
        PERFORM update_infotype_0019 .
      ENDIF.
    * Populate zerror return code
    *  ld_error = sy-subrc.
    **  stop .
    *  READ TABLE t_receivers WITH KEY retrn_code = '0' .
    *  IF sy-subrc = 0 .
    *    v_update_flag = '1' .
    *    EXPORT v_update_flag TO MEMORY ID 'MEM2' .
    *  ENDIF .
    ** Populate zreceiver return code
    *  LOOP AT t_receivers.
    *    ld_receiver = t_receivers-retrn_code.
    *  ENDLOOP.
    ENDFORM.                    "send_file_as_email_attachment
    *&      Form  GET_NEXT_MONTH
    FORM get_next_month .
      CLEAR v_month .
      v_month = vl_nmth+4(2).
      REFRESH it_t247 .
      CLEAR it_t247 .
      CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
        EXPORTING
          langu = 'E'
          month = v_month
        IMPORTING
          t247  = it_t247.
      CLEAR v_mon_text .
      v_mon_text = it_t247-ltx .
    ENDFORM.                    " GET_NEXT_MONTH
    Edited by: Katie Doody on Feb 24, 2010 12:30 AM

    Thank you for your response, this has allowed me to identify the problem. It is when I create the spool by using the code below. If I add a wait after this, the program works successfully. Is there another way to write the data to create a spool within my initial program rather than doing the submit? Could it be that it is putting data in memory?
    SUBMIT zhr_pm_appandprogemail TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          SPOOL PARAMETERS mstr_print_parms
          VIA SELECTION-SCREEN AND RETURN.
    *& Report  ZHR_PM_APPANDPROGEMAIL
    REPORT  ZHR_PM_APPANDPROGEMAIL
            NO STANDARD PAGE HEADING
            LINE-SIZE 80
            LINE-COUNT 65(8).
    *        MESSAGE-ID zhr.
    * INTERNAL TABLES DECLARATION
    DATA: it_pdf TYPE tline OCCURS 0 ." WITH HEADER LINE .
    * WORK AEA DECLARATION
    DATA: wa_pdf TYPE tline .
    * Spool to PDF conversions
    *DATA: "gd_spool_nr TYPE tsp01-rqident,
    *      gd_destination TYPE rlgrap-filename,
    *      gd_bytecount TYPE tst01-dsize,
    DATA:v_update_flag TYPE c .                                   "flag for updating infotype 41 last appraisal date
    DATA: v_gd_buffer TYPE string.
    DATA: BEGIN OF it_final1 OCCURS 0 ,
            supervisor      TYPE persno ,
            pernr           TYPE persno ,
            ename           TYPE pa0001-ename ,
            subgroup        TYPE persk ,
            stext           TYPE t503t-ptext ,
            lastapp         TYPE dats ,
            lastjob         TYPE dats ,
            email           TYPE ztype,
            darxx(5)        TYPE c,
            progression(1)  TYPE c,
            supervisor_desc(50) TYPE c,
          END OF it_final1 .
    DATA:   t_packing_list TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers TYPE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header TYPE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data TYPE sodocchgi1 .
    DATA: gd_error    TYPE sy-subrc,
          gd_reciever TYPE sy-subrc.
    DATA: v_flag TYPE c VALUE '1' .
    DATA: BEGIN OF it_final OCCURS 0 ,
            subgroup       TYPE persk ,
            supervisor     TYPE persno ,
            pernr          TYPE persno ,
            ename          TYPE pa0001-ename ,
            stext          TYPE t503t-ptext ,
            lastapp        TYPE dats ,
            lastjob        TYPE dats ,
            email          TYPE ztype,
            progression(1) TYPE c,
            supervisor_desc(50) TYPE c,
          END OF it_final .
    DATA:it_t247 TYPE STANDARD TABLE OF t247 WITH HEADER LINE .
    DATA: it_email TYPE STANDARD TABLE OF zemail WITH HEADER LINE.
    *VARIABLE DECLARATION
    DATA: p_date   TYPE sy-datum ,               "excution date
          vl_date  TYPE sy-datum ,
          p_email1 TYPE somlreci1-receiver ,     "receiver
          p_sender TYPE somlreci1-receiver .     "sender
    DATA:  w_recsize TYPE i.
    DATA: gd_recsize TYPE i.
    DATA : vl_nmth TYPE sy-datum.
    DATA: v_month(2) TYPE n .
    DATA: v_mon_text TYPE t247-ltx .
    *START OF SELECTION
    START-OF-SELECTION .
      REFRESH t_receivers.
      IMPORT it_final1 it_email p_email1 p_sender p_date vl_nmth FROM MEMORY ID 'MEM'.
      PERFORM get_next_month .
      LOOP AT it_final1 .
        IF  it_final1-progression IS NOT INITIAL.
          MOVE-CORRESPONDING it_final1 TO it_final .
          APPEND it_final .
          CLEAR  it_final .
    *   Add the recipients email address
          t_receivers-receiver = it_final1-email.
          t_receivers-rec_type = 'U'.
          t_receivers-com_type = 'INT'.
          t_receivers-notif_del = 'X'.
          t_receivers-notif_ndel = 'X'.
          APPEND t_receivers.
        ENDIF.
      ENDLOOP .
      PERFORM write_output .
    *END OF SELECTION
    END-OF-SELECTION .
    *&      Form  WRITE_OUTPUT
    FORM write_output .
      DATA: l_date(14) TYPE c ,
            l_date_temp(14) TYPE c ,
            v_date(10) TYPE c ,
            v_date1(20) TYPE c ,
            v_date1_temp(20) TYPE c ,
            f_date(10) TYPE c.
      DATA: lv_stext TYPE t503t-ptext .
      CLEAR : v_date, v_date1.
      CONCATENATE p_date+4(02) p_date+6(02) p_date+0(04)'.' INTO v_date.
      CONCATENATE v_mon_text p_date+0(4) INTO l_date_temp SEPARATED BY space.
      CONCATENATE l_date_temp '.' INTO l_date.
      CONCATENATE v_mon_text vl_nmth+6(2) INTO v_date1_temp SEPARATED BY space.
      CONCATENATE v_date1_temp ',' INTO v_date1_temp.
      CONCATENATE v_date1_temp vl_nmth(4) INTO v_date1_temp SEPARATED BY space.
      CONCATENATE v_date1_temp '.' INTO v_date1.
      CONDENSE l_date .
      FORMAT INTENSIFIED ON.
      SKIP 4.
      WRITE:/(80) text-001 CENTERED .         "'METROPOLITAN UTILITIES DISTRICT'.
      WRITE:/(80) text-002 CENTERED .         "'OMAHA NEBR.'.
      SKIP 2.
      WRITE:/(80) text-003 CENTERED .        "'Inter-Departmental Communication'.
      FORMAT INTENSIFIED OFF.
      WRITE  :/(80) v_date CENTERED using edit mask '__/__/____'.   " v_date.
      SKIP 2.
      WRITE: /10 text-004.                     "'SUBJECT:   Performance Appraisals and Progression Increase'.
      SKIP 1.
      WRITE: /10 text-005, it_final1-supervisor_desc.  "'TO: Supervisor'.
      SKIP 1.
      WRITE: /10 text-006.                     "'FROM:      Anne M. Undajon, Director of Compensation and Benefits'.
      SKIP 2.
      WRITE:/10 text-007 .                       "'Listed below are the employees in your area who are due a '.
      WRITE:/10 text-008 ,l_date.                "'Performance Appraisal during the month of ',l_date.'.      "v_mon_text , P_date+0(4)
      WRITE:/10 text-009 .                       "'These employees are also eligible for a progression increase.
      WRITE:/10 text-010 .                       "' A performance appraisal form can be found on-line in the MUD '.
      WRITE:/10 text-011 .                       "'template section. The Performance Appraisal is to be completed '
      WRITE:/10 text-012 .                       "'and discussed with the employee by the immediate supervisor.'
      SKIP 2.
      WRITE:/10 text-013.                        "Signed forms should be returned to the Human Resource Department by '.
      WRITE:/10 v_date1.
      SKIP 2 .
      SORT it_final[] BY subgroup .
      LOOP AT it_final .
        CLEAR: lv_stext .
        lv_stext =  it_final-stext.
        AT NEW subgroup .
          TRANSLATE lv_stext TO UPPER CASE .
          WRITE:/(80) lv_stext CENTERED .
          SKIP 2 .
          WRITE: 10 text-014 .                      "'Employee name' .
          WRITE: 32 text-015 .                      "'Job Date' .
          WRITE :44 text-016 .                      "'Last Appraisal' .
          WRITE :59 text-021 .                      "'Employee' .
          WRITE :/10 '--------------------' , 32'----------', 44 '--------------', 59 '--------'.
        ENDAT .
        WRITE:/10 it_final-ename .
        WRITE: 32 it_final-lastjob using edit mask '__/__/____'.
        CONCATENATE it_final-lastapp+4(02) it_final-lastapp+6(02) it_final-lastapp+0(04) INTO f_date.
        WRITE :44 f_date using edit mask '__/__/____'.
        SHIFT it_final-pernr left deleting leading '0'.
        WRITE : 59 it_final-pernr.
        SKIP 2 .
      ENDLOOP.
      SKIP 4.
      WRITE :10 text-017.             "'Anne M. Undajon'.
      FORMAT INTENSIFIED ON.
      WRITE:/10 text-018.              "'Director of Compensation & Benefits'.
      FORMAT INTENSIFIED OFF.
    ENDFORM.                    " WRITE_OUTPUT
    *&      Form  GET_NEXT_MONTH
    FORM get_next_month .
      CLEAR v_month .
      v_month = vl_nmth+4(2).
      REFRESH it_t247 .
      CLEAR it_t247 .
      CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
        EXPORTING
          langu = 'E'
          month = v_month
        IMPORTING
          t247  = it_t247.
      CLEAR v_mon_text .
      v_mon_text = it_t247-ltx .
    ENDFORM.                    " GET_NEXT_MONTH
    Edited by: Katie Doody on Feb 24, 2010 4:07 PM

  • How to send an Email Message along with a PO PDF Attachment in Word.

    I want to send an Email to a customer. The subject of the email is the PDF attachment of the Purchase order.
    Then in the Body of the email, we need to put a small Mesasge in the Body of the Email: Example
    Hello,
    Please see attached Purchase Order.
    thank you...
    Does anyone have a suggestion on how to do this? Best approach?
    thanks
    Walter Poe

    Hi Walter,
    In NACE transaction, select Application EF , then select your P.O Message ( standard is NEU ) .
    Then in "processing routing" parts check that there is an entry for medium 5 ( external send ) , if not please set it with corresponding print program, from routine and forms to use .
    Then in "Mail Title and Text" parts  you can define your mail title with variable and your mail body . Please find below a sample for this. To define the mail body just click on the icon for text ( it's like sapscript text ).
    Mail Title : "Your P.O &EKKO-EBELN"
    Mail Body : "Please find enclosed our P.O &EKKO-EBELN....."
    That's all for NACE parts.
    After this you have to define thru condition that the medium will be used for each P.O. For this check with functionnal consultant if everything is ok and the same that for medium 1.
    Then when you create a P.O, SAP will generate a mail with supplier e-mail adress define in his masterdata . The forms will be converted according to your customizing in transaction SCOT ( node SMTP , Support address type parts) .
    Of course you also have to define a job for sending the mail .
    Hope this help you
    Regards
    Bertrand

  • Send email in pdf format

    i have a function which returns purchase orders list.
    in my program i want my program sends the purchase order document through email in pdf format when i select an order from the list.
    how can i do that.

    This reference program might help:
    http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Maybe you are looking for