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: 

urgent..

Former Member
0 Kudos

hello everyone,

i have an urgent requirement, my alv report when it is run in background the output should be downloaded.

then the file needs to be sent as an attachment to a list of mail ids .

please send me the process steps for this as this is an urgent requirement.

will be rewarded .

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI.

refer this code.

Sending an attachment via email

FORM SEND_MAIL.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA L_NUM(3).

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.

  • Mail Contents

OBJTXT = 'Object text'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

LOOP AT ITAB_DATA.

CONCATENATE ITAB_DATA-PRODUCTOR

ITAB_DATA-VBELN

ITAB_DATA-POSNR

ITAB_DATA-MATNR INTO OBJBIN.

APPEND OBJBIN.

ENDLOOP.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'ORDERS'.

APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'WEBSITE'.

OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

  • Completing the recipient list

  • target recipent

clear RECLIST.

RECLIST-RECEIVER = 'test@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • copy recipents

clear RECLIST.

RECLIST-RECEIVER = 'secondtest@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

RECLIST-COPY = 'X'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM. " SEND_MAIL

Reward all helpfull answers.

Regards.

Jay

7 REPLIES 7

Former Member
0 Kudos

&----


*& Report ZGS_TEST3

*&

&----


*&

*&

&----


REPORT ZGS_TEST3.

TABLES: ekko.

PARAMETERS: p_email TYPE somlreci1-receiver

DEFAULT 'test@sapdev.co.uk'.

TYPES: BEGIN OF t_ekpo,

ebeln TYPE ekpo-ebeln,

ebelp TYPE ekpo-ebelp,

aedat TYPE ekpo-aedat,

matnr TYPE ekpo-matnr,

END OF t_ekpo.

DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,

wa_ekpo TYPE t_ekpo.

TYPES: BEGIN OF t_charekpo,

ebeln(10) TYPE c,

ebelp(5) TYPE c,

aedat(8) TYPE c,

matnr(18) TYPE c,

END OF t_charekpo.

DATA: wa_charekpo TYPE t_charekpo.

DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

DATA: it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0

WITH HEADER LINE.

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,

gd_error TYPE sy-subrc,

gd_reciever TYPE sy-subrc.

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

*START_OF_SELECTION

START-OF-SELECTION.

  • Retrieve sample data from table ekpo

PERFORM data_retrieval.

  • Populate table with detaisl to be entered into .xls file

PERFORM build_xls_data_table.

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

*END-OF-SELECTION

END-OF-SELECTION.

  • Populate message body text

perform populate_email_message_body.

  • Send file by email as .xls speadsheet

PERFORM send_file_as_email_attachment

tables it_message

it_attach

using p_email

'Example .xls documnet attachment'

'XLS'

'filename'

' '

' '

' '

changing gd_error

gd_reciever.

  • Instructs mail send program for SAPCONNECT to send email(rsconn01)

PERFORM initiate_mail_execute_program.

&----


*& Form DATA_RETRIEVAL

&----


  • Retrieve data form EKPO table and populate itab it_ekko

----


FORM data_retrieval.

SELECT ebeln ebelp aedat matnr

UP TO 10 ROWS

FROM ekpo

INTO TABLE it_ekpo.

ENDFORM. " DATA_RETRIEVAL

&----


*& Form BUILD_XLS_DATA_TABLE

&----


  • Build data table for .xls document

----


FORM build_xls_data_table.

CONSTANTS: con_cret(2) TYPE c VALUE '0D', "OK for non Unicode

con_tab(2) TYPE c VALUE '09'. "OK for non Unicode

*If you have Unicode check active in program attributes thnen you will

*need to declare constants as follows

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,

  • con_cret type c value cl_abap_char_utilities=>CR_LF.

CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

LOOP AT it_ekpo INTO wa_charekpo.

CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp

wa_charekpo-aedat wa_charekpo-matnr

INTO it_attach SEPARATED BY con_tab.

CONCATENATE con_cret it_attach INTO it_attach.

APPEND it_attach.

ENDLOOP.

