cancel
Showing results for 
Search instead for 
Did you mean: 

Email:Text and PDF Forms

Former Member
0 Kudos

Hi Experts,

There is a requirement for sending smartform as Text attachements from one action and smartform as PDF attachements from another action.

Kindly let me know,How can I do this?

Thanks,

Adi.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

The above reply requires spool i guess without that, we can do it this way.

&----


*& Report ZTEST_ATTACHMENT

*&

&----


*&

*&

&----


REPORT ztest_attachment.

DATA: lf_fm_name TYPE rs38l_fnam.

DATA: ls_control_param TYPE ssfctrlop.

DATA: ls_composer_param TYPE ssfcompop.

DATA: ls_recipient TYPE swotobjid.

DATA: ls_sender TYPE swotobjid.

DATA: lf_formname TYPE tdsfname.

DATA: ls_addr_key LIKE addr_key.

DATA: document_output_info TYPE ssfcrespd,

tab_otf_data TYPE ssfcrescl,

job_output_options TYPE ssfcresop.

DATA: file_size TYPE i ,

bin_filesize TYPE i ,

my_tabix TYPE sy-tabix,

w_complines TYPE i .

DATA : pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE ,

pdf_buffered LIKE tline OCCURS 0 WITH HEADER LINE,

itab TYPE TABLE OF ty_tab,

itab_final TYPE itcoo OCCURS 0 WITH HEADER LINE,

t_attach_data TYPE TABLE OF solisti1,

t_objcont TYPE TABLE OF soli.

DATA : w_email TYPE string VALUE ' '.

TABLES: nast, "Messages

*nast, "Messages

tnapr, "Programs & Forms

itcpo, "Communicationarea for Spool

arc_params, "Archive parameters

toa_dara, "Archive parameters

addr_key. "Adressnumber for ADDRESS

DATA price_print_mode(1) TYPE c. "Print-mode

DATA: retcode LIKE sy-subrc. "Returncode

*"Work Areas for Sending Mail..........................................

Data:

wa_doc_data TYPE sodocchgi1, " Work Area to hold Attributes of New Document

wa_pack TYPE sopcklsti1, " Work Area for Packing List of Main Document

wa_objhead TYPE solisti1, " Work Area to store Header Text

wa_messbody TYPE solisti1, " Work Area to store Message Body

wa_receivers TYPE somlrec90, " Work Area to store Receiver Information

wa_attach_data TYPE solisti1, " Work Area to store the Attached Document

wa_objcont TYPE soli, " Work Area to store data upto 255 Lines.

t_receivers LIKE TABLE OF wa_receivers,

t_pack LIKE STANDARD TABLE OF wa_pack,

t_messbody type table of solisti1,

t_objhead like table of wa_objhead,

*"Work Variables for Sending Mail......................................

w_tablines TYPE i, " Variable to store Table Lines

w_line TYPE so_text255, " Line of text

w_title LIKE kna1-anred. "#EC NEEDED

PERFORM set_print_param CHANGING ls_control_param

ls_composer_param.

  • determine smartform function module for test

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'Z_TESTYH1055'

IMPORTING

fm_name = lf_fm_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

Write : 'Smart form name not recognised'.

ENDIF.

*Calling Function module generated by ssf call...

CALL FUNCTION lf_fm_name

EXPORTING

  • ARCHIVE_INDEX = ARCHIVE_INDEX

  • ARCHIVE_INDEX_TAB = ARCHIVE_INDEX_TAB

  • ARCHIVE_PARAMETERS = ARCHIVE_PARAMETERS

control_parameters = ls_control_param

  • MAIL_APPL_OBJ = MAIL_APPL_OBJ

  • MAIL_RECIPIENT = MAIL_RECIPIENT

  • MAIL_SENDER = MAIL_SENDER

output_options = ls_composer_param

user_settings = 'X'

IMPORTING

  • DOCUMENT_OUTPUT_INFO = DOCUMENT_OUTPUT_INFO

job_output_info = tab_otf_data

  • JOB_OUTPUT_OPTIONS = JOB_OUTPUT_OPTIONS

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

.

IF sy-subrc <> 0.

Write : 'Function module name not recognised'.

ENDIF.

itab_final[] = tab_otf_data-otfdata[].

*These lines to be inserted in case when two smart forms are called from the same program

*DELETE tab_otf_data-otfdata WHERE tdprintcom = '//'.

*READ TABLE itab_final WITH KEY tdprintcom = 'EP'.

*my_tabix = sy-tabix + 1.

*

*INSERT lines of tab_otf_data-otfdata INTO itab_final INDEX my_tabix.

PERFORM otf_to_pdf.

&----


*& Form set_print_param

&----


  • Setting smart form print parameters

----


  • <--P_LS_CONTROL_PARAM text

  • <--P_LS_COMPOSER_PARAM text

  • <--P_LS_RECIPIENT text

  • <--P_LS_SENDER text

  • <--P_RETCODE text

----


FORM set_print_param CHANGING cs_control_param TYPE ssfctrlop

cs_composer_param TYPE ssfcompop.

DATA: ls_itcpo TYPE itcpo.

DATA: lf_repid TYPE sy-repid.

*Setting composer parameters and control parameters for display

cs_composer_param-tddest = 'LP01'. "Note 591576

cs_control_param-no_dialog = 'X'.

cs_control_param-preview = space.

cs_control_param-getotf = 'X'.

ENDFORM. " set_print_param

&----


*& Form otf_to_pdf

&----


  • Convrting Smart-form otf output into PDF Format

----


  • --> p1 text

  • <-- p2 text

----


FORM otf_to_pdf .

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

  • PDF_DELETE_OTFTAB = ' '

IMPORTING

bin_filesize = bin_filesize

  • * BIN_FILE = BIN_FILE

TABLES

otf = itab_final "Otf file of type itcoo

lines = pdf_tab "Pdf file of type tline

  • EXCEPTIONS

  • ERR_MAX_LINEWIDTH = 1

  • ERR_FORMAT = 2

  • ERR_CONV_NOT_POSSIBLE = 3

  • ERR_BAD_OTF = 4.

.

  • Downloading the file recieved while conversion of otf 2 pdf

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

bin_filesize = bin_filesize

filename = 'D:/TEST4.PDF'

filetype = 'BIN'

  • APPEND = ' '

  • WRITE_FIELD_SEPARATOR = ' '

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

IMPORTING

filelength = file_size

TABLES

data_tab = pdf_tab

  • FIELDNAMES = FIELDNAMES

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21.

  • Changing the pdf file size into the sixe reqd to send it as an attachment

PERFORM conversion_of_size.

PERFORM Subject_line_of_mail.

PERFORM body_of_mail.

PERFORM sending_of_mail.

ENDFORM. " otf_to_pdf.

&----


*& Form conversion_of_size

&----


  • Changing the pdf file size into the sixe reqd to send it as an attachment

&----


FORM conversion_of_size .

*"Declaring Local Constants............................................

CONSTANTS:

cnv_hexconst_zero TYPE x VALUE '00'.

"----


  • Internal table to hold 255 Char's Single Line. *

"----


DATA:

lv_big_lines(268) TYPE c

OCCURS 0 WITH HEADER LINE.

*"Local Work Variables.................................................

DATA:

lfl_flag TYPE c,

lv_left_t(268) TYPE c,

lv_left_i TYPE i,

tv_left_i TYPE i,

lv_curr_i TYPE i.

FIELD-SYMBOLS: <f>.

  • Get the lines into a table of 268 char as the first step to put it in

  • the pdf file of 255 chars

CLEAR lfl_flag.

LOOP AT pdf_tab INTO pdf_tab.

IF lfl_flag EQ ' '.

CLEAR lv_big_lines .

ASSIGN lv_big_lines(134) TO <f>.

<f> = pdf_tab.

lfl_flag = 'X'.

ELSE.

lv_big_lines+134 = pdf_tab.

APPEND lv_big_lines.

CLEAR: lfl_flag.

ENDIF. " If lfl_flag = ''..

ENDLOOP. " Loop at t_pdf

IF lfl_flag EQ 'X'.

APPEND lv_big_lines.

ENDIF. " If lflf_flag eq 'X'..

  • Next fill it into a 255 char table

CLEAR: lv_left_t, lv_left_i, tv_left_i.

lv_curr_i = 255.

LOOP AT lv_big_lines.

IF lv_left_i NE 0.

IF lv_curr_i NE 0.

wa_objcont(lv_left_i) = lv_left_t(lv_left_i).

wa_objcont+lv_left_i(lv_curr_i) = lv_big_lines(lv_curr_i).

ELSE.

wa_objcont = lv_left_t(lv_left_i).

ENDIF. " IF lv_curr_i NE 0

ELSE.

wa_objcont = lv_big_lines(lv_curr_i).

ENDIF. " IF lv_left_i NE 0

APPEND wa_objcont TO t_objcont.

tv_left_i = 268 - lv_curr_i.

IF tv_left_i > 255.

wa_objcont = lv_big_lines+lv_curr_i(255).

APPEND wa_objcont TO t_objcont.

lv_left_i = tv_left_i - 255.

tv_left_i = 255 + lv_curr_i.

lv_curr_i = 255 - lv_left_i.

lv_left_t = lv_big_lines+tv_left_i.

ELSE.

lv_left_t = lv_big_lines+lv_curr_i.

lv_left_i = 268 - lv_curr_i.

lv_curr_i = 255 - lv_left_i.

ENDIF. " IF tv_left_i > 255

ENDLOOP. " LOOP AT lv_big_lines.

CLEAR wa_objcont .

ASSIGN wa_objcont(lv_left_i) TO <f>.

<f> = lv_left_t(lv_left_i).

APPEND wa_objcont TO t_objcont.

ENDFORM. " conversion_of_size

&----


*& Form Subject_line_of_mail

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form Subject_line_of_mail .

CONSTANTS:

lc_f TYPE c VALUE 'F', " Sensitivity

lc_objname(6) TYPE c VALUE 'SAPRPT'.

*"Local Work Variables.................................................

DATA:

lc_descr(30) TYPE c. " Object Description

CLEAR wa_doc_data.

CONCATENATE 'Test mail' '1' into lc_descr.

*"Populate the subject/generic Message attributes......................

wa_doc_data-doc_size = 1.

wa_doc_data-obj_langu = sy-langu.

wa_doc_data-obj_name = lc_objname.

wa_doc_data-sensitivty = lc_f.

wa_doc_data-obj_descr = lc_descr.

endform. " Subject_line_of_mail

&----


*& Form body_of_mail

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form body_of_mail .

CONSTANTS:

lc_doc_type(3) TYPE c VALUE 'RAW'.

" Document type

REFRESH:

t_pack,

t_messbody.

CLEAR:

wa_pack,

wa_messbody.

*"Preparing Message Body Text..........................................

CONCATENATE 'This is sent to test for language solution , '

'Sorry for any inconvience caused'

INTO wa_messbody-line.

APPEND wa_messbody TO t_messbody.

wa_messbody-line = text-004.

APPEND wa_messbody TO t_messbody.

DESCRIBE TABLE t_messbody LINES w_tablines.

READ TABLE t_messbody INTO wa_messbody INDEX w_tablines.

*"Setting up Document Data Attribute...................................

wa_doc_data-doc_size = w_tablines.

*"Setting up Packing List Attributes...................................

wa_pack-transf_bin = ' '.

wa_pack-head_start = 1.

wa_pack-head_num = 0.

wa_pack-body_start = 1.

wa_pack-body_num = w_tablines.

wa_pack-doc_type = lc_doc_type.

APPEND wa_pack TO t_pack.

endform. " body_of_mail

&----


*& Form sending_of_mail

&----


  • Sending of mail with attachment

----


form sending_of_mail .

Refresh:

t_objhead,

t_attach_data.

CLEAR:

wa_attach_data.

  • Moving the table Recieved after conversion type soli

t_attach_data = t_objcont.

DESCRIBE TABLE t_attach_data LINES w_tablines.

wa_doc_data-doc_size = w_tablines.

*"Setting up Packing List Attributes...................................

wa_pack-transf_bin = 'X'.

wa_pack-head_start = 0.

wa_pack-head_num = 0.

wa_pack-body_start = 0.

wa_pack-body_num = w_tablines.

wa_pack-doc_size = w_tablines * 255.

wa_pack-doc_type = 'PDF'.

wa_pack-obj_name = 'Attachment'.

wa_pack-obj_descr = 'This is a SAP Report'.

APPEND wa_pack TO t_pack.

*"Setting up Receiver Attributes.......................................

wa_receivers-receiver = w_email.

wa_receivers-rec_type = 'U'.

APPEND wa_receivers TO t_receivers.

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = wa_doc_data

put_in_outbox = 'X'

  • SENDER_ADDRESS = SY-UNAME

  • SENDER_ADDRESS_TYPE = 'B'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL = SENT_TO_ALL

  • NEW_OBJECT_ID = NEW_OBJECT_ID

  • SENDER_ID = SENDER_ID

TABLES

packing_list = t_pack

OBJECT_HEADER = t_objhead

contents_bin = t_attach_data

CONTENTS_TXT = t_messbody

  • CONTENTS_HEX = CONTENTS_HEX

  • OBJECT_PARA = OBJECT_PARA

  • OBJECT_PARB = OBJECT_PARB

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

.

IF sy-subrc EQ 0 .

WRITE : 'Mail sent'.

ENDIF.

endform. " sending_of_mail

Try this.

Regards,

Nisrin.

Former Member
0 Kudos

Hi,

&----


*& Report ZSPOOLTOPDF *

*& *

&----


*& 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 zspooltopdf.

PARAMETER: p_email1 LIKE somlreci1-receiver

DEFAULT 'abapsapdev.co.uk',

p_sender LIKE somlreci1-receiver

DEFAULT 'abapsapdev.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 = 'U'.

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,

SHiva K