cancel
Showing results for 
Search instead for 
Did you mean: 

How to send a SMARTFORM as an email ?

Former Member
0 Kudos

Hello,

How can we send a smart form as an email?

Please explain with an exmaple.

ANy proper explonation will be appreciated...

Have a great day!

Thanks & Regards,

Krishna Chaitanya

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Please go through below weblog. It gives you step by step details about this requirement.

/people/gaurav.parmar2/blog/2008/02/13/issue-smart-form-output-to-email-as-pdf-attachment

Step 1: To convert SmartForm output to PDF

Smart Forms does not support direct output in PDF format. Instead, the OTF output has to be converted to PDF. The function module generated by the SmartForm has to be supplied with Control Structure parameters that will export the SmartForm output to OTF format. The Output Text Format (OTF) is the established SAP output format for printing forms. It consists of a number of simple, device-independent commands, thus allowing output to be directed to different output devices such as line printers and laser printers, or as an on-screen print preview. OTF is an explicit output format, which means that once SAP Smart Forms has generated an OTF output, no modifications can be made.

OTF is not a document; it is a format in which data becomes available after it is templated by a Script or Smartform. The SmartForm takes the data you have passed to it, formats it according to the output settings, layout, page size, styles etc. and then forwards it to it's intended destination which is normally a print device. Since SmartForm output is not necessarily targeted at print output, R/3 allows you to alternatively collect the formatted results of the SmartForm(or SAPScript) and use this data for other purposes, like creating a DOC(MS Word) file, create a PDF file, send mail etc. The standard format used after generation and formatting of SmartForm output is known as OTF.

The procedure for the form to be returned as a table in OTF format is as follows:

1. Define a structure of type SSFCTRLOP (control structure, standard parameter CONTROL_PARAMETERS) and another structure of type SSFCRESCL (to contain the output results, standard parameter JOB_OUTPUT_INFO):

DATA: my_control_pars TYPE ssfctrlop. "For CONTROL_PARAMETERS

DATA: my_output_info TYPE ssfcrescl. "For JOB_OUTPUT_INFO

2. To deactivate the dialogs and to inform SAP Smart Forms that you only want the OTF table to be returned, set the parameters NO_DIALOG and GETOTF of the control structure:

my_control_pars-no_dialog = 'X'.

my_control_pars-getotf = 'X'.

3. Pass both structures in the call of the generated function module.

Now access the OTF table in the formal parameter JOB_OUTPUT_INFO using the OTFDATA parameter of your structure.

4. Get the OTF output from table OTFDATA of the standard parameter JOB_OUTPUT_INFO.

5. To convert the OTF output to PDF, transfer the OTF table to the function module CONVERT_OTF. To do this, set the parameter FORMAT to 'PDF'. The output can be returned either as a binary string (parameter BIN_FILE) or as a character table (parameter LINES). SAP recommends the first variant.

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.

Thanks,

Vibha

Please mark all the useful answers

Answers (5)

Answers (5)

Former Member
0 Kudos

Hello,

I am very sorry for the late response!

I appreciate your resoponse!

Thank you very much!

Regards

Kittu

Former Member
0 Kudos

Hi Krishna,

  • When you pass the values to the Smartform by using the Function Module name of the Smartform, it will return you thr OTF format of the Smartform in the Importing Parameter 'job_output_info'. The following code will help you regarding the mail sending part:

If you still need help, Please let me know.If helpfull reward me points.*

TYPES: BEGIN OF tp_lips,

vbeln LIKE lips-vbeln,

posnr LIKE lips-posnr,

matnr LIKE lips-matnr,

lfimg LIKE lips-lfimg,

vgbel LIKE lips-vgbel,

vgpos LIKE lips-vgpos,

uecha LIKE lips-uecha,

END OF tp_lips,

BEGIN OF tp_vbap,

vbeln LIKE vbap-vbeln,

posnr LIKE vbap-posnr,

matnr LIKE vbap-matnr,

kbmeng LIKE vbap-kbmeng,

werks LIKE vbap-werks,

END OF tp_vbap,

BEGIN OF tp_lips_tmp ,

uecha LIKE lips-uecha,

vbeln LIKE lips-vbeln,

posnr LIKE lips-posnr,

matnr LIKE lips-matnr,

lfimg LIKE lips-lfimg,

vgbel LIKE lips-vgbel,

