Quantcast
Channel: SCN : All Content - ABAP Development
Viewing all articles
Browse latest Browse all 8332

send xml file as attachment

$
0
0

Hi,

 

    I'm using ABAP to send e-mail and xml & txt file as attachment ,  when I open the file I recieved in the email inbox I found xml file content has been truncated or the content of txt file is space. Then I send some other files, it's OK. I've used value 'BIN'  and  ' '  as parameter of "i_attachment_type " ,neither of them worked fine.

  

     I'm a newer in ABAP, any help will be appreciate.

 

     FYI, my source code:

 

*&---------------------------------------------------------------------*

*& Report  ZSENDMAILTEST

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

 

REPORT  ZSENDMAILTEST.

* This example shows how to send

*   - a simple text provided in an internal table of text lines

*   - and an attached MS word document provided in internal table

*   - to some internet email address.

*

* All activities done via facade CL_BCS!

 

DATA: send_request       TYPE REF TO cl_bcs.

DATA: text               TYPE bcsy_text.

data: hex_content        type solix_tab.

*DATA: hex_content       TYPE soli_tab.

DATA: document           TYPE REF TO cl_document_bcs.

DATA: sender             TYPE REF TO cl_sapuser_bcs.

DATA: recipient          TYPE REF TO if_recipient_bcs.

DATA: bcs_exception      type ref to cx_bcs.

data: sent_to_all        type os_boolean.

 

START-OF-SELECTION.

 

   PERFORM main.

 

 

*---------------------------------------------------------------------*

*       FORM main                                                     *

*---------------------------------------------------------------------*

FORM main.

 

   try.

*     -------- create persistent send request ------------------------

       send_request = cl_bcs=>create_persistent( ).

 

*     -------- create and set document with attachment ---------------

*     create document from internal table with text

       APPEND 'Hello world!' TO text.

       document = cl_document_bcs=>create_document(

                       i_type    = 'RAW'

                       i_text    = text

                       i_length  = '12'

                       i_subject = 'test created by BCS_EXAMPLE_2' ).

 

       DATA: file TYPE string.

 

       CALL FUNCTION 'FILE_GET_NAME'

        EXPORTING

          LOGICAL_FILENAME              = 'TEST-3'

          PARAMETER_1                    = '.txt'             "     change to '.xml' when sending xml file

        IMPORTING

          FILE_NAME                     = file

        EXCEPTIONS

          FILE_NOT_FOUND                = 1

          OTHERS                        = 2 .

       IF SY-SUBRC <> 0.

           write / 'cannot find phisical file name'.

       ENDIF.

 

      DATA : wa_bin type SOLIX.

*      DATA : wa_bin type SOLI.

       FIELD-SYMBOLS <hex_container> TYPE x.

*      FIELD-SYMBOLS <hex_container> TYPE c.

 

*      OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING UTF-8.

       OPEN DATASET file FOR INPUT IN BINARY MODE.

       DO.

         ASSIGN wa_bin TO <hex_container> CASTING.

         READ DATASET file INTO <hex_container>.

         IF sy-subrc = 0.

           append wa_bin to hex_content.

         ELSE.

           EXIT.

         ENDIF.

       ENDDO.

 

*     write: / wa_bin.

 

       CLOSE DATASET file.

 

*     add attachment to document

*     BCS expects document content here e.g. from document upload

*     binary_content = .

       CALL METHOD document->add_attachment

         EXPORTING

           i_attachment_type    = ''

           i_attachment_subject = 'test.txt'      "when sending xml file change to test.xml

           i_att_content_hex    = hex_content.

 

*     add document to send request

       CALL METHOD send_request->set_document( document ).

 

*     --------- set sender -------------------------------------------

*     note: this is necessary only if you want to set the sender

*           different from actual user (SY-UNAME). Otherwise sender is

*           set automatically with actual user.

 

       sender = cl_sapuser_bcs=>create( sy-uname ).

       CALL METHOD send_request->set_sender

         EXPORTING

           i_sender = sender.

 

*     --------- add recipient (e-mail address) -----------------------

*     create recipient - please replace e-mail address !!!

       recipient = cl_cam_address_bcs=>create_internet_address(

                                         'testrecipient@bwtest.com' ).

 

*     add recipient with its respective attributes to send request

       CALL METHOD send_request->add_recipient

         EXPORTING

           i_recipient = recipient

           i_express   = 'X'.

 

*     ---------- send document ---------------------------------------

       CALL METHOD send_request->send(

         EXPORTING

           i_with_error_screen = 'X'

         RECEIVING

           result              = sent_to_all ).

       if sent_to_all = 'X'.

         write text-003.

       endif.

 

       COMMIT WORK.

 

* -----------------------------------------------------------

* *                     exception handling

* -----------------------------------------------------------

* * replace this very rudimentary exception handling

* * with your own one !!!

* -----------------------------------------------------------

     catch cx_bcs into bcs_exception.

       write: 'Fehler aufgetreten.'(001).

       write: 'Fehlertyp:'(002), bcs_exception->error_type.

       exit.

 

   endtry.

 

ENDFORM.

 

--------------------------------------------------------------------------------------------------


content of test.xml


<?xml version="1.0"?>

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"

xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">

<Worksheet ss:Name="Tabelle1">

<Table>

<Row>

<Cell><Data ss:Type="String">CPDEMO</Data></Cell>

<Cell><Data ss:Type="String">20110711</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">CTVBC02</Data></Cell>

<Cell><Data ss:Type="String">20110602</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">CTVBC01</Data></Cell>

<Cell><Data ss:Type="String">20110628</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">CTVPUR01</Data></Cell>

<Cell><Data ss:Type="String">20110520</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">CTVCE01</Data></Cell>

<Cell><Data ss:Type="String">20110520</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">BWIT01</Data></Cell>

<Cell><Data ss:Type="String">20110603</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">ALEREMOTE</Data></Cell>

<Cell><Data ss:Type="String">20131213</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">BWIT02</Data></Cell>

<Cell><Data ss:Type="String">20110711</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">BEXATBOE</Data></Cell>

<Cell><Data ss:Type="String">20130701</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">DBA01</Data></Cell>

<Cell><Data ss:Type="String">20110621</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">DDIC</Data></Cell>

<Cell><Data ss:Type="String">20140108</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">SAP*</Data></Cell>

<Cell><Data ss:Type="String">20110419</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">SAPCPIC</Data></Cell>

<Cell><Data ss:Type="String">00000000</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">TMSADM</Data></Cell>

<Cell><Data ss:Type="String">20110401</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">CPADMIN</Data></Cell>

<Cell><Data ss:Type="String">20110616</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">SNDADMIN</Data></Cell>

<Cell><Data ss:Type="String">20130114</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">BWREMOTE</Data></Cell>

<Cell><Data ss:Type="String">00000000</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">17124</Data></Cell>

<Cell><Data ss:Type="String">20131216</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">F3228773</Data></Cell>

<Cell><Data ss:Type="String">20140108</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">SNDBWIT</Data></Cell>

<Cell><Data ss:Type="String">20140104</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">SAPBIMETA</Data></Cell>

<Cell><Data ss:Type="String">20111020</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">9041</Data></Cell>

<Cell><Data ss:Type="String">20130807</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">FSK001</Data></Cell>

<Cell><Data ss:Type="String">20130815</Data></Cell>

</Row>

<Row>

<Cell><Data ss:Type="String">F6969539</Data></Cell>

<Cell><Data ss:Type="String">20110801</Data></Cell>

</Row>

</Table>

</Worksheet>

</Workbook>


Viewing all articles
Browse latest Browse all 8332

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>