Hi all,
I am currently usign a background method to send a smartform as a PDF document to all the agents who approve.
When i send the smartform in mail as a PDF documetn throught the task i get an error message when opening the PDF document which says that 'The file could nto be opened because it was either not a supported file type or because the file was damaged(for example, it was sent as an email attachment and wasn't decoded correectly'.
The below is the code i am using to send the smartform
{ CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZFI_ASSET_PDA_NOTIF'
IMPORTING
fm_name = lv_form_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.}
{ ls_ctrlop-getotf = 'X'.
ls_ctrlop-no_dialog = ''.
ls_compop-tdnoprev = 'X'.
ls_ctrlop-DEVICE = 'LOCL'.
ls_ctrlop-preview = 'X'.
ls_ctrlop-no_dialog = 'X'.}
CALL FUNCTION lv_form_name
EXPORTING
control_parameters = ls_ctrlop
output_options = ls_compop
user_settings = 'X'
gv_prctr_txt = gv_prctr_txt
gv_cc_text = gv_cc_text
gv_class_txt = gv_class_txt
gv_lname = gv_lname
gv_fname = gv_fname
gv_position = gv_position
gv_initiator = gv_initiator
gv_bookcost = gv_bookcost
gv_bookvalue = gv_bookvalue
gv_date = gv_date
gv_prctr = gv_prctr
gs_anla = gs_anla
gv_emv = gv_emv
gv_cond = gv_cond
gv_operable = gv_operable
gv_action = gv_action
gv_justify = gv_justify
gv_replace = gv_replace
gv_replace_comment = gv_replace_comment
gv_process = gv_process
IMPORTING
job_output_info = lt_job_output
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_job_output-otfdata INTO ls_otf.
lt_otf = ls_otf.
APPEND lt_otf.
CLEAR lt_otf.
ENDLOOP.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = lv_len_in
TABLES
otf = lt_otf
lines = lt_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
Fehlerhandling
IF sy-subrc EQ 0.
ENDIF.
LOOP AT lt_tline.
TRANSLATE lt_tline USING '~'.
CONCATENATE ls_buffer lt_tline INTO ls_buffer.
ENDLOOP.
TRANSLATE ls_buffer USING '~'.
append ls_buffer TO lt_objbin.
DATA lv_counter TYPE i.
DO.
lt_record = ls_buffer.
APPEND lt_record.
SHIFT ls_buffer LEFT BY 255 PLACES.
IF ls_buffer IS INITIAL.
EXIT.
ENDIF.
ENDDO.
Attachment
REFRESH:
lt_reclist,
lt_objtxt,
lt_objbin,
lt_objpack.
CLEAR ls_objhead.
lt_objbin[] = lt_record[].
lt_objhex[] = lt_record[].
CLEAR lv_descp.
CONCATENATE 'Asset'
gs_anla-anln1
'Approval details'
INTO lv_descp
SEPARATED BY space.
Create Message Body
Title and Description
CONCATENATE 'Please find attached the approval details of asset : '
gs_anla-anln1
INTO lv_mail_descp
SEPARATED BY space .
lt_objtxt = lv_mail_descp.
APPEND lt_objtxt.
CLEAR lv_mail_descp .
appending space lines into text of mail.
DO 3 times.
CLEAR lt_objtxt.
APPEND lt_objtxt .
ENDDo.
CONCATENATE 'This is an automatically generated message.'
'Please do not reply to this mail.'
INTO lv_mail_descp
SEPARATED BY space .
lt_objtxt = lv_mail_descp.
APPEND lt_objtxt.
DESCRIBE TABLE lt_objtxt LINES lv_lines_txt.
READ TABLE lt_objtxt INDEX lv_lines_txt.
ls_doc_chng-obj_name = 'smartform'.
ls_doc_chng-expiry_dat = sy-datum + 10.
ls_doc_chng-obj_descr = lv_descp.
ls_doc_chng-sensitivty = 'F'.
ls_doc_chng-doc_size = ( lv_lines_txt - 1 ) * 255 + STRLEN( lt_objtxt ) .
Main Text
wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt ).
CLEAR lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = lv_lines_txt.
lt_objpack-doc_type = 'RAW'.
lt_objpack-doc_type = 'TXT'.
APPEND lt_objpack.
Attachment
(pdf-Attachment)
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
DESCRIBE TABLE lt_objbin LINES lv_lines_bin.
READ TABLE lt_objbin INDEX lv_lines_bin.
lt_objpack-doc_size = ( lv_lines_bin - 1 ) * 255 + STRLEN( lt_objbin ) .
lt_objpack-body_num = lv_lines_bin.
lt_objpack-doc_type = 'PDF'.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = lv_descp.
APPEND lt_objpack.
LOOP AT t_mail_addr.
CLEAR lt_reclist.
lt_reclist-receiver = t_mail_addr-mailid.
lt_reclist-rec_type = 'U'.
APPEND lt_reclist.
ENDLOOP.
IF t_mail_addr[] IS INITIAL.
CLEAR lt_reclist.
lt_reclist-receiver = mail id.
lt_reclist-rec_type = 'U'.
APPEND lt_reclist.
ENDIF.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_objpack
object_header = ls_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_reclist
CONTENTS_HEX = lt_objbin
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.
DATA: l TYPE sy-subrc.
l = sy-subrc.
.
When i run the above code in Se38, I get an email with a attachment that i am able to open. The problem seems to be with user WF_BATCH.
I have already checked all the existing threads on this. I did this coding as per one of the SDN threads itself.
I am able to open the PDF attachment even when i test the method. The problem is only when it is run through a task/workflow.
Please advice.
Thanks and Regards,
Soumya Gayatri.
Edited by: Soumya Gayatri on Apr 14, 2009 8:40 PM
Edited by: Soumya Gayatri on Apr 14, 2009 8:44 PM
Edited by: Soumya Gayatri on Apr 14, 2009 8:45 PM
Edited by: Soumya Gayatri on Apr 14, 2009 8:47 PM
Edited by: Soumya Gayatri on Apr 14, 2009 8:47 PM