vgpos LIKE lips-vgpos,

END OF tp_lips_tmp,

BEGIN OF tp_lips_split ,

uecha LIKE lips-uecha,

vbeln LIKE lips-vbeln,

posnr LIKE lips-posnr,

matnr LIKE lips-matnr,

lfimg LIKE lips-lfimg,

vgbel LIKE lips-vgbel,

vgpos LIKE lips-vgpos,

END OF tp_lips_split.

CONSTANTS : c_5(1) TYPE c VALUE '5',

c_otf(3) TYPE c VALUE 'OTF',

c_printer(7) TYPE c VALUE 'PRINTER',

c_x(1) TYPE c VALUE 'X',

c_pdf(3) TYPE c VALUE 'PDF',

c_o(1) TYPE c VALUE 'O',

c_mail(5) TYPE c VALUE 'EMAIL' ,

c_e TYPE so_escape VALUE 'E',

c_int TYPE tddevice VALUE 'INT' ,

c_ext(3) TYPE c VALUE 'EXT',

c_raw(3) TYPE c VALUE 'RAW',

c_b LIKE soos1-recesc VALUE 'B'.

DATA: ls_print_data_to_read TYPE ledlv_print_data_to_read.

DATA: ls_dlv_delnote TYPE ledlv_delnote.

DATA: lf_fm_name TYPE rs38l_fnam.

DATA: ls_control_param TYPE ssfctrlop.

DATA: ls_composer_param TYPE ssfcompop.

DATA: ls_recipient TYPE swotobjid.

DATA: ls_sender TYPE swotobjid.

DATA: lf_formname TYPE tdsfname.

DATA: ls_addr_key LIKE addr_key.

DATA: l_w_object_hd_change TYPE sood1,

l_w_header LIKE sood1-objdes.

*--Binary Data

DATA: BEGIN OF l_t_solix OCCURS 0.

INCLUDE STRUCTURE solix.

DATA: END OF l_t_solix.

*--Content to be mailed

DATA: BEGIN OF l_t_objcont OCCURS 0.

INCLUDE STRUCTURE soli.

DATA: END OF l_t_objcont.

*--PDF Data

DATA: BEGIN OF l_t_htline OCCURS 10.

INCLUDE STRUCTURE tline.

DATA: END OF l_t_htline.

DATA: BEGIN OF l_t_object_hd_change.

INCLUDE STRUCTURE sood1.

DATA: END OF l_t_object_hd_change.

*-- Recipient table with send attributes

DATA: BEGIN OF l_t_receivers OCCURS 0.

INCLUDE STRUCTURE soos1.

DATA: END OF l_t_receivers.

DATA: BEGIN OF l_t_objhead OCCURS 0.

INCLUDE STRUCTURE soli.

DATA: END OF l_t_objhead.

DATA: l_t_lips TYPE tp_lips OCCURS 0 WITH HEADER LINE,

l_t_vbap TYPE tp_vbap OCCURS 0 WITH HEADER LINE,

l_t_lips_tmp TYPE tp_lips_tmp OCCURS 0 WITH HEADER LINE,

l_t_lips_split TYPE tp_lips_split OCCURS 0 WITH HEADER LINE.

DATA : l_v_document_number TYPE likp-vbeln,

l_t_ssfcrespd TYPE ssfcrespd,

l_t_ssfcrescl TYPE ssfcrescl,

l_t_ssfcresop TYPE ssfcresop,

l_v_adrnr TYPE kna1-adrnr,

l_v_ls_address TYPE szadr_addr1_complete,

w_ls_adsmtpline TYPE szadr_adsmtp_line,

l_v_mail LIKE adr6-smtp_addr,

l_t_otf LIKE itcoo OCCURS 0,

l_v_hformat(10) TYPE c,

l_v_ld_binfile TYPE xstring,

l_v_doc_size TYPE i,

l_v_i TYPE i,

l_v_n TYPE i,

l_v_hkora(50) TYPE c,

w_soli TYPE soli,

w_solix TYPE solix,

l_v_var1(46) TYPE c ,

l_v_linecount TYPE p,

l_v_sent_to_all LIKE sonv-flag,

l_v_document_type LIKE soodk-objtp,

l_v_horiginator LIKE soos1-recextnam ,

l_w_lips TYPE tp_lips,

l_w_vbap TYPE tp_vbap,

