cancel
Showing results for 
Search instead for 
Did you mean: 

Attachment of PDF document to external Mail id - error

Former Member
0 Kudos

I am converting a smartform into pdf and then attaching it for sending to external mail id.

All this work fine and mail with attachment is sent successfully.

When i try to open the attachement i get the error msg "There was error opening this document. The file is damaged or could not be repaired."

I tried to search forum came across thread but no solution. I am using function modules CONVERT_OTF_2_PDF AND FM to send mail.

Thanks,

AP

Accepted Solutions (1)

Accepted Solutions (1)

brad_bohn
Active Contributor
0 Kudos

This is a commonly asked question - did you review other posts for the same message? There are OSS notes for the message as well. One thing to check is the succes of the conversion though. That function reverts to background processing for spools greater than 99 pages - did you actually get binary (PDF) data back or did you spawn a background job and simply attach a 0 byte file?

Former Member
0 Kudos

I am able to down load the file to hard drive and open it. But when I send the email, I am not able to open it. Tried to seach forun but did not get solution.

Thanks

brad_bohn
Active Contributor
0 Kudos

Did you convert the lines using SX_TABLE_LINE_WIDTH_CHANGE and move the result to a binary table (SOLIX_TAB based) before attaching (or some other similar method)? It helps if you post code...

Former Member
0 Kudos
DATA:it_nfal      TYPE nfal OCCURS 0 WITH HEADER LINE.
DATA:fm_name      TYPE rs38l_fnam.
DATA:ssfctrlop    TYPE ssfctrlop.
DATA:ssfcompop    TYPE ssfcompop.
DATA:it_otf_data  TYPE ssfcrescl.
DATA:it_otf_final TYPE itcoo OCCURS 0 WITH HEADER LINE.
DATA:bin_filesize TYPE i.
DATA:it_pdfdata   TYPE TABLE OF tline.
DATA:it_pdf       TYPE TABLE OF solisti1.
*--------------------------------------------------------*
"  Mail related declarations
*--------------------------------------------------------*
"Variables
DATA :
g_sent_to_all   TYPE sonv-flag,
g_tab_lines     TYPE i.
"Types
TYPES:
t_document_data  TYPE  sodocchgi1,
t_packing_list   TYPE  sopcklsti1,
t_attachment     TYPE  solisti1,
t_body_msg       TYPE  solisti1,
t_receivers      TYPE  somlreci1,
t_pdf            TYPE  tline.
"Workareas
DATA :
w_document_data  TYPE  t_document_data,
w_packing_list   TYPE  t_packing_list,
w_attachment     TYPE  t_attachment,
w_body_msg       TYPE  t_body_msg,
w_receivers      TYPE  t_receivers,
w_pdf            TYPE  t_pdf.
"Internal Tables
DATA :
i_document_data  TYPE STANDARD TABLE OF t_document_data,
i_packing_list   TYPE STANDARD TABLE OF t_packing_list,
i_attachment     TYPE STANDARD TABLE OF t_attachment,
i_body_msg       TYPE STANDARD TABLE OF t_body_msg,
i_receivers      TYPE STANDARD TABLE OF t_receivers,
i_pdf            TYPE STANDARD TABLE OF t_pdf.
PARAMETERS p_mail TYPE char120.
*START-OF-SELECTION.
START-OF-SELECTION.
"select data
SELECT * FROM nfal INTO TABLE it_nfal UP TO 10 ROWS.

ssfctrlop-no_dialog = 'X'.
ssfctrlop-preview   = 'X'.
ssfctrlop-getotf    = 'X'.

ssfcompop-tddest = 'LP01'.
"Get Function module name for given smartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZTESTASP'
IMPORTING
fm_name  = fm_name.
"Call Smartform function module.
CALL FUNCTION fm_name
EXPORTING
control_parameters = ssfctrlop
output_options     = ssfcompop
IMPORTING
job_output_info    = it_otf_data.
*TABLES
*it_nfal            = it_nfal.

************appending the otf data into the final table**********************
it_otf_final[] = it_otf_data-otfdata[].

