cancel
Showing results for 
Search instead for 
Did you mean: 

Error In emailing smartforms

Former Member
0 Kudos

I am trying to email my smartform output to a specified email address, but I am getting an error messege as mail could not me send as in the function module 'SO_NEW_DOCUMENT_SEND_API1'

Below is the code. The smartform contains a logo only.

Pls see the code and tell me what isn that I am missing!

&----


*& Report ZKHA_SMARTFORM

*&

&----


*&

*&

&----


REPORT zkha_smartform.

TYPE-POOLS: slis,

abap.

DATA : BEGIN OF it_mara OCCURS 0,

matnr LIKE mara-matnr,

END OF it_mara.

DATA: wa_ctrlop TYPE ssfctrlop, "Smart Forms: Control structure

wa_outopt TYPE ssfcompop, " SAP Smart Forms: Smart Composer (transfer)

t_otfdata TYPE ssfcrescl, "Smart Forms: Return value at end of form Printing

t_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE, "#EC *

t_otf TYPE itcoo OCCURS 100 WITH HEADER LINE,"#EC * "itcoo is OTF Struct

w_filesize TYPE i, "#EC *

w_bin_filesize TYPE i, "#EC NEEDED

fm_name TYPE rs38l_fnam.

DATA : fullpath TYPE string, "#EC *

filename TYPE string, "#EC *

path TYPE string, "#EC *

user_action TYPE i, "#EC *

encoding TYPE abap_encoding. "#EC *

PARAMETERS: p_file TYPE rlgrap-filename NO-DISPLAY.

DATA: numbytes TYPE i,

cancel.

*wa_outopt-tddest = ' '.

wa_ctrlop-getotf = 'X'.

wa_ctrlop-no_dialog = 'X'.

*wa_outopt-tdnoprev = 'X'.

*wa_outopt-tdnoprint = 'X'. " CHANGED HERE

*wa_ctrlop-device = 'MAIL'.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'Z_KHATEST1'

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

fm_name = fm_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.

CALL FUNCTION fm_name

EXPORTING

  • ARCHIVE_INDEX =

  • ARCHIVE_INDEX_TAB =

  • ARCHIVE_PARAMETERS =

control_parameters = wa_ctrlop " CHANGED HERE

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • output_options = wa_outopt " CHANGED HERE

  • user_settings = 'X'

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

job_output_info = t_otfdata

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

*CASE sy-ucomm.

*

  • WHEN 'PRNT'. " ADDED HERE

t_otf[] = t_otfdata-otfdata[].

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

  • PDF_DELETE_OTFTAB = ' '

IMPORTING

bin_filesize = w_bin_filesize

  • BIN_FILE =

TABLES

otf = t_otf

lines = t_pdf_tab

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.

************************************************

Data: t_objbin type standard table of SOLISTI1 with header line.

  • Converted to length of 255 Char

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

  • LINE_WIDTH_SRC =

LINE_WIDTH_DST = '255'

  • TRANSFER_BIN = ' '

TABLES

content_in = t_pdf_tab

content_out = t_objbin

EXCEPTIONS

ERR_LINE_WIDTH_SRC_TOO_LONG = 1

ERR_LINE_WIDTH_DST_TOO_LONG = 2

ERR_CONV_FAILED = 3

OTHERS = 4

.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*

*

*

*

PERFORM download_w_ext(rstxpdft) TABLES t_pdf_tab

USING p_file

'.pdf'

'BIN'

numbytes

cancel. "#EC *

  • CLEAR: wa_outopt, wa_ctrlop.

*ENDCASE.

DATA:

t_tline TYPE TABLE OF tline,

t_reclist TYPE TABLE OF somlreci1,

wa_doc_chng TYPE sodocchgi1,

wa_reclist TYPE somlreci1,

wa_return TYPE ssfcrescl,

v_descr TYPE so_obj_des,

v_mailid TYPE ad_smtpadr,

v_adrnr TYPE ad_addrnum ,

v_len_in TYPE string.

wa_doc_chng-obj_name = 'SMARTFORM'.

wa_doc_chng-expiry_dat = sy-datum + 10.

  • wa_doc_chng-obj_descr = v_descr.

wa_doc_chng-sensitivty = 'F'.

wa_doc_chng-obj_langu = sy-langu.

wa_doc_chng-no_change = 'X' .

                • Selecting email address depending on

                • address no.from ADR6 Table

                • SELECT smtp_addr "E-Mail Address

                • FROM adr6 UP TO 1 ROWS

                • INTO v_mailid

                • WHERE addrnumber = v_adrnr.

                • ENDSELECT .

              • wa_reclist-receiver = v_mailid.

wa_reclist-receiver = 'arnab.rudra1@gmail.com'.

" I have hard coded the mail address. It is automatically populating the adr6 table, I donno why???

Pls give immediate resolution!!!!

wa_reclist-rec_type = 'U'.

APPEND wa_reclist TO t_reclist.

break-point.

CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'

EXPORTING

document_data = wa_doc_chng

DOCUMENT_TYPE = 'PDF'

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

  • OBJECT_HEADER =

OBJECT_CONTENT = t_objbin

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = t_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.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Accepted Solutions (0)

