on 04-30-2009 4:05 PM
I have a requirement to print only, email only or print and email invoice to external customer depending on customer preference.
I would like to process the output via my custom print program at the same time. Is it possible and how? Can it be configured as only one output for both Email and print? Thanks
Hi,
check the below link
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/email%2bfrom%2bsap
Regards,
Madhu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Please check the below code
*&---------------------------------------------------------------------*
*& Report ZPUCHASEORDER_DETAILS_SMARTFRM
*&
*&---------------------------------------------------------------------*
*& Description: Code to send the Smartform to mail as PDF attachment.
*&---------------------------------------------------------------------*
report zpuchaseorder_details_smartfrm.
* Internal Table declarations
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 = 'ZPUCHASEORDER_DETAILS_SMARTFRM'
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.
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
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.
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 = 'email address'.
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'
commit_work = '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 <> 0.
write:/ 'Error When Sending the File', sy-subrc.
else.
write:/ 'Mail sent'.
endif.
Thanks,
suma.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suma,
Thanks for quick response. Yes, I know how to send invoice to print or email but my question is that can we process to print and email the same time for one output being configured as both email and print.
I know that when I send email I will have the table contains pdf data, is there any function module or method to send either otf data or pdf data to the printer. The invoice was designed using Sapscript, not SmartForm. If this is possible, I will configure to have 2 output types, one for print and one for email and the print program will process 2 times.
Suvendu, your code looks interesting. Is there a way I can view without word-wrap? It is hard to view. It happens to me also. I do not understand why sometimes after I cut and paste and all the text just wrap arount with no tab character or line break control.
yes u can print and email at the same time,
set the getotf parameter of the output optiond as X so u would get otf data, now u can send this otf data as email.
to print this otf data u can use the FM PRINT_OTF which will directly print without giving a preview.
in case u want to view the output u can use DISPLAY_OTF FM.
check dis code
call function 'GET_PRINT_PARAMETERS'
importing
* out_archive_parameters =
out_parameters = ipri_parameters
valid = valid
exceptions
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
others = 4.
if sy-subrc eq 0.
move ipri_parameters-pdest to zoption-tddest.
move ipri_parameters-prcop to zoption-tdcopies.
move ipri_parameters-prnew to zoption-tdnewid.
move ipri_parameters-prrel to zoption-tddelete.
move ipri_parameters-primm to zoption-tdimmed.
move ipri_parameters-prdsn to zoption-tddataset.
move ipri_parameters-pexpi to zoption-tdlifetime.
move ipri_parameters-armod to zoption-tdarmod.
move ipri_parameters-prsap to zoption-tdcover.
move ipri_parameters-prtxt to zoption-tdcovtitle.
move ipri_parameters-prrec to zoption-tdreceiver.
move ipri_parameters-prabt to zoption-tddivision.
move ipri_parameters-prber to zoption-tdautority.
endif.
CALL FUNCTION 'PRINT_OTF'
EXPORTING
printoptions = zoption
IMPORTING
* OTF_PRINTER =
* OTF_DEVICETYPE =
* PRINT_SUCCESSFUL =
SPOOLID = ispoolid
tables
otf = it_otfdata.
Edited by: Kartik Tarla on May 20, 2009 8:38 PM
please try this code.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = tnapr-sform
IMPORTING
fm_name = fm_name.
DATA: a TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Select A option !'
text_question = 'Want a Email file for this Transaction ?'
text_button_1 = 'Yes'(001)
text_button_2 = 'No'(002)
display_cancel_button = ' '
start_column = 25
start_row = 6
IMPORTING
answer = a.
IF a = '1'.
DATA: gw_ssfctrlop TYPE ssfctrlop, "for CONTROL_PARAMETERS
gw_ssfcompop TYPE ssfcompop, "for OUTPUT_OPTIONS
gw_ssfcrescl TYPE ssfcrescl. "for JOB_OUTPUT_INFO
DATA: gt_otf TYPE STANDARD TABLE OF itcoo ,
gt_tline TYPE STANDARD TABLE OF tline,
gv_len LIKE sood-objlen.
CALL FUNCTION fm_name
EXPORTING
control_parameters = gw_ssfctrlop
output_options = gw_ssfcompop
user_settings = 'X'
nast = nast
IMPORTING
job_output_info = gw_ssfcrescl
.
IF sy-subrc <> 0.
ENDIF.
gt_otf = gw_ssfcrescl-otfdata.
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 132
IMPORTING
bin_filesize = gv_len
TABLES
otf = gt_otf
lines = gt_tline
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 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.
boldCALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
pass the internal table to mailbold
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Select A option !'
text_question = 'Want to have a print privew for the same?'
text_button_1 = 'Yes'(001)
text_button_2 = 'No'(002)
display_cancel_button = ' '
start_column = 25
start_row = 6
IMPORTING
answer = a.
IF a = 1.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
*----
control_parameters = gw_ssfctrlop
*----
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
*----
output_options = gw_ssfcompop
user_settings = 'X'
*----
nast = nast
*----
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = gw_ssfcrescl
JOB_OUTPUT_OPTIONS =
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.
ENDIF.
ELSE .
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
*----
control_parameters = gw_ssfctrlop
*----
MAIL_APPL_OBJ =
MAIL_RECIPIENT =
MAIL_SENDER =
*----
output_options = gw_ssfcompop
user_settings = 'X'
*----
nast = nast
*----
IMPORTING
DOCUMENT_OUTPUT_INFO =
job_output_info = gw_ssfcrescl
JOB_OUTPUT_OPTIONS =
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.
*----
ENDIF.
Hope this will solve your problem.
Edited by: Suvendu Swain on May 1, 2009 11:40 AM
Edited by: Suvendu Swain on May 1, 2009 11:41 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.