ENDFORM. " BUILD_XLS_DATA_TABLE

&----


*& Form SEND_FILE_AS_EMAIL_ATTACHMENT

&----


  • Send email

----


FORM send_file_as_email_attachment tables pit_message

pit_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.

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[] = pit_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.

&----


*& Form INITIATE_MAIL_EXECUTE_PROGRAM

&----


  • Instructs mail send program for SAPCONNECT to send email.

----


FORM initiate_mail_execute_program.

WAIT UP TO 2 SECONDS.

SUBMIT rsconn01 WITH mode = 'INT'

WITH output = 'X'

AND RETURN.

ENDFORM. " INITIATE_MAIL_EXECUTE_PROGRAM

&----


*& Form POPULATE_EMAIL_MESSAGE_BODY

&----


  • Populate message body text

----


form populate_email_message_body.

REFRESH it_message.

it_message = 'Please find attached a list test ekpo records'.

APPEND it_message.

endform. " POPULATE_EMAIL_MESSAGE_BODY

Pawan_Kesari
Active Contributor
0 Kudos

try this program .. in foreground program will display the ALV report .. if you execute this in background with variant it will email the report to sender

REPORT zpwtest .

TABLES : t001 .

TYPE-POOLS slis .

DATA : t_t001 TYPE TABLE OF t001 ,

t_abaplist TYPE TABLE OF abaplist .

DATA : w_abaplist TYPE abaplist .

SELECT-OPTIONS : s_bukrs FOR t001-bukrs OBLIGATORY .

PARAMETERS : p_list TYPE c NO-DISPLAY .

START-OF-SELECTION .

IF sy-batch = 'X' AND p_list IS INITIAL .

  • Submit report and get list in memory

SUBMIT zpwtest EXPORTING LIST TO MEMORY

WITH s_bukrs IN s_bukrs

WITH p_list = 'X'

AND RETURN.

  • Get the list from memory.

CALL FUNCTION 'LIST_FROM_MEMORY'

TABLES

listobject = t_abaplist

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Send report to mail receipent

PERFORM send_mail .

ELSE.

PERFORM select_data .

PERFORM display_data .

ENDIF.

*SO_NEW_DOCUMENT_SEND_API1

&----


*& Form select_data

&----


FORM select_data.

SELECT *

INTO TABLE t_t001

FROM t001

WHERE bukrs IN s_bukrs .

ENDFORM. " select_data

&----


*& Form display_data

&----


FORM display_data.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

i_structure_name = 'T001'

TABLES

t_outtab = t_t001

EXCEPTIONS

program_error = 1

OTHERS = 2.

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. " display_data

&----


*& Form send_mail

&----


FORM send_mail.

DATA: message_content LIKE soli OCCURS 10 WITH HEADER LINE,

receiver_list LIKE soos1 OCCURS 5 WITH HEADER LINE,

packing_list LIKE soxpl OCCURS 2 WITH HEADER LINE,

listobject LIKE abaplist OCCURS 10,

compressed_attachment LIKE soli OCCURS 100 WITH HEADER LINE,

w_object_hd_change LIKE sood1,

compressed_size LIKE sy-index.

  • Fot external email id

  • receiver_list-recextnam = 'XXXXXXXXXXXX@XXXXXX.COM'.

  • receiver_list-recesc = 'E'.

  • receiver_list-sndart = 'INT'.

  • receiver_list-sndpri = '1'.

  • FOr internal email id

receiver_list-recnam = sy-uname .

receiver_list-esc_des = 'B'.

APPEND receiver_list.

  • General data

w_object_hd_change-objla = sy-langu.

w_object_hd_change-objnam = 'Object name'.

w_object_hd_change-objsns = 'P'.

  • Mail subject

w_object_hd_change-objdes = 'Message subject'.

  • Mail body

APPEND 'Message content' TO message_content.

CALL FUNCTION 'TABLE_COMPRESS'

IMPORTING

compressed_size = compressed_size

TABLES

in = t_abaplist

out = compressed_attachment.

