Application Development 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: 

mailing through SAP

Former Member
0 Kudos
324

I want to send a e-mail through sap program which should contain a file as attachment, which i have downloaded in the same program. Which function should I use.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
170

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = IS_DOCDATA

commit_work = 'X'

TABLES

packing_list = lt_objpack

  • object_header = lt_objhead

contents_txt = lt_objhead

contents_bin = it_content

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

-Sample Code-

data: IS_DOCDATA type SODOCCHGI1,

IS_RECEIVERS type SOMLRECI1,

IS_RECEIVERS_COPY type SOMLRECI1,

IT_RECEIVERS type table of SOMLRECI1,

IS_CONTENT type SOLISTI1,

IT_CONTENT type table of SOLISTI1,

*500369789+

l_txt(255) type c,

lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

l_tab_lines TYPE i,

l_att_type LIKE soodk-objtp.

*500369789+

IS_DOCDATA-OBJ_NAME = 'MAIL'.

IS_DOCDATA-PRIORITY = 5.

IS_DOCDATA-OBJ_LANGU = SY-LANGU.

IS_DOCDATA-NO_CHANGE = 'X'.

IS_DOCDATA-OBJ_DESCR = SY-CPROG.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

  • move IS_MESSAGE-LINE to IS_CONTENT-LINE. "500369789-

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT to IT_CONTENT.

endloop.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT1, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT1 to IT_CONTENT1.

endloop.

*---select_email_address

select single

EMAILADDR

CCEMAILADDR

into (IS_RECEIVERS-RECEIVER, IS_RECEIVERS_COPY-RECEIVER)

from ZGL_EMAILCTRL

where IDENT = ''

and ZPROGRAM = 'Z_L_SO_CREA'

and ACTIVE = 'X'.

if IS_RECEIVERS-RECEIVER is not initial.

IS_RECEIVERS-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-COPY = 'X'.

append IS_RECEIVERS to IT_RECEIVERS.

append IS_RECEIVERS_COPY to IT_RECEIVERS.

*500369789+

lt_objhead-line = 'USA Order Report'.

append lt_objhead.

DESCRIBE TABLE lt_objhead LINES l_tab_lines.

CLEAR lt_objpack-transf_bin.

lt_objpack-doc_size = STRLEN( lt_objhead ).

lt_objpack-head_start = 1.

lt_objpack-head_num = 1.

lt_objpack-body_start = 1.

lt_objpack-body_num = 1.

lt_objpack-doc_type = 'RAW'.

APPEND lt_objpack.

l_att_type = 'RAW'.

DESCRIBE TABLE it_content LINES l_tab_lines.

READ TABLE it_content into is_content INDEX l_tab_lines.

lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255.

lt_objpack-doc_size = lt_objpack-doc_size + STRLEN( is_content ).

lt_objpack-transf_bin = 'X'.

lt_objpack-head_start = 1.

lt_objpack-head_num = 2.

lt_objpack-body_start = 1.

lt_objpack-body_num = l_tab_lines.

lt_objpack-doc_type = l_att_type.

lt_objpack-obj_name = 'ATTACHMENT'.

concatenate 'Usa' SY-DATUM6(2) SY-DATUM4(2) into

lt_objpack-obj_descr. "#EC *

APPEND lt_objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = IS_DOCDATA

commit_work = 'X'

TABLES

packing_list = lt_objpack

  • object_header = lt_objhead

contents_txt = lt_objhead

contents_bin = it_content

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

11 REPLIES 11

Former Member
0 Kudos
171

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = IS_DOCDATA

commit_work = 'X'

TABLES

packing_list = lt_objpack

  • object_header = lt_objhead

contents_txt = lt_objhead

contents_bin = it_content

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

-Sample Code-

data: IS_DOCDATA type SODOCCHGI1,

IS_RECEIVERS type SOMLRECI1,

IS_RECEIVERS_COPY type SOMLRECI1,

IT_RECEIVERS type table of SOMLRECI1,

IS_CONTENT type SOLISTI1,

IT_CONTENT type table of SOLISTI1,

*500369789+

l_txt(255) type c,

lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,

lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,

lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,

l_tab_lines TYPE i,

l_att_type LIKE soodk-objtp.

*500369789+

IS_DOCDATA-OBJ_NAME = 'MAIL'.

IS_DOCDATA-PRIORITY = 5.

IS_DOCDATA-OBJ_LANGU = SY-LANGU.

IS_DOCDATA-NO_CHANGE = 'X'.

IS_DOCDATA-OBJ_DESCR = SY-CPROG.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

  • move IS_MESSAGE-LINE to IS_CONTENT-LINE. "500369789-

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT to IT_CONTENT.

endloop.

loop at IT_MESSAGE into IS_MESSAGE.

clear : IS_CONTENT1, l_txt. "500369789+

move is_message-line to l_txt. "500369789+

move l_txt to IS_CONTENT-LINE. "500369789+

append IS_CONTENT1 to IT_CONTENT1.

endloop.

*---select_email_address

select single

EMAILADDR

CCEMAILADDR

