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

Email attachment or internal table

Former Member
0 Likes
861

Hi

I would like to email a txt file with multiple records( length of 512 characters).

What functions are available?

record1 field1(512characters)
record2 field1(512characters)

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
817

Check below code...

DATA : l_email_title TYPE sood1-objdes.

DATA : l_file_name TYPE soobjchgi1-obj_descr.

DATA : lit_email_receiver TYPE zphr1_email_tab.

DATA : lit_email_msg LIKE soli.

DATA : lit_attachment LIKE soli.

DATA: l_lines LIKE sy-tabix,

l_msg_lines LIKE sy-tabix.

  • Creation of the document to be sent

CLEAR: l_email_title,

l_file_name,

lit_email_receiver,

lit_email_msg,

lit_attachment,

gf_doc_chng,

it_objtxt,

it_objbody,

it_objpack,

it_objhead,

it_reclist.

REFRESH: it_objtxt,

it_objbody,

it_objpack,

it_objhead,

it_reclist.

*Passing mail subject

gf_doc_chng-obj_name = text-035.

gf_doc_chng-obj_descr = text-036.

  • Fill the document data.

gf_doc_chng-doc_size = 1.

  • Populate the subject/generic message attributes

gf_doc_chng-obj_langu = sy-langu.

gf_doc_chng-obj_name = c_saprpt.

gf_doc_chng-sensitivty = c_value_f.

  • Fill the document data and get size of attachment

  • DESCRIBE TABLE it_output_soli LINES l_lines.

gf_doc_chng-doc_size =

( l_lines - 1 ) * 255 + STRLEN( it_output_soli ).

gf_doc_chng-obj_langu = sy-langu.

gf_doc_chng-obj_name = c_saprpt.

gf_doc_chng-sensitivty = c_value_f.

*Passing text for mail body

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = c_hi.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = text-036.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = c_thanks.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

DESCRIBE TABLE it_objbody LINES l_msg_lines.

READ TABLE it_objbody INDEX l_msg_lines.

gf_doc_chng-doc_size = ( l_msg_lines - 1 ) * 255 + STRLEN( it_objbody

).

  • Creation of the entry for the compressed document

it_objpack-transf_bin = ' '.

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = l_msg_lines.

it_objpack-doc_type = c_doc_type.

APPEND it_objpack.

CLEAR it_objpack.

LOOP AT it_output_soli.

it_objtxt = it_output_soli.

APPEND it_objtxt.

CLEAR it_objtxt.

ENDLOOP.

  • Passing the heading of the report

it_objhead = text-037.

APPEND it_objhead.

CLEAR it_objhead.

*To compress the table to size of 255 characters

CALL FUNCTION 'TABLE_COMPRESS'

TABLES

in = it_objtxt

out = it_comprsd.

IF sy-subrc <> 0.

ENDIF.

  • To decompress the compressed table

CALL FUNCTION 'TABLE_DECOMPRESS'

TABLES

in = it_comprsd

out = it_decomprsd.

IF sy-subrc <> 0.

ENDIF.

  • Creation of the document attachment

CLEAR : l_msg_lines,l_lines.

DESCRIBE TABLE it_decomprsd LINES l_lines.

IF l_lines <> 0. "Don't create attachment if no data is present

  • Creation of the entry for the compressed attachment

it_objpack-transf_bin = c_value_x.

it_objpack-head_start = 1.

it_objpack-head_num = 1.

it_objpack-body_start = 1.

it_objpack-body_num = l_lines.

it_objpack-doc_type = c_excel.

it_objpack-obj_name = sy-repid.

it_objpack-obj_descr = text-036.

it_objpack-doc_size = l_lines * 255.

APPEND it_objpack.

CLEAR it_objpack.

ENDIF.

LOOP AT s_email.

it_reclist-receiver = s_email-low.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

ENDLOOP.

*Passing maild of the user(who runs the report)

  • with extension @eur.appliedbiosystems.com

CLEAR it_reclist.

CONCATENATE sy-uname text-031 INTO it_reclist-receiver.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

  • with extension @applera.com

CLEAR it_reclist.

CONCATENATE sy-uname text-032 INTO it_reclist-receiver.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

*Sending mail with attachment

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = gf_doc_chng

put_in_outbox = c_val

commit_work = c_val

TABLES

packing_list = it_objpack

contents_bin = it_decomprsd

contents_txt = it_objbody

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

IF sy-subrc IS NOT INITIAL.

WRITE: / text-034.

ELSE.

WRITE: / text-033.

ENDIF.

ENDFORM. " send_email

Hi

I would like to email a txt file with multiple records( length of 512 characters).

What functions are available?

record1 field1(512characters)
record2 field1(512characters)

5 REPLIES 5
Read only

Former Member
0 Likes
818

Check below code...

DATA : l_email_title TYPE sood1-objdes.

DATA : l_file_name TYPE soobjchgi1-obj_descr.

DATA : lit_email_receiver TYPE zphr1_email_tab.

DATA : lit_email_msg LIKE soli.

DATA : lit_attachment LIKE soli.

DATA: l_lines LIKE sy-tabix,

l_msg_lines LIKE sy-tabix.

  • Creation of the document to be sent

