Search on this Website

Friday, June 22, 2007

How to send emails to a recipient address containing the smart form in the PDF format as an attachment

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-line+v1(v2) = l_str+0(v2).

ENDIF.

APPEND objbin.

CLEAR objbin.

v1 = v3.
v3 = 134 - v1.

IF NOT v1 IS INITIAL.

objbin-line+0(v1) = l_str+v3(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 ‘INT’ 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.

Designed By : Srikanth Vadlamani
Netweaver Integration team

Source : http://abapcode.blogspot.com

No comments: