cancel
Showing results for 
Search instead for 
Did you mean: 

hi friends i have some doubt on sending form as a mail.

Former Member
0 Kudos

i would like to know how can we generate an sapmail after printing a form and convert it to pdf format and doc format to particular folder. thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

raguraman_c
Active Contributor
0 Kudos

Hi,

This code will help you i feel..

REPORT ZGRO_EMAIL_ITAB_EINFACH.

*

  • --- Parameter für SO_DOCUMENT_SEND_API1

DATA: OBJ_PACK LIKE SOPCKLSTI1 OCCURS 0 WITH HEADER LINE,

OBJ_HEAD LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

OBJ_BIN LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

OBJ_TXT LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE,

REC_LIST LIKE SOMLRECI1 OCCURS 0 WITH HEADER LINE,

DOC_DATA LIKE SODOCCHGI1.

*

DATA: BEGIN OF ITAB OCCURS 0,

TEXT(72),

END OF ITAB.

*

DATA: ITAB_LINE TYPE I.

*

START-OF-SELECTION.

*

PERFORM VERSORGEN_ITAB.

*

CHECK: ITAB_LINE > 1.

*

PERFORM EMAIL_ITAB_RAW.

*

PERFORM RSCONN01_EXECUTE.

*

END-OF-SELECTION.

*

FORM VERSORGEN_ITAB.

  • Fill itab as you like

READ REPORT SY-REPID INTO ITAB.

*

DESCRIBE TABLE ITAB LINES ITAB_LINE.

*

ENDFORM.

*

FORM EMAIL_ITAB_RAW.

*

CLEAR: DOC_DATA, OBJ_PACK, OBJ_HEAD, OBJ_BIN, OBJ_TXT, REC_LIST.

REFRESH: OBJ_PACK, OBJ_HEAD, OBJ_BIN, OBJ_TXT, REC_LIST.

  • email füllen

  • Betreff-Zeile

CLEAR: DOC_DATA.

DOC_DATA-OBJ_NAME = SY-REPID.

DOC_DATA-OBJ_DESCR = 'Send Abap via email RAW'.

  • Empfängerliste

  • email-User (U)

CLEAR REC_LIST.

REC_LIST-RECEIVER = 'test1@test.de'. "email address

REC_LIST-REC_TYPE = 'U'.

APPEND REC_LIST.

REC_LIST-RECEIVER = 'test2@test.de'. "email address

APPEND REC_LIST.

*

  • PACKING_LIST: 1. Zeile gilt immer für email-Inhalt

CLEAR OBJ_PACK.

OBJ_PACK-BODY_START = 01.

OBJ_PACK-BODY_NUM = 03.

OBJ_PACK-DOC_TYPE = 'RAW'.

APPEND OBJ_PACK.

*

  • PACKING_LIST: 2.

CLEAR OBJ_PACK.

OBJ_PACK-TRANSF_BIN = 'X'.

OBJ_PACK-BODY_START = 01.

OBJ_PACK-BODY_NUM = ITAB_LINE.

OBJ_PACK-DOC_TYPE = 'RAW'.

OBJ_PACK-OBJ_NAME = 'Anhang_RAW'.

OBJ_PACK-OBJ_DESCR = SY-REPID.

APPEND OBJ_PACK.

*

*emailinhalt

CLEAR: OBJ_TXT.

OBJ_TXT-LINE = 'Hallo,'.

APPEND OBJ_TXT.

CONCATENATE 'report:' SY-REPID 'als RAW' INTO OBJ_TXT-LINE

SEPARATED BY SPACE.

APPEND OBJ_TXT.

CONCATENATE 'Gruß' SY-UNAME INTO OBJ_TXT-LINE

SEPARATED BY SPACE.

APPEND OBJ_TXT.

*

CLEAR: OBJ_BIN.

LOOP AT ITAB.

OBJ_BIN = ITAB.

APPEND OBJ_BIN.

ENDLOOP.

*

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_DATA

PUT_IN_OUTBOX = 'X'

COMMIT_WORK = 'X'

TABLES

PACKING_LIST = OBJ_PACK

CONTENTS_TXT = OBJ_TXT

CONTENTS_BIN = OBJ_BIN

RECEIVERS = REC_LIST

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.

WRITE: / SY-SUBRC.

ENDIF.

*

ENDFORM.

*

FORM RSCONN01_EXECUTE.

  • Besser 2 Sekunden warten, damit alles versendet ist

WAIT UP TO 2 SECONDS.

*

SUBMIT RSCONN01 WITH MODE = 'INT'

WITH OUTPUT = ' '

AND RETURN.

*

ENDFORM.

Feel free to revert back.

--Ragu

Former Member
0 Kudos

thank u for your replay raman, but i think SAP should be connected to the webmail server. so is it possible to set an SAP mail to the reciepeint, if u have that coding please let me know. thanks in advance.