CLEAR: l_email_title,

l_file_name,

lit_email_receiver,

lit_email_msg,

lit_attachment,

gf_doc_chng,

it_objtxt,

it_objbody,

it_objpack,

it_objhead,

it_reclist.

REFRESH: it_objtxt,

it_objbody,

it_objpack,

it_objhead,

it_reclist.

*Passing mail subject

gf_doc_chng-obj_name = text-035.

gf_doc_chng-obj_descr = text-036.

  • Fill the document data.

gf_doc_chng-doc_size = 1.

  • Populate the subject/generic message attributes

gf_doc_chng-obj_langu = sy-langu.

gf_doc_chng-obj_name = c_saprpt.

gf_doc_chng-sensitivty = c_value_f.

  • Fill the document data and get size of attachment

  • DESCRIBE TABLE it_output_soli LINES l_lines.

gf_doc_chng-doc_size =

( l_lines - 1 ) * 255 + STRLEN( it_output_soli ).

gf_doc_chng-obj_langu = sy-langu.

gf_doc_chng-obj_name = c_saprpt.

gf_doc_chng-sensitivty = c_value_f.

*Passing text for mail body

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = c_hi.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = text-036.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = c_thanks.

APPEND it_objbody.

CLEAR it_objbody.

it_objbody = space.

APPEND it_objbody.

CLEAR it_objbody.

DESCRIBE TABLE it_objbody LINES l_msg_lines.

READ TABLE it_objbody INDEX l_msg_lines.

gf_doc_chng-doc_size = ( l_msg_lines - 1 ) * 255 + STRLEN( it_objbody

).

  • Creation of the entry for the compressed document

it_objpack-transf_bin = ' '.

it_objpack-head_start = 1.

it_objpack-head_num = 0.

it_objpack-body_start = 1.

it_objpack-body_num = l_msg_lines.

it_objpack-doc_type = c_doc_type.

APPEND it_objpack.

CLEAR it_objpack.

LOOP AT it_output_soli.

it_objtxt = it_output_soli.

APPEND it_objtxt.

CLEAR it_objtxt.

ENDLOOP.

  • Passing the heading of the report

it_objhead = text-037.

APPEND it_objhead.

CLEAR it_objhead.

*To compress the table to size of 255 characters

CALL FUNCTION 'TABLE_COMPRESS'

TABLES

in = it_objtxt

out = it_comprsd.

IF sy-subrc <> 0.

ENDIF.

  • To decompress the compressed table

CALL FUNCTION 'TABLE_DECOMPRESS'

TABLES

in = it_comprsd

out = it_decomprsd.

IF sy-subrc <> 0.

ENDIF.

  • Creation of the document attachment

CLEAR : l_msg_lines,l_lines.

DESCRIBE TABLE it_decomprsd LINES l_lines.

IF l_lines <> 0. "Don't create attachment if no data is present

  • Creation of the entry for the compressed attachment

it_objpack-transf_bin = c_value_x.

it_objpack-head_start = 1.

it_objpack-head_num = 1.

it_objpack-body_start = 1.

it_objpack-body_num = l_lines.

it_objpack-doc_type = c_excel.

it_objpack-obj_name = sy-repid.

it_objpack-obj_descr = text-036.

it_objpack-doc_size = l_lines * 255.

APPEND it_objpack.

CLEAR it_objpack.

ENDIF.

LOOP AT s_email.

it_reclist-receiver = s_email-low.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

ENDLOOP.

*Passing maild of the user(who runs the report)

  • with extension @eur.appliedbiosystems.com

CLEAR it_reclist.

CONCATENATE sy-uname text-031 INTO it_reclist-receiver.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

  • with extension @applera.com

CLEAR it_reclist.

CONCATENATE sy-uname text-032 INTO it_reclist-receiver.

it_reclist-rec_type = c_rec_type.

it_reclist-express = c_value_x.

APPEND it_reclist.

*Sending mail with attachment

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = gf_doc_chng

put_in_outbox = c_val

commit_work = c_val

TABLES

packing_list = it_objpack

contents_bin = it_decomprsd

contents_txt = it_objbody

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

IF sy-subrc IS NOT INITIAL.

WRITE: / text-034.

ELSE.

WRITE: / text-033.

ENDIF.

ENDFORM. " send_email

Read only

0 Likes
817

Hi

Thanks, but when i open up the text file only 255 characters are displayed in the file. The rest are lost.

I'm using CALL FUNCTION 'SO_DOCUMENT_SEND_API1. The contents_bin only permits 255 characters

regards

Giovanni.

Edited by: Giovanni Baumann on Feb 19, 2009 10:36 AM

Read only

Former Member
0 Likes
817

hi

set the exporting parameter, Commit_work = 'X' in the function module. and check whether it works.

Read only

0 Likes
817

Manjo, this field has already been set to 'X'.

How would one pick up a file from a network/server drive to include as an email attachment ?

Read only

Former Member
0 Likes
817

N.B:declate lv_mime_type(34) TYPE c VALUE 'APPLICATION/MSEXCEL; charset=UTF-8',

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

these are the FM to use. if you need more details about how to build the excel file. just let me know.