************ converting OTF data into pdf data**************************
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format                = 'PDF'
IMPORTING
bin_filesize          = bin_filesize
*     bin_file              =
TABLES
otf                   = it_otf_final
lines                 = it_pdfdata[]
EXCEPTIONS
err_max_linewidth     = 1
err_format            = 2
err_conv_not_possible = 3
err_bad_otf           = 4
OTHERS                = 5.
* To send data as email attachment, we need to have a table of SOLISTI1.
* This table contains line size of 255 characters. Below function module
* does the trick of changing the table from X character sized lines into
* any given Y character sized lines.
REFRESH it_pdf[].

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst              = '255'
TABLES
content_in                  = it_pdfdata[]
content_out                 = it_pdf[]
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.
ELSE.
"Subject of the mail.
w_document_data-obj_name  = 'MAIL_TO_HEAD'.
w_document_data-obj_descr = 'Regarding Mail Program by SAP ABAP'.

"Body of the mail
w_body_msg = 'This is body of mail msg.'.
APPEND w_body_msg TO i_body_msg.
CLEAR  w_body_msg.
"Write Packing List for Body
DESCRIBE TABLE i_body_msg LINES g_tab_lines.
w_packing_list-head_start = 1.
w_packing_list-head_num   = 0.
w_packing_list-body_start = 1.
w_packing_list-body_num   = g_tab_lines.
w_packing_list-doc_type   = 'RAW'.
APPEND w_packing_list TO i_packing_list.
CLEAR  w_packing_list.

"Write Packing List for Attachment
w_packing_list-transf_bin = 'X'.
w_packing_list-head_start = 1.
w_packing_list-head_num   = 1.
w_packing_list-body_start = 1.
DESCRIBE TABLE it_pdf LINES w_packing_list-body_num.
w_packing_list-doc_type   = 'PDF'.
w_packing_list-obj_descr  = 'PDF Attachment'.
w_packing_list-obj_name   = 'PDF_ATTACHMENT'.
w_packing_list-doc_size   = w_packing_list-body_num * 255.
APPEND w_packing_list TO i_packing_list.
CLEAR  w_packing_list.

"Fill the document data and get size of attachment
w_document_data-obj_langu  = sy-langu.
READ TABLE it_pdf INTO w_pdf INDEX g_tab_lines.
w_document_data-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( w_attachment ).

"Receivers List.
w_receivers-rec_type   = 'U'."Internet address
w_receivers-receiver   = p_mail.
w_receivers-com_type   = 'INT'.
w_receivers-notif_del  = 'X'.
w_receivers-notif_ndel = 'X'.
APPEND w_receivers TO i_receivers .
CLEAR:w_receivers.

"Function module to send mail to Recipients
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data              = w_document_data
put_in_outbox              = 'X'
commit_work                = 'X'
IMPORTING
sent_to_all                = g_sent_to_all
TABLES
packing_list               = i_packing_list
contents_bin               = it_pdf
contents_txt               = i_body_msg
receivers                  = i_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.

IF sy-subrc = 0 .
MESSAGE i303(me) WITH 'Mail has been Successfully Sent.'.
ENDIF.
ENDIF.

Edited by: AP on Dec 1, 2010 10:25 PM

brad_bohn
Active Contributor
0 Kudos

You posted too much code and made it unreadable - just post the relevant parts. However, I can see that you're using the email function - why don't you use the CL_BCS class? There are articles, Wikis, and posts with code for it with attachment processing, not to mention how easy it is to figure out without any documentation. Stop using the function unless of course you're one of the (relatively) few customers in extended maintenance below NW6.0.

I certainly would NOT follow the other poster's recommendation of the RSCONN01 submit along with the code; I can't believe a team lead allows it...

Former Member
0 Kudos

Thank you everyone. I solved the issue by implementing OSS note 1430123.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Try this way...

Regards

Raj

  • Declaration for email functionality

DATA : L_TAB_DOCS LIKE TABLE OF DOCS WITH HEADER LINE,

IT_PDF_OUTPUT LIKE TABLE OF TLINE WITH HEADER LINE,

L_OBJPACK LIKE TABLE OF SOPCKLSTI1 WITH HEADER LINE,

L_RECLIST LIKE TABLE OF SOMLRECI1 WITH HEADER LINE,