l_v_avl_date TYPE erdat,

l_f_oos_status TYPE flag,

l_lfimg LIKE lips-lfimg.

l_v_document_number = nast-objky.

*--To get the smartform name

lf_formname = tnapr-sform.

*-- Determine print data

PERFORM set_print_data_to_read USING lf_formname

CHANGING ls_print_data_to_read

cf_retcode.

IF cf_retcode = 0.

*--select print data

PERFORM get_data USING ls_print_data_to_read

CHANGING ls_addr_key

ls_dlv_delnote

cf_retcode.

ENDIF.

*-- Begin of Insertion AG2K946177 Scan - Avail date

CLEAR: l_t_lips,

l_t_vbap.

*-- Get the items from the delivery table

SELECT vbeln posnr matnr lfimg vgbel vgpos uecha FROM lips INTO TABLE l_t_lips

WHERE vbeln = nast-objky.

IF sy-subrc = 0.

IF NOT l_t_lips[] IS INITIAL.

*-- Get the items from the order table

SELECT vbeln posnr matnr kbmeng werks FROM vbap INTO TABLE l_t_vbap

FOR ALL ENTRIES IN l_t_lips

WHERE vbeln = l_t_lips-vgbel AND

posnr = l_t_lips-vgpos.

IF sy-subrc = 0.

LOOP AT l_t_lips.

MOVE l_t_lips-vbeln TO l_t_lips_tmp-vbeln.

MOVE l_t_lips-posnr TO l_t_lips_tmp-posnr.

MOVE l_t_lips-matnr TO l_t_lips_tmp-matnr.

MOVE l_t_lips-lfimg TO l_t_lips_tmp-lfimg.

MOVE l_t_lips-vgbel TO l_t_lips_tmp-vgbel.

MOVE l_t_lips-vgpos TO l_t_lips_tmp-vgpos.

MOVE l_t_lips-uecha TO l_t_lips_tmp-uecha.

APPEND l_t_lips_tmp.

CLEAR l_t_lips_tmp.

ENDLOOP.

LOOP AT l_t_lips INTO l_w_lips where uecha is INITIAL.

CLEAR: l_lfimg.

LOOP AT l_t_lips_tmp WHERE uecha = l_w_lips-posnr.

MOVE l_t_lips_tmp-vbeln TO l_t_lips_split-vbeln.

MOVE l_t_lips_tmp-uecha TO l_t_lips_split-uecha.

MOVE l_t_lips_tmp-posnr TO l_t_lips_split-posnr.

MOVE l_t_lips_tmp-matnr TO l_t_lips_split-matnr.

MOVE l_t_lips_tmp-vgbel TO l_t_lips_split-vgbel.

MOVE l_t_lips_tmp-vgpos TO l_t_lips_split-vgpos.

l_lfimg = l_lfimg + l_t_lips_tmp-lfimg.

AT END OF uecha.

l_t_lips_split-lfimg = l_lfimg.

APPEND l_t_lips_split.

CLEAR l_t_lips_split.

ENDAT.

ENDLOOP.

READ TABLE l_t_lips_split WITH KEY uecha = l_w_lips-posnr.

IF sy-subrc = 0 .

READ TABLE l_t_vbap INTO l_w_vbap WITH KEY vbeln = l_w_lips-vgbel

posnr = l_w_lips-vgpos.

IF sy-subrc = 0.

IF l_t_lips_split-lfimg LT l_w_vbap-kbmeng.

SELECT SINGLE avl_dat FROM /mars/ou_avl_dat INTO l_v_avl_date

WHERE werks = l_w_vbap-werks AND

matnr = l_w_vbap-matnr.

IF sy-subrc = 0.

IF l_v_avl_date IS INITIAL OR l_v_avl_date < sy-datum.

l_f_oos_status = c_x.

t_objcont-line = l_w_vbap-matnr.

APPEND t_objcont.

CLEAR t_objcont.

ENDIF.

ELSE.

l_f_oos_status = c_x.

t_objcont-line = l_w_vbap-matnr.

APPEND t_objcont.

CLEAR t_objcont.

ENDIF.

ENDIF.

ENDIF.

ELSE.

READ TABLE l_t_vbap INTO l_w_vbap WITH KEY vbeln = l_w_lips-vgbel

posnr = l_w_lips-vgpos.

IF sy-subrc = 0.

