Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

smartform

Former Member
0 Likes
569

HI all,

How to send emails to a recipient address containing the smartform in the PDF format as an attachment.

thanks

jagruthi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
546

hi,

This document can be utilized while sending a smartform output as an attachment in the PDF format to any recipient email address in the World Wide Web.

Step1: Call the function module of the smartform and pass the final internal table (output table) into the form interface, also exporting the control parameters output options and user settings importing the structure job_output_info and transfer the contents of STRUC_JOB_OUTPUT_INFO-OTFDATA[] into an internal table I_OTFDATA[] which contains the records in OTF format.

Sample Code

CALL FUNCTION v_function_module

EXPORTING

CONTROL_PARAMETERS = STRUC_SSFCTRLOP

OUTPUT_OPTIONS = STRUC_OUTPUT_OPTIONS

USER_SETTINGS = C_NO

IMPORTING

JOB_OUTPUT_INFO = STRUC_JOB_OUTPUT_INFO

TABLES

p_write_file = i_write_file

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5

.

Transferring the data into an internal table

I_OTFDATA[] = STRUC_JOB_OUTPUT_INFO-OTFDATA[].

Step 2: Creation of the document to be sent .Populate the exporting structure doc_chng with the text containing the name of the document and the calculated document size and also populate the table objtxt .

Sample Code

doc_chng-obj_name = text-001. "'ACCOUNT_STATEMENT'.

doc_chng-obj_descr = text-001. "'ACCOUNT_STATEMENT'.

objtxt = text-001. "'ACCOUNT_STATEMENT'.

APPEND objtxt.

CLEAR objtxt.

APPEND objtxt.

APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

Step 3: Creation of the entry for the compressed document by populating the table objpack.

Sample Code

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_raw.

APPEND objpack.

Step 4: Converting the form to PDF format by passing the table in OTF format and storing the returned value in PDF format.

Sample Code

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = l_numbytes

TABLES

otf = i_otfdata

doctab_archive = doctab

lines = i_pdf

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

Step 5: Creation of the document to be attached and storing it in the table objbin to be later on passed on, in the function module.

Sample Code

LOOP AT i_pdf.

CLEAR l_str.

l_str+0(2) = i_pdf-tdformat.

l_str+2(132) = i_pdf-tdline.

v2 = v1 + c_134.

IF v2 LE c_255.

objbin-line+v1(c_134) = l_str.

v1 = v2.

ELSE.

v3 = v2 - c_255.

v2 = c_255 - v1.

IF NOT v2 IS INITIAL.

objbin-linev1(v2) = l_str0(v2).

ENDIF.

APPEND objbin.

CLEAR objbin.

v1 = v3.

v3 = 134 - v1.

IF NOT v1 IS INITIAL.

objbin-line0(v1) = l_strv3(v1).

ENDIF.

ENDIF.

ENDLOOP.

APPEND objbin.

CLEAR objbin.

DESCRIBE TABLE objbin LINES tab_lines.

Step 6: Populating the table objhead to be later on passed in the function module.

Sample Code

Describe table objbin lines tab_lines.

objhead = text-001. "'Account Statement'.

APPEND objhead.

Step 7: Creation of the entry for the compressed attachment

Sample Code

objpack-transf_bin = c_x.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_pdf.

objpack-obj_name = text-001. "''

objpack-obj_descr = text-001. "''

objpack-doc_size = tab_lines * 255.

APPEND objpack.

Step 8: Populating the recipient internet addresses where mails are to be sent in the table reclist to be passed on the function module.

Sample Code

IF NOT i_reclist[] is initial.

SELECT addrnumber

smtp_addr

INTO TABLE i_reclist

FROM adr6

FOR ALL ENTRIES IN i_adrc

WHERE addrnumber = i_adrc-addrnumber.

if sy-subrc = 0.

LOOP AT i_reclist.

reclist-receiver = i_reclist-smtp_addr.

reclist-rec_type = c_u.

APPEND reclist.

CLEAR reclist.

ENDLOOP.

Step 9: CALL FUNCTION 'SO_DOCUMENT_SEND_API1' and pass the already populated structures and tables. The sender address type is u2018INTu2019 and the sender address can be left as default blank.This will mail the contents of OBJBIN (PDF file containing the smartform output) to the recipient internet addresses stored in the table reclist.

Sample Code

EXPORTING

document_data = doc_chng

put_in_outbox = c_x

sender_address = l_sender

sender_address_type = c_int

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

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

thanks

shankar

3 REPLIES 3
Read only

Former Member
0 Likes
546

Hi Jagruthi hanma,

WELCOME TO SDN!!!

Please check this link

Smartform PDF as Mail

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

and also look at this thread

Also check some of the blogs posted by Thomas Jung

/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

Best regards,

raam

Edited by: Kodandarami Reddy.S on Jun 6, 2008 10:14 AM