L_OBJBIN LIKE TABLE OF SOLISTI1 WITH HEADER LINE,

L_OBJHEAD LIKE TABLE OF SOLISTI1 WITH HEADER LINE,

L_OBJTXT LIKE TABLE OF SOLISTI1 WITH HEADER LINE,

L_OBJHEX LIKE TABLE OF SOLIX WITH HEADER LINE,

IT_MESS_ATT LIKE TABLE OF SOLISTI1 WITH HEADER LINE,

L_FILESIZE TYPE TST01-DSIZE,

L_TAB_LINES TYPE I,

L_DOCDATA LIKE SODOCCHGI1,

ATT_TYPE LIKE SOPCKLSTI1-DOC_TYPE,

GD_BUFFER TYPE STRING,

L_SUB(50),

gv_maild type COMM_ID_LONG.

CLEAR:L_TAB_DOCS[],IT_PDF_OUTPUT[],L_OBJPACK[],L_RECLIST[],L_OBJBIN[],

L_OBJHEAD[],L_OBJTXT[],L_OBJHEX[],IT_MESS_ATT[],

L_FILESIZE, L_TAB_LINES, L_DOCDATA,ATT_TYPE,GD_BUFFER, L_SUB.

IT_PDF_OUTPUT[] = pdf_tab[]. "This is your result from FM CONVERT_OTF_2_PDF

*Transfer the 132-long strings to 255-long strings

LOOP AT IT_PDF_OUTPUT.

TRANSLATE IT_PDF_OUTPUT USING ' ~'.

CONCATENATE GD_BUFFER IT_PDF_OUTPUT INTO GD_BUFFER.

ENDLOOP.

TRANSLATE GD_BUFFER USING '~ '.

DO.

IT_MESS_ATT = GD_BUFFER.

APPEND IT_MESS_ATT.

SHIFT GD_BUFFER LEFT BY 255 PLACES.

IF GD_BUFFER IS INITIAL.

EXIT.

ENDIF.

ENDDO.

L_OBJBIN[] = IT_MESS_ATT[].

*Create Message Attachment

ATT_TYPE = 'PDF'.

DESCRIBE TABLE L_OBJBIN LINES L_TAB_LINES.

READ TABLE L_OBJBIN INDEX L_TAB_LINES.

L_OBJPACK-DOC_SIZE = ( L_TAB_LINES - 1 ) * 255 + STRLEN( L_OBJBIN ).

L_OBJPACK-TRANSF_BIN = 'X'.

L_OBJPACK-HEAD_START = 1.

L_OBJPACK-HEAD_NUM = 0.

L_OBJPACK-BODY_START = 1.

L_OBJPACK-BODY_NUM = L_TAB_LINES.

L_OBJPACK-DOC_TYPE = ATT_TYPE.

L_OBJPACK-OBJ_NAME = 'Dependent'.

L_OBJPACK-OBJ_DESCR = 'Dependent Certification'.

APPEND L_OBJPACK.

*Create subject

L_DOCDATA-OBJ_LANGU = SY-LANGU.

L_DOCDATA-OBJ_NAME = 'Dependent'.

concatenate 'Dependent Certification ' wa_emp-pernr into L_SUB separated by space.

L_DOCDATA-OBJ_DESCR = L_SUB.

*Receivers list

select single usrid_long into gv_maild

from pa0105

where pernr = wa_emp-pernr

and subty = '0010'

AND begda <= sy-datum

AND endda >= sy-datum.

if sy-subrc = 0.

L_RECLIST-RECEIVER = gv_maild.

L_RECLIST-REC_TYPE = 'U'.

APPEND L_RECLIST.

endif.

  • CC

L_RECLIST-RECEIVER = 'youemail address.

L_RECLIST-REC_TYPE = 'U'.

L_RECLIST-copy = 'X'.

APPEND L_RECLIST.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = L_DOCDATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = L_OBJPACK

OBJECT_HEADER = L_OBJHEAD

CONTENTS_BIN = L_OBJBIN

CONTENTS_TXT = L_OBJTXT

CONTENTS_HEX = L_OBJHEX

RECEIVERS = L_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.

  • WAIT UP TO 1 SECONDS.

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = ' '

AND RETURN.

endif.