into (IS_RECEIVERS-RECEIVER, IS_RECEIVERS_COPY-RECEIVER)

from ZGL_EMAILCTRL

where IDENT = ''

and ZPROGRAM = 'Z_L_SO_CREA'

and ACTIVE = 'X'.

if IS_RECEIVERS-RECEIVER is not initial.

IS_RECEIVERS-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-REC_TYPE = 'U'.

IS_RECEIVERS_COPY-COPY = 'X'.

append IS_RECEIVERS to IT_RECEIVERS.

append IS_RECEIVERS_COPY to IT_RECEIVERS.

*500369789+

lt_objhead-line = 'USA Order Report'.

append lt_objhead.

DESCRIBE TABLE lt_objhead LINES l_tab_lines.

CLEAR lt_objpack-transf_bin.

lt_objpack-doc_size = STRLEN( lt_objhead ).

lt_objpack-head_start = 1.

lt_objpack-head_num = 1.

lt_objpack-body_start = 1.

lt_objpack-body_num = 1.

lt_objpack-doc_type = 'RAW'.

APPEND lt_objpack.

l_att_type = 'RAW'.

DESCRIBE TABLE it_content LINES l_tab_lines.

READ TABLE it_content into is_content INDEX l_tab_lines.

lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255.

lt_objpack-doc_size = lt_objpack-doc_size + STRLEN( is_content ).

lt_objpack-transf_bin = 'X'.

lt_objpack-head_start = 1.

lt_objpack-head_num = 2.

lt_objpack-body_start = 1.

lt_objpack-body_num = l_tab_lines.

lt_objpack-doc_type = l_att_type.

lt_objpack-obj_name = 'ATTACHMENT'.

concatenate 'Usa' SY-DATUM6(2) SY-DATUM4(2) into

lt_objpack-obj_descr. "#EC *

APPEND lt_objpack.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = IS_DOCDATA

commit_work = 'X'

TABLES

packing_list = lt_objpack

  • object_header = lt_objhead

contents_txt = lt_objhead

contents_bin = it_content

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

Former Member
0 Kudos
170

hi,

Use this function module

CALL FUNCTION 'MC_SEND_MAIL'

EXPORTING

MS_MAIL_SENDMODE = 'B' " Batch Mode

MS_MAIL_TITLE = TITLE

MS_MAIL_DESCRIPTION = DESCRIPTION

MS_MAIL_RECEIVER = USER

MS_MAIL_EXPRESS = 'X'

MS_MAIL_LANGU = 'E'

TABLES

MS_MAIL_CONT = (file object u want to send).

Rewards good answers,

Regards,

Shrita

Former Member
0 Kudos
170

You can use FM SO_DOCUMENT_SEND_API1

Former Member
0 Kudos
170

yOU CAN HAVE A LOOK AT THIS CODE

type-pools: sdydo.

data: do type ref to cl_dd_document.

data: is_displayed.

data: v_email_sent type c,

v_attached type c.

data: begin of gt_extab occurs 0,

fcode like rsmpe-func,

end of gt_extab.

types: begin of t_data,

matnr type matnr,

zzdaycod type zzdaycod,

zzgroes type groes,

zzcsstrttm type zzcsstrttm,

zzcsendtm type zzcsendtm,

zzstkhld type zzstkhld,

end of t_data,

begin of t_comp,

field type rollname,

text(30) type c,

end of t_comp.

data: gt_data type standard table of t_data,

gs_data type t_data,

gt_comp type standard table of t_comp,

gs_comp type t_comp.

parameters: p_qmnum like qmel-qmnum obligatory

default '000000402194'.

parameters: p_mailid(255) type c obligatory

default 'joe.ries@genmills.com' lower case.

select matnr zzdaycod zzgroes zzcsstrttm zzcsendtm zzstkhld

from viqmel

into table gt_data

where refnum = '402194'.

  • Event Handler Definition, handling changes of GUI fonts, colors,...

class cl_my_event_handler definition.

public section.

methods:

use_new_resources for event resources_changed of cl_gui_resources.

endclass. "cl_my_event_handler DEFINITION

data: my_handler type ref to cl_my_event_handler.

create object my_handler.

  • Call Screen

call screen 100.

&----


*& Module STATUS_0100 OUTPUT

&----


module status_0100 output.

set pf-status 'BRP' excluding gt_extab.

if is_displayed is initial.

set handler my_handler->use_new_resources.

  • create document

create object do.

  • fill document

  • PERFORM dd_add_text USING do.

perform zf_dd_add_text using do.

  • merge document

call method do->merge_document.

  • display document

call method do->display_document

exporting

container = 'HTML'

exceptions

html_display_error = 1.

" do some exception handling ...

is_displayed = 'X'.

endif.

endmodule. " STATUS_0100 OUTPUT

&----


  • MODULE user_command_0100 INPUT

&----


module user_command_0100 input.

case sy-ucomm.

when 'BACK'. "Beenden

leave program.

when 'ATTACH'.

perform zf_attach_html.

append 'ATTACH' to gt_extab.

