Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Error opening pdf in email

I am trying to email a smartform as pdf. But getting the error that File cannot be opened as it is damaged and cannot be repaired.

I am getting the otf data from Smartform FM. Then convert it to pdf. And then sending it through SO_NEW_DOCUMENT_ATT_SEND_API1. Attached is my code. I don't know what I am doing wrong. I first tried to send it directly through smartform email parameters. It didn't work. I also tried other functions for OTF to PDF conversions. But always getting the same error . I've also checked SCOT for SMTP node setup. The o/p format for smartforms is PDF.

Has anybody ever succeeded in getting the good pdf from smart form in the email ? Any idea what I am doing wrong ?

V_FORMNAME = 'ZSD_DAILY_SHEET_DB'.

call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = v_formname
importing
fm_name = fm_name
exceptions
no_form = 1
no_function_module = 2
others = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

w_ctrlop-getotf = 'X'.
w_ctrlop-no_dialog = 'X'.
w_compop-tdnoprev = 'X'.

CALL FUNCTION fm_name
  EXPORTING
   CONTROL_PARAMETERS         = w_ctrlop
   OUTPUT_OPTIONS             = w_compop
   USER_SETTINGS              = 'X'
   VTITLE                     = SY-TITLE
   VDATE                      = P_DATE
   VDATE2                     = SY-DATUM
IMPORTING
   JOB_OUTPUT_INFO            = w_return
  TABLES
    I_DAILY                    = it_daily
    I_MONTHLY                  = it_monthly
    I_YEARLY                   = it_yearly
EXCEPTIONS
   FORMATTING_ERROR           = 1
   INTERNAL_ERROR             = 2
   SEND_ERROR                 = 3
   USER_CANCELED              = 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.

i_otf[] = w_return-otfdata[].

CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = v_len_in
TABLES
otf = i_otf
lines = i_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 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.

* Convert PDF from 132 to 255.
LOOP AT i_tline.
* Replacing space by ~
TRANSLATE i_tline USING ' ~'.
CONCATENATE w_buffer i_tline INTO w_buffer.
ENDLOOP.

* Replacing ~ by space
TRANSLATE w_buffer USING '~ '.
DO.
i_record = w_buffer.
* Appending 255 characters as a record
APPEND i_record.
SHIFT w_buffer LEFT BY 255 PLACES.
IF w_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.

Refresh: i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear w_objhead.

* Object with PDF.
i_objbin[] = i_record[].
DESCRIBE TABLE i_objbin LINES v_lines_bin.
* Object with main text of the mail.
i_objtxt = 'Find attached the Daily Dashboard Sheet.'.
APPEND i_objtxt.
i_objtxt = 'Regards,'.
APPEND i_objtxt.
i_objtxt = 'Dummy.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.

* Document information.
w_doc_chng-obj_name = 'Smartform'.
w_doc_chng-expiry_dat = sy-datum + 10.
w_doc_chng-obj_descr = 'Smart form output'.
w_doc_chng-sensitivty = 'F'. "Functional object
w_doc_chng-doc_size = v_lines_txt * 255.
* Pack to main body as RAW.
* Obj. to be transported not in binary form
CLEAR i_objpack-transf_bin.
* Start line of object header in transport packet

i_objpack-head_start = 1.
* Number of lines of an object header in object packet
i_objpack-head_num = 0.
* Start line of object contents in an object packet
i_objpack-body_start = 1.
* Number of lines of the object contents in an object packet
i_objpack-body_num = v_lines_txt.
* Code for document class
i_objpack-doc_type = 'RAW'.
APPEND i_objpack.

* Packing as PDF.
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
i_objpack-obj_descr = 'Dashboard Sheet'.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
* Document information.
CLEAR i_reclist.

* e-mail receivers.
i_reclist-receiver = p_mail.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
* Sending mail.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = w_objhead
contents_bin = i_objbin
contents_txt = i_objtxt
receivers = i_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.

Edited by: Arbaab Rahim on Sep 15, 2008 2:41 PM

Not what you were looking for? View more on this topic or Ask a question