cancel
Showing results for 
Search instead for 
Did you mean: 

How to send email using BCS interface with attachment as pdf?

Former Member
0 Kudos

Hi Experts,

I am trying to send email from my WD application using BCS interface.

I was able to send the email with attachment as XLS.

But when I am trying to send it as PDF attachment,the attachment is not opening.

Can you please advice me how to overcome that?

Thanks in advance.

Subhasis

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

answered

aaron_morden2
Contributor
0 Kudos

See below code:

* BCS data
  DATA  send_request       TYPE REF TO cl_bcs.
  DATA  text               TYPE bcsy_text.
  DATA  subject            TYPE so_obj_des.
  DATA  document           TYPE REF TO cl_document_bcs.
  DATA  recipient          TYPE REF TO if_recipient_bcs.
  DATA  bcs_exception      TYPE REF TO cx_bcs.
  DATA  sent_to_all        TYPE os_boolean.
  DATA  pdf_content        TYPE solix_tab.
  DATA  lp_pdf_size        TYPE so_obj_len.
  DATA  pdf                TYPE xstring.

* ---------- create persistent send request ----------------------
  send_request = cl_bcs=>create_persistent( ).

* ---------- add document ----------------------------------------
* get PDF xstring and convert it to BCS format
  lp_pdf_size = XSTRLEN( pdf ).

  pdf_content = cl_document_bcs=>xstring_to_solix(
      ip_xstring = pdf ).

 subject = 'Email Subject'.

  document = cl_document_bcs=>create_document(
        i_type    = 'PDF'
        i_hex     = pdf_content
        i_length  = lp_pdf_size
        i_subject = subject ).

* add document to send request
  send_request->set_document( document ).

* ---------- add recipient (e-mail address) ----------------------
  recipient = cl_cam_address_bcs=>create_internet_address(
      i_address_string = i_email ).

* add recipient to send request
  send_request->add_recipient( i_recipient = recipient ).

* ---------- send document ---------------------------------------
  sent_to_all = send_request->send(
      i_with_error_screen = 'X' ).

  IF sent_to_all = 'X'.
    MESSAGE i022(so).
  ENDIF.

  COMMIT WORK.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This doesn't really sound like a WDA question. Just because you are calling some ABAP logic from within WDA doesn't mean that it actually relates to WDA. Sending mail with BCS is something that is just normal ABAP and the question should be posted in the ABAP general forum, not the WDA. Incidentally I think you will have to support more details about how you are building and attaching your PDF document before anyone would be able to help you.