IF l_t_lips-lfimg LT l_w_vbap-kbmeng.

SELECT SINGLE avl_dat FROM /mars/ou_avl_dat INTO l_v_avl_date

WHERE werks = l_w_vbap-werks AND

matnr = l_w_vbap-matnr.

IF sy-subrc = 0.

IF l_v_avl_date IS INITIAL OR l_v_avl_date < sy-datum.

l_f_oos_status = c_x.

t_objcont-line = l_w_vbap-matnr.

APPEND t_objcont.

CLEAR t_objcont.

ENDIF.

ELSE.

l_f_oos_status = c_x.

t_objcont-line = l_w_vbap-matnr.

APPEND t_objcont.

CLEAR t_objcont.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF.

ENDIF.

IF l_f_oos_status NE c_x.

*-- End of Insertion AG2K946177 Scan - Avail date

*-- Begin of Insertion AG2K942430 Delivery Note

IF cf_retcode = 0.

IF nast-nacha NE c_5.

*-- End of Insertion AG2K942430 Delivery Note

PERFORM set_print_param USING ls_addr_key

CHANGING ls_control_param

ls_composer_param

ls_recipient

ls_sender

cf_retcode.

ls_control_param-no_dialog = space .

*-- Begin of Insertion AG2K942430 Delivery Note

ELSEIF nast-nacha EQ c_5.

SELECT SINGLE adrnr FROM kna1 INTO l_v_adrnr WHERE kunnr = nast-parnr.

IF sy-subrc = 0.

CLEAR l_v_ls_address.

  • -- To get the address Details

CALL FUNCTION 'ADDR_GET_COMPLETE'

EXPORTING

addrnumber = l_v_adrnr

IMPORTING

addr1_complete = l_v_ls_address

EXCEPTIONS

OTHERS = 5.

IF sy-subrc = 0.

LOOP AT l_v_ls_address-adsmtp_tab INTO w_ls_adsmtpline

WHERE date_from <= sy-datlo.

IF ( NOT w_ls_adsmtpline-adsmtp-smtp_addr IS INITIAL ).

*--Email Address

l_v_mail = w_ls_adsmtpline-adsmtp-smtp_addr.

ENDIF.

ENDLOOP.

ENDIF.

*--To fill the control paramters for Email

IF NOT l_v_mail IS INITIAL AND nast-nacha EQ c_5.

ls_control_param-device = c_printer.

ls_control_param-no_dialog = c_x.

ls_control_param-langu = sy-langu.

ls_control_param-preview = space.

ls_control_param-getotf = c_x.

*--Setting LS_COMPOSER_PARAM values

ls_composer_param-tddest = nast-ldest.

ls_composer_param-tdimmed = space.

ls_composer_param-tdnoprev = c_x.

ls_composer_param-faxformat = c_otf.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

*-- End of Insertion AG2K942430 Delivery Note

IF cf_retcode = 0.

*-- Determine smartform function module for delivery note

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

cf_retcode = sy-subrc.

PERFORM protocol_update.

ENDIF.

ENDIF.

IF cf_retcode = 0.

*-- Call smartform delivery note

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

user_settings = space

is_dlv_delnote = ls_dlv_delnote

is_nast = nast

*-- Begin of Insertion AG2K942430 Delivery Note

IMPORTING

document_output_info = l_t_ssfcrespd

job_output_info = l_t_ssfcrescl

job_output_options = l_t_ssfcresop

*-- End of Insertion AG2K942430 Delivery Note

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

*-- Error handling

cf_retcode = sy-subrc.

PERFORM protocol_update.

*-- Get SmartForm protocol and store it in the NAST protocoll

PERFORM add_smfrm_prot.

ENDIF.

ENDIF.

*-- Begin of Insertion AG2K942430 Delivery Note

IF nast-nacha EQ c_5.

IF NOT l_t_ssfcrescl-otfdata[] IS INITIAL .

MOVE l_t_ssfcrescl-otfdata[] TO l_t_otf[].

ENDIF.

IF NOT l_t_otf[] IS INITIAL.

IF l_v_hformat IS INITIAL.

l_v_hformat = c_pdf.

ENDIF.

CLEAR l_t_htline.

REFRESH l_t_htline.

*-- Convert OTF Data to PDF Data

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = l_v_hformat

IMPORTING

bin_filesize = l_v_doc_size

bin_file = l_v_ld_binfile

