Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in sending PDF as attachment in E-Mail

Former Member
0 Kudos

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 along with example Program.

Sorry, I could not attach the program here.

Thanks and regards,

Jagan Mohan.

6 REPLIES 6

Former Member
0 Kudos

Please try this link

Former Member
0 Kudos

Hi,

Try using SO_NEW_DOCUMENT_ATT_SEND_API1

it will don't corrupt your data it's used in standard Workflow with PDF attachment.

Hope magic Works!

Regards,

Purvesh Patel.

Former Member
0 Kudos

Hi,

You have to get the size in importing parameter while generating the pdf from spool and need to pass the value in the exporting parameter of gui_download.

Regards,

Anupam

Former Member
0 Kudos

DATA:ig_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

ig_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.

DATA : ig_pdf1 TYPE TABLE OF solisti1.

DATA: g_tab_lines LIKE sy-tabix.

DATA: ig_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE,

ig_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

ig_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

ig_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE,

ig_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: wg_doc_chng LIKE sodocchgi1.

PERFORM convert_pdf.

PERFORM sendmail.

FORM convert_pdf .

REFRESH : ig_otf , ig_pdf_tab.

ig_otf[] = wg_otf_from_fm-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = wg_bin_fsize

TABLES

otf = ig_otf

lines = ig_pdf_tab

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " convert_pdf

FORM sendmail .

REFRESH : ig_pdf1.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_dst = '255'

TABLES

content_in = ig_pdf_tab[]

content_out = ig_pdf1[]

EXCEPTIONS

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

OTHERS = 4.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

MOVE : 'U' TO ig_reclist-rec_type,

'.....' TO ig_reclist-receiver, " move email id here

'X' TO ig_reclist-express,

'INT' TO ig_reclist-com_type.

APPEND ig_reclist.

REFRESH ig_objtxt.

CONCATENATE 'Payslip of employee -' wg_vbak-vbeln INTO ig_objtxt SEPARATED BY ' '.

APPEND ig_objtxt.

  • Creating the document to be sent

wg_doc_chng-obj_descr = 'Pay Slip'.

wg_doc_chng-obj_name = 'PAYSLIP'.

wg_doc_chng-obj_langu = sy-langu.

  • Get length of objtxt.

DESCRIBE TABLE ig_objtxt LINES g_tab_lines.

READ TABLE ig_objtxt INDEX g_tab_lines.

wg_doc_chng-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( ig_objtxt ).

  • Creating the entry for the compressed document

CLEAR ig_objpack-transf_bin.

ig_objpack-head_start = 1.

ig_objpack-head_num = 0.

ig_objpack-body_start = 1.

ig_objpack-body_num = g_tab_lines.

ig_objpack-doc_type = 'RAW'.

APPEND ig_objpack.

DESCRIBE TABLE ig_pdf1 LINES g_tab_lines.

g_tab_lines = g_tab_lines + 1.

ig_objhead-line = 'PAYSLIP'.

APPEND ig_objhead.

  • Creating the entry for the compressed attachment

ig_objpack-transf_bin = 'X'.

ig_objpack-head_start = 1.

ig_objpack-head_num = 1.

ig_objpack-body_start = 1.

ig_objpack-body_num = g_tab_lines.

ig_objpack-doc_type = 'PDF'.

ig_objpack-obj_name = 'PAYSLIP'.

ig_objpack-obj_descr = 'Pay Slip'.

ig_objpack-doc_size = g_tab_lines * 255.

APPEND ig_objpack.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = wg_doc_chng

  • put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = ig_objpack

object_header = ig_objhead

contents_bin = ig_pdf1

contents_txt = ig_objtxt

receivers = ig_reclist

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 .

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM.

Former Member
0 Kudos

satsrockford
Active Participant
0 Kudos

hi

chk these threads:

hope it helps

regards

Satish