‎2009 Jun 18 9:54 AM
Hello to all great ABAPPERS,
My requirement is to send the smartform layout through E-Mail.Suppose there is a Y screen who updates the the Y table whenever user saved all the entries, a smartform generate. Now when Smartform generate automatically a mail should go with same smartform layout to concern person.
How can I do the same!
Please suggest.
‎2009 Jun 18 10:09 AM
Hi,
please refer to the link.
/people/gaurav.parmar2/blog/2008/02/13/issue-smart-form-output-to-email-as-pdf-attachment
hope it helps.
Regards,
Bhanu
‎2009 Jun 18 10:12 AM
Hi Supriya,
Please refer to these two links
https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/smartformtoMailasPDF+attachment&
Hope this helps.
Regards,
Janaki.
‎2009 Jun 18 10:16 AM
Hi Supriya,
You can generate spool request for the smartform and then convert it into PDF.
Following is not the excat code. It will guide you how to code. If you want more details let me know.
CALL FUNCTION lf_fm_name
EXPORTING
archive_index = ls_toa_dara
archive_index_tab = ls_tsfdara
archive_parameters = ls_arc_params
control_parameters = ls_control_param
mail_appl_obj = ls_mail_appl_obj
mail_recipient = ls_recipient
mail_sender = ls_sender
output_options = ls_composer_param
user_settings = ' ' "Disable User Printer
is_ekko = l_doc-xekko
is_pekko = l_doc-xpekko
is_nast = l_nast
iv_from_mem = l_from_memory
iv_druvo = iv_druvo
iv_xfz = iv_xfz
IMPORTING
document_output_info = ls_ssfcrespd
job_output_info = ls_ssfcrescl
job_output_options = ls_ssfcresop
TABLES
it_ekpo = l_doc-xekpo[]
it_ekpa = l_doc-xekpa[]
it_pekpo = l_doc-xpekpo[]
it_eket = l_doc-xeket[]
it_tkomv = l_doc-xtkomv[]
it_ekkn = l_doc-xekkn[]
it_ekek = l_doc-xekek[]
it_komk = l_xkomk[]
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
DATA: ls_spoolid LIKE LINE OF ls_ssfcrescl-spoolids.
LOOP AT ls_ssfcrescl-spoolids INTO ls_spoolid.
IF ls_spoolid NE space.
PERFORM otf_pdf USING ls_spoolid l_doc-xekko-ebeln l_doc-xekko-ekorg
l_doc-xekko-ekgrp
CHANGING ent_retco.
ENDIF.
ENDLOOP.
**************************************************************************************
FORM otf_pdf USING p_spoolid TYPE tsp01-rqident
p_ebeln TYPE ekko-ebeln
p_ekorg TYPE ekko-ekorg
p_ekgrp TYPE ekko-ekgrp
CHANGING p_retco.
DATA: dst_device LIKE tsp03-padest,
w_bytecount LIKE tst01-dsize,
i_pdf_output TYPE TABLE OF tline WITH HEADER LINE,
w_string(510) TYPE c,
w_counts TYPE i,
i_mess_att LIKE solisti1 OCCURS 0 WITH HEADER LINE,
receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
w_receiver LIKE somlreci1-receiver,
notif_del LIKE somlreci1-notif_del,
notif_read LIKE somlreci1-notif_read,
notif_ndel LIKE somlreci1-notif_ndel,
i_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
contents_txt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
e_doc_data LIKE sodocchgi1,
sender LIKE soextreci1-receiver.
DATA: gwa_t024 TYPE t024,
gv_eknam(36) TYPE c,
gv_tel_number(46) TYPE c.
CONSTANTS: c_nospace(02) TYPE c VALUE ' ~',
c_wdspace(02) TYPE c VALUE '~ ',
c_x(01) TYPE c VALUE 'X',
c_u(01) TYPE c VALUE 'U',
c_f(01) TYPE c VALUE 'F',
c_1 TYPE i VALUE 1,
c_0 TYPE i VALUE 0,
c_raw(03) TYPE c VALUE 'RAW',
c_pdf(03) TYPE c VALUE 'PDF',
c_sap(06) TYPE c VALUE 'SAPRPT',
c_sender_type LIKE soextreci1-adr_typ VALUE 'U'.
DATA: w_title TYPE so_obj_des.
***Concatenated for getting the PO Number in the PDF File as the Title
CONCATENATE text-001 p_ebeln INTO w_title.
Function module to convert the OTF Format to PDF format
CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = p_spoolid
no_dialog = 'X'
dst_device = dst_device
IMPORTING
pdf_bytecount = w_bytecount
TABLES
pdf = i_pdf_output
EXCEPTIONS
err_no_otf_spooljob = 1
err_no_spooljob = 2
err_no_permission = 3
err_conv_not_possible = 4
err_bad_dstdevice = 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.
IF NOT sy-subrc IS INITIAL.
RAISE spool_error.
ENDIF.
*" Convert PDF format to attachment format.
WHILE sy-subrc IS INITIAL.
READ TABLE i_pdf_output INDEX sy-index.
CHECK sy-subrc IS INITIAL.
TRANSLATE i_pdf_output USING c_nospace.
CONCATENATE w_string i_pdf_output INTO w_string.
ADD 134 TO w_counts.
IF w_counts GE 255.
MOVE: w_string(255) TO i_mess_att.
TRANSLATE i_mess_att USING c_wdspace.
APPEND i_mess_att.
CLEAR: i_mess_att.
SHIFT w_string LEFT BY 255 PLACES.
SUBTRACT 255 FROM w_counts.
ENDIF.
ENDWHILE.
WHILE NOT w_string IS INITIAL.
MOVE: w_string(255) TO i_mess_att.
TRANSLATE i_mess_att USING c_wdspace.
APPEND i_mess_att.
CLEAR: i_mess_att.
SHIFT w_string LEFT BY 255 PLACES.
ENDWHILE.
Send Email with PDF Attachment
Internal table for email ids(smtp_addr) as per the address
no(addrnumber) of the Vendor from lfa1.
DATA: BEGIN OF t_adr6 OCCURS 0,
addrnumber TYPE adr6-addrnumber,
smtp_addr TYPE adr6-smtp_addr,
END OF t_adr6.
TYPES: BEGIN OF t_adrt,
addrnumber TYPE adrt-addrnumber,
consnumber TYPE adrt-consnumber,
END OF t_adrt.
*Variable for Recepient information
DATA: l_rec TYPE somlreci1 OCCURS 0 WITH HEADER LINE.
REFRESH receivers.
CLEAR l_rec.
*Get data from ADR6 table
SELECT SINGLE addrnumber
smtp_addr
FROM adr6
INTO t_adr6
WHERE addrnumber = ls_addr_key.
IF sy-subrc EQ 0
AND NOT t_adr6-smtp_addr IS INITIAL.
Move email id and recepient type to Recepient variable
MOVE: t_adr6-smtp_addr TO l_rec-receiver,
c_u TO l_rec-rec_type.
l_rec-com_type = 'INT'.
APPEND l_rec TO receivers.
ENDIF.
Fetch data from table T024 - Purchasing Groups
CLEAR: gwa_t024.
SELECT SINGLE *
FROM t024
INTO gwa_t024
WHERE ekgrp EQ p_ekgrp.
IF NOT gwa_t024-smtp_addr IS INITIAL.
CLEAR: l_rec.
MOVE: gwa_t024-smtp_addr TO l_rec-receiver,
c_u TO l_rec-rec_type.
l_rec-com_type = 'INT'.
APPEND l_rec TO receivers.
ENDIF.
CLEAR: l_rec.
MOVE: email id TO l_rec-receiver,
c_u TO l_rec-rec_type.
l_rec-com_type = 'INT'.
APPEND l_rec TO receivers.
*" Describe the Email Body
MOVE: text-002 TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
MOVE: text-003 TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
MOVE: text-004 TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
MOVE: text-005 TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
CONCATENATE text-006 ' ' gwa_t024-eknam INTO gv_eknam.
MOVE: gv_eknam TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
MOVE: text-007 TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
CONCATENATE text-008 ' ' gwa_t024-tel_number INTO gv_tel_number.
MOVE: gv_tel_number TO contents_txt-line.
APPEND contents_txt.
CLEAR: contents_txt.
MOVE: space TO i_packing_list-transf_bin,
c_0 TO i_packing_list-head_num,
c_1 TO i_packing_list-head_start,
c_1 TO i_packing_list-body_start,
c_raw TO i_packing_list-doc_type.
DESCRIBE TABLE contents_txt LINES i_packing_list-body_num.
APPEND i_packing_list.
CLEAR: i_packing_list.
Create Attachment Notification
MOVE: c_x TO i_packing_list-transf_bin,
c_1 TO i_packing_list-head_start,
c_1 TO i_packing_list-head_num,
c_1 TO i_packing_list-body_start,
c_pdf TO i_packing_list-doc_type,
w_title TO i_packing_list-obj_descr.
DESCRIBE TABLE i_mess_att LINES i_packing_list-body_num.
i_packing_list-doc_size = i_packing_list-body_num * 255.
APPEND i_packing_list.
CLEAR: i_packing_list.
*" Specify Document Data
MOVE: sy-langu TO e_doc_data-obj_langu,
c_sap TO e_doc_data-obj_name,
w_title TO e_doc_data-obj_descr,
c_f TO e_doc_data-sensitivty,
c_1 TO e_doc_data-doc_size.
CLEAR: w_counts.
DESCRIBE TABLE i_mess_att LINES w_counts.
READ TABLE i_mess_att INDEX w_counts.
e_doc_data-doc_size = ( w_counts * 255 ) + STRLEN( i_mess_att ).
*********************************************************************
Send Email in the PDF Format to the vendor directly via the email id
picked from table ADR6
*********************************************************************
IF NOT receivers IS INITIAL.
***IF TRANSACTION CODE ID ME9F THEN ONLY ALLOW IT TO MAIL OR GIVE A
***MESSAGE SAYING USE ME9F TRANSACTION TO PRINT.
IF receivers[] IS INITIAL.
MESSAGE i208(00) WITH 'Receiver does not exist'.
ELSE.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = e_doc_data
put_in_outbox = c_x
sender_address = sender
sender_address_type = c_sender_type
commit_work = 'X'
TABLES
packing_list = i_packing_list
contents_bin = i_mess_att
contents_txt = contents_txt
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 NOT sy-subrc IS INITIAL.
p_retco = sy-subrc.
PERFORM protocol_update_i.
ELSE.
MESSAGE s208(00) WITH 'Purchase Order sent'.
ENDIF.
ENDIF.
ENDFORM. " OTF_PDF
Regards,
Anil
‎2009 Jun 18 10:18 AM
Hi,
Please refer the following link for Sending the Smart form in PDF format via Email.
https://wiki.sdn.sap.com/wiki/display/ABAP/SmartformSendvia+Email
Hope this helps you.
Regards,
Tarun
‎2009 Jun 18 10:26 AM
‎2009 Jul 22 7:05 AM
‎2009 Jul 27 4:05 PM
Hi Supriya,
I am having the same requirement so can u please guide me so as how to send the smartform text in email body rather than as pdf attachment.
Thanks in advance,
Mayank
‎2009 Jul 28 5:20 AM
Hi Mayank,
Smartform will be send as a PDF attachment only. I did the same as attcahment of PDF.
Regards,
Supriya.