TABLES

otf = l_t_otf

lines = l_t_htline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc = 0.

CLEAR l_t_solix.

REFRESH l_t_solix.

CLEAR l_t_objcont.

REFRESH l_t_objcont.

l_v_i = 0.

l_v_n = XSTRLEN( l_v_ld_binfile ).

WHILE l_v_i < l_v_n.

l_t_solix-line = l_v_ld_binfile+l_v_i.

APPEND l_t_solix.

CLEAR l_t_solix.

l_v_i = l_v_i + 255.

ENDWHILE.

FIELD-SYMBOLS: <ptr_hex> TYPE solix.

LOOP AT l_t_solix INTO w_solix.

CLEAR w_soli.

ASSIGN w_soli TO <ptr_hex> CASTING.

MOVE w_solix TO <ptr_hex>.

APPEND w_soli TO l_t_objcont.

ENDLOOP.

IF l_v_hformat = c_pdf.

*--Do nothing

ELSE.

CLEAR l_t_objcont.

REFRESH l_t_objcont.

LOOP AT l_t_htline.

l_t_objcont = l_t_htline.

APPEND l_t_objcont.

CLEAR l_t_htline.

ENDLOOP.

ENDIF.

ENDIF.

*--To Suppress zero's

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = l_v_document_number

IMPORTING

output = l_v_document_number.

CONCATENATE text-001 l_v_document_number INTO l_v_var1 SEPARATED BY space.

l_v_hkora = l_v_var1.

CLEAR l_t_object_hd_change.

l_t_object_hd_change-objnam = c_mail.

l_t_object_hd_change-objdes = l_v_hkora.

l_t_object_hd_change-objla = sy-langu.

l_t_object_hd_change-objsns = c_o.

l_t_object_hd_change-objlen = l_v_doc_size .

IF l_v_hformat = c_pdf.

l_t_object_hd_change-file_ext = c_pdf.

ENDIF.

CLEAR l_t_receivers.

REFRESH l_t_receivers.

l_t_receivers-recextnam = l_v_mail.

l_t_receivers-recesc = c_e.

l_t_receivers-sndart = c_int.

APPEND l_t_receivers.

CLEAR l_t_receivers.

DESCRIBE TABLE l_t_objcont LINES l_v_linecount.

CLEAR l_t_objhead.

REFRESH l_t_objhead.

IF l_v_hformat = c_pdf.

l_v_document_type = c_ext.

ELSE.

l_v_document_type = c_raw.

l_t_objhead = l_v_linecount.

APPEND l_t_objhead.

CLEAR l_t_objhead.

ENDIF.

l_v_horiginator = sy-uname.

*--Sending the PDF data as Email attachment

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = l_t_object_hd_change

object_type = l_v_document_type

originator = l_v_horiginator

originator_type = c_b

IMPORTING

sent_to_all = l_v_sent_to_all

TABLES

objcont = l_t_objcont

objhead = l_t_objhead

receivers = l_t_receivers

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

originator_not_exist = 20

x_error = 21

OTHERS = 22.

  • IF sy-subrc = 0.

  • COMMIT WORK AND WAIT.

  • ENDIF.

ENDIF.

ENDIF.

*-- End of Insertion AG2K942430 Delivery Note

*-- Begin of Insertion AG2K946177 Scan - Avail date

ELSE.

*-- Get the details for sending the email

PERFORM get_details TABLES t_objparb

t_receivers

CHANGING v_obj_type

v_owner

v_sender

w_object_hd_change.

*-- Sending Email

PERFORM send_email.

ENDIF.

*-- End of Insertion AG2K946177 Scan - Avail date

ENDFORM. "PROCESSING

*-- Begin of Insertion AG2K946177 Scan - Avail date

&----


*& Form get_details

&----


  • Get details for Sending Email

----


  • -->P_T_OBJPARB Parameter for Dialog Modules

  • -->P_T_RECEIVERS recipient with attributes

  • <--P_V_OBJ_TYPE Code for document class

  • <--P_V_OWNER Owner

  • <--P_V_SENDER Sender

  • <--P_W_OBJECT_HD_CHANGE object definition, change attributes

----


FORM get_details TABLES p_t_objparb STRUCTURE t_objparb

p_t_receivers STRUCTURE t_receivers

CHANGING p_v_obj_type

p_v_owner

p_v_sender

p_w_object_hd_change.