when 'EMAIL'.

perform zf_send_email.

  • perform zf_send_email2.

append 'EMAIL' to gt_extab.

endcase.

endmodule. " USER_COMMAND_0100 INPUT

&----


*& Form DD_ADD_TEXT

&----


  • text

----


form dd_add_text using p_do type ref to cl_dd_document.

data ta type ref to cl_dd_table_element.

data col1 type ref to cl_dd_area.

data col2 type ref to cl_dd_area.

data text type sdydo_text_element.

data text1 type sdydo_text_element.

data text2 type sdydo_text_element.

data text3 type sdydo_text_element.

data texttable type sdydo_text_table.

data buffer(4).

  • set Heading

text = 'Text display in dynamic documents'(001).

call method p_do->add_text

exporting

text = text

sap_style = 'heading'.

call method p_do->new_line.

call method p_do->new_line.

text = 'Methods ADD_TEXT, NEW_LINE, UNDERLINE; Rel99'(002).

call method p_do->add_text

exporting

text = text.

call method p_do->new_line.

call method p_do->underline.

call method p_do->new_line.

  • create table

call method p_do->add_table

exporting

no_of_columns = 2

cell_background_transparent = space

importing

table = ta.

  • set columns

call method ta->add_column

exporting

width = '70%' "'30%'

importing

column = col1.

call method ta->add_column

exporting

width = '30%' "70%'

importing

column = col2.

call method ta->set_column_style

exporting

col_no = 1

sap_color = cl_dd_area=>list_key.

  • fill columns

text = 'Passing a text element - recommended for' &

'texts that need translation'(003).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

text = '(ADD_TEXT, Parameter: TEXT )'(018).

call method col1->add_text

exporting

text = text.

text = 'Text elem.'(500).

call method col2->add_text

exporting

text = text.

call method ta->new_row.

text = 'Text originates in a field (up to 255 chars)'(004).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

text = '(ADD_TEXT, Parameter: TEXT )'(005).

call method col1->add_text

exporting

text = text.

text =

'111111111 222222222 333333333 444444444 555555555 ' &

'666666666 777777777 888888888 999999999 000000000 ' &

'111111111 222222222 333333333 444444444 555555555 ' &

'666666666 777777777 888888888 999999999 000000000 ' &

'111111111 222222222 333333333 444444444 555555555 '.

call method col2->add_text

exporting

text = text.

call method ta->new_row.

text =

'Text originates in a table and is displayed as continuous text'(007).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

text = '(ADD_TEXT, Parameter: TEXT_TABLE )'(008).

call method col1->add_text

exporting

text = text.

do 30 times.

text = 'Text display...'(009).

buffer = sy-index.

concatenate text buffer into text.

append text to texttable.

enddo.

call method col2->add_text

exporting

text_table = texttable.

call method ta->new_row.

text =

'Text originates in a table and is displayed in lines'(017).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

text = '(ADD_TEXT, Parameter: TEXT_TABLE und FIX_LINES )'(010).

call method col1->add_text

exporting

text = text.

clear texttable.

do 10 times.

text = 'Text display....'(009).

buffer = sy-index.

concatenate text buffer into text.

append text to texttable.

enddo.

call method col2->add_text

exporting

text_table = texttable

fix_lines = 'X'.

call method ta->new_row.

text = 'Hard line feed between texts'(011).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

call method col1->add_text

exporting

text = '(NEW_LINE)'.

text1 = 'First line ...'(012).

call method col2->add_text

exporting

text = text1.

call method col2->new_line.

text2 = 'Second line ...'(013).

call method col2->add_text

exporting

text = text2.

call method col2->new_line.

text3 = 'Third line ...'(014).

call method col2->add_text

exporting

text = text3.

call method ta->new_row.

text = 'Blank line between texts'(015).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

call method col1->add_text

exporting

text = '(NEW_LINE)'.

call method col2->add_text

exporting

text = text1.

call method col2->new_line

exporting

repeat = 1.

call method col2->add_text

exporting

text = text2.

call method col2->new_line

exporting

repeat = 2.

call method col2->add_text

exporting

text = text3.

call method ta->new_row.

text = 'Underscore between texts'(016).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

call method col1->add_text

exporting

text = '(UNDERLINE)'.

call method col2->add_text

exporting

text = text1.

call method col2->underline.

call method col2->add_text

exporting

text = text2.

call method col2->underline.

call method col2->add_text

exporting

text = text3.

call method ta->new_row.

text = 'Space between text output'(019).

call method col1->add_text

exporting

text = text.

call method col1->new_line.

text = '(ADD_GAP, Parameter: WIDTH)'(020).

call method col1->add_text

exporting

text = text.

call method col2->add_text

exporting

text = text1.

call method col2->add_gap.

call method col2->add_text

exporting

text = text1.

call method col2->new_line.

call method col2->add_text

exporting

text = text2.

call method col2->add_gap

exporting

width = 10.

call method col2->add_text

exporting

text = text2.

call method col2->new_line.

call method col2->add_text

exporting

text = text3.

