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

smartforms

Former Member
0 Likes
326

<b>how can u send output of smartform through mail?</b>

2 REPLIES 2
Read only

Former Member
0 Likes
300

Hi

convert the SPOOL of smartform to PDf using the function module CONVERT_ABAPSPOOLJOB_2_PDF

ans send that as mail using the function module

SO_NEW_DOCUMENT_ATT_SEND_API1

see the sample code

----


  • INCLUDE ZINCUSMAIL *

----


include <symbol>.

data : i_doc_data like sodocchgi1.

data : begin of i_pack_list occurs 0.

include structure sopcklsti1.

data : end of i_pack_list.

data : begin of i_receivers occurs 0.

include structure somlreci1.

data : end of i_receivers.

data : begin of i_contents occurs 0.

include structure solisti1.

data : end of i_contents.

data : begin of i_header occurs 0.

include structure solisti1.

data : end of i_header.

data : begin of i_att occurs 0.

include structure solisti1.

data : end of i_att.

  • Internal Table for Internet address.

data: begin of it_inad occurs 0,

kunnr like kna1-kunnr, " Customer Code

name1 like kna1-name1, " Customer Name

ssobl like knkk-ssobl, " Security Deposit

klimk like knkk-klimk, " Credit Limit

opbal like bsid-wrbtr, " Opening Balance

clbal like bsid-wrbtr, " Closing Balance

smtp like adr6-smtp_addr, " Internet mail (SMTP) address

end of it_inad.

data : pdf_line(134),

asdf like pdf_line occurs 0 with header line.

data : pdf_table like tline occurs 0 with header line,

pdf_fsize type i.

data : stuff(65000),

len type i,

pos type i,

tab_lines like sy-tabix.

data: spoolid type tsp01-rqident,

spdel type tsp01sys.

data: v_gjahrt like bsid-gjahr,

fmondest(10),

tmondest(10),

kunnr1 like kna1-kunnr,

gjah(4),

fmon(10).

&----


*& Form hide_write

&----


form hide_write.

new-page print on

line-size 160

  • line-count 58

no-title

no-heading

destination 'LOCL'

immediately ' '

new list identification 'X'

no dialog.

set blank lines on.

endform. " hide_write

&----


*& Form end_write

&----


form end_write using kunnr1.

set blank lines off.

new-page print off.

***Using Spoolid we are getting PDF formated file

spoolid = spdel-rqident = sy-spono.

spdel-sys = sy-sysid.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = spoolid

no_dialog = 'X'

importing

pdf_bytecount = pdf_fsize

tables

pdf = pdf_table

exceptions

others = 0.

***Delleting Spool request

call function 'RSPO_IDELETE_SPOOLREQ'

exporting

spoolreq = spdel

exceptions

others = 2.

***Converting PDF table line size 134 into standard list size 255

loop at pdf_table into pdf_line.

if pos = 34170.

perform attach.

endif.

stuff+pos(134) = pdf_line.

add 134 to pos.

endloop.

if not ( stuff is initial ).

perform attach.

endif.

clear pdf_line.

clear pdf_table[].

describe table i_att lines tab_lines.

i_pack_list-transf_bin = 'X'.

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = tab_lines.

i_pack_list-doc_type = 'PDF'.

i_pack_list-obj_name = 'LedgerMail'.

concatenate fmon '-' gjah into i_pack_list-obj_descr.

*i_pack_list-obj_descr = '2092-Oct03'.

i_pack_list-obj_langu = 'E'.

i_pack_list-doc_size = tab_lines * 255.

append i_pack_list.

***Data for receivers list

loop at it_inad where kunnr eq kunnr1.

i_receivers-receiver = it_inad-smtp.

i_receivers-rec_type = 'U'.

i_receivers-rec_date = sy-datum.

i_receivers-express = 'X'.

i_receivers-com_type = 'INT'.

i_receivers-notif_del = 'X'.

append i_receivers.

endloop.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = i_doc_data

  • PUT_IN_OUTBOX = ' '

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

tables

packing_list = i_pack_list

object_header = i_header

contents_bin = i_att

contents_txt = i_contents

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

.

refresh i_att. clear i_att.

refresh i_receivers. clear i_receivers.

delete i_pack_list where doc_type = 'PDF'.

*refresh i_header.

*refresh i_contents.

*clear i_doc_data.

endform. " end_write

&----


*& Form doc_data

&----


form doc_data using fmondest v_gjahrt.

gjah = v_gjahrt.

fmon = fmondest.

***Data for Document Data

i_doc_data-obj_name = 'LedgerMail'.

concatenate 'Customer Ledger for : ' fmondest gjah

into i_doc_data-obj_descr separated by space.

i_doc_data-obj_langu = 'E'.

i_doc_data-obj_prio = '1'.

i_doc_data-no_change = 'X'.

i_doc_data-doc_size = '5101'.

***Data for Packing list

i_pack_list-head_start = '1'.

i_pack_list-head_num = '1'.

i_pack_list-body_start = '1'.

i_pack_list-body_num = '20'.

i_pack_list-doc_type = 'RAW'.

i_pack_list-obj_langu = 'E'.

append i_pack_list.

***Data for Header

i_header-line = 'Header'. append i_header.

***Data for contents

i_contents-line = 'Dear Customer,'. append i_contents.

i_contents-line = ' '. append i_contents.

concatenate 'Please find your enclosed Ledger for the month of : '

fmondest gjah into i_contents-line separated by space.

append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'This is a computer generated document and does not

require a signature.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'Note : If you do not have Acrobat Reader please click

on the below link.'. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = 'http://www.adobe.com/products/acrobat/readstep2.html'

. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

i_contents-line = ' '. append i_contents.

endform. " doc_data

&----


*& Form attach

&----


form attach.

clear pos.

len = strlen( stuff ).

while len > 0.

subtract 255 from len.

i_att = stuff+pos(255).

append i_att.

add 255 to pos.

endwhile.

clear pos.

clear stuff.

endform. " attach

Reward points if useful

Regards

Anji

Read only

sreeramkumar_madisetty
Active Contributor
0 Likes
300

Hi

Use FM:

SO_NEW_DOCUMENT_ATT_SEND_API1

Regards,

Sreeram

Have a look on the sample code:

  • Type for binary attachment table.

types: l_ty_tab_objbin type solisti1 occurs 0.

data: l_objbin type l_ty_tab_objbin.

  • Tables to hold PDF data

data: t_doctab type docs occurs 0,

t_line type tline occurs 0.

tables : soli. "SAPoffice: line, length 255

tables : zpsdsalrep. "ZPSDSALREP

data: l_email type soli-line.

data: l_email1 type soli-line.

data: l_adrnr like kna1-adrnr.

data: l_objky type nast-objky.

data: l_zzterrmg type zpsdsalrep-zzterrmg.

data: l_zsupervisor type zpsdsalrep-zsupervisor.

data: l_kunnr type kna1-kunnr.

data: l_kunnr1 type vbak-kunnr.

data: l_reclist like somlreci1 occurs 0 with header line.

data: l_objtxt like solisti1 occurs 0 with header line.

data: l_objpack like sopcklsti1 occurs 0 with header line.

data: l_doc_chng like sodocchgi1.

data: l_objhead like solisti1 occurs 0 with header line.

data: l_tab_lines like sy-tabix.

constants: k_true type boolean_flg value 'X'.

data: l_mail type somlreci1-receiver.

data: l_mail1 type somlreci1-receiver.

data:

  • l_l_mail2 TYPE somlreci1-receiver.

l_l_mail type somlreci1-receiver.

data: l_zzsalesrep type zpsdsalrep-zzsalesrep.

data: l_recipents type somlreci1-receiver.

constants: k_x(1) type c value 'X',

k_u(1) type c value 'U',

k_raw(3) type c value 'RAW'.

call function 'CONVERT_OTF_2_PDF'

  • EXPORTING

  • USE_OTF_MC_CMD = 'X'

  • ARCHIVE_INDEX =

  • IMPORTING

  • BIN_FILESIZE =

tables

otf = t_otfdata

doctab_archive = t_doctab

lines = t_line

exceptions

err_conv_not_possible = 1

err_otf_mc_noendmarker = 2

others = 3.

if sy-subrc <> 0.

write: / 'error', sy-subrc.

endif.

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

**attachment.

call function 'QCE1_CONVERT'

tables

t_source_tab = t_line

t_target_tab = l_objbin

exceptions

convert_not_possible = 1

others = 2.

if sy-subrc <> 0.

write: / 'error', sy-subrc.

endif.

select single kunnr from vbak into l_kunnr1

where vbeln = nast-objky.

select single adrnr from kna1 into l_adrnr

where kunnr = l_kunnr1.

check sy-subrc is initial.

select single smtp_addr from adr6 into l_email

where addrnumber = l_adrnr.

  • SELECT SINGLE zzterrmg FROM zpsdsalrep INTO l_zzterrmg

  • WHERE zzsalesrep = l_kunnr1.

  • SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor

  • WHERE zzterrmg = l_zzterrmg.

  • SELECT SINGLE kunnr FROM kna1 INTO l_kunnr

  • WHERE sortl = l_zsupervisor.

