2011 Feb 09 7:32 AM
Hi all,
I would like to send a sapscript per mail as PDF attachment. I checked on the forum and followed some threads for that, but I still have a problem :
- I'm using the open_form function with ITCPO-TDGETOTF = 'X'
- in the CLOSE_FORM i get the OTF data in the internal table it_otf
CALL FUNCTION 'CLOSE_FORM'
TABLES
OTFDATA = it_otf
- than I'm using the function: (it_otf as input it_pdf as output table):
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
PDF_DELETE_OTFTAB = 'X'
IMPORTING
BIN_FILESIZE = W_bin_filesize
BIN_FILE = g_binfile
TABLES
OTF = it_otf
LINES = it_pdf
this function dumps with the message : "*255" nicht als Zahl interpretierbar
what' wrong ?
thank you in advance for your help.
2011 Feb 09 7:52 AM
Hi,
Write as below ...
*data : lit_tline TYPE TABLE OF tline WITH HEADER LINE. " <-- declaration*
lit_record LIKE solisti1 OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = dl_len_in
TABLES
otf = lit_otf
lines = lit_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
***---Convert 132 to length 255
LOOP AT lit_tline INTO lwa_tline.
dl_pos = 255 - dl_len.
IF dl_pos > 134. "length of pdf_table
dl_pos = 134.
ENDIF.
lwa_record+dl_len = lwa_tline(dl_pos).
dl_len = dl_len + dl_pos.
IF dl_len = 255.
APPEND lwa_record TO lit_record.
CLEAR: lit_record, dl_len.
IF dl_pos < 134.
lwa_record = lwa_tline+dl_pos.
dl_len = 134 - dl_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF dl_len > 0.
APPEND lwa_record TO lit_record.
ENDIF.
***---Send Mail
PERFORM send_mail TABLES lit_record.
ENDIF.
Regards,
Srini.
2011 Feb 09 7:52 AM
Hi,
Write as below ...
*data : lit_tline TYPE TABLE OF tline WITH HEADER LINE. " <-- declaration*
lit_record LIKE solisti1 OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = dl_len_in
TABLES
otf = lit_otf
lines = lit_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5.
***---Convert 132 to length 255
LOOP AT lit_tline INTO lwa_tline.
dl_pos = 255 - dl_len.
IF dl_pos > 134. "length of pdf_table
dl_pos = 134.
ENDIF.
lwa_record+dl_len = lwa_tline(dl_pos).
dl_len = dl_len + dl_pos.
IF dl_len = 255.
APPEND lwa_record TO lit_record.
CLEAR: lit_record, dl_len.
IF dl_pos < 134.
lwa_record = lwa_tline+dl_pos.
dl_len = 134 - dl_pos.
ENDIF.
ENDIF.
ENDLOOP.
IF dl_len > 0.
APPEND lwa_record TO lit_record.
ENDIF.
***---Send Mail
PERFORM send_mail TABLES lit_record.
ENDIF.
Regards,
Srini.
2011 Feb 09 8:27 AM
Hi Srini,
thanks for your example it is very helpfull, but I still have some questions for the conversion from 123 to 255
In your example, you are using dl_len_in in the function module. In the loop you use dl_len... is it the same variable and if not where does it come from ?
In my cas I checked dl_len_in returned by the function and it contains 15796... therfor I do not understand the
"dl_pos = 255 - dl_len."... in my cqse I've a negative value.
Could you please clarify that for me ?
thank you very much
2011 Feb 09 9:25 AM
Hi,
dl_len and dl_len_in are 2 different fields.
dl_len will be initial.
Regards,
Srini.
2011 Feb 09 9:50 AM
Hi Fred,
Just uncomment the Importing statement in the "CONVERT_OTF" function module. Finally your PDF table will have the PDF data with 132 charaters which will be used to send the mail using the API function module.
Please review this and let me know in case if you face any problem in implementing this.
Regards,
SRinivas
2011 Feb 09 10:19 AM
Hi all,
thank you for your help. Finally I got the solution. I'll post it beelow maybe this can be helpfull for someone.
to send a sapscrpt by mail as a PDF attachment :
- in FUNCTION 'OPEN_FORM' the paraneter ITCPO-TDGETOTF from the options must be set to 'X'.
- in FUNCTION CLOSE_FORM get the form in an internal table :
CALL FUNCTION 'CLOSE_FORM'
TABLES
OTFDATA = it_otf
- convert the OTF file obtained in a PDF file :
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = W_bin_filesize
BIN_FILE = c_binfile
TABLES
OTF = it_otf
LINES = it_pdf
- change the HEX PDF file obtained in a binary PDF file (linewidth to 255) by calling the function :
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = c_binfile
TABLES
binary_tab = lt_solix.
- send the mail :
in the packing_list table you have to insert 2 lines : the 1st is for the text int the mail, the second is for the PDF as attachement :
describe table i_message lines it_packing_list-body_num.
it_packing_list-transf_bin = space.
it_packing_list-head_start = 1.
it_packing_list-head_num = 0.
it_packing_list-body_start = 1.
it_packing_list-doc_type = 'RAW'.
append it_packing_list.
clear it_packing_list.
it_packing_list-transf_bin = 'X'.
it_packing_list-head_start = 1.
it_packing_list-head_num = 1.
it_packing_list-body_start = 1.
DESCRIBE TABLE lt_solix LINES it_packing_list-body_num.
it_packing_list-doc_type = 'PDF'.
it_packing_list-obj_descr = 'test'.
it_packing_list-obj_name = 'test'.
it_packing_list-doc_size = it_packing_list-body_num * 255.
APPEND it_packing_list.
... don't forget the other paraneters...
and send the mail :
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = l_doc_data
PUT_IN_OUTBOX = 'X'
COMMIT_WORK = 'X'
TABLES
PACKING_LIST = it_packing_list
CONTENTS_HEX = lt_solix
RECEIVERS = it_receivers
I hope this helps...
2011 Apr 13 7:11 PM
Hi Fred,
Using the functions that you used, i can send the sapscript in a pdf attachments file in a e-mail, but a i have a problem the attachment file not have the same format that the sapscript, do you have the same problem ??
Thanks for your comments.
Noemi H
2011 Apr 14 6:29 AM
Hi Noemi,
what do you mean with "not the same format" ?. My PDF document looks like the sapscript...
2011 Apr 14 4:15 PM
Hi Fred !!!
When a generate the output the sapscript throught printer device, we can see the diferent kind of fonts, size, the output data in the right columns, and when convert the sapscript in pdf attached to the e-mail , i only can see ONE kind of fonts, the output de data are moved, not looks like sapscript =(
These are the the parameters that set to the call function open_form and the close form.
ITCPO-TDPAGESLCT = SPACE. "Todas las páginas
ITCPO-TDNEWID = 'X'. "Crear nuevo spool
ITCPO-TDCOPIES = 1. "Número de copias
ITCPO-TDDEST = 'LOCL'. "Nombre de la impresora
ITCPO-TDPREVIEW = SPACE. "No Preview
ITCPO-TDCOVER = SPACE. "No Portada
ITCPO-TDIMMED = 'X'. "Imprime inmediatamente
ITCPO-TDDELETE = 'X'. "Borra después de salir
ITCPO-TDGETOTF = 'X'.
ITCPO-TDSCRNPOS = '1'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
device = 'OTF_MEM'
dialog = 'X'
form = FORMULARIO
language = SY-LANGU
options = ITCPO
mail_sender = lw_sender
mail_recipient = lw_recipient
RAW_DATA_INTERFACE = '*'
EXCEPTIONS
canceled = 1
device = 2
form = 3
options = 4
unclosed = 5
OTHERS = 6.
CALL FUNCTION 'CLOSE_FORM'
TABLES
OTFDATA = TI_OTF
EXCEPTIONS
UNOPENED = 1
BAD_PAGEFORMAT_FOR_PRINT = 2
SEND_ERROR = 3
SPOOL_ERROR = 4
CODEPAGE = 5
OTHERS = 6.
I don´t know if this is for parameters in the functions or is other problem in the system.
Can you have any suggestion.
Thanks for your help !!!
Noemi
2011 Apr 15 7:14 AM
Hi Noemi,
I think your problem does not come from the options sent to the functions, but from the pdf converter itself and the font it uses.
I don't know how to handle this, but maybe you can take a look to this SAP report wich permits to handle TTF fonts for the PDF converter : RSTXPDF2UC
I hope this helps
2011 Apr 15 4:55 PM
Hi Fred,
Thanks for your help, i'm looking for information, about your recomentarions.
kind Regards 😃
Noemí H.
2013 Sep 23 4:40 PM
Hi Fred,
I'm with this issue and doing exactly what you said, but it is not working.
Below my code. Is it missing something?
1 - tb_otf is retrieving the correct values.
CALL FUNCTION 'CLOSE_FORM'
IMPORTING
RESULT = RESULT
tables
otfdata = tb_otf.
2 - c_binfile is populated correctly but nothing happens with table lt_otf
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
MAX_LINEWIDTH = 132
PDF_DELETE_OTFTAB = ' '
IMPORTING
BIN_FILESIZE = L_SIZE
BIN_FILE = c_binfile
TABLES
OTF = tb_otf
LINES = lt_otf.
3 - lt_solix is populated correctly
DATA : BEGIN OF lt_solix OCCURS 0,
line TYPE x LENGTH 255,
END OF lt_solix.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = c_binfile
TABLES
binary_tab = lt_solix.
4 - data packing all right
* E-mail body
CLEAR lt_packing_list.
REFRESH lt_packing_list.
lt_packing_list-transf_bin = ''.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = l_numbytes.
lt_packing_list-doc_type = 'RAW'.
lt_packing_list-obj_name = 'BODY'.
lt_packing_list-obj_descr = 'CORPO'.
lt_packing_list-doc_size = l_numbytes.
APPEND lt_packing_list.
* E-mail attachment
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 0.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = l_numbytes.
lt_packing_list-doc_type = 'PDF'.
lt_packing_list-obj_descr = nast-objky.
lt_packing_list-obj_name = 'PICTURE'.
lt_packing_list-doc_size = l_numbytes.
APPEND lt_packing_list.
5 - send e-mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_document_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = lt_packing_list
object_header = lt_object_header
* contents_bin = lt_objbin
contents_HEX = lt_solix
contents_txt = lt_contents_txt
receivers = lt_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.
When I check SOST transaction I see the e-mail but the body content I cant see and the attachment I cant open.
The same logic was working in version 5.0 (now we're in 6.0). But it was using content_bin parameter which is obsolete now, from now we need to use to content_hex parameter.
Please, could you help me?
Thanks
2011 Feb 09 10:18 AM
Hi Fred,
After getting the PDF output from FM 'CONVERT_OTF' you can convert line width to 255 using FM 'SX_TABLE_LINE_WIDTH_CHANGE'
DATA: BEGIN OF i_pdf_output OCCURS 0.
INCLUDE STRUCTURE tline.
DATA: END OF i_pdf_output,
i_binary_content_pdf_temp TYPE soli_tab,
i_binary_content_pdf TYPE solix_tab.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_src = 134
line_width_dst = 255
TABLES
content_in = i_pdf_output "<= Returned from FM 'CONVERT_OTF'
content_out = i_binary_content_pdf_temp
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
IF sy-subrc NE 0.
MESSAGE s000(0k) WITH 'Conversion Failed'.
EXIT.
ENDIF.
Also if you are using BCS for mailing, you can convert from soli to solix tab as below:
CALL METHOD cl_bcs_convert=>soli_to_solix
EXPORTING
it_soli = i_binary_content_pdf_temp
receiving
et_solix = i_binary_content_pdf.
2013 Jul 09 2:02 PM
Hello
I'm sending an email to my provider with the purchase order attached in PDF format from the tx ME22N.
Only now I have a detail that I can not solve: S.. I want to send a text like body in the mail, say for example: "I send the purchase order attached to this email for your review. Thanks" but I can not add this text
I'm using the functions:
ADDR_GET_NEXT_COMM_TYPE
CONVERT_COMM_TYPE_DATA
OPEN_FORM
thank you very much
2013 Jul 10 8:32 AM
Hi,
as fare as I know you d not need to program it. You can send your smartform as PDF just by doing the correct custimizing for the purchase order.
take a look at transaction code NACE
choose applicatiion EF for purchase orders / click on button output type
there you can find a mail tab to do the customizing + in the list on the left you can select Mail title / mail text in which you can also use some variables like "Purchase ordre no &EKKO-EBELN&" for the title.
In processing routings I think you have to create a medium 5 (external send)
I hope this helps
regards
2013 Jul 10 10:46 AM
Thank you very much for the reply, I'll look. Thank you.
Carol.