raguraman_c
Active Contributor
0 Kudos

Hi,

Obviously your should be configured with a mail server, Done through transaction code <b>SCOT</b>. Here you maintatin your mail server (your company mail server).

Hope I was clear.

Feel free to revert back.

--Ragu

Answers (2)

Answers (2)

Former Member
0 Kudos

HI,

&----


*& Report ZLAXMI_ALVMAIL_PDF *

*& *

&----


*& Converts spool request into PDF document and emails it to *

*& recipicant. *

*& *

*& Execution *

*& -


*

*& This program must be run as a background job in-order for the write *

*& commands to create a Spool request rather than be displayed on *

*& screen *

&----


report zlaxmi_alvmail_pdf .

parameter: p_email1 like somlreci1-receiver

default 'abap@sapdev.co.uk',

p_sender like somlreci1-receiver

default 'abap@sapdev.co.uk',

p_delspl as checkbox.

*DATA DECLARATION

data: gd_recsize type i.

  • Spool IDs

types: begin of t_tbtcp.

include structure tbtcp.

types: end of t_tbtcp.

data: it_tbtcp type standard table of t_tbtcp initial size 0,

wa_tbtcp type t_tbtcp.

  • Job Runtime Parameters

data: gd_eventid like tbtcm-eventid,

gd_eventparm like tbtcm-eventparm,

gd_external_program_active like tbtcm-xpgactive,

gd_jobcount like tbtcm-jobcount,

gd_jobname like tbtcm-jobname,

gd_stepcount like tbtcm-stepcount,

gd_error type sy-subrc,

gd_reciever type sy-subrc.

data: w_recsize type i.

data: gd_subject like sodocchgi1-obj_descr,

it_mess_bod like solisti1 occurs 0 with header line,

it_mess_att like solisti1 occurs 0 with header line,

gd_sender_type like soextreci1-adr_typ,

gd_attachment_desc type so_obj_nam,

gd_attachment_name type so_obj_des.

  • Spool to PDF conversions

data: gd_spool_nr like tsp01-rqident,

gd_destination like rlgrap-filename,

gd_bytecount like tst01-dsize,

gd_buffer type string.

  • Binary store for PDF

data: begin of it_pdf_output occurs 0.

include structure tline.

data: end of it_pdf_output.

constants: c_dev like sy-sysid value 'DEV',

c_no(1) type c value ' ',

c_device(4) type c value 'LOCL'.

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

*START-OF-SELECTION.

start-of-selection.

  • Write statement to represent report output. Spool request is created

  • if write statement is executed in background. This could also be an

  • ALV grid which would be converted to PDF without any extra effort

write 'Hello World'.

new-page.

commit work.

new-page print off.

if sy-batch eq 'X'.

perform get_job_details.

perform obtain_spool_id.

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

      • Alternative way could be to submit another program and store spool

      • id into memory, will be stored in sy-spono.

*submit ZSPOOLTOPDF2

  • to sap-spool

  • spool parameters %_print

  • archive parameters %_print

  • without spool dynpro

  • and return.

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

  • Get spool id from program called above

  • IMPORT w_spool_nr FROM MEMORY ID 'SPOOLTOPDF'.

perform convert_spool_to_pdf.

perform process_email.

if p_delspl eq 'X'.

perform delete_spool.

endif.

if sy-sysid = c_dev.

wait up to 5 seconds.

submit rsconn01 with mode = 'INT'

with output = 'X'

and return.

endif.

else.

skip.

write:/ 'Program must be executed in background in-order for spool',

'request to be created.'.

endif.

----


  • FORM obtain_spool_id *

----


form obtain_spool_id.

check not ( gd_jobname is initial ).

check not ( gd_jobcount is initial ).

select * from tbtcp

into table it_tbtcp

where jobname = gd_jobname

and jobcount = gd_jobcount

and stepcount = gd_stepcount

and listident <> '0000000000'

order by jobname

jobcount

stepcount.

read table it_tbtcp into wa_tbtcp index 1.

if sy-subrc = 0.

message s004(zdd) with gd_spool_nr.

gd_spool_nr = wa_tbtcp-listident.

message s004(zdd) with gd_spool_nr.

else.

message s005(zdd).

endif.

endform.

----


  • FORM get_job_details *

----


form get_job_details.

  • Get current job details

call function 'GET_JOB_RUNTIME_INFO'

importing

eventid = gd_eventid

eventparm = gd_eventparm

external_program_active = gd_external_program_active

jobcount = gd_jobcount

jobname = gd_jobname

stepcount = gd_stepcount

exceptions

no_runtime_info = 1

others = 2.

endform.

----


  • FORM convert_spool_to_pdf *

----


form convert_spool_to_pdf.

call function 'CONVERT_ABAPSPOOLJOB_2_PDF'

exporting

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

importing

pdf_bytecount = gd_bytecount

tables

pdf = it_pdf_output

exceptions

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

others = 12.

check sy-subrc = 0.

  • Transfer the 132-long strings to 255-long strings

loop at it_pdf_output.

translate it_pdf_output using ' ~'.

concatenate gd_buffer it_pdf_output into gd_buffer.

endloop.

translate gd_buffer using '~ '.

do.

it_mess_att = gd_buffer.

append it_mess_att.

shift gd_buffer left by 255 places.

if gd_buffer is initial.

exit.

endif.

enddo.

endform.

----


  • FORM process_email *

----


form process_email.

describe table it_mess_att lines gd_recsize.

check gd_recsize > 0.

perform send_email using p_email1.

  • perform send_email using p_email2.

endform.

----


  • FORM send_email *

----


  • --> p_email *

----


form send_email using p_email.

check not ( p_email is initial ).

refresh it_mess_bod.

  • Default subject matter

gd_subject = 'Subject'.

gd_attachment_desc = 'Attachname'.

  • CONCATENATE 'attach_name' ' ' INTO gd_attachment_name.

it_mess_bod = 'Message Body text, line 1'.

append it_mess_bod.

it_mess_bod = 'Message Body text, line 2...'.

append it_mess_bod.

  • If no sender specified - default blank

if p_sender eq space.

gd_sender_type = space.

else.

gd_sender_type = 'INT'.

endif.

  • Send file by email as .xls speadsheet

perform send_file_as_email_attachment

tables it_mess_bod

it_mess_att

using p_email

'Example .xls documnet attachment'

'PDF'

gd_attachment_name

gd_attachment_desc

p_sender

gd_sender_type

changing gd_error

gd_reciever.

endform.

----


  • FORM delete_spool *

----


form delete_spool.

data: ld_spool_nr type tsp01_sp0r-rqid_char.

ld_spool_nr = gd_spool_nr.

check p_delspl <> c_no.

call function 'RSPO_R_RDELETE_SPOOLREQ'

exporting

spoolid = ld_spool_nr.

endform.

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


form send_file_as_email_attachment tables it_message

it_attach

using p_email

p_mtitle

p_format

p_filename

p_attdescription

p_sender_address

p_sender_addres_type

changing p_error

p_reciever.

data: ld_error type sy-subrc,

ld_reciever type sy-subrc,

ld_mtitle like sodocchgi1-obj_descr,

ld_email like somlreci1-receiver,

ld_format type so_obj_tp ,

ld_attdescription type so_obj_nam ,

ld_attfilename type so_obj_des ,

ld_sender_address like soextreci1-receiver,

ld_sender_address_type like soextreci1-adr_typ,

ld_receiver like sy-subrc.

data: t_packing_list like sopcklsti1 occurs 0 with header line,

t_contents like solisti1 occurs 0 with header line,

t_receivers like somlreci1 occurs 0 with header line,

t_attachment like solisti1 occurs 0 with header line,

t_object_header like solisti1 occurs 0 with header line,

w_cnt type i,

w_sent_all(1) type c,

w_doc_data like sodocchgi1.

ld_email = p_email.

ld_mtitle = p_mtitle.

ld_format = p_format.

ld_attdescription = p_attdescription.

ld_attfilename = p_filename.

ld_sender_address = p_sender_address.

ld_sender_address_type = p_sender_addres_type.

  • Fill the document data.

w_doc_data-doc_size = 1.

  • Populate the subject/generic message attributes

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle .

w_doc_data-sensitivty = 'F'.

  • Fill the document data and get size of attachment

clear w_doc_data.

read table it_attach index w_cnt.

w_doc_data-doc_size =

( w_cnt - 1 ) * 255 + strlen( it_attach ).

w_doc_data-obj_langu = sy-langu.

w_doc_data-obj_name = 'SAPRPT'.

w_doc_data-obj_descr = ld_mtitle.

w_doc_data-sensitivty = 'F'.

clear t_attachment.

refresh t_attachment.

t_attachment[] = it_attach[].

  • Describe the body of the message

clear t_packing_list.

refresh t_packing_list.

t_packing_list-transf_bin = space.

t_packing_list-head_start = 1.

t_packing_list-head_num = 0.

t_packing_list-body_start = 1.

describe table it_message lines t_packing_list-body_num.

t_packing_list-doc_type = 'RAW'.

append t_packing_list.

  • Create attachment notification

t_packing_list-transf_bin = 'X'.

t_packing_list-head_start = 1.

t_packing_list-head_num = 1.

t_packing_list-body_start = 1.

describe table t_attachment lines t_packing_list-body_num.

t_packing_list-doc_type = ld_format.

t_packing_list-obj_descr = ld_attdescription.

t_packing_list-obj_name = ld_attfilename.