*

*

    • SELECT SINGLE zsupervisor FROM zpsdsalrep INTO l_zsupervisor

    • WHERE zzsalesrep = l_kunnr1.

    • SELECT SINGLE zzsalesrep FROM zpsdsalrep INTO l_zzsalesrep

    • WHERE zzterrmg = l_zsupervisor.

    • SELECT SINGLE adrnr FROM kna1 INTO l_adrnr

    • WHERE kunnr = l_zzsalesrep.

      • CHECK sy-subrc IS INITIAL.

    • SELECT SINGLE smtp_addr FROM adr6 INTO l_email1

    • WHERE addrnumber = l_adrnr.

*

*

*

  • SELECT SINGLE adrnr FROM kna1 INTO l_adrnr

  • WHERE kunnr = l_kunnr.

    • CHECK sy-subrc IS INITIAL.

  • SELECT SINGLE smtp_addr FROM adr6 INTO l_email1

  • WHERE addrnumber = l_adrnr.

l_mail = l_email.

  • l_mail1 = l_email1.

  • l_l_mail2 = text-006.

l_l_mail = text-007.

  • Creation of the document to be sent

  • File Name

l_doc_chng-obj_name = 'SENDFILE'.

  • Mail Subject

concatenate text-001 nast-objky into l_doc_chng-obj_descr.

  • l_doc_chng-obj_descr = text-001.

  • Completing the recipient list

l_reclist-receiver = l_mail.

l_reclist-rec_type = k_u.

append l_reclist.

  • l_reclist-receiver = l_mail1.

  • l_reclist-rec_type = 'U'.

  • APPEND l_reclist.

l_reclist-receiver = l_l_mail.

l_reclist-rec_type = k_u.

append l_reclist.

  • l_reclist-receiver = l_l_mail2.

  • l_reclist-rec_type = 'U'.

  • APPEND l_reclist.

  • Mail Contents

l_objtxt = text-002.

append l_objtxt.

clear l_objtxt. " put in a blank line

append l_objtxt.

data: l_subject type solisti1.

concatenate text-003 '-' nast-objky into l_subject.

l_objtxt = l_subject.

append l_objtxt.

l_objtxt = text-004 .

append l_objtxt.

  • Calculate email size in bytes

describe table l_objtxt lines l_tab_lines.

read table l_objtxt index l_tab_lines.

l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + strlen( l_objtxt ).

  • Creation of the entry for the compressed document

  • for the email text

clear l_objpack-transf_bin.

l_objpack-head_start = 1.

l_objpack-head_num = 0.

l_objpack-body_start = 1.

l_objpack-body_num = l_tab_lines.

l_objpack-doc_type = k_raw.

append l_objpack.

  • Creation of the document attachment

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

describe table l_objbin lines l_tab_lines.

l_objhead = text-001 .

append l_objhead.

clear l_objpack.

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

l_objpack-transf_bin = k_true.

l_objpack-head_start = 1.

l_objpack-head_num = 1.

l_objpack-body_start = 1.

l_objpack-body_num = l_tab_lines.

l_objpack-doc_type = 'PDF'.

l_objpack-obj_name = text-005.

l_objpack-obj_descr = text-001.

l_objpack-doc_size = l_tab_lines * 255.

append l_objpack. "/ .

delete l_reclist where receiver = ''.

  • Sending the document

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1' " IN UPDATE TASK "/ .

exporting

document_data = l_doc_chng

put_in_outbox = k_x

tables

packing_list = l_objpack

object_header = l_objhead

contents_bin = l_objbin

contents_txt = l_objtxt

receivers = l_reclist

exceptions

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

others = 99.

if sy-subrc <> 0.

write: / 'unsuccessful', sy-subrc.

else.

concatenate l_mail ',' l_mail1 ',' l_l_mail into l_recipents.

syst-msgid = '8I'.

syst-msgno = '000'.

syst-msgty = 'S'.

syst-msgv1 = text-008.

skip.

syst-msgv2 = text-009.

syst-msgv3 = l_recipents.

clear: syst-msgv4. "syst-msgv2, syst-msgv3,

perform protocol_update.

write: / 'successful'.

endif.

**/Take_note it is a requirement to do a commit work for the

  • email to go into transaction SOST.

  • COMMIT WORK. "/Take_note .

  • if sy-subrc eq 0.

  • endif.

Regards,

Sreeram