ALV report as an e-mail attachment

Hi,
I know this topic has been discussed many times. The program is not run background so if any of you could let me know the steps to achieve this it will be great !
Thanks a lot.

Hi,
   Download The ALV Report in An Excel Or HTML Format And Send It as An Attachment With The Mail.
DATA :  it_html LIKE w3html OCCURS 0 .
      CALL FUNCTION 'WWW_LIST_TO_HTML'
        EXPORTING
          list_index = v_lind  " list index
        TABLES
          html       = it_html.
After Downloading into a table it Send This As An Attachment with the Mail as follows
DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_message1 TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                WITH HEADER LINE.
DATA    v_num  TYPE i.
DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
        t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
        t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
        w_cnt TYPE i,
        w_sent_all(1) TYPE c,
        w_doc_data LIKE sodocchgi1,
        gd_error    TYPE sy-subrc,
        gd_reciever TYPE sy-subrc.
PERFORM send_file_as_email_attachment
                               TABLES it_message
                                      it_attach
                                USING '[email protected]'
                                      'TCS Details'
                                      'HTM'
                                      'filename'
                             CHANGING gd_error
                                      gd_reciever.
FORM send_file_as_email_attachment TABLES pit_message
                                          pit_attach
                                    USING p_email
                                          p_mtitle
                                          p_format
                                          p_filename
                                          p_attdescription
                                          p_sender_address
                                          p_sender_addres_type
                                 CHANGING p_error
                                          p_reciever.
  CONSTANTS:
      con_tab  TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
      con_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf.
  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,
        w_doc_data LIKE sodocchgi1.
  DATA v_sent TYPE  sonv-flag.
  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 = 'P'.
  CLEAR it_message.
  REFRESH it_message.
  it_message[] = pit_attach[].
Describe the body of the message
  CLEAR t_packing_list.
  REFRESH t_packing_list.
  t_packing_list-transf_bin = space.
  t_packing_list-head_start = 1.
  t_packing_list-head_num = 1.
  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
  REFRESH it_message.
  it_message[] = it_html[].
  t_packing_list-transf_bin = ' '.
  t_packing_list-head_start = 1.
  t_packing_list-head_num   = 4.
  t_packing_list-body_start = 1.
  CLEAR v_num.
  DESCRIBE TABLE it_message 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   =  'TCS Scenario'.
  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.
  SELECT SINGLE email FROM zdrp_tcsmail INTO v_email WHERE vkorg = p_vkorg.
  SPLIT v_email AT ',' INTO TABLE itab_temp_email.
  LOOP AT itab_temp_email.
    t_receivers-receiver = itab_temp_email-emailid.
    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_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data                    = w_doc_data
     put_in_outbox                    = 'X'
     commit_work                      = 'X'
   IMPORTING
      sent_to_all                      = v_sent
    NEW_OBJECT_ID                    =
    TABLES
      packing_list                     = t_packing_list
    OBJECT_HEADER                    =
    CONTENTS_BIN                     =
      contents_txt                     = it_message
    CONTENTS_HEX                     =
    OBJECT_PARA                      =
    OBJECT_PARB                      =
      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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
Populate zreceiver return code
  LOOP AT t_receivers.
    ld_receiver = t_receivers-retrn_code.
  ENDLOOP.
ENDFORM.                    "send_file_as_email_attachment
Regards
Ahasan
Message was edited by: Ahsan
Message was edited by: Ahsan
Message was edited by: Ahsan