t_packing_list-doc_size = t_packing_list-body_num * 255.

append t_packing_list.

  • Add the recipients email address

clear t_receivers.

refresh t_receivers.

t_receivers-receiver = ld_email.

t_receivers-rec_type = 'B'.

t_receivers-com_type = 'INT'.

t_receivers-notif_del = 'X'.

t_receivers-notif_ndel = 'X'.

append t_receivers.

call function 'SO_DOCUMENT_SEND_API1'

exporting

document_data = w_doc_data

put_in_outbox = 'X'

sender_address = ld_sender_address

sender_address_type = ld_sender_address_type

commit_work = 'X'

importing

sent_to_all = w_sent_all

tables

packing_list = t_packing_list

contents_bin = t_attachment

contents_txt = it_message

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

  • Populate zerror return code

ld_error = sy-subrc.

  • Populate zreceiver return code

loop at t_receivers.

ld_receiver = t_receivers-retrn_code.

endloop.

endform.

Regards,

Laxmi.

Former Member
0 Kudos

Check the following program, it may help u.

REPORT Z_SCRIPT .

DATA: itcpo LIKE itcpo,

tab_lines LIKE sy-tabix.

  • Variables for EMAIL functionality

DATA: maildata LIKE sodocchgi1.

DATA: mailpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

DATA: mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.

DATA: mailbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.

DATA: mailrec LIKE somlrec90 OCCURS 0 WITH HEADER LINE.

DATA: solisti1 LIKE solisti1 OCCURS 0 WITH HEADER LINE.

PERFORM send_form_via_email.

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

  • FORM SEND_FORM_VIA_EMAIL *

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

FORM send_form_via_email.

CLEAR: maildata, mailtxt, mailbin, mailpack, mailhead, mailrec.

REFRESH: mailtxt, mailbin, mailpack, mailhead, mailrec.

  • Creation of the document to be sent File Name

maildata-obj_name = 'TEST'.

  • Mail Subject

maildata-obj_descr = 'Subject'.

  • Mail Contents

mailtxt-line = 'Here is your file'.

APPEND mailtxt.

  • Prepare Packing List

PERFORM prepare_packing_list.

  • Set recipient - email address here!!!

mailrec-receiver = 'RAVINDRANATH.K@IN.BOSCH.COM'.

mailrec-rec_type = 'U'.

APPEND mailrec.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = maildata

put_in_outbox = ' '

TABLES

packing_list = mailpack

object_header = mailhead

contents_bin = mailbin

contents_txt = mailtxt

receivers = mailrec

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

ENDFORM.

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

  • Form PREPARE_PACKING_LIST

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

FORM prepare_packing_list.

CLEAR: mailpack, mailbin, mailhead.

REFRESH: mailpack, mailbin, mailhead.

DESCRIBE TABLE mailtxt LINES tab_lines.

READ TABLE mailtxt INDEX tab_lines.

maildata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( mailtxt ).

  • Creation of the entry for the compressed document

CLEAR mailpack-transf_bin.

mailpack-head_start = 1.

mailpack-head_num = 0.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'RAW'.

APPEND mailpack.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM get_otf_code.

LOOP AT solisti1.

MOVE-CORRESPONDING solisti1 TO mailbin.

APPEND mailbin.

ENDLOOP.

DESCRIBE TABLE mailbin LINES tab_lines.

mailhead = 'TEST.OTF'.

APPEND mailhead.

    • Creation of the entry for the compressed attachment

mailpack-transf_bin = 'X'.

mailpack-head_start = 1.

mailpack-head_num = 1.

mailpack-body_start = 1.

mailpack-body_num = tab_lines.

mailpack-doc_type = 'OTF'.

mailpack-obj_name = 'TEST'.

mailpack-obj_descr = 'Subject'.

mailpack-doc_size = tab_lines * 255.

APPEND mailpack.

ENDFORM.

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

  • Form GET_OTF_CODE

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

FORM get_otf_code.

DATA: BEGIN OF otf OCCURS 0.

INCLUDE STRUCTURE itcoo .

DATA: END OF otf.

DATA: itcpo LIKE itcpo.

DATA: itcpp LIKE itcpp.

CLEAR itcpo.

itcpo-tdgetotf = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

form = 'Z08V3_COLLI'

language = sy-langu

options = itcpo

dialog = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

window = 'MAIN'

EXCEPTIONS

error_message = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

error_message = 01

OTHERS = 02.

MOVE-CORRESPONDING itcpo TO itcpp.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

result = itcpp

TABLES

otfdata = otf

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR solisti1. REFRESH solisti1.

LOOP AT otf.

solisti1-line = otf.

APPEND solisti1.

ENDLOOP.

ENDFORM.

Regards

Former Member
0 Kudos

thanks ravi, but may iknow how can we send the attachment in a pdf format. please let me know.