Read only

Former Member
0 Likes
546

HI,

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 = '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 = 'zyz@mailid'.

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.

Reward if Helpfull

Naresh.

Read only

Former Member
0 Likes
547

hi,

This document can be utilized while sending a smartform output as an attachment in the PDF format to any recipient email address in the World Wide Web.

Step1: Call the function module of the smartform and pass the final internal table (output table) into the form interface, also exporting the control parameters output options and user settings importing the structure job_output_info and transfer the contents of STRUC_JOB_OUTPUT_INFO-OTFDATA[] into an internal table I_OTFDATA[] which contains the records in OTF format.

Sample Code

CALL FUNCTION v_function_module

EXPORTING

CONTROL_PARAMETERS = STRUC_SSFCTRLOP

OUTPUT_OPTIONS = STRUC_OUTPUT_OPTIONS

USER_SETTINGS = C_NO

IMPORTING

JOB_OUTPUT_INFO = STRUC_JOB_OUTPUT_INFO

TABLES

p_write_file = i_write_file

EXCEPTIONS

FORMATTING_ERROR = 1

INTERNAL_ERROR = 2

SEND_ERROR = 3

USER_CANCELED = 4

OTHERS = 5

.

Transferring the data into an internal table

I_OTFDATA[] = STRUC_JOB_OUTPUT_INFO-OTFDATA[].

Step 2: Creation of the document to be sent .Populate the exporting structure doc_chng with the text containing the name of the document and the calculated document size and also populate the table objtxt .

Sample Code

doc_chng-obj_name = text-001. "'ACCOUNT_STATEMENT'.

doc_chng-obj_descr = text-001. "'ACCOUNT_STATEMENT'.

objtxt = text-001. "'ACCOUNT_STATEMENT'.

APPEND objtxt.

CLEAR objtxt.

APPEND objtxt.

APPEND objtxt.

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

Step 3: Creation of the entry for the compressed document by populating the table objpack.

Sample Code

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_raw.

APPEND objpack.

Step 4: Converting the form to PDF format by passing the table in OTF format and storing the returned value in PDF format.

Sample Code

CALL FUNCTION 'CONVERT_OTF_2_PDF'

IMPORTING

bin_filesize = l_numbytes

TABLES

otf = i_otfdata

doctab_archive = doctab

lines = i_pdf

EXCEPTIONS

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

OTHERS = 3.

Step 5: Creation of the document to be attached and storing it in the table objbin to be later on passed on, in the function module.

Sample Code

LOOP AT i_pdf.

CLEAR l_str.

l_str+0(2) = i_pdf-tdformat.

l_str+2(132) = i_pdf-tdline.

v2 = v1 + c_134.

IF v2 LE c_255.

objbin-line+v1(c_134) = l_str.

v1 = v2.

ELSE.

v3 = v2 - c_255.

v2 = c_255 - v1.

IF NOT v2 IS INITIAL.

objbin-linev1(v2) = l_str0(v2).

ENDIF.

APPEND objbin.

CLEAR objbin.

v1 = v3.

v3 = 134 - v1.

IF NOT v1 IS INITIAL.

objbin-line0(v1) = l_strv3(v1).

ENDIF.

ENDIF.

ENDLOOP.

APPEND objbin.

CLEAR objbin.

DESCRIBE TABLE objbin LINES tab_lines.

Step 6: Populating the table objhead to be later on passed in the function module.

Sample Code

Describe table objbin lines tab_lines.

objhead = text-001. "'Account Statement'.

APPEND objhead.

Step 7: Creation of the entry for the compressed attachment

Sample Code

objpack-transf_bin = c_x.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = c_pdf.

objpack-obj_name = text-001. "''

objpack-obj_descr = text-001. "''

objpack-doc_size = tab_lines * 255.

APPEND objpack.

Step 8: Populating the recipient internet addresses where mails are to be sent in the table reclist to be passed on the function module.

Sample Code

IF NOT i_reclist[] is initial.

SELECT addrnumber

smtp_addr

INTO TABLE i_reclist

FROM adr6

FOR ALL ENTRIES IN i_adrc

WHERE addrnumber = i_adrc-addrnumber.

if sy-subrc = 0.

LOOP AT i_reclist.

reclist-receiver = i_reclist-smtp_addr.

reclist-rec_type = c_u.

APPEND reclist.

CLEAR reclist.

ENDLOOP.

Step 9: CALL FUNCTION 'SO_DOCUMENT_SEND_API1' and pass the already populated structures and tables. The sender address type is u2018INTu2019 and the sender address can be left as default blank.This will mail the contents of OBJBIN (PDF file containing the smartform output) to the recipient internet addresses stored in the table reclist.

Sample Code

EXPORTING

document_data = doc_chng

put_in_outbox = c_x

sender_address = l_sender

sender_address_type = c_int

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

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

thanks

shankar