CONSTANTS: c_colon(1) TYPE c VALUE ':'.

DATA:

*-- To Get the Entry from ZZOURULE

BEGIN OF l_w_zzourule,

zzvalue1_1 LIKE zzourule-zzvalue1_1,

zzvalue2_1 LIKE zzourule-zzvalue2_1,

zzvalue3_1 LIKE zzourule-zzvalue3_1,

END OF l_w_zzourule,

*-- To get the entry from sofd

BEGIN OF l_w_sofd,

foltp LIKE sofd-foltp,

folyr LIKE sofd-folyr,

folno LIKE sofd-folno,

END OF l_w_sofd,

*-- To get the entry from sofm

BEGIN OF l_w_sofm,

foltp LIKE sofm-foltp,

folyr LIKE sofm-folyr,

folno LIKE sofm-folno,

doctp LIKE sofm-doctp,

docyr LIKE sofm-docyr,

docno LIKE sofm-docno,

END OF l_w_sofm,

BEGIN OF l_w_swotobjid,

logsys LIKE swotobjid-logsys,

objtype LIKE swotobjid-objtype,

objkey LIKE swotobjid-objkey,

END OF l_w_swotobjid.

DATA: l_w_header LIKE sood1-objdes.

*-- Fill exporting parameters of FM SO_OBJECT_SEND

CONCATENATE text-004 nast-objky c_colon text-002 INTO l_w_header SEPARATED BY space.

  • l_w_header = text-002.

w_object_hd_change-objla = sy-langu.

w_object_hd_change-objnam = c_notify.

w_object_hd_change-objdes = l_w_header.

v_obj_type = c_raw.

v_owner = sy-uname.

v_sender = sy-uname.

t_objparb-name = c_wi_id.

APPEND t_objparb.

CLEAR t_objparb.

t_objparb-name = text-003.

t_objparb-value = sy-datum.

APPEND t_objparb.

CLEAR t_objparb.

*-- Get the folder Name from the ZZOURULE table

SELECT zzvalue1_1 zzvalue2_1 zzvalue3_1

FROM zzourule INTO l_w_zzourule UP TO 1 ROWS

WHERE zzprog = sy-repid AND

zzdata = c_oos.

ENDSELECT.

IF sy-subrc = 0.

SELECT foltp folyr folno

FROM sofd INTO l_w_sofd UP TO 1 ROWS

WHERE objnam = l_w_zzourule-zzvalue1_1 AND

folrg = c_q.

ENDSELECT.

IF sy-subrc = 0.

SELECT foltp folyr folno doctp docyr docno

FROM sofm INTO l_w_sofm UP TO 1 ROWS

WHERE doctp = l_w_sofd-foltp AND

docyr = l_w_sofd-folyr AND

docno = l_w_sofd-folno.

ENDSELECT.

IF sy-subrc = 0.

CLEAR t_receivers.

MOVE l_w_zzourule-zzvalue1_1 TO t_receivers-recnam.

*-- C means Shared distribution List

MOVE c_c TO t_receivers-recesc.

APPEND t_receivers.

CLEAR t_receivers.

l_w_swotobjid-logsys = l_w_zzourule-zzvalue2_1.

l_w_swotobjid-objtype = l_w_zzourule-zzvalue3_1.

CONCATENATE l_w_sofm-foltp

l_w_sofm-folyr

l_w_sofm-folno

l_w_sofm-doctp

l_w_sofm-docyr

l_w_sofm-docno INTO l_w_swotobjid-objkey.

t_receivers-recextnam = l_w_swotobjid.

*-- J means external Object

MOVE c_j TO t_receivers-recesc.

APPEND t_receivers.

CLEAR t_receivers.

ENDIF.

ENDIF.

ENDIF.

ENDFORM. " get_details

&----


*& Form send_email

&----


  • Sending Email

----


FORM send_email .

*-- Email send to the receipent maintained in the shared folder

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = v_obj_type

owner = v_owner

sender = v_sender

IMPORTING

object_id_new = w_object_id_new

sent_to_all = v_sent_to_all

TABLES

objcont = t_objcont

objhead = t_objhead

objparb = t_objparb

receivers = t_receivers

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_email

*-- End of Insertion AG2K946177 Scan - Avail date

Former Member
0 Kudos

Hi,

Check this blog, its vey help ful for sending various objects as HTML mail from SAP including smartforms.

