Sending smartform output as PDF attachment, Error opening PDF attachment
Hi Experts,
I am using the code form the following link to send a smartform output as PDF attachment. I can able to see the message, but can not open PDF document.
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/convertSmartformtoPDFformat&
The information should be on my smartform are some text, company logo and a barcode.
With all of these received error: "There was an error opening this document. The file is damaged and could not be repaired."
I tried different ways like only text, text with company logo, text with barcode. I got the following errors:
An unrecognized token 'Td0' was found
There was problem reading this document(16).
There was problem reading this document(111).
Does anyone have idea of these ? Your help is greatly appreciated.
Thank you,
Surya
please see this code ... for sending the Email as PDF attach file,
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
* Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
* Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att 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.
* Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
* Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
* Write statement to represent report output. Spool request is created
* if write statement is executed in background. This could also be an
* ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
*** Alternative way could be to submit another program and store spool
*** id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
* to sap-spool
* spool parameters %_print
* archive parameters %_print
* without spool dynpro
* and return.
* Get spool id from program called above
* IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
* FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
* FORM get_job_details *
FORM get_job_details.
* Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
* FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 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.
CHECK sy-subrc = 0.
* 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.
ENDFORM.
* FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
* perform send_email using p_email2.
ENDFORM.
* FORM send_email *
* --> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
* Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
* CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
* If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
* Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
* FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
* Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
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 ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_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,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
reward points if it is usefull ....
Girish
Similar Messages
-
How to send SMARTFORMS output as attachment through?
how to send SMARTFORMS output as attachment through e-mail?
after executing SMARTFORMS how to send that output via e-mail.
Help me.
thanks
surya.
Moderator Message: Please search for available information first
Edited by: kishan P on Nov 7, 2010 7:19 PMhi Vinod,
Can you please tell me how you have zipped the file.
I am having a text file in application server. I need to zip that file. Then the middleware moves it to Legacy system.
I used the following code. With this I am having the data in Binary format which my midleware cannot understand.
What I need on the whole is just to reduce the size of the file.
form ZIP_FILE .
DATA: lt_data TYPE TABLE OF x255,
lt_textdata TYPE TABLE OF x255.
DATA: ls_data LIKE LINE OF lt_data.
DATA: lv_dsn1(100) VALUE '/ECD/120/GIS/FTP/IB/DNBPAYDEX.TXT'.
DATA: lv_dsn3(100) VALUE '/ECD/120/GIS/FTP/IB/DNBPAYDEXZIP.zip'.
*DATA: lv_dsn3(100) VALUE '/interfaces/SM5/test.zip'. " Contains sample1.xls and sample2.xls
DATA: lv_file_length TYPE i.
DATA: lv_content TYPE xstring.
DATA: lo_zip TYPE REF TO cl_abap_zip.
CREATE OBJECT lo_zip.
Read the data as a string
clear lv_content .
OPEN DATASET lv_dsn1 FOR INPUT IN BINARY MODE.
READ DATASET lv_dsn1 INTO lv_content .
CLOSE DATASET lv_dsn1.
lo_zip->add( name = 'sample.TXT' content = lv_content ).
lv_content = lo_zip->save( ).
*clear lv_content .
Conver the xstring content to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_content
IMPORTING
output_length = lv_file_length
TABLES
binary_tab = lt_data.
OPEN DATASET lv_dsn3 FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT lt_textdata INTO ls_data.
TRANSFER ls_data TO lv_dsn3.
ENDLOOP.
CLOSE DATASET lv_dsn3.
IF sy-subrc EQ '0'.
MESSAGE s999(zfi_ap_gl) WITH text-t10.
ENDIF.
Can you please help.
Thanks Aravind -
To send smartform output in an email without attachment
Hi All,
How to send smartform output in an email without attachment?
Thanks & Regards,
Mamta Gupta.Try this,
DATA:
ls_control_param TYPE ssfctrlop, "Control paramters
ls_output_options TYPE ssfcompop. "Output options
DATA:
lv_ip_mailaddr TYPE so_name, "Address of a Mail Recipient
lv_ip_type_id TYPE so_escape, "Recipient type
ls_recipient_id TYPE swotobjid, "Structure for recvr obj ID
ls_sender_id TYPE swotobjid. "Structure for sender obj id
CONSTANTS:
lc_ip_type_id TYPE so_escape VALUE 'U', "For internet address.
lc_smartform TYPE tdsfname VALUE 'ZVSF_ASN_DELNOTE', "Smart form name
lc_mail TYPE tddevice VALUE 'MAIL'. "Mail device
Assign recipient
lv_ip_mailaddr = gv_smtp_addr. "CSAM email id
lv_ip_type_id = lc_ip_type_id. "External address
Create Mail title
CONCATENATE text-001
nast-objky
INTO ls_output_options-tdtitle.
Create recipient object
CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
EXPORTING
ip_mailaddr = lv_ip_mailaddr
ip_type_id = lv_ip_type_id
IMPORTING
ep_recipient_id = ls_recipient_id
EXCEPTIONS
invalid_recipient = 1
OTHERS = 2.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Get sender object id.
CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
EXPORTING
ip_sender = sy-uname
IMPORTING
ep_sender_id = ls_sender_id
EXCEPTIONS
invalid_sender = 1
OTHERS = 2.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Assign the smart form name
w_ssfname = lc_smartform.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = w_ssfname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
For Print output:
IF nast-nacha = '1'. "Print output
ls_control_param-preview = 'X'.
ls_control_param-no_dialog = 'X'.
ENDIF.
For Email output.
IF nast-nacha = '2'. "Email
Output options
ls_output_options-tdteleland = gs_kna1-land1.
ls_output_options-tdtelenum = gs_kna1-telfx.
ls_output_options-tdfaxuser = sy-uname.
ls_output_options-BCS_COMMIT = 'X'.
ls_control_param-device = lc_mail.
ENDIF.
dynamically call Fm behind the Smart form
CALL FUNCTION lf_fm_name
EXPORTING
control_parameters = ls_control_param
mail_recipient = ls_recipient_id
mail_sender = ls_sender_id
output_options = ls_output_options
user_settings = ' '
TABLES
delivery = gt_delivery
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc 0.
cf_retcode = sy-subrc.
PERFORM protocol_update.
ENDIF.
Regards,
Joan -
How to send smartform output in body of email?
Hi all ,
I have to send smartform output in body of email (not as an attachement in mail) .PLease help me in this regard.
Thanks,
Ananth S.Hi Ananth
See these threads.
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6889194]
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6861330]
[https://forums.sdn.sap.com/click.jspa?searchID=23497094&messageID=6855364]
Regards
Hareesh Menon -
How to send smartform output through email
Hi,
I want to send smartform output through email.....
can u give me sample program to send it through email......
Regards,
Jenifer
MOderator Message: Basic and Frequently asked question. Please search before posting.
Edited by: kishan P on Nov 26, 2010 11:11 AMHi Jenifer,
There are many threads available on SDN.
Just have a look at this thread
<<link removed by moderator>>
Kindly search before you post.
Regard
Abhii
Moderator Message: You have been warned many times against point-hunting. Continuing ignoring of the Moderator warnings will lead to account deletion. Consider this your last warning
Edited by: kishan P on Nov 26, 2010 11:09 AM -
To send smartform output through email and fax
Hi,
I need to send smartform output through email if the email address is present else if the email address is present then it has to be sent through fax.If both the email address and fax are present,then it has to send an email.
Now the issue is I am able to send the email and I am getting the message as 'Output was successfully issued'.But the entry corresponding to this is not shown in SOST transaction.
Can anyone tell me what would be the reason for this?HI,
Try to look in transaction SCOT
Regards,
Egle -
Error opening PDF file when send as attachment via email
Hi,
I searched around the forum to resolve my issue and there's alot of post that is related but i can't find any answer to my issues.
Here's the scenario :-
I try to convert the smartform to PDF and then send the PDF as an attachment via email.
After converting the smartform to PDF, i managed to download the file and view it without any problem but i can't view the PDF as an attachment. It has the following error :-
Adobe Reader could not open '4500002325.PDF' because it is either not a supported fle type or because the file has been damaged (for example, it was sent as an email and wasn't correctly decoded
The following is the snapshot of my code:-
* Determine smartform function module for invoice
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lf_formname
IMPORTING
fm_name = lf_fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* error handling
ent_retco = sy-subrc.
PERFORM protocol_update_i.
ENDIF.
ls_control_param-getotf = 'X'.
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = toa_dara
archive_parameters = arc_params
control_parameters = ls_control_param
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
zxekko = l_doc-xekko " user_settings = ' '
zxpekko = l_doc-xpekko
IMPORTING
document_output_info = l_ssfcrespd
job_output_info = l_ssfcrescl
job_output_options = l_ssfcresop
TABLES
l_xekpo = l_doc-xekpo[]
l_xekpa = l_doc-xekpa[]
l_xpekpo = l_doc-xpekpo[]
l_xeket = l_doc-xeket[]
l_xtkomv = l_doc-xtkomv[]
l_xekkn = l_doc-xekkn[]
l_xekek = l_doc-xekek[]
l_xkomk = l_xkomk
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc = 0.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
IMPORTING
BIN_FILESIZE = v_len_in
BIN_FILE = v_bin_file
TABLES
OTF = l_ssfcrescl-otfdata
LINES = l_pdf
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5.
* email subject
CONCATENATE 'Purchase order' l_doc-xekko-ebeln INTO lw_subject
SEPARATED BY space.
* RECIPIENTS
lwa_recipients-rec_type = 'U'.
lwa_recipients-express = 'X'.
SELECT adr6~smtp_addr
INTO TABLE gv_smtp_addr
FROM ekko AS ekko INNER JOIN
lfa1 AS lfa1 ON ekko~lifnr = lfa1~lifnr INNER JOIN
adr6 AS adr6 ON adr6~addrnumber = lfa1~adrnr
WHERE ekko~ebeln = l_doc-xekko-ebeln.
IF NOT gv_smtp_addr[] IS INITIAL.
LOOP AT gv_smtp_addr INTO gv_smtp_addr_line FROM 2.
lwa_recipients-receiver = gv_smtp_addr_line.
lwa_recipients-copy = ''.
APPEND lwa_recipients TO ptb_recipients.
ENDLOOP.
* Text Data
CALL FUNCTION 'READ_TEXT'
EXPORTING
id = 'ST'
language = 'E'
name = 'TEST'
object = 'TEXT'
TABLES
lines = lv_lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
LOOP AT lv_lines INTO lv_lines_line.
ltb_objtxt = lv_lines_line-tdline.
APPEND ltb_objtxt.
ENDLOOP.
DESCRIBE TABLE ltb_objtxt LINES lw_tab_lines.
READ TABLE ltb_objtxt INDEX lw_tab_lines.
* document data contains information for the whole message
lwa_doc_chng-obj_descr = 'ABAPlist'.
* Control Data
lwa_doc_chng-obj_name = 'TESTING'.
lwa_doc_chng-sensitivty = 'F'.
lwa_doc_chng-no_change = 'X'.
lwa_doc_chng-priority = '1'.
lwa_doc_chng-obj_prio = '1'.
lwa_doc_chng-obj_langu = sy-langu.
CLEAR ltb_objpack-transf_bin.
*Attachment
*Move the binary attachment to other internal table.
ltb_objpack-head_start = 1.
ltb_objpack-head_num = 0.
ltb_objpack-body_start = 1.
ltb_objpack-body_num = lw_tab_lines.
ltb_objpack-doc_type = 'RAW'.
APPEND ltb_objpack.
clear : lw_tab_lines.
*Get the number of lines in the Attachment (PDF FILE)
* DESCRIBE TABLE it_mess_att LINES lw_tab_lines.
DESCRIBE TABLE l_objbin lines lw_tab_lines.
ltb_objpack-transf_bin = 'X'.
ltb_objpack-head_start = 1.
ltb_objpack-head_num = 1.
ltb_objpack-body_start = 1.
ltb_objpack-body_num = lw_tab_lines.
ltb_objpack-doc_type = 'PDF'.
ltb_objpack-obj_descr = l_doc-xekko-ebeln.
ltb_objpack-doc_size = lw_tab_lines * 255.
APPEND ltb_objpack.
*Email Subject
lwa_doc_chng-obj_descr = lw_subject.
lwa_recipients-receiver = recipeint.
lwa_recipients-rec_type = 'U'.
lwa_recipients-copy = 'X'.
lwa_recipients-express = 'X'.
APPEND lwa_recipients TO ptb_recipients.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = lwa_doc_chng
COMMIT_WORK = 'X'
TABLES
packing_list = ltb_objpack
contents_bin = l_objbin
contents_txt = ltb_objtxt
receivers = ptb_recipients.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDIF.
Edited by: ~loObie on Apr 23, 2010 12:01 PM
Edited by: ~loObie on Apr 23, 2010 12:02 PMDid you send the pdf in the following format ...
2. Sending PDF as mail.
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = sy-uname.
t_receivers-rec_type = 'B'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Quote from the Following [LINK|http://www.sap-basis-abap.com/smartforms/convert-the-smart-form-into-pdf-and-send.htm] -
Sending smartform output as mail attachment (PDF)
Hi,
I am trying to send a smartform output in PDF format as a mail attachment. This has to be fired in the save of a Invoice.. configured by the output type.
Here is the code which i have .. and it does not work.
DATA: ls_bil_invoice TYPE lbbil_invoice.
tables: nast.
DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
i_tline TYPE TABLE OF tline WITH HEADER LINE,
i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
Objects to send mail.
i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
Work Area declarations
wa_objhead TYPE soli_tab,
w_ctrlop TYPE ssfctrlop,
w_compop TYPE ssfcompop,
w_return TYPE ssfcrescl,
wa_doc_chng typE sodocchgi1,
w_data TYPE sodocchgi1,
wa_buffer TYPE string,"To convert from 132 to 255
Variables declarations
v_form_name TYPE rs38l_fnam,
v_len_in LIKE sood-objlen,
v_len_out LIKE sood-objlen,
v_len_outn TYPE i,
v_lines_txt TYPE i,
v_lines_bin TYPE i.
call function 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSDDLB_BIL_INVOICE'
IMPORTING
fm_name = v_form_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 v_form_name
EXPORTING
control_parameters = w_ctrlop
output_options = w_compop
user_settings = 'X'
is_bil_invoice = ls_bil_invoice
is_nast = nast
is_repeat = 'X'
IMPORTING
job_output_info = w_return
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 EQ 0.
endif.
Convert PDF from 132 to 255.
loop at i_tline.
translate i_tline using '~'.
concatenate wa_buffer i_tline into wa_buffer.
endloop.
translate wa_buffer using '~'.
do.
i_record = wa_buffer.
append i_record.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
refresh:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear wa_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 output of the smart form.'.
APPEND i_objtxt.
DESCRIBE TABLE i_objtxt LINES v_lines_txt.
Document information.
wa_doc_chng-obj_name = 'Smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'Smart form output'.
wa_doc_chng-sensitivty = 'F'. "Functional object
wa_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 Smart Forms
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 = 1.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'Smartform'.
CONCATENATE 'Smartform_output' '.pdf'
INTO i_objpack-obj_descr.
i_objpack-doc_size = v_lines_bin * 255.
APPEND i_objpack.
Document information.
CLEAR i_reclist.
e-mail receivers.
i_reclist-receiver = '[email protected]'.
i_reclist-express = 'X'.
i_reclist-rec_type = 'U'. "Internet address
APPEND i_reclist.
call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
TABLES
packing_list = i_objpack
object_header = wa_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 EQ 0.
ENDIF.Hi Aviroop,
Compare your part of code with the below given code.
*& Report YSSN_SIMPLE_SMARTFORM *
report zhr_bhaskar_pdf_to_email message-id zmsg.
parameters: p_vbeln type vbak-vbeln default '35'.
data: it_items type table of vbap,
v_fm_name type rs38l_fnam,
v_tot_lines type i,
v_sy_tabix type i,
output_data type ssfcrescl. " To hold Output information
constants:
c_sep type c value '-', " Value -
c_x type c value 'X', " Value X
c_space type c value ' '. " Space
*****MAIL START
include .
data: g_mail_rec_obj type swotobjid,
g_mail_sen_obj type swotobjid,
g_mail_app_obj type swotobjid,
g_cont_par type ssfctrlop,
folder type swc_object,
begin of sofmfol_key,
foldertype like sofm-foltp,
folderyear like sofm-folyr,
foldernumber like sofm-folno,
type like sofm-doctp,
year like sofm-docyr,
number like sofm-docno,
forwarder like soub-usrnam,
end of sofmfol_key,
bor_key like swotobjid-objkey,
g_mail TYPE ppfdmailad VALUE '[email protected]',
g_mail type so_name value '[email protected]',
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_mail TYPE ppfdmailad VALUE '[email protected]' ,
g_rectype type so_escape value 'U'. " 'B'.
data: job_output_info type ssfcrescl,
hotfdata like itcoo occurs 1 with header line,
htline like tline occurs 1 with header line,
x_objcont like soli occurs 1 with header line,
ld_packing_list like soxpl occurs 1 with header line,
x_object_hd_change like sood1 occurs 1 with header line,
x_objhead like soli occurs 1 with header line,
x_receivers like soos1 occurs 1 with header line,
format_pdf(10) value 'PDF',
doc_size(12) type c,
hltlines type i,
htabix like sy-tabix,
fle1(2) type p,
fle2(2) type p,
off1 type p,
hfeld(500) type c.
tables: soud.
*****MAIL END
select *
into table it_items
from vbap
where vbeln = p_vbeln.
if it_items[] is initial.
exit.
endif.
perform call_smartform.
*& Form call_smartform
text
--> p1 text
<-- p2 text
form call_smartform .
*DATA: lx_control_parameters TYPE SSFCTRLOP,
lx_OUTPUT_OPTIONS type SSFCOMPOP.
lx_OUTPUT_OPTIONS-TDIMMED = ' '.
lx_OUTPUT_OPTIONS-TDfinal = 'X'.
lx_OUTPUT_OPTIONS-TDDELETE = 'X'.
lx_CONTROL_PARAMETERS-NO_CLOSE = 'X'.
lx_CONTROL_PARAMETERS-NO_OPEN = ' '.
data: x_ssfcompop type ssfcompop,
x_ssfctrlop like ssfctrlop,
x_ssfcrescl type ssfcrescl.
**MAIL
g_cont_par-langu = sy-langu.
g_cont_par-no_dialog = 'X'.
g_cont_par-getotf = 'X'.
g_cont_par-device = 'MAIL'.
Get BOR-Objects for Recipient, Sender und Applikation
perform mail_recipient_object changing g_mail_rec_obj.
perform mail_sender_object changing g_mail_sen_obj.
perform mail_appl_object changing g_mail_app_obj.
**MAIL
*--Internal table is having more than 1 record
if v_tot_lines gt 1.
if v_sy_tabix = 1.
*--For first record of table
x_ssfctrlop-no_open = c_space.
x_ssfctrlop-no_close = c_x.
elseif v_sy_tabix = v_tot_lines.
*--For last record of table
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_space.
else.
x_ssfctrlop-no_open = c_x.
x_ssfctrlop-no_close = c_x.
endif.
endif.
IF r_previ = c_x.
x_ssfctrlop-preview = c_x.
x_ssfctrlop-getotf = c_x.
ENDIF.
call function 'SSF_FUNCTION_MODULE_NAME'
exporting
formname = 'YSSN_SMARTFORM'
VARIANT = ' '
DIRECT_CALL = ' '
importing
fm_name = v_fm_name
EXCEPTIONS
NO_FORM = 1
NO_FUNCTION_MODULE = 2
OTHERS = 3
if sy-subrc <> 0.
message i000 with 'Smart form module name failure'.
exit.
endif.
CALL FUNCTION '/1BCDWB/SF00000199'
call function v_fm_name
exporting
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
control_parameters = g_cont_par
mail_appl_obj = g_mail_app_obj
mail_recipient = g_mail_rec_obj
mail_sender = g_mail_sen_obj
OUTPUT_OPTIONS = lx_OUTPUT_OPTIONS
USER_SETTINGS = 'X'
t_vbap = it_items
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = job_output_info
JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
perform send_pdf_mail.
endform. " call_smartform
*& Form send_pdf_mail
text
--> p1 text
<-- p2 text
form send_pdf_mail .
data ld_binfile type xstring.
pdf_table type rcl_bag_tline,
data: ld_originator like soos1-recextnam.
convert form
loop at job_output_info-otfdata into hotfdata.
append hotfdata.
endloop.
call function 'CONVERT_OTF'
exporting
format = format_pdf
max_linewidth = 132
importing
bin_filesize = doc_size
bin_file = ld_binfile
tables
otf = output_data-otfdata
lines = htline
exceptions
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
others = 4.
*-Itab 134 Zeichen nach 255 Zeichen überführen
describe table htline lines hltlines.
describe field htline length fle1 in character mode.
describe field x_objcont length fle2 in character mode.
loop at htline.
htabix = sy-tabix.
move htline to hfeld+off1.
if htabix = hltlines.
fle1 = strlen( htline ).
endif.
off1 = off1 + fle1.
if off1 ge fle2.
clear x_objcont.
x_objcont = hfeld(fle2).
append x_objcont.
shift hfeld by fle2 places.
off1 = off1 - fle2.
endif.
if htabix = hltlines.
if off1 gt 0.
clear x_objcont.
x_objcont = hfeld(off1).
append x_objcont.
endif.
endif.
endloop.
x_object_hd_change-objnam = 'EMAIL'.
x_object_hd_change-objdes = 'Smart Form'.
x_object_hd_change-objla = sy-langu.
x_object_hd_change-objsns = 'O'.
x_object_hd_change-objlen = doc_size.
x_object_hd_change-file_ext = 'TXT'.
ld_packing_list-transf_bin = 'X'.
ld_packing_list-head_start = 1.
ld_packing_list-head_num = 0.
ld_packing_list-body_start = 1.
describe table x_objcont lines ld_packing_list-body_num.
ld_packing_list-objtp = 'EXT'.
ld_packing_list-objdes = 'Smart Form'.
ld_packing_list-objla = sy-langu.
ld_packing_list-objlen = doc_size.
ld_packing_list-file_ext = 'PDF'.
append ld_packing_list.
x_receivers-recextnam = g_mail.
x_receivers-recesc = 'E'.
x_receivers-sndart = 'INT'.
append x_receivers.
ld_originator = '[email protected]'.
ld_originator = FSABE-USRNAM.
call function 'SO_OBJECT_SEND'
exporting
object_hd_change = x_object_hd_change
object_type = 'RAW'
originator_type = 'B' "Einfügen
originator = ld_originator "Einfügen
tables
objcont = ld_text
receivers = x_receivers
packing_list = ld_packing_list
att_cont = x_objcont
att_head = x_objhead
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
x_error = 20
others = 21.
endform. " send_pdf_mail
*& Form mail_sender_object
text
<--P_G_MAIL_SEN_OBJ text
form mail_sender_object changing p_mail_sen_obj.
call function 'CREATE_SENDER_OBJECT_PPF'
exporting
ip_sender = sy-uname
importing
ep_sender_id = p_mail_sen_obj
exceptions
invalid_sender = 1
others = 2.
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. " mail_sender_object
*& Form mail_appl_object
text
<--P_G_MAIL_APP_OBJ text
form mail_appl_object changing p_mail_app_obj.
SELECT * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
ENDSELECT.
IF sy-subrc NE 0.
call function 'SO_USER_AUTOMATIC_INSERT'
exporting
sapname = sy-uname
exceptions
no_insert = 1
sap_name_exist = 2
x_error = 3
others = 4.
if sy-subrc ne 0.
clear soud.
else.
select * from soud where sapnam like sy-uname and deleted = ' '.
endselect.
endif.
ENDIF.
clear sofmfol_key.
sofmfol_key-type = 'FOL'.
sofmfol_key-year = soud-inbyr.
sofmfol_key-number = soud-inbno.
bor_key = sofmfol_key.
if not bor_key is initial.
swc_create_object folder 'SOFMFOL' bor_key.
if sy-subrc = 0.
swc_object_to_persistent folder p_mail_app_obj.
if sy-subrc ne 0.
clear p_mail_app_obj.
endif.
endif.
else.
clear p_mail_app_obj.
endif.
endform. " mail_appl_object
*& Form mail_recipient_object
text
<--P_G_MAIL_REC_OBJ text
form mail_recipient_object changing p_mail_rec_obj.
call function 'CREATE_RECIPIENT_OBJ_PPF'
exporting
IP_COUNTRY =
IP_FAXNO =
ip_mailaddr = g_mail
ip_type_id = g_rectype " 'U'
importing
ep_recipient_id = p_mail_rec_obj
EP_ADDRESS =
ET_RECIPIENT =
exceptions
invalid_recipient = 1
others = 2.
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. " mail_recipient_object
I hope this code should definitely work and helps you a lot.
Do reward me if it helps you.
Cheers,
Sampath -
Reg: sending smartform output as PDF attachment
hii all,
i am using 'SX_OBJECT_CONVERT_OTF_PDF' func. module to convert my otf data to pdf and using the func. module 'SO_NEW_DOCUMENT_ATT_SEND_API1' for sending the mail with the PDF attachment. I am able to send the mail and i can see the mail attachment in my out box of business work place..i can open the attachment and read it. but after i sent the mail to other e-mail if i open the document..it is showing as the attachment file is corrupted and i am unable to read it.
can any one help me on this.
Edited by: sandeep akella on Dec 13, 2008 9:54 AM* Transfer the 132-long strings to 255-long strings
LOOP AT gt_pdf_output INTO wa_pdf_output.
TRANSLATE wa_pdf_output USING '~'.
CONCATENATE v_buffer wa_pdf_output INTO v_buffer.
ENDLOOP.
* TO CONVERT THE DATA INTO PDF FORMAT
TRANSLATE v_buffer USING '~'.
CLEAR : wa_messg_att,
gt_messg_att.
DO.
wa_messg_att = v_buffer.
APPEND wa_messg_att TO gt_messg_att.
SHIFT v_buffer LEFT BY 255 PLACES.
IF v_buffer IS INITIAL.
EXIT.
ENDIF.
CLEAR wa_messg_att.
ENDDO.
For the body of the email message, pass doc type as RAW
for the PDF attachment pass doc type as PDF
So the internal table for Packing List
* Describe the body of the message
lwa_packing_list-transf_bin = space.
lwa_packing_list-head_start = 1.
lwa_packing_list-head_num = 0.
lwa_packing_list-body_start = 1.
DESCRIBE TABLE gt_messg_body LINES lwa_packing_list-body_num.
lwa_packing_list-doc_type = 'RAW'.
APPEND lwa_packing_list TO lgt_packing_list.
CLEAR lwa_packing_list.
* Create attachment notification
lwa_packing_list-transf_bin = 'X'.
lwa_packing_list-head_start = 1.
lwa_packing_list-head_num = 1.
lwa_packing_list-body_start = 1.
DESCRIBE TABLE gt_messg_att LINES lwa_packing_list-body_num.
lwa_packing_list-doc_type = 'PDF'.
lwa_packing_list-doc_size = lwa_packing_list-body_num * 255.
APPEND lwa_packing_list TO lgt_packing_list. -
Sending Smartform output as a body of the mail not as the attachement
Hi All,
my requirement is like this...
I need to send a smartform output as the body of a mail. and not as the attachment.
Hope you got my question
Regards
RaghuHi,
I hope the following links might help you,
Smartform output as Email.
Smartform to PDF and e_mail? Urgent
Regards,
Hema.
Reward points if it is useful. -
Error opening PDF attachment (via email)
Hello,
I've problems to send a PDF file with the function:
'SO_DOCUMENT_SEND_API1'
At first a small overview of my process:
- 'SCMS_DOC_READ' -> to read the file from the archive
- 'SCMS_BINARY_TO_FTEXT' -> to convert from bin. to pdf
- 'SO_DOCUMENT_SEND_API1' -> to send the email
My pdf result:
% P D F - 1 . 4 % â ã Ï Ó 1 0 o b j < < / T y p e
Project scope:
%PDF-1.4%âãÏÓ1 0 obj<</Type
As a result, by opening the PDF file an error occured.
Further information:
objpack-transf_bin = 'X'.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = doc_data
put_in_outbox = ''
commit_work = 'X'
tables
packing_list = objpack
object_header = objhead
contents_bin = data <- PDF content
contents_txt = objtxt
receivers = reclist
exceptionsmost possible reason has been discussed in:
Error in opening PDF attachment -
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 PMRahim,
in the FM, SO_NEW_DOCUMENT_ATT_SEND_API1 give COMMIT_WORK = 'X'.
The following code works for me. Try this.
* START-OF-SELECTION EVENT *
START-OF-SELECTION.
*" Read the HFA records into internal table............................
SELECT *
FROM zhfa
INTO TABLE t_zhfa
WHERE zz_vin6 IN s_vin6.
IF sy-subrc NE 0.
MESSAGE text-002 TYPE 'W'.
ENDIF. " IF SY-SUBRC NE 0
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'YH1145_HFA1'
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = w_name
EXCEPTIONS
no_form = 1
no_function_module = 2.
w_control-getotf = 'X'.
w_control-no_dialog = 'X'.
w_output-tdnoprev = 'X'.
LOOP AT t_zhfa INTO fs_zhfa.
CALL FUNCTION '/1BCDWB/SF00000457'
EXPORTING
* ARCHIVE_INDEX = ARCHIVE_INDEX
* ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB
* ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS
control_parameters = w_control
* MAIL_APPL_OBJ = MAIL_APPL_OBJ
* MAIL_RECIPIENT = MAIL_RECIPIENT
* MAIL_SENDER = MAIL_SENDER
output_options = w_output
user_settings = 'X'
fs_zhfa = fs_zhfa
IMPORTING
* DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO
job_output_info = w_return
* JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4.
*" w_return-otfdata holds the smartform OTF data.................
append lines of w_return-otfdata to t_otf.
ENDLOOP.
*" t_otf is the OTF data.........................................
*" t_line is the PDF data.......................................
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
* ASCII_BIDI_VIS2LOG = ' '
* PDF_DELETE_OTFTAB = ' '
IMPORTING
bin_filesize = w_filesize
* BIN_FILE = BIN_FILE
TABLES
otf = t_otf
lines = t_line
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4.
LOOP AT t_line.
CONCATENATE w_string t_line INTO w_string.
ENDLOOP.
*" convert the 132 line character to 255 character ..................
DO.
t_attach = w_string.
APPEND t_attach.
SHIFT w_string LEFT BY 255 PLACES.
IF w_string IS INITIAL.
EXIT.
ENDIF.
ENDDO.
t_objbin[] = t_attach[].
*" body of the mail..................................................
CLEAR t_message. REFRESH t_message.
t_message = 'This is a mail from SAP ECC6'.
APPEND t_message.
t_message = 'Thanks and Regards'.
APPEND t_message.
t_message = 'Indu'.
APPEND t_message.
DESCRIBE TABLE t_message LINES w_msg.
w_docdata-obj_name = 'SAPRPT'.
w_docdata-expiry_dat = sy-datum + 10.
w_docdata-obj_descr = 'Smartform mail from Indu'.
w_docdata-sensitivty = 'F'.
w_docdata-doc_size = w_msg * 255.
w_docdata-obj_langu = sy-langu .
*" type of the mail send: packing_list.........................
CLEAR t_packing_list. REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
t_packing_list-body_num = w_msg.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
t_packing_list-transf_bin = 'X'.
DESCRIBE TABLE t_objbin LINES w_objbin.
*" doc_size = (lines in pdf table) * 255......................
t_packing_list-doc_size = w_objbin * 255.
t_packing_list-body_num = w_objbin.
t_packing_list-doc_type = 'PDF'.
t_packing_list-obj_name = 'smart'.
t_packing_list-obj_descr = 'test'.
APPEND t_packing_list.
CLEAR t_receivers.
t_receivers-receiver = '<email id>'.
t_receivers-rec_type = 'U'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_docdata
put_in_outbox = 'X'
sender_address = sender
* SENDER_ADDRESS_TYPE = 'B'
commit_work = 'X'
* IMPORTING
* SENT_TO_ALL = SENT_TO_ALL
* NEW_OBJECT_ID = NEW_OBJECT_ID
* SENDER_ID = SENDER_ID
TABLES
packing_list = t_packing_list
* OBJECT_HEADER = OBJECT_HEADER
contents_bin = t_objbin
contents_txt = t_message
* CONTENTS_HEX = CONTENTS_HEX
* OBJECT_PARA = OBJECT_PARA
* OBJECT_PARB = OBJECT_PARB
receivers = t_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.
IF sy-subrc NE 0.
WRITE:/ 'Error When Sending the File', sy-subrc.
ELSE.
WRITE:/ 'Mail sent'.
ENDIF.
SUBMIT rsconn01 USING SELECTION-SET 'INT' AND RETURN.
CALL FUNCTION 'SO_DEQUEUE_UPDATE_LOCKS'.
ELSEIF p_fax EQ 'X'. -
Hi, im tring to use the SO_DOCUMENT_SEND_API1 FM to send a smartform output by mail. Im able to convert the smartform output to pdf and save it to teh hard drive and works great but when i try to send the pdf doc by mail it comes corrupted... can anyone help me on this... heres a piece of my code
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.
* Fehlerhandling
if sy-subrc <> 0.
endif.
******* I THINK THE ERROR MAYBE ON THIS PIECE OF CODE ************
loop at i_tline.
translate i_tline using ' ~'.
concatenate wa_buffer i_tline into wa_buffer.
endloop.
translate wa_buffer using '~ '.
do.
i_record = wa_buffer.
append i_record.
shift wa_buffer left by 255 places.
if wa_buffer is initial.
exit.
endif.
enddo.
***************** it message ****************************************
refresh it_message.
it_message = 'Em anexo vai a tabela interna de utilizadores '.
APPEND it_message.
it_message = 'Clique no link '.
APPEND it_message.
**************** Assunto do Email *****************
* Fill the document data and get size of attachment
CLEAR w_doc_data.
DESCRIBE TABLE It_message LINES x.
READ TABLE It_message INDEX x.
w_doc_data-DOC_SIZE =
( x - 1 ) * 255 + STRLEN( It_message ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = 'ASSUNTO EMAIL'.
w_doc_data-sensitivty = 'F'.
************************ fim assunto email *********************
data linha type i.
data lv_cntl type i.
CLEAR t_attachment.
REFRESH t_attachment.
************************** Mensagem ******************
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
clear t_packing_list-transf_bin.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
describe table it_message lines t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
***************************-Filling the attch table with data *************************
CLEAR : L_TABLE_LINES.
* clear wa_objhead.
* loop at i_record.
t_attachment[] = i_tline[].
* append t_attachment.
* endloop.
* Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES L_TABLE_LINES.
t_packing_list-body_num = L_TABLE_LINES.
t_packing_list-obj_descr = 'output'.
t_packing_list-doc_type = 'BIN'.
t_packing_list-doc_size = L_TABLE_LINES * 255.
t_packing_list-obj_langu = sy-langu.
t_packing_list-obj_name = 'Teste'.
APPEND t_packing_list.
*************** Endereços de email dos destinatários *************************
CLEAR receivers.
REFRESH receivers.
receivers-receiver = '[email protected]'.
receivers-rec_type = 'U'.
receivers-com_type = 'INT'.
receivers-notif_del = 'X'.
receivers-EXPRESS = 'X'.
* receivers-notif_ndel = 'X'.
APPEND receivers.
************************Fim de email dos Dest. ******************************
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = w_doc_data
PUT_IN_OUTBOX = 'X'
* SENDER_ADDRESS = ld_sender_address
* SENDER_ADDRESS_TYPE = ld_sender_address_type
COMMIT_WORK = 'X'
IMPORTING
SENT_TO_ALL = w_sent_all
* NEW_OBJECT_ID =
* SENDER_ID =
TABLES
PACKING_LIST = t_packing_list
* OBJECT_HEADER = wa_objhead
CONTENTS_BIN = t_attachment
CONTENTS_TXT = it_message
* CONTENTS_HEX = contents_hex
* OBJECT_PARA =
* OBJECT_PARB =
RECEIVERS = 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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
wait up to 2 seconds.
if sy-subrc eq 0.
submit rsconn01 "with mode = 'INT'
*with output = 'X'
and return.
endif.Hi Joao,
Try using this code .
*& Report ZSPOOLTOPDF *
*& Converts spool request into PDF document and emails it to *
*& recipicant. *
*& Execution *
*& This program must be run as a background job in-order for the write *
*& commands to create a Spool request rather than be displayed on *
*& screen *
REPORT zspooltopdf.
PARAMETER: p_email1 LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_sender LIKE somlreci1-receiver
DEFAULT '[email protected]',
p_delspl AS CHECKBOX.
*DATA DECLARATION
DATA: gd_recsize TYPE i.
Spool IDs
TYPES: BEGIN OF t_tbtcp.
INCLUDE STRUCTURE tbtcp.
TYPES: END OF t_tbtcp.
DATA: it_tbtcp TYPE STANDARD TABLE OF t_tbtcp INITIAL SIZE 0,
wa_tbtcp TYPE t_tbtcp.
Job Runtime Parameters
DATA: gd_eventid LIKE tbtcm-eventid,
gd_eventparm LIKE tbtcm-eventparm,
gd_external_program_active LIKE tbtcm-xpgactive,
gd_jobcount LIKE tbtcm-jobcount,
gd_jobname LIKE tbtcm-jobname,
gd_stepcount LIKE tbtcm-stepcount,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: w_recsize TYPE i.
DATA: gd_subject LIKE sodocchgi1-obj_descr,
it_mess_bod LIKE solisti1 OCCURS 0 WITH HEADER LINE,
it_mess_att 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.
Spool to PDF conversions
DATA: gd_spool_nr LIKE tsp01-rqident,
gd_destination LIKE rlgrap-filename,
gd_bytecount LIKE tst01-dsize,
gd_buffer TYPE string.
Binary store for PDF
DATA: BEGIN OF it_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF it_pdf_output.
CONSTANTS: c_dev LIKE sy-sysid VALUE 'DEV',
c_no(1) TYPE c VALUE ' ',
c_device(4) TYPE c VALUE 'LOCL'.
*START-OF-SELECTION.
START-OF-SELECTION.
Write statement to represent report output. Spool request is created
if write statement is executed in background. This could also be an
ALV grid which would be converted to PDF without any extra effort
WRITE 'Hello World'.
new-page.
commit work.
new-page print off.
IF sy-batch EQ 'X'.
PERFORM get_job_details.
PERFORM obtain_spool_id.
Alternative way could be to submit another program and store spool
id into memory, will be stored in sy-spono.
*submit ZSPOOLTOPDF2
to sap-spool
spool parameters %_print
archive parameters %_print
without spool dynpro
and return.
Get spool id from program called above
IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.
PERFORM convert_spool_to_pdf.
PERFORM process_email.
if p_delspl EQ 'X'.
PERFORM delete_spool.
endif.
IF sy-sysid = c_dev.
wait up to 5 seconds.
SUBMIT rsconn01 WITH mode = 'INT'
WITH output = 'X'
AND RETURN.
ENDIF.
ELSE.
SKIP.
WRITE:/ 'Program must be executed in background in-order for spool',
'request to be created.'.
ENDIF.
FORM obtain_spool_id *
FORM obtain_spool_id.
CHECK NOT ( gd_jobname IS INITIAL ).
CHECK NOT ( gd_jobcount IS INITIAL ).
SELECT * FROM tbtcp
INTO TABLE it_tbtcp
WHERE jobname = gd_jobname
AND jobcount = gd_jobcount
AND stepcount = gd_stepcount
AND listident <> '0000000000'
ORDER BY jobname
jobcount
stepcount.
READ TABLE it_tbtcp INTO wa_tbtcp INDEX 1.
IF sy-subrc = 0.
message s004(zdd) with gd_spool_nr.
gd_spool_nr = wa_tbtcp-listident.
MESSAGE s004(zdd) WITH gd_spool_nr.
ELSE.
MESSAGE s005(zdd).
ENDIF.
ENDFORM.
FORM get_job_details *
FORM get_job_details.
Get current job details
CALL FUNCTION 'GET_JOB_RUNTIME_INFO'
IMPORTING
eventid = gd_eventid
eventparm = gd_eventparm
external_program_active = gd_external_program_active
jobcount = gd_jobcount
jobname = gd_jobname
stepcount = gd_stepcount
EXCEPTIONS
no_runtime_info = 1
OTHERS = 2.
ENDFORM.
FORM convert_spool_to_pdf *
FORM convert_spool_to_pdf.
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = gd_spool_nr
no_dialog = c_no
dst_device = c_device
IMPORTING
pdf_bytecount = gd_bytecount
TABLES
pdf = it_pdf_output
EXCEPTIONS
err_no_abap_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_destdevice = 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.
CHECK sy-subrc = 0.
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.
ENDFORM.
FORM process_email *
FORM process_email.
DESCRIBE TABLE it_mess_att LINES gd_recsize.
CHECK gd_recsize > 0.
PERFORM send_email USING p_email1.
perform send_email using p_email2.
ENDFORM.
FORM send_email *
--> p_email *
FORM send_email USING p_email.
CHECK NOT ( p_email IS INITIAL ).
REFRESH it_mess_bod.
Default subject matter
gd_subject = 'Subject'.
gd_attachment_desc = 'Attachname'.
CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.
it_mess_bod = 'Message Body text, line 1'.
APPEND it_mess_bod.
it_mess_bod = 'Message Body text, line 2...'.
APPEND it_mess_bod.
If no sender specified - default blank
IF p_sender EQ space.
gd_sender_type = space.
ELSE.
gd_sender_type = 'INT'.
ENDIF.
Send file by email as .xls speadsheet
PERFORM send_file_as_email_attachment
tables it_mess_bod
it_mess_att
using p_email
'Example .xls documnet attachment'
'PDF'
gd_attachment_name
gd_attachment_desc
p_sender
gd_sender_type
changing gd_error
gd_reciever.
ENDFORM.
FORM delete_spool *
FORM delete_spool.
DATA: ld_spool_nr TYPE tsp01_sp0r-rqid_char.
ld_spool_nr = gd_spool_nr.
CHECK p_delspl <> c_no.
CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'
EXPORTING
spoolid = ld_spool_nr.
ENDFORM.
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
Send email
FORM send_file_as_email_attachment tables it_message
it_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription
p_sender_address
p_sender_addres_type
changing p_error
p_reciever.
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 ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
data: t_packing_list like sopcklsti1 occurs 0 with header line,
t_contents like solisti1 occurs 0 with header line,
t_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,
w_sent_all(1) type c,
w_doc_data like sodocchgi1.
ld_email = p_email.
ld_mtitle = p_mtitle.
ld_format = p_format.
ld_attdescription = p_attdescription.
ld_attfilename = p_filename.
ld_sender_address = p_sender_address.
ld_sender_address_type = p_sender_addres_type.
Fill the document data.
w_doc_data-doc_size = 1.
Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
Fill the document data and get size of attachment
CLEAR w_doc_data.
READ TABLE it_attach INDEX w_cnt.
w_doc_data-doc_size =
( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'SAPRPT'.
w_doc_data-obj_descr = ld_mtitle.
w_doc_data-sensitivty = 'F'.
CLEAR t_attachment.
REFRESH t_attachment.
t_attachment[] = it_attach[].
Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
Create attachment notification
t_packing_list-transf_bin = 'X'.
t_packing_list-head_start = 1.
t_packing_list-head_num = 1.
t_packing_list-body_start = 1.
DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
t_packing_list-doc_type = ld_format.
t_packing_list-obj_descr = ld_attdescription.
t_packing_list-obj_name = ld_attfilename.
t_packing_list-doc_size = t_packing_list-body_num * 255.
APPEND t_packing_list.
Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
t_receivers-receiver = ld_email.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
contents_bin = t_attachment
contents_txt = it_message
receivers = t_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.
Populate zerror return code
ld_error = sy-subrc.
Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
ENDFORM.
Hope this resolves your query.
Reward all the helpful answers.
Regards -
Error opening PDF downloaded from Interactive Report
hi -- I'm getting an error opening a PDF file downloaded from an interactive report.
I've seen on the forum that this could be related to the size of the file, but I've tried
this out on 10-row results (1k files) and it's still an issue.
I save the file to my file system. If I try to open it in Adobe Reader, I get:
File does not begin with '%PDF-'
and
Adobe Reader could not open <filename>.pdf because it is either not a supported
file type or because the file has been damaged (for example, it was sent as an email
attachment and wasn't correctly decoded).
If I try to open in Internet Explorer, I get:
File does not begin with '%PDF-'
Other users are having the same problem. Download to csv and open in Excel works fine.
Do I need to have special print attributes for this? I didn't think so... I'm just using the defaults
(response header = report settings, content disposition = attachment).
Ideas?
Thanks,
CarolHi,
I'm having the same problem that was described above, and my site does have BI Publisher installed, and it does successfully produce readable pdfs for many reports.
But there are other reports, even reports produced using the Apex Wizard and all defaults, that just keep producing the same Adobe Reader error reported above, ie
"Adobe Reader could not open <filename>.pdf because it is either not a supported
file type or because the file has been damaged (for example, it was sent as an email
attachment and wasn't correctly decoded)."
Any suggestions?
Cheers,
Peter -
Error opening pdf and file can't be found,why
I received an attachment in my BT emails and opened it,then printed it.When I tried to find it so I could copy it to my Outlook emails it had disappeared. Adobe said there had been an error opening it and the file could not be found.What happened and why?
HacienI described what had happened when I tried to view a pdf, and said that when I found the pdf and tried to open it again, all I had was a message telling me there had been “an error” and as a result the file could not be found. I don’t know if it was hidden or deleted and asked “why did it happen”
If Adobe does not give me any more information than that, how am I supposed to give any more information?
It was the first time I had used the Adobe reader, and I was not expecting someone to be so terse in their reply to my query. As the song says, “Everybody’s got to learn some-time.” It would be easier if the ones who DO know could remember the time when they didn’t know.
To avoid further embarrassment, I will withdraw and not attempt to use your forum again.
Maybe you are looking for
-
Spry dataset is not working properly in IE8, Help me plz...
I am a new user of dreamweaver CS5. I have designed some pages which are using Spry Dataset. It is working perfect in Firefox and IE 7 but it was not working at all in IE 8. Ben asked me to paste the following into the <HEAD> section <meta http-equiv
-
Which headphones with 3.5 mm jack is the best?
Hello could you help me? I need a headphones for mobile, with 3.5 mm jack. You know I have a Sony NWZ-B142F 2GB but it's headphones has been damaged. I really liked them. could you tell me what is the model of that headphones? or could you suggest me
-
Hi all, i would like to send data from BW to XI using RFC adapter. so far i have created a RFC destination and RFC Communication channel in ID with consistent program id.I have created a process chain in BW to execute the infopackage and call an ABAP
-
Problem executing external command in OS400
Hi, When i try to run an external os command from SM49, i am getting the following message, but ideally the message should display, job has been sent. Can anyone one help this out. Command executed: sbmjob : CMD(CALL PGM(SEAEDIPGM/EDISLCCL)) JO
-
Can't insert to a table which has a trigger uses distributed transaction.
Hello! I'm using Oracle 8.1.6 and ODBC driver 8.01.0500. The trigger selects some data from an other Oracle database using database link. If I insert into this table with ODBC (from Access or from Oracle ODBC test app), I get an oracle error about PL