Similar Messages

  • Convert ALV report into PDF and mail ( Hierarchical List View )

    Hi All,
    I see many posts of PDF download but none resolve my issue.
    I am writing a report in APO SNP which fetches data and displays an alv using REUSE_ALV_HIERSEQ_LIST_DISPLAY as i need to show the result as a Hierarchical sequential list.
    I need to provide the functionality of PDF download ( online ) and Email with PDF as attachement ( Background ) for the list output.
    I read the post http://www.sapdev.co.uk/reporting/rep_spooltopdf2.htm which provides a sample program and tried to incorporate but the control doesn't come back from the ALV function module.
    How do i trigger the spool creation while still showing the output  and then send email?
    Suggestions and pointers are highly appreciated
    Regards,
    KD

    Hi.,
    Check this wiki: [Convert ALV as PDF  Attachment|http://wiki.sdn.sap.com/wiki/display/Snippets/SENDALVGRIDASPDFATTACHMENTTOSAPINBOXUSINGCLASSES]
    hope this helps u.,
    Thanks & Regards,
    Kiran

  • ALV Report to be send as a mail as an Excel sheet attachment

    Hi,
             I have designed a Report that has the mailing functionality by attaching the ALV report output in the Excel sheet.
    1. I am using SUBMITT PROGRAM....EXPORTING MEMORY ID.
              Here  I am retrieving the required ALV report.
    2. I am passing of ALV Report output to internal table, say XLS_TAB using FM LIST_TO_ASCI.
    I can see the data in the internal table. But the problem is when the report output has many columns (i.e) greater than 255 Char, the columns get truncated(data is missed).
    So, how to prevent the missing of the columns. I don't want split each record into new line. Because, when it is passed to Excel, each record should be in a single line without missing any column.
                   If you say the FM can be valid upto 255 Char, what can be the alternative solution?
    Immediate response is appreciated.
    Thanks for your help.
    Sravan.

    Hi deepan
    DESCRIBE TABLE objtxt LINES tab_lines.
      READ TABLE objtxt INDEX tab_lines.
    docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ) . <---- make it 1024 instead of 255
      CLEAR objpack-transf_bin.
    objpack-head_start = 1.
    objpack-head_num = 0.
    objpack-body_start = 1.
    objpack-body_num = gv_tab_lines.
    objpack-doc_type = RAW
      APPEND objpack
    then looping contents of the final table to OBJBIN1.
    DESCRIBE TABLE objbin1 LINES tab_lines.
      objpack-doc_size = tab_lines * 255 .    <-------- make it has 1024 instead of 255
      objpack-transf_bin = 'X'.
      objpack-head_start = 1.
      objpack-head_num = 1.
      objpack-body_start = 1.
      objpack-body_num = tab_lines.
      objpack-doc_type = .XLS
      APPEND objpack.
    Regards
    vijay

  • How to send ALV report Output through mail in background !

    Hi ,
    I had an ALV Report. I want to send this report output to patricular email id every day ! Presenty i do this manually. I run the report and send the output to the particular email address. Now i want to schecule the report daily in background and the out put of the report should be mailed to particular email ids in background itself. How can i do this ?
    Is there and method or setting through which we can do this ?
    Regards

    Hi Nau,
    For this requirement you will have to write another program.
    This program will convert the spool requests into PDF document and sends an email  to the recipients that you specify.
    These are the threads which are already posted in The SDN.
    *http://wiki.sdn.sap.com/wiki/display/Snippets/Converts+spool+request+into+PDF+document+and+emails*
    *<a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="353650"></a>*
    *<a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="902985"></a>*
    You need to use the Function module :
    -- Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    I will provide you with the code to get this functionality.
    *&      Form  SEND_EMAIL
    form SEND_EMAIL .
    DATA:   t_mailpack   TYPE sopcklsti1 OCCURS 0 WITH HEADER LINE,
              t_mailhead   TYPE solisti1   OCCURS 0 WITH HEADER LINE,
              t_mailbin    TYPE solisti1   OCCURS 0 WITH HEADER LINE,
              t_mailtxt    TYPE solisti1   OCCURS 0 WITH HEADER LINE,
              t_mailrec    TYPE somlreci1  OCCURS 0 WITH HEADER LINE.
      DATA: wa_maildata    TYPE sodocchgi1,
            l_filename(50) TYPE c,
            l_fldname(30)  TYPE c,
            l_fldval(100)  TYPE c,
            l_lines        TYPE i,
            l_text         TYPE text128 .
      DATA: w_email_subrc  TYPE i.
      DATA: w_ship like vbfa-vbeln.
      CLEAR: wa_maildata,
             t_mailtxt,
             t_mailbin,
             t_mailpack,
             t_mailhead,
             t_mailrec.
      REFRESH: t_mailtxt,
               t_mailbin,
               t_mailpack,
               t_mailhead,
               t_mailrec.
    *-- Fill output file
    *- Fill header
      CLEAR: t_mailbin.
    *  t_mailbin[] = pdf_tab[].
      t_mailbin[] = it_att[].     "Uthaman
    *This line is added to get the shipment no in Subject Line
    SELECT SINGLE * FROM vbfa WHERE vbelv EQ nast-objky
                                AND vbtyp_v EQ c_vbtyp_v_j
                                AND vbtyp_n EQ c_vbtyp_n_8.
    w_ship = vbfa-vbeln.
    shift w_ship left deleting leading '0'.
    *-- File name
    if nast-kschl EQ 'ZFPL'.
      CLEAR l_filename.
      CONCATENATE 'Packing List -'
                  sy-datum+4(2) sy-datum+6(2) sy-datum(4) '.PDF' INTO l_filename.
    *-- Creation of the document to be sent File Name
      wa_maildata-obj_name = 'Packing List'.
    *-- Mail Subject
      CONCATENATE l_filename '-' 'Shipment No -' w_ship INTO wa_maildata-obj_descr SEPARATED BY space.
    *-- Mail Contents
      t_mailtxt-line = 'Packing List'.
      APPEND t_mailtxt.
    ENDIF.
    if nast-kschl EQ 'ZFBA'.
      CLEAR l_filename.
      CONCATENATE 'Booking Advice -'
                  sy-datum+4(2) sy-datum+6(2) sy-datum(4) '.PDF'
                  INTO l_filename.
    *-- Creation of the document to be sent File Name
      wa_maildata-obj_name = 'Booking Advice'.
    *-- Mail Subject
      CONCATENATE l_filename '-' 'Shipment No -' w_ship INTO wa_maildata-obj_descr SEPARATED BY space.
    *-- Mail Contents
      t_mailtxt-line = 'Packing List'.
      APPEND t_mailtxt.
    ENDIF.
    *-- Prepare Packing List
    *-- Write Packing List (Main Subject)
      CLEAR: l_lines, t_mailpack.
      DESCRIBE TABLE t_mailtxt LINES l_lines.
    *  READ TABLE t_mailtxt INDEX l_lines.
      t_mailpack-doc_size = ( l_lines - 1 ) * 255 + STRLEN( t_mailtxt ).
    *  CLEAR t_mailpack-transf_bin.
      t_mailpack-transf_bin = ' '.
      t_mailpack-head_start = 1.
      t_mailpack-head_num = 0.
      t_mailpack-body_start = 1.
      t_mailpack-body_num = l_lines.
      t_mailpack-doc_type = 'RAW'.
      APPEND t_mailpack.
      t_mailhead = l_filename.
      APPEND t_mailhead.
    *-- Write Packing List (Attachment)
      CLEAR: l_lines, t_mailpack.
      DESCRIBE TABLE pdf_tab[] LINES l_lines.
    *  READ TABLE pdf_tab INDEX l_lines.
      t_mailpack-doc_size = ( l_lines - 1 ) * 255 + STRLEN( t_mailbin ).
      t_mailpack-transf_bin = 'X'.
      t_mailpack-head_start = 1.
      t_mailpack-head_num = 1.
      t_mailpack-body_start = 1.
      t_mailpack-body_num = l_lines.
      t_mailpack-doc_type = 'PDF'.
      t_mailpack-obj_name = l_filename.
      t_mailpack-obj_descr = l_filename.
      t_mailpack-obj_langu = 'E'.
      APPEND t_mailpack.
    *-- Set recipients
    tables :  ztotcemail.
    SELECT SINGLE * FROM vbfa WHERE vbelv EQ nast-objky
                                AND vbtyp_v EQ c_vbtyp_v_j
                                AND vbtyp_n EQ c_vbtyp_n_8.
    CLEAR vttk.
    SELECT SINGLE * FROM vttk WHERE tknum EQ vbfa-vbeln.
    SELECT SINGLE * FROM ztotcemail WHERE tplst = vttk-tplst
                                      AND lifnr = vttk-tdlnr.
    IF SY-SUBRC EQ 0.
      t_mailrec-receiver = ztotcemail-smtp_addr. "'Here you will give the email address'.
      t_mailrec-rec_type  = 'U'.
      APPEND t_mailrec.
    ENDIF.
    **-- Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = wa_maildata
          put_in_outbox              = 'X'
    *      commit_work                = 'X'  " N-16
        TABLES
          packing_list               = t_mailpack
          object_header              = t_mailhead
          contents_bin               = t_mailbin[]
          contents_txt               = t_mailtxt[]
          receivers                  = t_mailrec
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      w_email_subrc = sy-subrc.
      IF sy-subrc EQ 0.
        MESSAGE s000(zotc) WITH 'Email output sent successfully'.
      ELSE.
        MESSAGE s000(zotc) WITH 'Can not send email output'.
      ENDIF.
    endform.                    " SEND_EMAIL
    Hope the above information will be helpful.
    Regards,
    Kittu

  • Problem to send text file to mail from ALV report

    Hi Friends,
    I have a problem in my ALV report with text file.  As per the requirment, when we execute the program then text attachment should go to the particual email.
    When i am using file type as XLS i am getting attachment with all 4 recoreds( input for 4 records) in mail. But all 4 records are coming in SAME ROW. It should come 4 records in 4 rows. when I use file type as TXT and separated by pipe symble in code, it is showing only one recored for same above input.
    When i use file type as XLS and click the attachment in email, it will triggire one popul with three options like SAVE, OPEN, CANCEL.
    But when i click on text file attachment, it is directly showing ony one recored.
    Please correct me on this.
    my code is
    PERFORM send_file_as_email_attachment
                                   tables i_message
                                          i_attach
                                    using v_email
                                          'User last log on details'
                                          'XLS'
                                          'User log on list'
                                 changing v_error
                                          v_reciever.
    FORM send_file_as_email_attachment tables pi_message
                                              pi_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: l_error    TYPE sy-subrc,
              l_reciever TYPE sy-subrc,
              l_mtitle LIKE sodocchgi1-obj_descr,
              l_email LIKE  somlreci1-receiver,
              l_format TYPE  so_obj_tp ,
              l_attdescription TYPE  so_obj_nam ,
              l_attfilename TYPE  so_obj_des ,
              l_sender_address LIKE  soextreci1-receiver,
              l_sender_address_type LIKE  soextreci1-adr_typ,
              l_receiver LIKE  sy-subrc.
      l_email   = p_email.
      l_mtitle = p_mtitle.
      l_format              = p_format.
      l_attdescription      = p_attdescription.
      l_attfilename         = p_filename.
      l_sender_address      = p_sender_address.
      l_sender_address_type = p_sender_addres_type.
    Fill the document data.
      v_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      v_doc_data-obj_langu = sy-langu.
      v_doc_data-obj_name  = 'SAPRPT'.
      v_doc_data-obj_descr = l_mtitle .
      v_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR v_doc_data.
      READ TABLE i_attach INDEX v_cnt.
      v_doc_data-doc_size =
         ( v_cnt - 1 ) * 255 + STRLEN( i_attach ).
      v_doc_data-obj_langu  = sy-langu.
      v_doc_data-obj_name   = 'SAPRPT'.
      v_doc_data-obj_descr  = l_mtitle.
      v_doc_data-sensitivty = 'F'.
      CLEAR i_attachment.
      REFRESH i_attachment.
      i_attachment[] = pi_attach[].
    Describe the body of the message
      CLEAR i_packing_list.
      REFRESH i_packing_list.
      i_packing_list-transf_bin = space.
      i_packing_list-head_start = 1.
      i_packing_list-head_num = 0.
      i_packing_list-body_start = 1.
      DESCRIBE TABLE i_message LINES i_packing_list-body_num.
      i_packing_list-doc_type = 'RAW'.
      APPEND i_packing_list.
    Create attachment notification
      i_packing_list-transf_bin = 'X'.
      i_packing_list-head_start = 1.
      i_packing_list-head_num   = 1.
      i_packing_list-body_start = 1.
      DESCRIBE TABLE i_attachment LINES i_packing_list-body_num.
      i_packing_list-doc_type   =  l_format.
      i_packing_list-obj_descr  =  l_attdescription.
      i_packing_list-obj_name   =  l_attfilename.
      i_packing_list-doc_size   =  i_packing_list-body_num * 255.
      APPEND i_packing_list.
    Add the recipients email address
      CLEAR i_receivers.
      REFRESH i_receivers.
      i_receivers-receiver = l_email.
      i_receivers-rec_type = 'U'.
      i_receivers-com_type = 'INT'.
      i_receivers-notif_del = 'X'.
      i_receivers-notif_ndel = 'X'.
      APPEND i_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = v_doc_data
                put_in_outbox              = 'X'
                sender_address             = l_sender_address
                sender_address_type        = l_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = v_sent_all
           TABLES
                packing_list               = i_packing_list
                contents_bin               = i_attachment[]
                contents_txt               = i_message
                receivers                  = i_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
      l_error = sy-subrc.

    Hi,
    declare the following constant in u r program and concatenate at the end of each and every record in your internal table.
    CONSTANTS : LV_CRLF TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.
    for eg.
    if u internal table has values like
    row1
    row2
    row3
    concatenate the 1st record lv_crlf into first record.
    conactenate second record lv_crlf into second record.
    concatenate third record lv_crlf into third record.
    now attach  the internal table to the FM which u use for sending email. Each and every row will come in new line. The LV_CRLF will hold nothing but a line feed character (#).
    Hope it will solve u r problem
    Regards,
    Rose.

  • Output of ALV report as attachment in email

    Dear all ,
    I would like to send output of ALV report as attachment in email.
    i already written code for this using FM SO_NEW_DOCUMENT_ATT_SEND_API1.
    I can able to send list output as HTM format. But I want to send ALV report output
    As a attachment. How can I do this….please explain…
    Thanks in advance…
    Regards
    Manohar

    Hello,
    U can sent like this.
    Check this report
    REPORT ZV_SEND_MAIL .
    TABLES: EKKO.
    PARAMETERS: P_EMAIL   TYPE SOMLRECI1-RECEIVER
                                      DEFAULT '[email protected]'.
    TYPES: BEGIN OF T_EKPO,
      EBELN TYPE EKPO-EBELN,
      EBELP TYPE EKPO-EBELP,
      AEDAT TYPE EKPO-AEDAT,
      MATNR TYPE EKPO-MATNR,
    END OF T_EKPO.
    DATA: IT_EKPO TYPE STANDARD TABLE OF T_EKPO INITIAL SIZE 0,
          WA_EKPO TYPE T_EKPO.
    TYPES: BEGIN OF T_CHAREKPO,
      EBELN(10) TYPE C,
      EBELP(5)  TYPE C,
      AEDAT(8)  TYPE C,
      MATNR(18) TYPE C,
    END OF T_CHAREKPO.
    DATA: WA_CHAREKPO TYPE T_CHAREKPO.
    DATA:   IT_MESSAGE TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   IT_ATTACH TYPE STANDARD TABLE OF SOLISTI1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   T_PACKING_LIST LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,
            T_CONTENTS LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            T_RECEIVERS LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,
            T_ATTACHMENT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            T_OBJECT_HEADER LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,
            W_CNT TYPE I,
            W_SENT_ALL(1) TYPE C,
            W_DOC_DATA LIKE SODOCCHGI1,
            GD_ERROR    TYPE SY-SUBRC,
            GD_RECIEVER TYPE SY-SUBRC.
    *START_OF_SELECTION
    START-OF-SELECTION.
    *   Retrieve sample data from table ekpo
      PERFORM DATA_RETRIEVAL.
    *   Populate table with detaisl to be entered into .xls file
      PERFORM BUILD_XLS_DATA_TABLE.
    *END-OF-SELECTION
    END-OF-SELECTION.
    * Populate message body text
      PERFORM POPULATE_EMAIL_MESSAGE_BODY.
    * Send file by email as .xls speadsheet
      PERFORM SEND_FILE_AS_EMAIL_ATTACHMENT
                                   TABLES IT_MESSAGE
                                          IT_ATTACH
                                    USING P_EMAIL
                                          'Example .xls documnet attachment'
                                          'XLS'
                                          'filename'
                                 CHANGING GD_ERROR
                                          GD_RECIEVER.
    *   Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
    *&      Form  DATA_RETRIEVAL
    *       Retrieve data form EKPO table and populate itab it_ekko
    FORM DATA_RETRIEVAL.
      SELECT EBELN EBELP AEDAT MATNR
       UP TO 10 ROWS
        FROM EKPO
        INTO TABLE IT_EKPO.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_XLS_DATA_TABLE
    *       Build data table for .xls document
    FORM BUILD_XLS_DATA_TABLE.
      CONSTANTS: CON_CRET TYPE X VALUE '0D',  "OK for non Unicode
                 CON_TAB TYPE X VALUE '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    *constants:
    *    con_tab  type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
    *    con_cret type c value cl_abap_char_utilities=>CR_LF.
      CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
             INTO IT_ATTACH SEPARATED BY CON_TAB.
      CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
      APPEND  IT_ATTACH.
      LOOP AT IT_EKPO INTO WA_CHAREKPO.
        CONCATENATE WA_CHAREKPO-EBELN WA_CHAREKPO-EBELP
                    WA_CHAREKPO-AEDAT WA_CHAREKPO-MATNR
               INTO IT_ATTACH SEPARATED BY CON_TAB.
        CONCATENATE CON_CRET IT_ATTACH  INTO IT_ATTACH.
        APPEND  IT_ATTACH.
      ENDLOOP.
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *       Send email
    FORM SEND_FILE_AS_EMAIL_ATTACHMENT TABLES PIT_MESSAGE
                                              PIT_ATTACH
                                        USING P_EMAIL
                                              P_MTITLE
                                              P_FORMAT
                                              P_FILENAME
                                              P_ATTDESCRIPTION
                                              P_SENDER_ADDRESS
                                              P_SENDER_ADDRES_TYPE
                                     CHANGING P_ERROR
                                              P_RECIEVER.
      DATA: LD_ERROR    TYPE SY-SUBRC,
            LD_RECIEVER TYPE SY-SUBRC,
            LD_MTITLE LIKE SODOCCHGI1-OBJ_DESCR,
            LD_EMAIL LIKE  SOMLRECI1-RECEIVER,
            LD_FORMAT TYPE  SO_OBJ_TP ,
            LD_ATTDESCRIPTION TYPE  SO_OBJ_NAM ,
            LD_ATTFILENAME TYPE  SO_OBJ_DES ,
            LD_SENDER_ADDRESS LIKE  SOEXTRECI1-RECEIVER,
            LD_SENDER_ADDRESS_TYPE LIKE  SOEXTRECI1-ADR_TYP,
            LD_RECEIVER LIKE  SY-SUBRC.
      LD_EMAIL   = P_EMAIL.
      LD_MTITLE = P_MTITLE.
      LD_FORMAT              = P_FORMAT.
      LD_ATTDESCRIPTION      = P_ATTDESCRIPTION.
      LD_ATTFILENAME         = P_FILENAME.
      LD_SENDER_ADDRESS      = P_SENDER_ADDRESS.
      LD_SENDER_ADDRESS_TYPE = P_SENDER_ADDRES_TYPE.
    * Fill the document data.
      W_DOC_DATA-DOC_SIZE = 1.
    * Populate the subject/generic message attributes
      W_DOC_DATA-OBJ_LANGU = SY-LANGU.
      W_DOC_DATA-OBJ_NAME  = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR = LD_MTITLE .
      W_DOC_DATA-SENSITIVTY = 'F'.
    * Fill the document data and get size of attachment
      CLEAR W_DOC_DATA.
      READ TABLE IT_ATTACH INDEX W_CNT.
      W_DOC_DATA-DOC_SIZE =
         ( W_CNT - 1 ) * 255 + STRLEN( IT_ATTACH ).
      W_DOC_DATA-OBJ_LANGU  = SY-LANGU.
      W_DOC_DATA-OBJ_NAME   = 'SAPRPT'.
      W_DOC_DATA-OBJ_DESCR  = LD_MTITLE.
      W_DOC_DATA-SENSITIVTY = 'F'.
      CLEAR T_ATTACHMENT.
      REFRESH T_ATTACHMENT.
      T_ATTACHMENT[] = PIT_ATTACH[].
    * Describe the body of the message
      CLEAR T_PACKING_LIST.
      REFRESH T_PACKING_LIST.
      T_PACKING_LIST-TRANSF_BIN = SPACE.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM = 0.
      T_PACKING_LIST-BODY_START = 1.
      DESCRIBE TABLE IT_MESSAGE LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE = 'RAW'.
      APPEND T_PACKING_LIST.
    * Create attachment notification
      T_PACKING_LIST-TRANSF_BIN = 'X'.
      T_PACKING_LIST-HEAD_START = 1.
      T_PACKING_LIST-HEAD_NUM   = 1.
      T_PACKING_LIST-BODY_START = 1.
      DESCRIBE TABLE T_ATTACHMENT LINES T_PACKING_LIST-BODY_NUM.
      T_PACKING_LIST-DOC_TYPE   =  LD_FORMAT.
      T_PACKING_LIST-OBJ_DESCR  =  LD_ATTDESCRIPTION.
      T_PACKING_LIST-OBJ_NAME   =  LD_ATTFILENAME.
      T_PACKING_LIST-DOC_SIZE   =  T_PACKING_LIST-BODY_NUM * 255.
      APPEND T_PACKING_LIST.
    * Add the recipients email address
      CLEAR T_RECEIVERS.
      REFRESH T_RECEIVERS.
      T_RECEIVERS-RECEIVER = LD_EMAIL.
      T_RECEIVERS-REC_TYPE = 'U'.
      T_RECEIVERS-COM_TYPE = 'INT'.
      T_RECEIVERS-NOTIF_DEL = 'X'.
      T_RECEIVERS-NOTIF_NDEL = 'X'.
      APPEND T_RECEIVERS.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                DOCUMENT_DATA              = W_DOC_DATA
                PUT_IN_OUTBOX              = 'X'
                SENDER_ADDRESS             = LD_SENDER_ADDRESS
                SENDER_ADDRESS_TYPE        = LD_SENDER_ADDRESS_TYPE
                COMMIT_WORK                = 'X'
           IMPORTING
                SENT_TO_ALL                = W_SENT_ALL
           TABLES
                PACKING_LIST               = T_PACKING_LIST
                CONTENTS_BIN               = T_ATTACHMENT
                CONTENTS_TXT               = IT_MESSAGE
                RECEIVERS                  = T_RECEIVERS
           EXCEPTIONS
                TOO_MANY_RECEIVERS         = 1
                DOCUMENT_NOT_SENT          = 2
                DOCUMENT_TYPE_NOT_EXIST    = 3
                OPERATION_NO_AUTHORIZATION = 4
                PARAMETER_ERROR            = 5
                X_ERROR                    = 6
                ENQUEUE_ERROR              = 7
                OTHERS                     = 8.
    * Populate zerror return code
      LD_ERROR = SY-SUBRC.
    * Populate zreceiver return code
      LOOP AT T_RECEIVERS.
        LD_RECEIVER = T_RECEIVERS-RETRN_CODE.
      ENDLOOP.
    ENDFORM.
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
    *       Instructs mail send program for SAPCONNECT to send email.
    FORM INITIATE_MAIL_EXECUTE_PROGRAM.
      WAIT UP TO 2 SECONDS.
      SUBMIT RSCONN01 WITH MODE = 'INT'
                    WITH OUTPUT = 'X'
                    AND RETURN.
    ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
    *&      Form  POPULATE_EMAIL_MESSAGE_BODY
    *        Populate message body text
    FORM POPULATE_EMAIL_MESSAGE_BODY.
      REFRESH IT_MESSAGE.
      IT_MESSAGE = 'Please find attached a list test ekpo records'.
      APPEND IT_MESSAGE.
    ENDFORM.                    " POPULATE_EMAIL_MESSAGE_BODY
    If useful reward.
    Vasanth

  • Problem in Auto Mail of ALV Report :  Urgent

    Hello All ,
    I have created one ALV Report contain 240 Columns . This report is need to schedule for auto mail in HTML Format.
    My Problem is when I am sending this report manually the html output displays all the columns in the mail attachment.  While it is scheduled thro' SM36 in background mode the HTML format displays only restricted columns (say upto 132 columns)
    Also, we have tried to create new page format  X_65_512/2 to accomodate the output.  However this option did not work.
    Any solution to resolve the same is most welcome !
    Regards
    Swati Namdeo

    Hi
       This problem was not resolved. I tried few things but not good. So what we did we created a few profile like MM/SD/FICA and we executed report based on profile and sent them only the column relevant to them.
    Regards,
    Atul Joshi

  • Send ALV report as email attachment but in background scheduling mode

    Hi All,
           I have ALV report which runs fine in  the foreground.
    But i need to display it in the spool that is by scheduling in the background.
    can i send an excel attachement as e-mail in the background scheduling?  my report contains
    10 columns and i need them in proper format on excel sheet attachment? plz help me out?if possible
    give me abap code..

    HI,
    Use the below link
    Sending Mail to the schedular of Background Job
    Thanks

  • Sending ALV report(As a attachment ) through EMail

    Dear Friends,
    Could anyone please help me to solve this problem.
    I need to send ALV report <b>as an attachment</b> to External mail-id as well as SAP USER ID..The user wants to schedule this ABAP program in background, at the end the final output should be send to his ID. I facing problem to locate correct Functional Module....
    I would like to thank, if anyone give some idea on this issue also if possible a sample code.
    Thanks in advance
    With Reg
    Babu

    HI Kamal Babu
    After sending your ABAP List to the spool request (SP01), you can use the SAP standard spool PDF conversion program.
    RSTXPDFT4 - This report program converts ABAP List to PDF files.
    Or Just try this sample code:
    After running the background jobs, send the spool to the SAP users Office Mail Box.
    REPORT ZMAILSPOOL.
    INCLUDE LBTCHDEF.
    Include the Business Object Repository object
    INCLUDE <CNTN01>.
    DATA ABAPNM LIKE SY-REPID.
    DATA BEGIN OF LOCAL_JOB.
    INCLUDE STRUCTURE TBTCJOB.
    DATA END OF LOCAL_JOB.
    DATA BEGIN OF LOCAL_STEP_TBL OCCURS 10.
    INCLUDE STRUCTURE TBTCSTEP.
    DATA END OF LOCAL_STEP_TBL.
    Data declarations for the mail recipient
    DATA RECIPIENT TYPE SWC_OBJECT.
    DATA RECIPIENT_OBJ LIKE SWOTOBJID.
    SWC_CONTAINER CONTAINER.
    Data declarations for the background job
    PARAMETERS ABAPNAME(20) DEFAULT 'ZTEST1'.
    PARAMETERS EMPFNAME LIKE SY-UNAME DEFAULT SY-UNAME.
    ABAPNM = ABAPNAME.
    LOCAL_JOB-JOBNAME = ABAPNAME.
    Generate recipient object (see report RSSOKIF1 for an example)
    1. Create the recipient:
    IF EMPFNAME <> SPACE.
    "** 1.1 Generate an object reference to a recipient object
    SWC_CREATE_OBJECT RECIPIENT 'RECIPIENT' SPACE.
    "** 1.2 Write the import parameters for method
    "** recipient.createaddress into the container
    "** and empty the container
    SWC_CLEAR_CONTAINER CONTAINER.
    "** Set address element (internal user 'JSMITH')
    SWC_SET_ELEMENT CONTAINER 'AddressString' EMPFNAME.
    "** Set address type (internal user)
    SWC_SET_ELEMENT CONTAINER 'TypeId' 'B'.
    "** 1.3 Call the method recipient.createaddress
    SWC_CALL_METHOD RECIPIENT 'CreateAddress' CONTAINER.
    "** Issue any error message generated by a method exception
    IF SY-SUBRC NE 0.
    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO.
    ENDIF.
    SWC_CALL_METHOD RECIPIENT 'Save' CONTAINER.
    SWC_OBJECT_TO_PERSISTENT RECIPIENT RECIPIENT_OBJ.
    ENDIF.
    Recipient has been generated and is ready for use in a
    background job
    CALL FUNCTION 'JOB_OPEN'
         exporting
         DELANFREP              = ' '
         JOBGROUP               = ' '
           jobname                = LOCAL_JOB-JOBNAME
         SDLSTRTDT              = NO_DATE
         SDLSTRTTM              = NO_TIME
         IMPORTING
           JOBCOUNT               = LOCAL_JOB-JOBCOUNT
         EXCEPTIONS
           CANT_CREATE_JOB        = 1
           INVALID_JOB_DATA       = 2
           JOBNAME_MISSING        = 3
           OTHERS                 = 4
       if sy-subrc <> 0.
          WRITE: / 'JOB_OPEN PROBLEM ', SY-SUBRC.
       ELSE.
          WRITE: / 'JOB OPEN SUCCESS',
                                      LOCAL_JOB-JOBNAME, LOCAL_JOB-JOBCOUNT.
       endif.
    CALL FUNCTION 'JOB_SUBMIT'
         exporting
         ARCPARAMS                         =
           authcknam                         = SY-UNAME
         COMMANDNAME                       = ' '
         OPERATINGSYSTEM                   = ' '
         EXTPGM_NAME                       = ' '
         EXTPGM_PARAM                      = ' '
         EXTPGM_SET_TRACE_ON               = ' '
         EXTPGM_STDERR_IN_JOBLOG           = 'X'
         EXTPGM_STDOUT_IN_JOBLOG           = 'X'
         EXTPGM_SYSTEM                     = ' '
         EXTPGM_RFCDEST                    = ' '
         EXTPGM_WAIT_FOR_TERMINATION       = 'X'
           jobcount                          = LOCAL_JOB-JOBCOUNT
           jobname                           = LOCAL_JOB-JOBNAME
         LANGUAGE                          = SY-LANGU
         PRIPARAMS                         = ' '
           REPORT                            = ABAPNM
         REPORT                            = 'ZTEST1'
         VARIANT                           = ' '
       IMPORTING
         STEP_NUMBER                       = LOCAL_JOB-STEPCOUNT
         EXCEPTIONS
           BAD_PRIPARAMS                     = 1
           BAD_XPGFLAGS                      = 2
           INVALID_JOBDATA                   = 3
           JOBNAME_MISSING                   = 4
           JOB_NOTEX                         = 5
           JOB_SUBMIT_FAILED                 = 6
           LOCK_FAILED                       = 7
           PROGRAM_MISSING                   = 8
           PROG_ABAP_AND_EXTPG_SET           = 9
           OTHERS                            = 10
       if sy-subrc <> 0.
          WRITE: / 'JOB_SUBMIT PROBLEM ', LOCAL_JOB-JOBCOUNT,
                   LOCAL_JOB-JOBNAME, ABAPNAME, SY-SUBRC.
       endif.
    IF EMPFNAME <> SPACE.
    CALL FUNCTION 'JOB_CLOSE'
      exporting
      AT_OPMODE                         = ' '
      AT_OPMODE_PERIODIC                = ' '
      CALENDAR_ID                       = ' '
      EVENT_ID                          = ' '
      EVENT_PARAM                       = ' '
      EVENT_PERIODIC                    = ' '
        jobcount                          = LOCAL_JOB-JOBCOUNT
        jobname                           = LOCAL_JOB-JOBNAME
      LASTSTRTDT                        = NO_DATE
      LASTSTRTTM                        = NO_TIME
      PRDDAYS                           = 0
      PRDHOURS                          = 0
      PRDMINS                           = 0
      PRDMONTHS                         = 0
      PRDWEEKS                          = 0
      PREDJOB_CHECKSTAT                 = ' '
      PRED_JOBCOUNT                     = ' '
      PRED_JOBNAME                      = ' '
      SDLSTRTDT                         = NO_DATE
      SDLSTRTTM                         = NO_TIME
      STARTDATE_RESTRICTION             = BTC_PROCESS_ALWAYS
        STRTIMMED                         = 'X'
      TARGETSYSTEM                      = ' '
      START_ON_WORKDAY_NOT_BEFORE       = SY-DATUM
      START_ON_WORKDAY_NR               = 0
      WORKDAY_COUNT_DIRECTION           = 0
        RECIPIENT_OBJ                     = RECIPIENT_OBJ
      TARGETSERVER                      = ' '
      DONT_RELEASE                      = ' '
    IMPORTING
      JOB_WAS_RELEASED                  = 'X'
      EXCEPTIONS
        CANT_START_IMMEDIATE              = 1
        INVALID_STARTDATE                 = 2
        JOBNAME_MISSING                   = 3
        JOB_CLOSE_FAILED                  = 4
        JOB_NOSTEPS                       = 5
        JOB_NOTEX                         = 6
        LOCK_FAILED                       = 7
        OTHERS                            = 8
    IF ( SY-SUBRC <> 0 ).
      WRITE: / 'Job_Close Problem:', ABAPNAME, SY-SUBRC.
    ELSE.
      WRITE: / 'Job_Close done'.
    ENDIF.
    ELSE. "no empfname
    ENDIF.
    Cheers,
    Vijay Raheja

  • Mailing ALV report OUTPUT

    Hi Experts,
    Can you give an example program on mailing ALV report output to any ID.
    Thanks in advance.
    Regards,
    Ram

    Hi ram
    Here i'm posting u sample code try to execute it. It will convert all the data in the related tables to excel format and transfer it to respective mail id
    *& Report  ZTESTMAIL                                                   *
    REPORT  ZTESTMAIL                               .
    tables: ekko.
    parameters: p_email type somlreci1-receiver default
    '[email protected]'.
    types: begin of t_ekpo,
    ebeln type ekpo-ebeln,
    ebelp type ekpo-ebelp,
    aedat type ekpo-aedat,
    matnr type ekpo-matnr,
    end of t_ekpo.
    data: it_ekpo type standard table of t_ekpo initial size 0,
    wa_ekpo type t_ekpo.
    types: begin of t_charekpo,
    ebeln(10) type c,
    ebelp(5) type c,
    aedat(8) type c,
    matnr(18) type c,
    end of t_charekpo.
    data: wa_charekpo type t_charekpo.
    data: it_message type standard table of solisti1 initial size 0
    with header line.
    data: it_attach type standard table of solisti1 initial size 0
    with header line.
    data: t_packing_list like sopcklsti1 occurs 0 with header line,
    t_contents like solisti1 occurs 0 with header line,
    t_receivers like somlreci1 occurs 0 with header line,
    t_attachment like solisti1 occurs 0 with header line,
    t_object_header like solisti1 occurs 0 with header line,
    w_cnt type i,
    w_sent_all(1) type c,
    w_doc_data like sodocchgi1,
    gd_error type sy-subrc,
    gd_reciever type sy-subrc.
    t_object_header = 'Text.xls'. append t_object_header.
    *START_OF_SELECTION
    start-of-selection.
    * Retrieve sample data from table ekpo
    perform data_retrieval.
    * Populate table with detaisl to be entered into .xls file
    perform build_xls_data_table.
    *END-OF-SELECTION
    end-of-selection.
    * Populate message body text
    perform populate_email_message_body.
    * Send file by email as .xls speadsheet
    perform send_file_as_email_attachment
    tables it_message
    it_attach
    using p_email
    'Example .xls documnet attachment'
    'XLS'
    'filename'
    changing gd_error
    gd_reciever.
    * Instructs mail send program for SAPCONNECT to send email(rsconn01)
    perform initiate_mail_execute_program.
    *& Form DATA_RETRIEVAL
    * Retrieve data form EKPO table and populate itab it_ekko
    form data_retrieval.
    select ebeln ebelp aedat matnr
    up to 10 rows
    from ekpo
    into table it_ekpo.
    endform. " DATA_RETRIEVAL
    *& Form BUILD_XLS_DATA_TABLE
    * Build data table for .xls document
    form build_xls_data_table.
    *CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
    *con_tab TYPE x VALUE '09'. "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    constants:
    con_tab type c value cl_abap_char_utilities=>horizontal_tab,
    con_cret type c value cl_abap_char_utilities=>cr_lf.
    concatenate 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
    into it_attach separated by con_tab.
    concatenate con_cret it_attach into it_attach.
    append it_attach.
    loop at it_ekpo into wa_charekpo.
    concatenate wa_charekpo-ebeln wa_charekpo-ebelp
    wa_charekpo-aedat wa_charekpo-matnr
    into it_attach separated by con_tab.
    concatenate con_cret it_attach into it_attach.
    append it_attach.
    endloop.
    endform. " BUILD_XLS_DATA_TABLE
    *& Form SEND_FILE_AS_EMAIL_ATTACHMENT
    * Send email
    form send_file_as_email_attachment tables pit_message
    pit_attach
    using p_email
    p_mtitle
    p_format
    p_filename
    p_attdescription
    p_sender_address
    p_sender_addres_type
    changing p_error
    p_reciever.
    data: ld_error type sy-subrc,
    ld_reciever type sy-subrc,
    ld_mtitle like sodocchgi1-obj_descr,
    ld_email like somlreci1-receiver,
    ld_format type so_obj_tp ,
    ld_attdescription type so_obj_nam ,
    ld_attfilename type so_obj_des ,
    ld_sender_address like soextreci1-receiver,
    ld_sender_address_type like soextreci1-adr_typ,
    ld_receiver like sy-subrc.
    ld_email = p_email.
    ld_mtitle = p_mtitle.
    ld_format = p_format.
    ld_attdescription = p_attdescription.
    ld_attfilename = p_filename.
    ld_sender_address = p_sender_address.
    ld_sender_address_type = p_sender_addres_type.
    * Fill the document data.
    w_doc_data-doc_size = 1.
    * Populate the subject/generic message attributes
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle .
    w_doc_data-sensitivty = 'F'.
    * Fill the document data and get size of attachment
    clear w_doc_data.
    read table it_attach index w_cnt.
    w_doc_data-doc_size =
    ( w_cnt - 1 ) * 255 + strlen( it_attach ).
    w_doc_data-obj_langu = sy-langu.
    w_doc_data-obj_name = 'SAPRPT'.
    w_doc_data-obj_descr = ld_mtitle.
    w_doc_data-sensitivty = 'F'.
    clear t_attachment.
    refresh t_attachment.
    t_attachment[] = pit_attach[].
    * Describe the body of the message
    clear t_packing_list.
    refresh t_packing_list.
    t_packing_list-transf_bin = space.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 0.
    t_packing_list-body_start = 1.
    describe table it_message lines t_packing_list-body_num.
    t_packing_list-doc_type = 'RAW'.
    append t_packing_list.
    * Create attachment notification
    t_packing_list-transf_bin = 'X'.
    t_packing_list-head_start = 1.
    t_packing_list-head_num = 1.
    t_packing_list-body_start = 1.
    describe table t_attachment lines t_packing_list-body_num.
    t_packing_list-doc_type = ld_format.
    t_packing_list-obj_descr = ld_attdescription.
    t_packing_list-obj_name = ld_attfilename.
    t_packing_list-doc_size = t_packing_list-body_num * 255.
    append t_packing_list.
    * Add the recipients email address
    clear t_receivers.
    refresh t_receivers.
    t_receivers-receiver = ld_email.
    t_receivers-rec_type = 'U'.
    t_receivers-com_type = 'INT'.
    t_receivers-notif_del = 'X'.
    t_receivers-notif_ndel = 'X'.
    append t_receivers.
    call function 'SO_DOCUMENT_SEND_API1'
    exporting
    document_data = w_doc_data
    put_in_outbox = 'X'
    sender_address = ld_sender_address
    sender_address_type = ld_sender_address_type
    commit_work = 'X'
    importing
    sent_to_all = w_sent_all
    tables
    object_header = t_object_header
    packing_list = t_packing_list
    contents_bin = t_attachment
    contents_txt = it_message
    receivers = t_receivers
    exceptions
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    others = 8.
    * Populate zerror return code
    ld_error = sy-subrc.
    * Populate zreceiver return code
    loop at t_receivers.
    ld_receiver = t_receivers-retrn_code.
    endloop.
    endform.
    *& Form INITIATE_MAIL_EXECUTE_PROGRAM
    * Instructs mail send program for SAPCONNECT to send email.
    form initiate_mail_execute_program.
    wait up to 2 seconds.
    submit rsconn01 with mode = 'INT'
    with output = 'X'
    and return.
    endform. " INITIATE_MAIL_EXECUTE_PROGRAM
    *& Form POPULATE_EMAIL_MESSAGE_BODY
    * Populate message body text
    form populate_email_message_body.
    refresh it_message.
    it_message = 'Please find attached a list test ekpo records'.
    append it_message.
    endform. " POPULATE_EMAIL_MESSAGE_BODY
    *PARAMETERS: psubject(40) type c default 'Testing',
    *p_email(40) type c default '[email protected]'. "use ur email id
    *data: it_packing_list like sopcklsti1 occurs 0 with header line,
    *it_contents like solisti1 occurs 0 with header line,
    *it_receivers like somlreci1 occurs 0 with header line,
    *it_attachment like solisti1 occurs 0 with header line,
    *gd_cnt type i,
    *gd_sent_all(1) type c,
    *gd_doc_data like sodocchgi1,
    *gd_error type sy-subrc.
    *data: it_message type standard table of SOLISTI1 initial size 0
    *with header line.
    **START-OF-SELECTION.
    *START-OF-SELECTION.
    *Perform populate_message_table.
    **Send email message, although is not sent from SAP until mail send
    **program has been executed(rsconn01)
    *PERFORM send_email_message.
    **Instructs mail send program for SAPCONNECT to send email(rsconn01)
    *perform initiate_mail_execute_program.
    **& Form POPULATE_MESSAGE_TABLE
    ** Adds text to email text table
    *form populate_message_table.
    *Append 'Line1' to it_message.
    *Append 'Line2' to it_message.
    *Append 'Line3' to it_message.
    *Append 'Test- 1' to it_message.
    *endform. " POPULATE_MESSAGE_TABLE
    **& Form SEND_EMAIL_MESSAGE
    ** Send email message
    *form send_email_message.
    ** Fill the document data.
    *gd_doc_data-doc_size = 1.
    ** DATA: TAB_LINES LIKE sy-tabix.
    ** DESCRIBE TABLE it_message LINES TAB_LINES.
    ** READ TABLE it_message INDEX TAB_LINES.
    ** gd_doc_data-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( it_message )
    ** Populate the subject/generic message attributes
    *gd_doc_data-obj_langu = sy-langu.
    *gd_doc_data-obj_name = 'SAPRPT'.
    *gd_doc_data-obj_descr = psubject.
    *gd_doc_data-sensitivty = 'F'.
    ** Describe the body of the message
    ** Information about structure of data tables
    *clear it_packing_list.
    *refresh it_packing_list.
    *it_packing_list-transf_bin = space.
    *it_packing_list-head_start = 1.
    *it_packing_list-head_num = 0.
    *it_packing_list-body_start = 1.
    *describe table it_message lines it_packing_list-body_num.
    *it_packing_list-doc_type = 'RAW'.
    *append it_packing_list.
    ** Add the recipients email address
    *clear it_receivers.
    *refresh it_receivers.
    *it_receivers-receiver = p_email.
    *it_receivers-rec_type = 'U'.
    ** it_receivers-com_type = 'INT'.
    ** it_receivers-notif_del = 'X'.
    ** it_receivers-notif_ndel = 'X'.
    *append it_receivers.
    ** Call the FM to post the message to SAPMAIL
    *call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    *exporting
    *document_data = gd_doc_data
    *put_in_outbox = 'X'
    *importing
    *sent_to_all = gd_sent_all
    *tables
    *packing_list = it_packing_list
    *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.
    ** Store function module return code
    *gd_error = sy-subrc.
    ** Get it_receivers return code
    *loop at it_receivers.
    *endloop.
    *endform. " SEND_EMAIL_MESSAGE
    **& Form INITIATE_MAIL_EXECUTE_PROGRAM
    ** Instructs mail send program for SAPCONNECT to send email.
    *form initiate_mail_execute_program.
    *wait up to 2 seconds.
    *if gd_error eq 0.
    *submit rsconn01 with mode = 'INT'
    *with output = 'X'
    *and return.
    *endif.
    *endform. " INITIATE_MAIL_EXECUTE_PROGRAM
    Rewards if helpfull
    Regards
    Pavan

  • Cant send an e-mail in ALV report for background executaion

    Hello friends,
    I am displaying ALV report using container.
    Now when i run this report in background, an e-mail should be go with an EXCEL attachment of report.
    I am  able to send e-mail and attachment in foreground .
    I am also able to run alv report in background.
    now, only problem is that i am am not able to send e-mail in background.
    any sujjetions ?
    Points will rewarded if little bit useful.
    Regards,
    nimesh
    if  cl_gui_alv_grid=>offline( ) is initial.
    Create custom container
      CREATE OBJECT g_r_cust_container
        EXPORTING
          container_name = gv_ctrl_custom.
    Create TOP-Document
      CREATE OBJECT g_r_dd_document
        EXPORTING
          style = 'ALV_GRID'.
    Create Splitter for custom_container
      CREATE OBJECT g_r_splitter
        EXPORTING
          parent  = g_r_cust_container
          rows    = 2
          columns = 1.
    Split the grid in two parts- top and grid
      CALL METHOD g_r_splitter->get_container
        EXPORTING
          row       = 1
          column    = 1
        RECEIVING
          container = g_r_parent_top.
      CALL METHOD g_r_splitter->get_container
        EXPORTING
          row       = 2
          column    = 1
        RECEIVING
          container = g_r_parent_grid.
    Set height for g_parent_html
      CALL METHOD g_r_splitter->set_row_height
        EXPORTING
          id     = 1
          height = 1.
    Create grid object
      CREATE OBJECT g_r_alvgrid
        EXPORTING
          i_parent = g_r_parent_grid. "g_r_cust_container.
    else .
    Create grid object
    CREATE OBJECT g_r_alvgrid
        EXPORTING
          i_parent = or_doc. "g_r_cust_container.
    endif .
    Create object handler object (of type local class)
      CREATE OBJECT g_r_handler.
      SET HANDLER g_r_handler->top_of_page FOR g_r_alvgrid.
      SET HANDLER g_r_handler->print_top_of_page FOR g_r_alvgrid.
      w_disvariant-report  = sy-repid.
      w_disvariant-variant = p_vari.
      CALL METHOD g_r_alvgrid->set_table_for_first_display
        EXPORTING
          i_structure_name = 'ysds_sox_price_change'
          is_layout        = w_layout
          is_variant       = w_disvariant
          i_save           = yc_chara
        CHANGING
          it_outtab        = t_st_result
          it_fieldcatalog  = t_fieldcat[]
          it_sort          = t_sortinfo[].
      CALL METHOD g_r_dd_document->initialize_document
        EXPORTING
          background_color = cl_dd_area=>col_textarea.

    no i am using container for ALV.
    In above code i have mantioned If.......ELSE.....Condition.
    which give me allow to run ALV in background mode but my problem is that  i am not able to send e-mail with attachment in background mode.
    DATA : or_doc  type ref to cl_gui_docking_container .
    My report is working fine in foreground but not able to send email in background.
    so anybody can solve it?

  • Automatically send mail from ALV reports

    hi experts,
        I have created an ALV report for overtime calculation.The report will be generated on weekly basis in the background and will display calculated  overtime worked by employees in the previous week. I want the Report to run background and send the report in the HR dept concened officer in excel format automatically on weekly basis for his approval.
    how do i go about.
    regards,
    aero

    hi,
    <b>1</b>. u can prepare the output in an internal table ITAB.
    <b>2</b>. and then u can fill mail content with the help of ITAB data
    <b>3</b>. and then call function <b>'SO_NEW_DOCUMENT_SEND_API1'</b> if u have no attachement to be sent, but only normal mail with content in it.
    The sample code is below.
    FORM header_of_mail.
      CLEAR g_s_object_content.
      REFRESH g_t_object_content.
    Get an empty line
      MOVE space TO g_s_object_content+0(81).
      APPEND g_s_object_content TO g_t_object_content.
    Print partner number and description
      CLEAR g_s_object_content.
      MOVE text-t13 TO g_s_object_content.  " WMS
      MOVE sy-uline TO g_s_object_content+15(1).
      MOVE g_f_wms_descr TO g_s_object_content+30.
      APPEND g_s_object_content TO g_t_object_content.
    Print Division for which the mail is meant for
      CLEAR g_s_object_content.
      MOVE text-t14 TO g_s_object_content.  " Material with division
      MOVE sy-uline TO g_s_object_content+25(1).
      MOVE g_t_y16m_rcp_par-spart TO g_s_object_content+30.
      APPEND g_s_object_content TO g_t_object_content.
    Get an empty line
      CLEAR g_s_object_content.
      MOVE space TO g_s_object_content+0(81).
      APPEND g_s_object_content TO g_t_object_content.
    Get a dotted line.
      CLEAR g_s_object_content.
      MOVE sy-uline TO g_s_object_content+0(120).
      APPEND g_s_object_content TO g_t_object_content.
    Print column headings
      CLEAR g_s_object_content.
      MOVE text-t04 TO g_s_object_content+3(16). " IDoc number
      MOVE text-t05 TO g_s_object_content+27(18). " Material number
      MOVE text-t07 TO g_s_object_content+63(6). " Length
      MOVE text-t08 TO g_s_object_content+81(5). " Width
      MOVE text-t09 TO g_s_object_content+97(6). " Height
      MOVE text-t10 TO g_s_object_content+109(11). " Brut Weight
      APPEND g_s_object_content TO g_t_object_content.
    Get a dotted line.
      CLEAR g_s_object_content.
      MOVE sy-uline TO g_s_object_content+0(120).
      APPEND g_s_object_content TO g_t_object_content.
    ENDFORM.                    " HEADER_OF_MAIL
    FORM body_of_mail.
    Print contents such as IDoc number, material no. and measures
      LOOP AT g_t_mail_for_division.
        CLEAR g_s_object_content.
        MOVE g_t_mail_for_division-docnum TO g_s_object_content+3(16).
        MOVE g_t_mail_for_division-matnr TO g_s_object_content+27(18).
        MOVE text-t11 TO g_s_object_content+49(4).
        MOVE g_t_mail_for_division-laeng_from_sap TO
                                            g_s_object_content+57(13).
        MOVE g_t_mail_for_division-breit_from_sap TO
                                            g_s_object_content+74(13).
        MOVE g_t_mail_for_division-hoehe_from_sap TO
                                            g_s_object_content+91(13).
        MOVE g_t_mail_for_division-brgew_from_sap TO
                                            g_s_object_content+108(13).
        APPEND g_s_object_content TO g_t_object_content.
        CLEAR g_s_object_content.
        MOVE text-t12 TO g_s_object_content+49(4).
        MOVE g_t_mail_for_division-laeng_from_idoc TO
                                            g_s_object_content+57(13).
        MOVE g_t_mail_for_division-breit_from_idoc TO
                                            g_s_object_content+74(13).
        MOVE g_t_mail_for_division-hoehe_from_idoc TO
                                            g_s_object_content+91(13).
        MOVE g_t_mail_for_division-brgew_from_idoc TO
                                            g_s_object_content+108(13).
        APPEND g_s_object_content TO g_t_object_content.
      ENDLOOP.
    ENDFORM.                    " BODY_OF_MAIL
    FORM send_mail USING  p_y16m_rcp_par STRUCTURE y16m_rcp_par.
    Have a subject for the mail
      g_s_document_data-obj_name = text-t02.
      g_s_document_data-obj_descr = text-t03.
    Fill receiver information
      CLEAR g_s_receivers.
      REFRESH g_t_receivers.
      g_s_receivers-rec_type = p_y16m_rcp_par-rec_type.
      g_s_receivers-receiver = p_y16m_rcp_par-rec_id.
      g_s_receivers-express = 'X'.
      APPEND g_s_receivers TO g_t_receivers.
    Call function to send mail
      CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = g_s_document_data
               document_type              = 'RAW'
             PUT_IN_OUTBOX              = ' '
        IMPORTING
             SENT_TO_ALL                =
             NEW_OBJECT_ID              =
           TABLES
             OBJECT_HEADER              =
               object_content             =  g_t_object_content
             CONTENTS_HEX               =
             OBJECT_PARA                =
             OBJECT_PARB                =
                receivers                  = g_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.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " SEND_MAIL
    hope this helps.
    pls reward if useful...
    Message was edited by:
            pawan ambadas

  • Display Material |Attachment File in ALV report

    Dear All,
    I have to make ALV report for mutliple material attachment file.I want to display material wise attachment where user can see in report. We can see attachment list in Service For Object button in MM03 tcode for single material. And i also i do not want attachement list on tool bar where like MM03 is dispalying.
    I need ALV report for materialcodewise image/attachment file like,
    MaterialCode    File
    A101                any filename
    B101                 any filename
    So user can click on file base on material, then file will open and he can see image/attachment.
    Please guide me for above mentioned query.
    Regards,
    Shivam.

    Dear Shivam,
    You can have multiple attachments for a sinlge material. You need to consider that in your report.
    for getting the list of attachments using the static method CL_BINARY_RELATION=>READ_LINKS.
      DATA: lw_BOR TYPE sibflporb.
      DATA: lt_rel TYPE OBL_T_RELT,
                 lw_rel type OBL_S_RELT.
      DATA: lt_links TYPE obl_t_link,
                 lw_links type OBL_S_LINK.
      DATA: lo_root TYPE REF TO cx_root.
      lw_bor-instid = <Materail no.>   "<------- Materail No.
      lw_bor-typeid = 'BUS1001006'.
      lw_bor-catid  = 'BO'.
      lw_rel-sign = 'I'.
      lw_rel-option = 'EQ'.
      lw_rel-low = 'ATTA'.           "<----------Attachments
      APPEND lw_relt TO lt_rel.
      TRY.
          CALL METHOD cl_binary_relation=>read_links
            EXPORTING
              is_object           = lw_bor
              it_relation_options = lt_rel
            IMPORTING
              et_links            = lt_links.
        CATCH cx_root INTO lo_root.
      ENDTRY.
    Once you get the list of attachment populate your output table using the same.
    you can use FM SO_OBJECT_READ to get details of attachment.
    Make the column with attachment as hotspot, so that ALV take action in sinlge user click.
    In the user-command of ALV write the code to open the attachment.
    you can use the FM SO_DOCUMENTS_MANAGER
    Hope this helps you.
    Regards,
    Sachinkumar Mehta

  • How to run 2 reports to send 1 PDF e-mail attachment instead of 2 e-mails.

    I used 9i Reports to create 2 reports in a PDF format. I run these reports from a 9i form using the web.show_document command. XML is used to send the 2 e-mails with the reports.
    Is there a way I can combine the running of the reports to make one PDF to created 1 e-mail attachment or run the reports at the same time and attach 2 PDF files to 1 e-mail.
    I have no problems running 1 report and sending 1 e-mail attacment!
    This is example of the XML used in creating the e-mail:
    - <destinations>
    - <foreach>
    - <file id="Test" name="REPORT_1.pdf" format="pdf" instance="XXXX">
    <include src="report" />
    </file>
    </foreach>
    - <!-- Send a mail with an attachment
    -->
    - <mail id="ex1" to="&DESNAME" from="&DESNAME" subject="&DESNAME;*;&p_postal_number: was submitted for
    approval on &p_postal_date">
    <body srcType="text">This is to notify you of a new submission that requires an approval before being
    sent to out. Please use the URL link below to review the information as soon as possible.
    https://xxxx.aaaa.sss.com:234/web_html/static.html AAAA Administrator</body>
    - <attach format="pdf" name="Report_1&.pdf" srcType="report">
    <include src="mainSection" />
    </attach>
    </mail>
    </destinations>

    You can use iText to combine two PDF files into one.

  • How to send the ALV report output in mail

    Dear all,
                        I have developed an ALV report.I need to send this output in the mail.Can anyone help me with the sample code of how to do this.

    Hi Ramya,
    Check the links below :
    http://wiki.sdn.sap.com/wiki/display/Snippets/Sending+Mail
    http://wiki.sdn.sap.com/wiki/display/Snippets/AbapEMAILProgram
    http://wiki.sdn.sap.com/wiki/display/ABAP/SendMessagetoExternalemailidandSAPUseridvia+ABAP
    They will explain you to send an email.
    Regards,
    Kittu

Maybe you are looking for

  • Lightroom vs photoshop color management in printing.

    lightshop gives me completely different results when printing even using the same exact profile info (let printer decide) and relative method. same image works well in photoshop but shows sky as purple (instead of blue) in lightroom. any ideas what i

  • RE: OM Custom Infotype F4 functionality

    Hello Everyone,                     I need to add the F4 functionality on input field and check condition in custom infotype. where should I look to find the any existing F4 functionality in any other infotypes in the system. and where should I put t

  • Using JDK1.4 with Weblogic 6.1

    Does ne1 know of any documents(Installion Procedure...) available on Using JDK1.4 with Weblogic 6.1 I need to upgrade from JDK 1.3 to 1.4 using Wlserver6.1 Thanks, Lloyd [att1.html]

  • HT4314 How do I redeem a game that as been gifted to me?

    How do I redeem a game that has been gifted to me?

  • Coldfusion MX7 error with file upload

    Hi all,         I am using coldfusion mx7 server. While upload an excel file with(97-2003) format, I am getting the following error:  Unable to construct record instance, the following exception occured: null I am getting this error when I enters som