call method col2->add_gap

exporting

width = 20.

call method col2->add_text

exporting

text = text3.

endform. "dd_add_text

  • CLASS cl_my_event_handler IMPLEMENTATION.

class cl_my_event_handler implementation.

method use_new_resources.

if is_displayed = 'X'.

  • initialize document

call method do->initialize_document.

  • fill document

perform dd_add_text using do.

  • merge document

call method do->merge_document.

  • display document

call method do->display_document

exporting

reuse_control = 'X'

reuse_registration = 'X'.

endif.

endmethod. "use_new_resources

endclass. "cl_my_event_handler IMPLEMENTATION

&----


*& Form zf_attach_html

&----


  • text

----


form zf_attach_html.

data: i_files like bapifiles occurs 1 with header line,

i_signature like bapisignat occurs 1 with header line,

i_components like bapicompon occurs 1 with header line,

lv_logsys type tbdls-logsys,

lv_objectkey type bapibds01-objkey.

data: lt_doc_content1 type

standard table of bapiconten with header line.

data: g_numbytes type i.

data: lt_ascii type standard table of bapiascont with header line.

data: v_binary_flag type bapibds01-x.

data: wa_html type w3html.

*

loop at do->html_table into wa_html.

lt_ascii = wa_html.

append lt_ascii.

endloop.

*

*****Convert lt_ascii into stream format

data: ld_content_string type string.

data: ld_charsize_uc type i. "unicode

data: ld_size type sy-tabix,

ld_length type i,

lt_content like bapiascont occurs 1,

ls_content_line like line of lt_content.

field-symbols: <ld_html_c> type c. "unicode

loop at lt_ascii.

assign lt_ascii-line to <ld_html_c> casting. "unicode

concatenate ld_content_string <ld_html_c> "unicode

into ld_content_string. "unicode

endloop.

  • if ld_charsize_uc <= 1. "unicode

  • concatenate '</' gc_tag_isr_char '>' into ld_end_tag.

  • search ld_content_string for ld_end_tag.

  • ld_length = strlen( ld_end_tag ).

  • ld_size = sy-fdpos + ld_length.

  • else. "unicode

ld_size = strlen( ld_content_string ). "unicode

  • endif. "unicode

g_numbytes = ld_size.

do.

clear ls_content_line.

if ld_size >= 1022.

ld_length = 1022.

ls_content_line = ld_content_string(ld_length).

shift ld_content_string by ld_length places.

ld_size = ld_size - ld_length.

append ls_content_line to lt_content.

elseif ld_size > 0.

ld_length = ld_size.

ls_content_line(ld_length) =

ld_content_string(ld_length).

append ls_content_line to lt_content.

exit.

else.

exit.

endif.

enddo.

*

clear i_components.

i_components-doc_count = '1'.

i_components-comp_count = '1'.

i_components-comp_id = 'SAP_URL'.

i_components-mimetype = 'TEXT/HTML'.

i_components-comp_size = g_numbytes.

append i_components.

clear i_signature.

i_signature-doc_count = 1.

  • i_signature-prop_name = 'BDS_DOCUMENTCLASS'.

  • i_signature-prop_value = 'HTML'. "file_extension.

  • append i_signature.

i_signature-doc_id = 'Document ID'.

i_signature-doc_count = 1.

i_signature-prop_name = 'DESCRIPTION'.

i_signature-prop_value = 'Description'.

append i_signature.

*

  • clear i_components.

  • i_components-doc_count = '1'.

  • i_components-comp_count = '1'.

  • i_components-comp_id = 'SAP_URL'.

  • i_components-mimetype = 'TEXT/HTML'.

  • i_components-comp_size = g_numbytes.

  • append i_components.

*

*

  • i_signature-prop_name = 'BDS_DOCUMENTCLASS'.

  • i_signature-prop_value = 'HTML'. "file_extension.

  • append i_signature.

  • clear i_signature.

  • i_signature-doc_id = 'Document ID'.

  • i_signature-doc_count = 1.

  • i_signature-prop_name = 'TEST'.

  • i_signature-prop_value = 'Free Form Description Here'.

  • i_signature-doc_ver_no = 1.

  • append i_signature.

*

call function 'OWN_LOGICAL_SYSTEM_GET'

importing

own_logical_system = lv_logsys

exceptions

own_logical_system_not_defined = 1

others = 2.

clear: v_binary_flag.

lv_objectkey = p_qmnum.

call function 'BDS_BUSINESSDOCUMENT_CREA_TAB'

exporting

logical_system = lv_logsys

classname = 'QMSM'

  • classname = 'BUS2078'

classtype = 'BO'

client = sy-mandt

object_key = lv_objectkey

binary_flag = v_binary_flag

  • IMPORTING

  • OBJECT_KEY =

tables

signature = i_signature

components = i_components

ascii_content = lt_content "lt_ascii

exceptions

nothing_found = 1

parameter_error = 2

not_allowed = 3

error_kpro = 4

internal_error = 5

not_authorized = 6

others = 7

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

*

data: go_myobject type ref to cl_gos_manager,

