Skip to Content
0
Former Member
Nov 20, 2008 at 12:16 PM

Problem in sending PDF as attachment in E-Mail

21 Views

Hi All,

I have developed a program to convert the spool request as PDF file and sending it to an E-Mail address.

But when i'm opening the file, I'm getting an error in Adobe Reader.

I'm attaching the code here.

Please give me the suggestions.

REPORT ZSEND_MAIL_SAMPLE.

parameters: P_SPOOL type ITCPP-TDSPOOLID..

tables: NAST.

types: begin of ty_pdf.

include structure tline.

types: end of ty_pdf.

DATA: v_spool_id like tsp01-rqident,

v_numbytes type i,

v_pdfspoolid like tsp01-rqident,

v_jobname like tbtcjob-jobname,

v_jobcount like tbtcjob-jobcount.

DATA: V_SPOOL_DEL TYPE TSP01_SP0R-RQID_CHAR.

data: it_pdf type standard table of ty_pdf WITH HEADER LINE.

DATA: gd_spool_nr LIKE tsp01-rqident,

gd_destination LIKE rlgrap-filename,

gd_bytecount LIKE tst01-dsize,

v_buffer TYPE string.

DATA: gd_subject LIKE sodocchgi1-obj_descr,

it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,

it_attachment 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,

gd_recsize TYPE i.

DATA: v_email LIKE somlreci1-receiver,

p_sender LIKE somlreci1-receiver.

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 ,

V_sender_address LIKE soextreci1-receiver,

V_sender_address_type LIKE soextreci1-adr_typ,

ld_receiver LIKE sy-subrc.

data: it_packing_list like sopcklsti1 occurs 0 with header line,

t_contents like solisti1 occurs 0 with header line,

it_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,

v_sent_all(1) type c,

V_docu_data like sodocchgi1.

move P_SPOOL to v_spool_id.

call function 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = v_spool_id

no_dialog = ' ' " was space, now X

IMPORTING

pdf_bytecount = v_numbytes

pdf_spoolid = v_pdfspoolid

btc_jobname = v_jobname

btc_jobcount = v_jobcount

TABLES

pdf = IT_PDF

EXCEPTIONS

ERR_NO_OTF_SPOOLJOB = 1

ERR_NO_SPOOLJOB = 2

ERR_NO_PERMISSION = 3

ERR_CONV_NOT_POSSIBLE = 4

ERR_BAD_DSTDEVICE = 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.

refresh it_attachment.

clear it_attachment.

loop at IT_PDF.

move it_pdf to it_attachment.

APPEND it_attachment.

endloop.

  • Populate the subject/generic message attributes

v_docu_data-obj_langu = sy-langu.

v_docu_data-obj_name = 'PO IN PDF'.

CONCATENATE 'PURCHASE ORDER ' NAST-OBJKY 'SENT TO ' nast-parnr INTO v_docu_data-obj_descr.

v_docu_data-sensitivty = 'F'.

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_attachment LINES it_packing_list-body_num.

it_packing_list-doc_type = 'PDF'.

APPEND it_packing_list.

CLEAR it_receivers.

REFRESH it_receivers.

ld_email = 'jagan.m.kota at invista.com'.

it_receivers-receiver = ld_email.

it_receivers-rec_type = 'U'.

it_receivers-com_type = 'INT'.

APPEND it_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = V_docu_data

put_in_outbox = 'X'

commit_work = 'X'

IMPORTING

sent_to_all = v_sent_all

TABLES

packing_list = it_packing_list

contents_txt = it_attachment

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.

*ENDFORM. "SENDING_PDF_USING_SPOOL

&----


*& Form PROTOCOL_UPDATE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM PROTOCOL_UPDATE .

  • CHECK xscreen = space.

CALL FUNCTION 'NAST_PROTOCOL_UPDATE'

EXPORTING

msg_arbgb = syst-msgid

msg_nr = syst-msgno

msg_ty = syst-msgty

msg_v1 = syst-msgv1

msg_v2 = syst-msgv2

msg_v3 = syst-msgv3

msg_v4 = syst-msgv4

EXCEPTIONS

OTHERS = 1.

ENDFORM. " PROTOCOL_UPDATE

Thanks and regards,

Jagan Mohan.