on 02-20-2007 1:16 PM
HI i want to know how script and smartforms will send to mail and pdf formates>?
code for smartform.
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 = 'ZZZ_TEST1'
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'
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.
Fehlerhandling
if sy-subrc <> 0.
endif.
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.
Attachment
refresh:
i_reclist,
i_objtxt,
i_objbin,
i_objpack.
clear wa_objhead.
i_objbin[] = i_record[].
Create Message Body
Title and Description
i_objtxt = 'test with pdf-Attachment!'.
append i_objtxt.
describe table i_objtxt lines v_lines_txt.
read table i_objtxt index v_lines_txt.
wa_doc_chng-obj_name = 'smartform'.
wa_doc_chng-expiry_dat = sy-datum + 10.
wa_doc_chng-obj_descr = 'smartform'.
wa_doc_chng-sensitivty = 'F'.
wa_doc_chng-doc_size = v_lines_txt * 255.
Main Text
wa_doc_chng-doc_size = ( v_lines_txt - 1 ) * 255 + strlen( i_objtxt )
*.
clear i_objpack-transf_bin.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
i_objpack-body_num = v_lines_txt.
i_objpack-doc_type = 'RAW'.
append i_objpack.
Attachment
(pdf-Attachment)
i_objpack-transf_bin = 'X'.
i_objpack-head_start = 1.
i_objpack-head_num = 0.
i_objpack-body_start = 1.
Länge des Attachment ermitteln
describe table i_objbin lines v_lines_bin.
read table i_objbin index v_lines_bin.
i_objpack-doc_size = v_lines_bin * 255 .
i_objpack-body_num = v_lines_bin.
i_objpack-doc_type = 'PDF'.
i_objpack-obj_name = 'smart'.
i_objpack-obj_descr = 'test'.
append i_objpack.
clear i_reclist.
i_reclist-receiver = 'urmailid@mailserver.com'.
i_reclist-rec_type = 'U'.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes,
it is very much possible but u have to send it as string data appending each line explicitly.
for ur convinien im check the following code
FORM send_log_mail .
Local Constants
CONSTANTS: lc_raw(3) TYPE c VALUE 'RAW'. "Docuement Type
Creating the document to be sent with error message.
IF gt_error IS NOT INITIAL.
gs_doc_chng-obj_name = 'Error Price'(002).
gs_doc_chng-obj_descr =
'Material Standard Price Updation Errors'(003).
Mail Content
gs_objtxt = text-009.
APPEND gs_objtxt TO gt_objtxt.
gs_objtxt = text-020.
APPEND gs_objtxt TO gt_objtxt.
CLEAR gs_objtxt.
APPEND gs_objtxt TO gt_objtxt.
Error message Heading
CONCATENATE text-022 "Material
text-024 "Error Message
INTO gs_objtxt.
APPEND gs_objtxt TO gt_objtxt.
gs_objtxt = text-021. "under line in mail
APPEND gs_objtxt TO gt_objtxt.
LOOP AT gt_error INTO gs_error.
Remove leading zero's for Material
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = gs_error-matnr
IMPORTING
output = gs_error-matnr.
Genearte the error text
gs_objtxt = gs_error-matnr.
gs_objtxt+27 = gs_error-msg.
APPEND gs_objtxt TO gt_objtxt.
ENDLOOP.
ENDIF.
Add the Content to the E-mail
DESCRIBE TABLE gt_objtxt LINES gv_tab_lines.
READ TABLE gt_objtxt INTO gs_objtxt INDEX gv_tab_lines.
gs_doc_chng-doc_size =
( gv_tab_lines - 1 ) * 255 + STRLEN( gs_objtxt ).
Check for Internet Address or Distribution List
IF p_dlist IS NOT INITIAL.
SEARCH p_dlist FOR gc_at.
IF sy-subrc EQ 0.
gs_reclist-rec_type = gc_u.
ELSE.
gs_reclist-rec_type = gc_c.
ENDIF.
gs_reclist-receiver = p_dlist.
APPEND gs_reclist TO gt_reclist.
ENDIF.
Call the function module to send the mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
document_type = lc_raw
document_data = gs_doc_chng
put_in_outbox = gc_x
commit_work = gc_x
TABLES
object_header = gt_objhead
object_content = gt_objtxt
receivers = gt_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
CASE sy-subrc.
WHEN 0.
SKIP.
FORMAT COLOR 3 ON.
WRITE:/ 'Mail has been sent successfully to below mentioned IDs:->'(005)
.
FORMAT COLOR 3 OFF.
WRITE:/ p_dlist.
WRITE:/ sy-uname.
WHEN 1.
WRITE: / 'Too many receivers specified !'(017).
WHEN 2.
WRITE: / 'No receiver got the document !'(018).
WHEN 4.
WRITE: / 'Missing send authority !'(016).
WHEN OTHERS.
WRITE: / 'Unexpected error occurred !'(019).
ENDCASE.
Message was edited by:
Durgaprasad Kare
Dear Anees ,
Pleas pass on the parameter in itcpo - (getotf ) structure while calling OPEN_FORM as 'X' .
I have answered it in detail in your earlier post .
also giving below sample program for sending SAPSCRIPT as PDFattachment in email :
REPORT zsapscript_pdf_via_mail MESSAGE-ID zvele LINE-SIZE 68
NO STANDARD PAGE HEADING.
TABLES: itcpo.
Open your usual sapscript specifying that the output will be OTF
itcpo-tdgetotf = 'X'.
CALL FUNCTION 'OPEN_FORM'
EXPORTING
device = 'PRINTER'
dialog = ''
form = '............'
language = sy-langu
options = itcpo
EXCEPTIONS
canceled = 1
device = 2
form = 3
options = 4
unclosed = 5
OTHERS = 6.
CALL FUNCTION 'WRITE_FORM'
EXPORTING
window = '............'
element = '............'
EXCEPTIONS
window = 1
element = 2.
DATA: BEGIN OF t_otfdata OCCURS 0.
INCLUDE STRUCTURE itcoo.
DATA: END OF t_otfdata.
Closing the Sapscript, we save data (OTF) in a table
CALL FUNCTION 'CLOSE_FORM'
TABLES
otfdata = t_otfdata
EXCEPTIONS
unopened = 1
bad_pageformat_for_print = 2
send_error = 3
spool_error = 4
OTHERS = 5.
DATA: len_in LIKE sood-objlen,
len_out LIKE sood-objlen.
DATA: BEGIN OF t_pdfdata OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA: END OF t_pdfdata.
DATA: BEGIN OF t_otfdata2 OCCURS 0.
INCLUDE STRUCTURE solisti1.
DATA: END OF t_otfdata2.
Move OTF data to another table with lenght 255
LOOP AT t_otfdata.
CONCATENATE t_otfdata-tdprintcom t_otfdata-tdprintpar INTO t_otfdata2.
APPEND t_otfdata2.
ENDLOOP.
Convert OTF format to PDF
CALL FUNCTION 'SX_OBJECT_CONVERT_OTF_PDF'
EXPORTING
format_src = 'OTF'
format_dst = 'PDF'
devtype = 'PRINTER'
FUNCPARA =
len_in = len_in
IMPORTING
len_out = len_out
TABLES
content_in = t_otfdata2
content_out = t_pdfdata
EXCEPTIONS
err_conv_failed = 1
OTHERS = 2.
Download on local directory
*CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = len_out
FILENAME = 'c:\test.pdf'
FILETYPE = 'BIN'
TABLES
data_tab = t_pdfdata.
Mail settings
DATA: objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINe.
DATA: doc_chng LIKE sodocchgi1.
DATA righe_attachment TYPE i.
DATA righe_testo TYPE i.
DATA z_email(80) TYPE c.
Receivers parameters
SELECT-OPTIONS: s_email FOR z_email LOWER CASE NO INTERVALS.
PARAMETERS rec_type LIKE reclist-rec_type
DEFAULT 'U'. " type of sending address
CLEAR: reclist, reclist[],
objhead, objhead[],
objtxt, objtxt[],
objbin, objbin[],
objpack, objpack[].
Attachment filling
LOOP AT t_pdfdata.
objbin-line = t_pdfdata.
APPEND objbin.
ENDLOOP.
DESCRIBE TABLE objbin LINES righe_attachment.
Text filling
objtxt = 'Testo della Mail - Riga 1'.APPEND objtxt.
objtxt = 'Testo della Mail - Riga 2'.APPEND objtxt.
objtxt = 'Testo della Mail - Riga n'.APPEND objtxt.
DESCRIBE TABLE objtxt LINES righe_testo.
Other filling
doc_chng-obj_name = 'URGENT'.
doc_chng-expiry_dat = sy-datum + 10.
doc_chng-obj_descr = 'Prova invio Mail con PDF'.
doc_chng-sensitivty = 'O'.
doc_chng-doc_size = righe_testo * 255.
CLEAR objpack-transf_bin.
objpack-head_start = 1.
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = righe_testo.
objpack-doc_type = 'RAW'.
APPEND objpack.
objpack-transf_bin = 'X'.
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = righe_attachment.
objpack-doc_type = 'PDF'.
objpack-obj_name = 'TEST'.
objpack-obj_descr = 'File.pdf'.
objpack-doc_size = righe_attachment * 255.
APPEND objpack.
Receivers filling
LOOP AT s_email WHERE sign = 'I'
AND option = 'EQ'
AND NOT ( low IS initial ).
CLEAR reclist.
IF sy-tabix > 1.
reclist-copy = 'X'.
ENDIF.
reclist-receiver = s_email-low.
IF rec_type IS INITIAL.
reclist-rec_type = 'U'. " Internet e-mail
ELSE.
reclist-rec_type = rec_type.
ENDIF.
reclist-notif_del = 'X'. " request delivery notification
reclist-notif_ndel = 'X'. " request not delivered notification
APPEND reclist.
ENDLOOP.
Mail Send
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
OBJECT_PARA =
OBJECT_PARB =
receivers = reclist
CONTENTS_HEX =
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
You can create a PDF document out of a Smartform.
1. Get the OTF form data in OTF table by activating the flag in SSFCTRLOP - "Smart Forms: Control structure". You get the Form data in import parameter - JOB_OUTPUT_INFO-OTFDATA.
2. Convert this OTFData into PDF data by FM " CONVERT_OTF_2_PDF ".
3. Download the PDF converted data into the local PC by FM " WS_DOWNLOAD / DOWNLOAD ".
4. You can open the downloaded file by using FM " WS_EXECUTE ".
<b>Sending PDF document as an attachment by mail:</b>
You have to create variables/structure/table of the following type.
1) Data of an object which can be changed.
2) Description of Imported Object Components.
3) Single List with Column Length 255.
4) Structure of the API Recipient List.
When the data is converted into the PDF format from OTF (Function Module Convert_OTF), it is stored in an internal table, which has a similar structure as Text Lines (TLINE). Let this internal table name be LT_PDFDATA. Hence any operation that is to be performed on the data, this table is taken into consideration.
Following steps have to be followed to send the PDF as an attachment.
1) Conversion of the content in LT_PDFDATA in binary format.
The table LT_PDFDATA has two columns. Convert the entire table into a single line and replace all the space with a special character (say ~).
Then convert the entire string into lines of size 255 characters, and store it in an internal table (OBJBIN).
2) Create Receivers List.
This table will contain the receiver name and receiver type(Internet Address, Remote SAP, etc.).
3) Create Message body, Title, and Description.
4) Create Message Attachment.
Function Module Used :
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
DOCUMENT_DATA = DOCDATA
PUT_IN_OUTBOX = 'X'
TABLES
PACKING_LIST = OBJPACK
OBJECT_HEADER = OBJHEAD
CONTENTS_BIN = OBJBIN
CONTENTS_TXT = OBJTXT
RECEIVERS = RECLIST.
I hope it helps.
Best Regards,
Vibha
*Please mark all the helpful answers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.