ls_object type borident.

ls_object-objkey = lv_objectkey.

ls_object-objtype = 'QMSM'.

ls_object-logsys = lv_logsys.

create object go_myobject

exporting is_object = ls_object.

*

if sy-subrc = 0.

endif.

call function 'BAPI_TRANSACTION_COMMIT'.

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

message i004(zbc) with 'Content has been attached to QN' p_qmnum.

clear: i_signature, i_components, lt_content.

refresh: i_signature, i_components, lt_content.

call function 'BDS_BUSINESSDOCUMENT_GET_TAB'

exporting

LOGICAL_SYSTEM = lv_logsys

classname = 'QMSM'

classtype = 'BO'

CLIENT = SY-MANDT

OBJECT_KEY = lv_objectkey

BINARY_FLAG = 'X'

TEXT_AS_STREAM = ' '

tables

signature = i_signature

components = i_components

  • CONTENT = lt_content

ASCII_CONTENT = lt_content

EXCEPTIONS

NOTHING_FOUND = 1

PARAMETER_ERROR = 2

NOT_ALLOWED = 3

ERROR_KPRO = 4

INTERNAL_ERROR = 5

NOT_AUTHORIZED = 6

OTHERS = 7.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

data: lv_doc_id type BAPIBDS01-DOC_ID.

loop at i_signature.

lv_doc_id = i_signature-doc_id.

exit.

endloop.

call function 'BDS_DOCUMENT_DISPLAY'

exporting

  • CLIENT = SY-MANDT

doc_id = lv_doc_id

  • TABLES

  • SIGNATURE =

EXCEPTIONS

NOTHING_FOUND = 1

PARAMETER_ERROR = 2

NOT_ALLOWED = 3

ERROR_KPRO = 4

INTERNAL_ERROR = 5

NOT_AUTHORIZED = 6

OTHERS = 7

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " zf_attach_html

&----


*& Form zf_send_email

&----


  • text

----


form zf_send_email .

data: i_content type standard table of soli with header line,

i_recipients type standard table of soli with header line,

l_subject(200) type c.

data: wa_html type w3html.

*

l_subject = 'Testing HTML email'.

*

clear i_recipients. refresh i_recipients.

i_recipients-line = p_mailid.

append i_recipients.

*

clear i_content. refresh i_content.

loop at do->html_table into wa_html.

i_content = wa_html.

append i_content.

endloop.

call function 'Z_BC_ABAP_EXTERNAL_SENDMAIL'

exporting

l_subject = l_subject

l_html_content = 'X'

l_return_address = p_mailid

tables

i_content = i_content

i_recipients = i_recipients

exceptions

send_failed = 1

  • FILENAME_INUSE = 2

others = 3

.

if sy-subrc <> 0.

message e006(z1) with 'Send Failed'.

  • message id sy-msgid type sy-msgty number sy-msgno

  • with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

else.

message i004(zbc) with 'Content has sent as email to' p_mailid.

endif.

endform. " zf_send_email

&----


*& Form zf_dd_add_text

&----


  • text

----


form zf_dd_add_text using p_do type ref to cl_dd_document.

data ta type ref to cl_dd_table_element.

data col1 type ref to cl_dd_area.

data col2 type ref to cl_dd_area.

data col3 type ref to cl_dd_area.

data col4 type ref to cl_dd_area.

data col5 type ref to cl_dd_area.

data col6 type ref to cl_dd_area.

data col7 type ref to cl_dd_area.

data col8 type ref to cl_dd_area.

data lv_col type ref to object.

data text type sdydo_text_element.

data: lt_comp type standard table of rstrucinfo,

lv_program type sy-repid,

lv_structure type tfdir-funcname,

comp1 type i.

data: lv_cols type i,

lv_percent(03) type n,

lv_colw type sdydo_value,

lv_coln(04) type c,

lv_idx type sy-tabix.

field-symbols: <col> type ref to cl_dd_area.

lv_program = 'ZJOETEST10'.

lv_structure = 'GS_DATA'.

call function 'GET_COMPONENT_LIST'

exporting

program = lv_program

fieldname = lv_structure

tables

components = lt_comp[].

select rollname ddtext

from dd04t

into table gt_comp

for all entries in lt_comp

where rollname = lt_comp-compname

and ddlanguage = sy-langu.

  • set Heading

text = 'EMAIL TO WMS SITES (DETAIL LEVEL)'.

call method p_do->add_text

exporting

text = text

sap_style = 'heading'.

call method p_do->new_line.

call method p_do->new_line.

text = '** This is a test **'.

call method p_do->add_text

exporting

text = text.

call method p_do->new_line.

call method p_do->underline.

call method p_do->new_line.

lv_cols = lines( gt_comp ).

lv_percent = 100 / lv_cols.

  • create table

call method p_do->add_table

exporting

no_of_columns = lv_cols

cell_background_transparent = space

importing

table = ta.

  • JR

call method ta->new_row

exporting

sap_color = 'LIST_TOTAL'

sap_fontsize = 'LARGE'.

data lv_first.