/people/pavan.bayyapu/blog/2005/08/30/sending-html-email-from-sap-crmerp

Refer

https://forums.sdn.sap.com/click.jspa?searchID=11214131&messageID=4470111

Regards

Kiran Sure

Former Member
0 Kudos

Hi,

Check this sample Program,

In the place of email address maintain reciepant email id

REPORT zmm_vendor_reminder_mail.

TABLES : ekko,ekpo,eket,makt,adrc,adr6,lfa1.

DATA: fm_name TYPE rs38l_fnam.

DATA: BEGIN OF itab1 OCCURS 0.

INCLUDE STRUCTURE lfa1.

DATA: END OF itab1.

DATA : BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE zmm_podetails.

DATA: END OF itab.

DATA : BEGIN OF it_pos OCCURS 0 ,

bukrs LIKE ekpo-bukrs,

werks LIKE ekpo-werks,

ebeln LIKE eket-ebeln,

ebelp LIKE eket-ebelp,

etenr LIKE eket-etenr,

bedat LIKE eket-bedat,

matnr LIKE ekpo-matnr,

meins LIKE ekpo-meins,

menge LIKE eket-menge,

wemng LIKE eket-wemng,

eindt LIKE eket-eindt,

lifnr LIKE ekko-lifnr,

END OF it_pos.

DATA : BEGIN OF it_vendor OCCURS 0 ,

lifnr LIKE lfa1-lifnr,

name1 LIKE adrc-name1,

street LIKE adrc-street,

str_suppl1 LIKE adrc-str_suppl1,

str_suppl2 LIKE adrc-str_suppl2,

city1 LIKE adrc-city1,

post_code1 LIKE adrc-post_code1,

smtp_addr LIKE adr6-smtp_addr,

adrnr LIKE lfa1-adrnr,

telf1 LIKE lfa1-telf1,

telf2 LIKE lfa1-telf2,

END OF it_vendor.

*RAMESH **********

tables: soud.

data: control_parameters TYPE ssfctrlop,

output_options TYPE ssfcompop,

EMail_Subject(50) TYPE c value 'abc'.

DATA: email_recipient TYPE SWOTOBJID,

email_sender TYPE SWOTOBJID,

g_mail_app_obj type SWOTOBJID.

*concatenate text-004 '400000124' into EMail_Subject.

control_parameters-device = 'MAIL'.

control_parameters-no_dialog = 'X'.

control_parameters-preview = space.

output_options-tdnewid = 'X'.

output_options-tdtitle = EMail_Subject.

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

SELECT-OPTIONS : s_bukrs FOR ekpo-bukrs,

s_werks FOR ekpo-werks,

s_ekgrp FOR ekko-ekgrp,

s_lifnr FOR ekko-lifnr,

s_ebeln FOR ekko-ebeln,

s_eindt FOR eket-eindt,

s_mtart FOR ekpo-mtart,

s_matkl FOR ekpo-matkl,

s_matnr FOR ekpo-matnr.

SELECTION-SCREEN : END OF BLOCK b1.

PERFORM mail_recipient_object.

PERFORM mail_sender_object.

PERFORM mail_appl_object changing g_mail_app_obj.

*******************************SELECTION-SCREEN************

AT SELECTION-SCREEN.

  • Validate test for Plant in selections

LOOP AT s_werks.

IF NOT s_werks-high IS INITIAL.

SELECT SINGLE * FROM ekpo

WHERE werks = s_werks-high.

IF sy-subrc NE 0.

MESSAGE e600(fr) WITH 'This Plant'

s_werks-high ' does not exist.'

.

ENDIF.

ENDIF.

IF NOT s_werks-low IS INITIAL.

SELECT SINGLE * FROM ekpo

WHERE werks = s_werks-low.

IF sy-subrc NE 0.

MESSAGE e600(fr) WITH 'This Plant'

s_werks-low ' does not exist.'

.

ENDIF.

ENDIF.

ENDLOOP.

START-OF-SELECTION.

PERFORM get_data.

*----


CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZMM_VENDOR_REMINDER_MAIL'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

WRITE: / 'ERROR 1'.

ENDIF.

CALL FUNCTION fm_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

CONTROL_PARAMETERS = control_parameters

MAIL_APPL_OBJ = g_mail_app_obj

MAIL_RECIPIENT = email_recipient