DESCRIBE TABLE compressed_attachment.

CLEAR packing_list.

packing_list-transf_bin = 'X'.

packing_list-head_start = 0.

packing_list-head_num = 0.

packing_list-body_start = 1.

packing_list-body_num = sy-tfill.

packing_list-objtp = 'ALI'.

packing_list-objnam = 'Object name'.

packing_list-objdes = 'Attachment description'.

packing_list-objlen = compressed_size.

APPEND packing_list.

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = w_object_hd_change

object_type = 'RAW'

owner = sy-uname

TABLES

objcont = message_content

receivers = receiver_list

packing_list = packing_list

att_cont = compressed_attachment.

ENDFORM. " send_mail

0 Kudos

hi pawan,

what is the need for table compress ?

0 Kudos

Initially data is stored in table 'T_ABAPLIST', structure of this table is not compatible with the structure in which we need to pass data to FM SO_OBJECT_SEND.

FM TABLE_COMPRESS will transfer bytes from internal table 'T_ABAPLIST' to 'COMPRESSED_ATTACHMENT' and also provide the size of the data.

Former Member
0 Kudos

Hi,

Try this code snippet.

FORM send_mail .

DATA : l_ftemp TYPE string,

lt_ccrf TYPE STANDARD TABLE OF zak_crf,

ls_ccrf TYPE zak_crf,

ls_crf TYPE gs_crf.

  • DATA : l_file TYPE rlgrap-filename VALUE 'C:\articles'.

*Data declarations for mail

DATA: l_doc_data TYPE sodocchgi1.

DATA: ls_mailhdr TYPE zak_mailhdr.

DATA: lt_objtxt TYPE STANDARD TABLE OF solisti1.

DATA: l_sytabix TYPE sy-tabix.

DATA: tab_lines TYPE sy-tabix.

DATA: ls_objtxt TYPE solisti1.

DATA: lt_objpack TYPE STANDARD TABLE OF sopcklsti1.

DATA: lt_objhead TYPE STANDARD TABLE OF solisti1.

DATA: lt_objbin TYPE STANDARD TABLE OF solix.

DATA: ls_objpack TYPE sopcklsti1.

DATA: lt_mail TYPE STANDARD TABLE OF zak_formatmail.

DATA: ls_mail TYPE zak_formatmail.

DATA: lt_reclist TYPE STANDARD TABLE OF somlreci1.

DATA: l_filename TYPE string. " VALUE 'C:\articles.xls'.

DATA: lt_datatab TYPE STANDARD TABLE OF solix.

DATA: ls_solix_wa TYPE solix.

DATA: ls_reclist_wa TYPE somlreci1.

DATA: ls_bannersender TYPE zak_bannersender.

DATA: lt_bannersender TYPE STANDARD TABLE OF zak_bannersender.

DATA: ls_objhead_wa TYPE solisti1.

DATA: l_ident_fm TYPE c LENGTH 4.

DATA: l_node_name TYPE c LENGTH 2 VALUE 'NR'.

*for downloading the internal table onto excel sheet

REFRESH lt_ccrf.

CLEAR : ls_crf , ls_ccrf.

TYPES : BEGIN OF ls_headers,

aktnr(100) TYPE c,

aktkt(100) TYPE c,

matnr(100) TYPE c,

maktx(100) TYPE c,

value_old(100) TYPE c,

value_new(100) TYPE c,

udate(100) TYPE c,

END OF ls_headers.

DATA : ls_headers1 TYPE ls_headers.

DATA : lt_headers TYPE TABLE OF ls_headers.

TYPES : BEGIN OF ls_fieldnames,

name(100) TYPE c,

END OF ls_fieldnames.

  • DATA : lt_fieldnames TYPE STANDARD TABLE OF ls_fieldnames.

ls_headers1-aktnr = 'Promotion number'(001).

ls_headers1-aktkt = 'Promotion description'(002).

ls_headers1-matnr = 'Article number'(003).

ls_headers1-maktx = 'Article description'(004).

ls_headers1-value_old = 'Original range flag'(005).