field-symbols: <text> type any.

loop at gt_data into gs_data.

clear lv_first.

at first.

lv_first = 'x'.

endat.

loop at gt_comp into gs_comp.

lv_idx = sy-tabix.

concatenate lv_percent '%' into lv_colw.

if lv_first = 'x'.

text = gs_comp-text.

else.

assign component lv_idx of structure gs_data to <text>.

if sy-subrc = 0.

text = <text>.

endif.

endif.

  • set columns

if lv_first = 'x'.

call method ta->add_column

exporting

width = lv_colw.

endif.

check lv_idx le ta->no_of_columns.

  • set text

read table ta->table_of_columns index lv_idx into lv_col.

col1 ?= lv_col. " Type cast from Object to CL_DD_AREA.

call method col1->add_text

exporting

text = text.

endloop.

at last.

exit.

endat.

call method ta->new_row.

endloop.

    • CALL METHOD ta->set_column_style

    • EXPORTING col_no = 1

    • sap_color = cl_dd_area=>list_key

*.

    • fill columns

  • text = 'Material'.

  • call method col1->add_text

  • exporting

  • text = text.

  • text = 'Material Desc'.

  • call method col2->add_text

  • exporting

  • text = text.

  • text = 'Size/Dimension'.

  • call method col3->add_text

  • exporting

  • text = text.

  • text = 'Code Date'.

  • call method col4->add_text

  • exporting

  • text = text.

  • text = 'Plant'.

  • call method col5->add_text

  • exporting

  • text = text.

*

*

  • call method ta->new_row.

  • text = '152080000'.

  • call method col1->add_text

  • exporting

  • text = text.

  • text = 'PB Biscuit'.

  • call method col2->add_text

  • exporting

  • text = text.

  • text = '15oz/8CT'.

  • call method col3->add_text

  • exporting

  • text = text.

  • text = '27JAN6NA'.

  • call method col4->add_text

  • exporting

  • text = text.

  • text = 'New Albany'.

  • call method col5->add_text

  • exporting

  • text = text.

*

  • text = '155550000'.

  • call method col1->add_text

  • exporting

  • text = text.

  • text = 'PB Biscuit'.

  • call method col2->add_text

  • exporting

  • text = text.

  • text = '22oz/12CT'.

  • call method col3->add_text

  • exporting

  • text = text.

  • text = '29JAN6NA'.

  • call method col4->add_text

  • exporting

  • text = text.

  • text = 'New Albany'.

  • call method col5->add_text

  • exporting

  • text = text.

*

  • text = 'Instructions for WMS Sites'.

  • call method p_do->add_text

  • exporting

  • text = text.

call method p_do->new_line.

call method p_do->new_line.

call method p_do->underline.

data: v_url type string.

data v_name type sdydo_element_name.

  • Portal links

case sy-sysid.

when 'ERD' or 'ERX'.

text = text-042.

when 'ERQ'.

text = 'http://gmlinkqa.genmills.com/irj'(043).

when 'ERP'.

text = 'http://gmlink.genmills.com/irj/index.html'(044).

endcase.

  • call method p_do->add_text

  • exporting

  • text = text.

v_name = 'Joe_Link'.

v_url = 'http://sapportaldev2.genmills.com/irj/portal'.

*v_url = 'http://www.google.com'.

  • SAP users title link line

text = 'Link Test'.

call method p_do->add_link

exporting

text = text

url = v_url.

endform. " zf_dd_add_text

&----


*& Form zf_send_email2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form zf_send_email2 .

data: g_lines type i,

g_numbytes type i,

g_form_name type rs38l_fnam,

g_pdfspoolid like tsp01-rqident,

g_jobname like tbtcjob-jobname,

g_jobcount like tbtcjob-jobcount,

g_otfspoolid like tsp01-rqident,

g_control_param type ssfctrlop,

g_output_options type ssfcompop,

g_document_data like sodocchgi1,

g_filename type string.

data:

i_contents like solisti1 occurs 1 with header line,

wa_html type solisti1,

i_packing_list like sopcklsti1 occurs 2 with header line,

i_object_header like solisti1 occurs 1 with header line,

i_receivers like somlreci1 occurs 1 with header line,

l_sender_address like soextreci1-receiver,

l_sender_adr_type like soextreci1-adr_typ.

data: lv_length type i,

lv_size like sodocchgi1-doc_size.

g_document_data-obj_name = 'obectname'.

g_document_data-obj_descr = 'object description'.

  • loop at do->html_table into wa_html.

  • i_contents = wa_html.

  • append i_contents.

  • endloop.

i_contents = 'This is a test'.

append i_contents.

describe table i_contents lines g_lines.

lv_size = ( g_lines - 1 ) * 255.

read table i_contents index g_lines.

lv_length = strlen( i_contents-line ).

g_document_data-doc_size = lv_size + lv_length.

clear i_packing_list.

i_packing_list-head_start = 1.

i_packing_list-head_num = 0.

i_packing_list-body_start = 1.

i_packing_list-body_num = 1.

i_packing_list-doc_type = 'HTM'.

