Skip to Content
author's profile photo
Former Member

abap spool to pdf as email

Hi Gurus

I have to send output of report as pdf attachment of the email.

I have used Fm CONVERT_ABAPSPOOLJOB_2_PDF to convet spool request to pdf format.

and SO_DOCUMENT_SEND_API1 Fm to send email. Its working Fine.

But Now i need to send email by using Methods,My code is as below

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.

DATA: it_pdf_output2 type SOLIX_TAB occurs 0.

DATA: BEGIN OF it_pdf_output OCCURS 0.


DATA: END OF it_pdf_output.


*it_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,

it_mess_att_wa TYPE solisti1,

gti_documents TYPE zsti_email_documents,

g_documents_wa TYPE LINE OF zsti_email_documents,

gti_recipients TYPE zsti_email_recipients,

g_recipients_wa TYPE LINE OF zsti_email_recipients,

gti_contents_hex TYPE solix_tab,

gti_contents_text TYPE soli_tab.



src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device


pdf_bytecount = gd_bytecount


pdf = it_pdf_output


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.

<b>it_pdf_output is to be converted into gti_contents_hex.</b>

LOOP AT it_pdf_output INTO mess_att_wa.

MOVE mess_att_wa-line TO contents_hex_wa-line.

APPEND contents_hex_wa TO gti_contents_hex.


g_documents_wa-type = 'RAW'.

g_documents_wa-subject = 'KUMAR TEST '.

g_documents_wa-content_hex = xcontent_hex.

APPEND g_documents_wa TO gti_documents.

DATA:email TYPE so_name.

email = ''.

g_recipients_wa-uname = 'KUMAR'.

g_recipients_wa-c_address = email.

APPEND g_recipients_wa TO gti_recipients.


  • -------- create persistent send request ------------------------

send_request = cl_bcs=>create_persistent( ).

APPEND 'hello world' TO text.

APPEND '20/09/2007' TO text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = text

i_length = '12'

i_subject = 'subject' ).

CALL METHOD document->add_attachment


i_attachment_type = 'PDF'

i_attachment_subject = gd_subject

<b>i_att_content_hex = gti_contents_hex.</b>

  • 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


i_sender = sender.

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

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

recipient = cl_cam_address_bcs=>create_internet_address( email ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient


i_recipient = recipient

i_express = 'X'.

  • set send immediately flag

send_request->set_send_immediately( 'X' ).

  • ---------- send document ----------------------------------

CALL METHOD send_request->send(


i_with_error_screen = 'X'


result = sent_to_all ).


  • -----------------------------------------------------------

  • exception handling

CATCH cx_bcs INTO bcs_exception.

WRITE: bcs_exception->error_type.



MY problem is:

Iam receiving 'hello world' and '20/09/2007' as a pdf file in mail.But the actual data

from CONVERT_ABAPSPOOLJOB_2_PDF (it_pdf_output) is not getting in the pdf file.

Iam receiving the email properly with pdf attached, but no data in pdf.

Can any one please help me,its very ugrent

The Bold line above is the problem here ,the data from Fm it_pdf_output is of type tline and the method takes data as HEX. How to convert ?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Posted on Sep 28, 2007 at 09:34 AM


    Refer to this link...

    Add comment
    10|10000 characters needed characters exceeded