ls_headers1-value_new = 'Changed range flag'(006).

ls_headers1-udate = 'Changed date'(007).

APPEND ls_headers1 TO lt_headers.

l_ftemp = 'C:\articles.xls'(008).

CONDENSE l_ftemp NO-GAPS.

LOOP AT gt_crf INTO ls_crf.

MOVE-CORRESPONDING ls_crf TO ls_ccrf.

APPEND ls_ccrf TO lt_ccrf.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = l_ftemp

filetype = 'DAT'

wk1_n_size = 'X'

wk1_n_format = 'X'

wk1_t_format = 'X'

wk1_t_size = 'X'

TABLES

data_tab = lt_headers

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

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = l_ftemp

filetype = 'DAT'

append = 'X'

TABLES

data_tab = lt_ccrf

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

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*sending the mail

l_filename = 'C:\articles.xls'(008).

CONCATENATE l_node_name g_banner INTO l_ident_fm.

SELECT SINGLE *

FROM zak_mailhdr

INTO ls_mailhdr

WHERE ident = g_banner

AND mail_type = l_node_name.

SELECT * FROM zak_formatmail

INTO TABLE lt_mail

WHERE ident = g_banner

AND mail_type = l_node_name.

*only the mail text column is selected

LOOP AT lt_mail INTO ls_mail.

ls_objtxt = ls_mail-mail_text.

APPEND ls_objtxt TO lt_objtxt.

ENDLOOP.

  • Populate the subject/generic message attributes

l_doc_data-obj_descr = ls_mailhdr-subject.

*new

l_doc_data-obj_langu = sy-langu.

*obtain document size for the mail content

DESCRIBE TABLE lt_objtxt LINES l_sytabix.

CLEAR ls_objtxt.

READ TABLE lt_objtxt INTO ls_objtxt INDEX l_sytabix.

l_doc_data-doc_size = ( l_sytabix - 1 ) * 255 + STRLEN( ls_objtxt ).

  • Creating the entry for the compressed document

  • Describe the body of the message

  • Information about structure of data tables

CLEAR ls_objpack-transf_bin. "flag to indicate that object to be transported in binary form = space

ls_objpack-head_start = 1.

ls_objpack-head_num = 0.

ls_objpack-body_start = 1.

ls_objpack-body_num = l_sytabix.

ls_objpack-doc_type = 'RAW'.

APPEND ls_objpack TO lt_objpack.

*SECTION WHICH ATTACHES THE EXCEL SHEET

*converting the excel sheet into binary format

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = l_filename

filetype = 'BIN'

CHANGING

data_tab = lt_datatab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

not_supported_by_gui = 17

error_no_gui = 18

OTHERS = 19.

LOOP AT lt_datatab INTO ls_solix_wa.

APPEND ls_solix_wa TO lt_objbin.

ENDLOOP.

*defining the header or name of the attachment ( i think!!)

ls_objhead_wa = 'C:\articles.xls'(008).

APPEND ls_objhead_wa TO lt_objhead.

  • lt_datatab contains our binary data

DESCRIBE TABLE lt_objbin LINES tab_lines.

  • Creating the entry for the compressed attachment

ls_objpack-transf_bin = 'X'.

ls_objpack-head_start = 1.

ls_objpack-head_num = 1.

ls_objpack-body_start = 1.

ls_objpack-body_num = tab_lines.

ls_objpack-doc_type = 'XLS'.

ls_objpack-obj_name = 'ATTACHMENT'.

ls_objpack-obj_descr = 'Changed range flag articles'(016). "'C:\articles'.

ls_objpack-doc_size = tab_lines * 255.

APPEND ls_objpack TO lt_objpack.

*obtain the email id of the banner manager

SELECT * FROM zak_bannersender INTO TABLE lt_bannersender

WHERE banner = g_banner.

LOOP AT lt_bannersender INTO ls_bannersender.

  • Entering names in the distribution list

ls_reclist_wa-receiver = ls_bannersender-sender_id.

ls_reclist_wa-rec_type = 'U'.

  • ls_reclist_wa-express = 'X'.