MAIL_SENDER = email_sender

OUTPUT_OPTIONS = output_options

USER_SETTINGS = 'X'

  • IMPORTING

  • DOCUMENT_OUTPUT_INFO =

  • JOB_OUTPUT_INFO =

  • JOB_OUTPUT_OPTIONS =

TABLES

itab1 = itab1

itab = itab

  • 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.

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT a~bukrs a~werks a~ebeln a~ebelp

b~bedat a~matnr a~meins b~menge

b~wemng b~eindt c~lifnr b~etenr

FROM ekpo AS a

INNER JOIN eket AS b

ON a~ebeln = b~ebeln AND

a~ebelp = b~ebelp

INNER JOIN ekko AS c

ON a~ebeln = c~ebeln AND

a~bukrs = c~bukrs

INTO CORRESPONDING FIELDS OF TABLE it_pos

WHERE a~bukrs IN s_bukrs

AND a~werks IN s_werks

AND b~eindt IN s_eindt

AND c~lifnr IN s_lifnr

AND c~ekgrp IN s_ekgrp

AND c~ebeln IN s_ebeln

AND a~mtart IN s_mtart

AND a~matkl IN s_matkl

AND a~matnr IN s_matnr

AND c~bstyp EQ 'F'

AND c~loekz EQ space

AND a~loekz EQ space

AND b~menge > b~wemng.

SELECT DISTINCT a~lifnr b~name1 b~street b~str_suppl1 b~str_suppl2

b~city1 b~post_code1 a~adrnr a~telf1 a~telf2

FROM lfa1 AS a

INNER JOIN adrc AS b

ON a~adrnr = b~addrnumber

INTO CORRESPONDING FIELDS OF TABLE it_vendor

FOR ALL ENTRIES IN it_pos

WHERE a~lifnr = it_pos-lifnr.

LOOP AT it_vendor.

SELECT SINGLE * FROM adr6

WHERE addrnumber = it_vendor-adrnr

AND persnumber EQ space.

IF sy-subrc = 0.

it_vendor-smtp_addr = adr6-smtp_addr.

ENDIF.

MODIFY it_vendor.

SELECT SINGLE * FROM lfa1

WHERE lifnr = it_vendor-lifnr.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING lfa1 TO itab1.

APPEND itab1.

ENDIF.

ENDLOOP.

LOOP AT it_pos.

itab-bukrs = it_pos-bukrs.

itab-ebeln = it_pos-ebeln.

itab-ebelp = it_pos-ebelp.

itab-matnr = it_pos-matnr.

itab-bedat = it_pos-bedat.

itab-meins = it_pos-meins.

itab-eindt = it_pos-eindt.

itab-lifnr = it_pos-lifnr.

itab-etenr = it_pos-etenr.

APPEND itab.

CLEAR itab.

ENDLOOP.

ENDFORM. "get_data

&----


*& Form mail_recipient_object

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form mail_recipient_object .

data: email_address TYPE SO_NAME.

email_address = ' '.

CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'

EXPORTING

  • IP_COUNTRY =

  • IP_FAXNO =

IP_MAILADDR = email_address

IP_TYPE_ID = 'U'

IMPORTING

EP_RECIPIENT_ID = email_recipient

  • 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

&----


*& Form mail_sender_object

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form mail_sender_object .

CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'

EXPORTING

IP_SENDER = sy-uname

IMPORTING

EP_SENDER_ID = email_sender

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_g_mail_app_obj.

include <cntn01>.

DATA: 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.

SELECT single * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.

IF sy-subrc NE 0.

CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'

EXPORTING

SAPNAME = SY-UNAME

  • SO_KEY = ' '

  • SEND_MAIL_IF_NO_ADDRESS = 'X'

  • IMPORTING

  • USRADR =

EXCEPTIONS

NO_INSERT = 1

SAP_NAME_EXIST = 2

X_ERROR = 3

SAP_NAME_NOT_EXIST = 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.

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 g_mail_app_obj.

IF sy-subrc ne 0.

clear g_mail_app_obj.

ENDIF.

ENDIF.

ELSE.

clear g_mail_app_obj.

ENDIF.

endform. " mail_appl_object

With Regards,

Kiran.G

Former Member
0 Kudos

hi,

Check out the below links

http://www.sapfans.com/forums/viewtopic.php?t=305936

Regards,

Santosh