append i_packing_list.

i_object_header = '123456'.

append i_object_header.

i_receivers-receiver = 'joe.ries@genmills.com'.

i_receivers-rec_type = 'U'.

append i_receivers.

l_sender_address = sy-uname.

l_sender_adr_type = 'B'.

  • i_packing_list defines the document to be sent. The first line

  • defines the document and the next lines define the attachment(s).

  • CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

call function 'SO_DOCUMENT_SEND_API1'

exporting

document_data = g_document_data

put_in_outbox = 'X'

sender_address = l_sender_address

sender_address_type = l_sender_adr_type

commit_work = 'X'

tables

packing_list = i_packing_list

object_header = i_object_header

  • contents_bin = i_pdf_255

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.

if sy-subrc = 0.

endif.

endform. " zf_send_email2

0 Kudos
170

hi Ravi,

can u plz tell me what is the type of zzdaycod in your code.

0 Kudos
170

it is CHAR010

Former Member
0 Kudos
170

Check these links,to get an idea,

http://www.sapdevelopment.co.uk/reporting/email/attach_xls.htm

Message was edited by: Srikanth Kidambi

Former Member
0 Kudos
170

Hi,

Hope this might help.

w_sub_tx = wa_ecm_objmngrec-objkt.

CONCATENATE 'PI Problem :' v_matnr INTO w_sub_tx SEPARATED BY space.

MOVE w_sub_tx TO w_doc_data-obj_descr.

w_doc_data-obj_prio = 1.

t_obj_content-line = space .

APPEND t_obj_content.

CLEAR t_obj_content.

t_obj_content-line = space .

APPEND t_obj_content.

CLEAR t_obj_content.

t_obj_content-line = space .

APPEND t_obj_content.

CLEAR t_obj_content.

t_obj_content-line = space .

APPEND t_obj_content.

CLEAR t_obj_content.

CONCATENATE 'THE PART NUMBER FOR PROBLEM INPUT' v_matnr

'BEING FORWARDED TO YOU ' INTO

w_var SEPARATED BY space.

t_obj_content-line = w_var.

APPEND t_obj_content.

CLEAR t_obj_content.

t_obj_content-line = 'BECAUSE IT DOES NOT HAVE A PRODUCT HIERARCHY OR'.

APPEND t_obj_content.

CLEAR t_obj_content.

t_obj_content-line =

'BECAUSE THE PRODUCT DOES NOT APPEAR IN THE PRODUCT HIERARCHY TABLE'.

APPEND t_obj_content.

CLEAR t_obj_content.

DESCRIBE TABLE t_obj_content LINES t_tab_lines_nb.

  • Filling OBJPACK internal table

CLEAR t_objpack.

t_objpack-transf_bin = ''.

t_objpack-head_start = 1.

t_objpack-head_num = 0.

t_objpack-body_start = 1.

t_objpack-body_num = t_tab_lines_nb.

t_objpack-doc_type = 'RAW'.

t_objpack-doc_size = ( t_tab_lines_nb - 1 ) * 255 +

STRLEN( t_obj_content ).

APPEND t_objpack.

  • Receiver's EMail-ID

CLEAR : t_receivers.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-receiver = 'SYED.M@TCS.COM'.

APPEND t_receivers.

CLEAR t_receivers.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-receiver = 'SOMNATH1.D@TCS.COM'.

APPEND t_receivers.

CLEAR t_receivers.

t_receivers-rec_type = 'U'.

t_receivers-com_type = 'INT'.

t_receivers-receiver = 'DAS.SOMNATH@GE.COM'.

APPEND t_receivers.

CLEAR t_receivers.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = t_objpack

  • object_header = t_objecthd

contents_txt = t_obj_content

receivers = t_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

operation_no_authorization = 4

OTHERS = 99.

This is a sample code to send a mail.

Regards

Syed

0 Kudos
170

hi syed,

can u plz tell me what is w_doc_data or how it should be declared.

Message was edited by: Tarka Karwadkar

0 Kudos
170

data: w_DOC_DATA type SODOCCHGI1.

Former Member
0 Kudos
170

HI

I worked on the sap object

Try this code . If you face any problem plz let me know

here CONTENTS_BIN is the attachment which you want to send as an attachment

&----


*& Form SEND_OBJECT

&----


FORM SEND_OBJECT.

  • Creation of the document to be sent

WS_TABTXT = 'Table'.

WS_TEXT1 = 'Number of discrepancy found are :'(500).

  • File Name

WS_DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

WS_SUBJ = 'Discrepancies of Tables'.

WS_DOC_CHNG-OBJ_DESCR = WS_SUBJ.

  • Mail Contents

WS_TEXT = 'This mail Shows the Discrepancy of below given Tables'(505)

.

WS_OBJTXT = WS_TEXT.

APPEND WS_OBJTXT.

CLEAR WS_OBJTXT.

LOOP AT TBL_REC.

CLEAR : WS_MAIL_BODY,

WS_COUNTER_CHAR,

WS_TEXT.