APPEND ls_reclist_wa TO lt_reclist.

*send mail

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = l_doc_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lt_objpack

object_header = lt_objhead

contents_txt = lt_objtxt

contents_hex = lt_objbin

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

CASE sy-subrc.

WHEN 0.

WRITE: / 'Result of the send process:'(011).

LOOP AT lt_reclist INTO ls_reclist_wa.

WRITE: / ls_reclist_wa-receiver(48), ':'.

IF ls_reclist_wa-retrn_code = 0.

WRITE 'Sent successfully'(012).

ELSE.

WRITE 'Not sent'(013).

ENDIF.

ENDLOOP.

WHEN 2.

WRITE: / 'Document could not be sent to any of the recipients!'(014).

WHEN OTHERS.

WRITE: / 'Error occurred during sending !'(015).

ENDCASE.

ENDLOOP.

ENDFORM. " send_mail

If useful please reward points.

Regards,

Raksha

Former Member
0 Kudos

HI.

refer this code.

Sending an attachment via email

FORM SEND_MAIL.

DATA: OBJPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: OBJHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: OBJBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: OBJTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: RECLIST LIKE SOMLRECI1 OCCURS 5 WITH HEADER LINE.

DATA: DOC_CHNG LIKE SODOCCHGI1.

DATA: TAB_LINES LIKE SY-TABIX.

DATA L_NUM(3).

  • Creation of the document to be sent

  • File Name

DOC_CHNG-OBJ_NAME = 'SENDFILE'.

  • Mail Subject

DOC_CHNG-OBJ_DESCR = 'Delivered Mail'.

  • Mail Contents

OBJTXT = 'Object text'.

APPEND OBJTXT.

DESCRIBE TABLE OBJTXT LINES TAB_LINES.

READ TABLE OBJTXT INDEX TAB_LINES.

DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( OBJTXT ).

  • Creation of the entry for the compressed document

CLEAR OBJPACK-TRANSF_BIN.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 0.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'RAW'.

APPEND OBJPACK.

  • Creation of the document attachment

LOOP AT ITAB_DATA.

CONCATENATE ITAB_DATA-PRODUCTOR

ITAB_DATA-VBELN

ITAB_DATA-POSNR

ITAB_DATA-MATNR INTO OBJBIN.

APPEND OBJBIN.

ENDLOOP.

DESCRIBE TABLE OBJBIN LINES TAB_LINES.

OBJHEAD = 'ORDERS'.

APPEND OBJHEAD.

    • Creation of the entry for the compressed attachment

OBJPACK-TRANSF_BIN = 'X'.

OBJPACK-HEAD_START = 1.

OBJPACK-HEAD_NUM = 1.

OBJPACK-BODY_START = 1.

OBJPACK-BODY_NUM = TAB_LINES.

OBJPACK-DOC_TYPE = 'TXT'.

OBJPACK-OBJ_NAME = 'WEBSITE'.

OBJPACK-OBJ_DESCR = 'ORDERS.TXT'.

OBJPACK-DOC_SIZE = TAB_LINES * 255.

APPEND OBJPACK.

  • Completing the recipient list

  • target recipent

clear RECLIST.

RECLIST-RECEIVER = 'test@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

APPEND RECLIST.

  • copy recipents

clear RECLIST.

RECLIST-RECEIVER = 'secondtest@here.com'.

RECLIST-EXPRESS = 'X'.

RECLIST-REC_TYPE = 'U'.

RECLIST-COPY = 'X'.

APPEND RECLIST.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = DOC_CHNG

TABLES

PACKING_LIST = OBJPACK

OBJECT_HEADER = OBJHEAD

CONTENTS_BIN = OBJBIN

CONTENTS_TXT = OBJTXT

RECEIVERS = RECLIST

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM. " SEND_MAIL

Reward all helpfull answers.

Regards.

Jay

0 Kudos

hello jay j and pawan kesari,,

I have finished the object with the help of u both , thanks a lot and i think u too are happy with my points.

thanks a lot.