Answers (1)

Answers (1)

Ashutosht09
Participant
0 Kudos

Use the following steps for doing the same. These steps are tested succesfully.

1. Get the Function Module Name for the Smart form

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = c_fmname

  • VARIANT = ' '

  • DIRECT_CALL = ' '

IMPORTING

FM_NAME = w_fmname

EXCEPTIONS

NO_FORM = 1

NO_FUNCTION_MODULE = 2

OTHERS = 3

.

2. Set the values to be passed in the Function Module to get the output of the Smart form in OTF format.

  • Set the call for OTF format.

t_control_parameters-no_dialog = c_x.

t_control_parameters-getotf = c_x.

3. Call the function Module for the smartform.

CALL FUNCTION w_fmname

EXPORTING

ARCHIVE_INDEX = H_ARCHIVE_INDEX

  • ARCHIVE_INDEX_TAB =

ARCHIVE_PARAMETERS = H_ARCHIVE_PARAMS

CONTROL_PARAMETERS = t_control_parameters

  • MAIL_APPL_OBJ =

  • MAIL_RECIPIENT =

  • MAIL_SENDER =

  • OUTPUT_OPTIONS =

  • USER_SETTINGS = 'X'

Variable = v_flag

IMPORTING

  • DOCUMENT_OUTPUT_INFO =

JOB_OUTPUT_INFO = w_job_output_info

  • JOB_OUTPUT_OPTIONS =

TABLES

I_table = t_itab

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5

.

4. Convert the OTF format to PDF format using the w_job_output_info-otfdata

DATA: l_filesize TYPE i,

t_lines LIKE tline OCCURS 0,

t_objbin TYPE ty_tab_objbin.

**/ Get the PDF version of the OTF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = l_filesize

  • bin_file = bin_file

TABLES

otf = w_job_output_info-otfdata

lines = t_lines

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

5. Convert the PDF format to format required for attachment.

**/ Convert the PDF format to the table type required for the attachment.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = t_lines

t_target_tab = t_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

6. Create the document to be sent by e-mail

  • Creation of the document to be sent

  • File Name: Name of the file to be attached

w_doc_chng-obj_name = ‘Flename’.

  • Mail Subject

w_doc_chng-obj_descr = ‘Test E-mail’(em1).

  • Completing the recipient list

t_reclist-receiver = t_rec. “e-mail id of the recipient

t_reclist-rec_type = 'U'.

APPEND t_reclist.

  • Mail Contents

t_objtxt = 'Line 1'(bd1).

APPEND t_objtxt.

CLEAR t_objtxt.

APPEND t_objtxt. " to put in a blank line

t_objtxt = 'Line 2'(bd2).

APPEND t_objtxt.

CLEAR t_objtxt.

t_objtxt = ‘Line 3'(bd3).

APPEND t_objtxt.

CLEAR t_objtxt.

APPEND t_objtxt. " to put in a blank line

t_objtxt = ‘Line 4’(bd3).

APPEND t_objtxt.

  • Calculate email size in bytes

DESCRIBE TABLE t_objtxt LINES w_tab_lines.

READ TABLE t_objtxt INDEX w_tab_lines.

w_doc_chng-doc_size = ( w_tab_lines - 1 ) * 255 + STRLEN( t_objtxt ).

  • Creation of the entry for the compressed document

  • for the email text

CLEAR t_objpack-transf_bin.

t_objpack-head_start = 1.

t_objpack-head_num = 0.

t_objpack-body_start = 1.

t_objpack-body_num = w_tab_lines.

t_objpack-doc_type = 'RAW'.

APPEND t_objpack.

  • Creation of the document attachment

  • (Assume that the data in OBJBIN is in BMP format)

DESCRIBE TABLE p_objbin LINES w_tab_lines.

t_objhead = ‘Fielname.PDF'(em5).

APPEND t_objhead.

CLEAR t_objpack.

**/ Creation of the entry for the compressed/attached document

t_objpack-transf_bin = c_x.

t_objpack-head_start = 1.

t_objpack-head_num = 1.

t_objpack-body_start = 1.

t_objpack-body_num = w_tab_lines.

t_objpack-doc_type = 'PDF'.

t_objpack-obj_name = 'Possibly hover name'.

t_objpack-obj_descr = ‘Mail Description'(em6).

t_objpack-doc_size = w_tab_lines * 255.

APPEND t_objpack.

7. Send the document by e-mail

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

put_in_outbox = c_x

TABLES

packing_list = t_objpack

object_header = t_objhead

contents_bin = t_objbin

contents_txt = t_objtxt

receivers = t_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

IF sy-subrc <> 0.

WRITE: / text-014, sy-subrc.

ELSE.

WRITE: / text-015.

ENDIF.

8. Commit work: this step is important to send the email to transaction SOST.

Once the email has reached the transaction SOST then it’s the job of the basis to do the configuration to send it to the specified e-mail id by internet.

**commit work for the email to go into transaction SOST.

COMMIT WORK.

9. In transaction SOST the mail will appear.

Ashutosht09
Participant
0 Kudos

Award points if above steps are useful.

Edited by: Ashutosh Tripathi on Mar 20, 2008 1:04 PM