MOVE TBL_REC-REC_NM TO WS_REC_CT.

MOVE WS_COUNTER TO WS_COUNTER_CHAR.

CONCATENATE WS_COUNTER_CHAR

WS_TABTXT

TBL_REC-TABLE_NM

WS_TEXT1

WS_REC_CT

INTO WS_MAIL_BODY

SEPARATED BY ' '.

MOVE WS_MAIL_BODY TO WS_OBJTXT.

APPEND WS_OBJTXT.

CLEAR WS_OBJTXT.

WS_COUNTER = WS_COUNTER + 1.

ENDLOOP.

WS_TEXT = 'RFC connection used is '.

CONCATENATE WS_TEXT P_RFCDES

INTO WS_MAIL_BODY

SEPARATED BY ' '.

MOVE WS_MAIL_BODY TO WS_OBJTXT.

APPEND WS_OBJTXT.

CLEAR : WS_OBJTXT,

WS_MAIL_BODY.

CONCATENATE ' ' ' ' INTO WS_MAIL_BODY .

MOVE WS_MAIL_BODY TO WS_OBJTXT.

APPEND WS_OBJTXT.

APPEND WS_OBJTXT.

APPEND WS_OBJTXT.

APPEND WS_OBJTXT.

CLEAR WS_MAIL_BODY.

CLEAR WS_TEXT.

WS_TEXT = 'Check the enclosed Attachment for detailed view '.

MOVE WS_TEXT TO WS_OBJTXT.

APPEND WS_OBJTXT.

CLEAR WS_OBJTXT.

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

DESCRIBE TABLE WS_OBJBIN LINES WS_TAB_LINES.

READ TABLE WS_OBJTXT INDEX WS_TAB_LINES.

WS_DOC_CHNG-DOC_SIZE = ( WS_TAB_LINES - 1 ) * 255 + STRLEN( WS_OBJBIN )

.

  • Creation of the entry for the compressed document

CLEAR WS_OBJPACK-TRANSF_BIN.

WS_OBJPACK-HEAD_START = 1.

WS_OBJPACK-HEAD_NUM = 0.

WS_OBJPACK-BODY_START = 1.

WS_OBJPACK-BODY_NUM = WS_TAB_LINES.

WS_OBJPACK-DOC_TYPE = 'RAW'.

APPEND WS_OBJPACK.

DESCRIBE TABLE WS_OBJBIN LINES WS_TAB_LINES.

IF WS_TAB_LINES < 30000.

WS_OBJHEAD = 'Attached PDF Document'(506). "'ORDERS'.

APPEND WS_OBJHEAD.

    • Creation of the entry for the compressed attachment

WS_OBJPACK-TRANSF_BIN = 'X'.

WS_OBJPACK-HEAD_START = 1.

WS_OBJPACK-HEAD_NUM = 1.

WS_OBJPACK-BODY_START = 1.

WS_OBJPACK-BODY_NUM = WS_TAB_LINES.

WS_OBJPACK-DOC_TYPE = 'PDF'.

WS_OBJPACK-OBJ_NAME = 'WEBSITE'.

WS_OBJPACK-OBJ_DESCR = WS_MAIL.

WS_OBJPACK-DOC_SIZE = WS_TAB_LINES * 255.

APPEND WS_OBJPACK.

ENDIF.

&----


*& Mail to External email

&----


DATA : SEND LIKE SONV-FLAG VALUE 'X',

V_LINE TYPE I.

DATA : SAP_INBOX_V_LINE TYPE I.

DESCRIBE TABLE S_RECNAM LINES SAP_INBOX_V_LINE.

LOOP AT S_RECNAM.

WS_SAP_INBOX-RECEIVER = S_RECNAM-LOW . "SY-UNAME. sap_inbox.

WS_SAP_INBOX-EXPRESS = 'X'.

WS_SAP_INBOX-REC_TYPE = 'B'.

APPEND WS_SAP_INBOX.

ENDLOOP.

LOOP AT S_RECNM1.

WS_SAP_INBOX-RECEIVER = S_RECNM1-LOW . "SY-UNAME. sap_inbox.

WS_SAP_INBOX-EXPRESS = 'X'.

WS_SAP_INBOX-REC_TYPE = 'U'.

APPEND WS_SAP_INBOX.

ENDLOOP.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = WS_DOC_CHNG

PUT_IN_OUTBOX = 'X'

SENT_TO_ALL = SEND "'X'

TABLES

PACKING_LIST = WS_OBJPACK

OBJECT_HEADER = WS_OBJHEAD

CONTENTS_BIN = WS_OBJBIN

CONTENTS_TXT = WS_OBJTXT

RECEIVERS = WS_SAP_INBOX

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 = 99.

CASE SY-SUBRC.

WHEN '1'.

RAISE TOO_MANY_RECEIVERS.

WHEN '2'.

RAISE DOCUMENT_NOT_SENT.

WHEN '4'.

RAISE OPERATION_NO_AUTHORIZATION.

  • WHEN OTHERS.

  • RAISE OTHERS.

ENDCASE.

  • ENDDO.