Quantcast
Channel: SCN : Unanswered Discussions - ABAP Development
Viewing all articles
Browse latest Browse all 8768

Send PDF attachment from AL11 as Mail

$
0
0

Hi Experts,

 

I have already checked the forum before posting this message.

 

REQUIREMENT: .pdf file available in AL11. Have to send it as attachment.

 

I am pasting my piece of code as its not working:

DATA : lo_document  TYPE REF TO cl_document_bcs,

        lo_bcs       TYPE REF TO cl_bcs,

        gr_recipient TYPE REF TO if_recipient_bcs,

        lv_subject   TYPE so_obj_des,

        lv_email     TYPE adr6-smtp_addr,

        lt_contents  TYPE soli_tab,

        lv_result    TYPE os_boolean,

        ls_contents  LIKE LINE OF lt_contents,

        pdf_file     TYPE solix_tab,

        gt_pdfout TYPE solix_tab,

        gs_pdfout TYPE solix.

 

DATA p_file(2000).

 

CLEAR ls_contents.

REFRESH lt_contents.

ls_contents-line = 'Vendor testing.'.

APPEND ls_contents TO lt_contents.

 

*-Create the document with contents

CREATE OBJECT lo_document.

lo_document = cl_document_bcs=>create_document(

     i_type       = 'RAW'

     i_subject    = 'Test Mail Subject Line'

     i_length     = '1000'

     i_language   = sy-langu

     i_importance = '1'

     i_text       = lt_contents ).

 

p_file = '/sap/usr/test/vendor.pdf'.

OPEN DATASET p_file FOR INPUT IN BINARY MODE.

DO.

   READ DATASET p_file INTO gs_pdfout-line.

   IF sy-subrc NE 0.

     APPEND gs_pdfout TO gt_pdfout.

     EXIT.

   ENDIF.

   APPEND gs_pdfout TO gt_pdfout.

ENDDO.

 

CLOSE DATASET p_file.

 

*-Attach the file, the attachment type should be bin to accept any

*-kind of attachment

CALL METHOD lo_document->add_attachment

   EXPORTING

     i_attachment_type    = 'PDF'

     i_attachment_subject = 'test.pdf'

     i_att_content_hex    = gt_pdfout.

 

*-Creating persistent object will allow you to set the document in the

*-mail

lo_bcs = cl_bcs=>create_persistent( ).

CALL METHOD lo_bcs->set_document( lo_document ).

 

*-Email as given in the selection screen.

lv_email = <email id>

gr_recipient = cl_cam_address_bcs=>create_internet_address( lv_email ).

 

*-Add recipient to send request

CALL METHOD lo_bcs->add_recipient

   EXPORTING

     i_recipient = gr_recipient

     i_express   = 'X'.

 

*-Send the mail

CALL METHOD lo_bcs->send(

   EXPORTING

     i_with_error_screen = 'X'

   RECEIVING

     result              = lv_result ).


 

 

Please suggest alternate solutions (if available)

 

Regards


Viewing all articles
Browse latest Browse all 8768

Trending Articles



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