Sending Excel Attachment
Hi ,
I am sending excel attachment through email .
This excel attachment is generated from an ALV Grid Output .
The excel file has all columns fixed to its initial length due to which the entire column content isnt visible unless its extended at the time of checking its content .
Can anyone suggest a remedy to this or send any code which can be used to read the Grid Output and Convert into excel sheet ?
Thanks and Regards
Soumyadip Pal
Hi Soumyadip Pal,
Check this code.
REPORT z_email_abap_report.
E-mail an Abap report *
DATA : w_name TYPE sos04-l_adr_name.
SELECT-OPTIONS :
Recipient address
s_name FOR w_name DEFAULT sy-uname NO INTERVALS.
START-OF-SELECTION.
E-mail Abap report
PERFORM f_send_mail.
Form f_send_mail
FORM f_send_mail.
Data Declaration
DATA:
l_datum(10),
ls_docdata TYPE sodocchgi1,
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,
lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,
lt_listobject TYPE TABLE OF abaplist WITH HEADER LINE,
l_tab_lines TYPE i,
l_att_type LIKE soodk-objtp.
WRITE sy-datum TO l_datum.
List of Users According to Logon Date and Password Change
NOTE: Create ALI/OTF Document in Spool
SUBMIT rsusr200 WITH valid = 'X'
WITH notvalid = space
WITH unlocked = 'X'
WITH locked = space
EXPORTING LIST TO MEMORY AND RETURN.
Read list from memory into table
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = lt_listobject
out = lt_objbin
EXCEPTIONS
compress_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
ls_docdata-obj_name = 'USERS_LIST'.
CONCATENATE 'List of Users' sy-sysid '-' l_datum "#EC *
INTO ls_docdata-obj_descr SEPARATED BY space.
Main Text
lt_objtxt = 'List of Users According to Logon Date' &
' and Password Change'. "#EC *
APPEND lt_objtxt.
Write Packing List (Main)
DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
READ TABLE lt_objtxt INDEX l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
CLEAR lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
APPEND lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
l_att_type = 'ALI'.
DESCRIBE TABLE lt_objbin LINES l_tab_lines.
READ TABLE lt_objbin INDEX l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = l_att_type.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'List_of_Users'. "#EC *
APPEND lt_objpack.
Create receiver list
LOOP AT s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'B'.
APPEND lt_reclist.
ENDLOOP.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
put_in_outbox = ''
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
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.
IF sy-subrc = 0.
Document sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.
ELSE.
Document <&> could not be sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH ls_docdata-obj_name.
ENDIF.
ENDFORM. " F_SEND_MAIL
END OF PROGRAM Z_EMAIL_ABAP_REPORT ******************
Hope this resolves your query.
Reward all the helpful answers.
Regards
Similar Messages
-
Send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1
Hi ABAPers,
I managed to send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1.
Let say I send it to my own email account.
But, when try to open the excel document, from lotus notes, there is warning message produced by the microsoft excel saying:
"The file is not in a recognizable format.
and so on....."
Anyway, when I click button 'OK', excel sheet will be opened and no information lost.
How can we code the abap program so that the message will not come each time I open the attachment from my lotus notes?
Or this is just the tab delimited issue?
Thank you.
Regards,
Edward.Hi Shan,
Thank you for replying.
I have the same as follows:
DESCRIBE TABLE lt_contents_hex LINES lv_lines.
lt_packing_list-transf_bin = 'X'.
lt_packing_list-head_start = 1.
lt_packing_list-head_num = 1.
lt_packing_list-body_start = 1.
lt_packing_list-body_num = lv_lines.
lt_packing_list-doc_type = 'XLS'.
lt_packing_list-obj_name = 'ATTACHMENT'.
lt_packing_list-obj_descr = 'Attachment'.
lt_packing_list-doc_size = lv_lines * 255.
APPEND lt_packing_list.
I'm using lt_contents_hex instead of lt_contents_bin.
Still the problem is there.
Is there any other way to calculate the doc size correctly?
Regards,
Edward. -
Sending Excel attachment in E-mail
Hi All,
I am sending excel attachment in mail, when I see in SO01 tcode I am able to see the attachment in outbox, but getting 'Error during send Process' in sent status and not getting any mails to my e-mail id.
Could you any one help me in this?
Thanks in advance.
Vijaya.Hi,
data: p_email type somlreci1-receiver
value 'Mail ID'.
data: begin of it001 occurs 0,
bukrs type t001-bukrs,
butxt type t001-butxt,
end of it001.
data: imessage type standard table of solisti1 with header line,
iattach type standard table of solisti1 with header line,
ipacking_list like sopcklsti1 occurs 0 with header line,
ireceivers like somlreci1 occurs 0 with header line,
iattachment like solisti1 occurs 0 with header line.
start-of-selection.
select bukrs butxt into table it001 from t001.
Populate table with detaisl to be entered into .xls file
perform build_xls_data .
Populate message body text
clear imessage. refresh imessage.
imessage = 'Please find attached excel file'.
append imessage.
Send file by email as .xls speadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
Form BUILD_XLS_DATA
form build_xls_data .
constants: con_cret type x value '0D', "OK for non Unicode
con_tab type x 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 'BUKRS' 'BUTXT'
into iattach separated by con_tab.
concatenate con_cret iattach into iattach.
append iattach.
loop at it001 .
concatenate it001-bukrs it001-butxt
into iattach separated by con_tab.
concatenate con_cret iattach into iattach.
append iattach.
endloop .
endform.
Form SEND_EMAIL_WITH_XLS
form send_email_with_xls tables pit_message
pit_attach
using p_email
p_mtitle
p_format
p_filename
p_attdescription.
data: xdocdata like sodocchgi1,
xcnt type i.
Fill the document data.
xdocdata-doc_size = 1.
Populate the subject/generic message attributes
xdocdata-obj_langu = sy-langu .
xdocdata-obj_name = 'SAPRPT' .
xdocdata-obj_descr = p_mtitle .
Fill the document data and get size of attachment
clear xdocdata.
read table iattach index xcnt.
xdocdata-doc_size =
( xcnt - 1 ) * 255 + strlen( iattach ).
xdocdata-obj_langu = sy-langu.
xdocdata-obj_name = 'SAPRPT'.
xdocdata-obj_descr = p_mtitle.
clear iattachment. refresh iattachment.
iattachment[] = pit_attach[].
Describe the body of the message
clear ipacking_list. refresh ipacking_list.
ipacking_list-transf_bin = space.
ipacking_list-head_start = 1.
ipacking_list-head_num = 0.
ipacking_list-body_start = 1.
describe table imessage lines ipacking_list-body_num.
ipacking_list-doc_type = 'RAW'.
append ipacking_list.
Create attachment notification
ipacking_list-transf_bin = 'X'.
ipacking_list-head_start = 1.
ipacking_list-head_num = 1.
ipacking_list-body_start = 1.
describe table iattachment lines ipacking_list-body_num.
ipacking_list-doc_type = p_format.
ipacking_list-obj_descr = p_attdescription.
ipacking_list-obj_name = p_filename.
ipacking_list-doc_size = ipacking_list-body_num * 255.
append ipacking_list.
Add the recipients email address
clear ireceivers. refresh ireceivers.
ireceivers-receiver = p_email.
ireceivers-rec_type = 'U'.
ireceivers-com_type = 'INT'.
ireceivers-notif_del = 'X'.
ireceivers-notif_ndel = 'X'.
append ireceivers.
call function 'SO_DOCUMENT_SEND_API1'
exporting
document_data = xdocdata
put_in_outbox = 'X'
commit_work = 'X'
tables
packing_list = ipacking_list
contents_bin = iattachment
contents_txt = imessage
receivers = ireceivers
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.
endform.
Check this Sample code.
Thanks,
Durai.V -
Experts:
I am working on sending Excel as an email attachment thro the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'
I am able to send mail successfully but I face the following two issues while opening the attachment.
1. While opening it says 'un recognized format' , on pressing 'OK' it opens the excel file.
2. The column heading (first row) which should be in Korean character is displayed in junk char. I tried to
specify the unicode (Code Page = '8500') but does not know how to do it.
I am reading the column header text from standard text.
Please let me know what mistake I have commited in my code and where I should specify the unicode transformation. I refered many samples but could not make it.
Please let me know the error.
The code is as follows.
FORM sendemail_barcodedata.
TYPE-POOLS: truxs.
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: objbin1 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_sent_to_all TYPE sonv-flag.
* Creating the document to be sent
* File Name
doc_chng-obj_name = 'BCODEINFO'.
* Mail Subject
doc_chng-obj_descr = 'Delivery Barcode Information'.
* Mail Content
objtxt = 'Hi:'.
APPEND objtxt.
objtxt = 'Find attached, Delivery Barcode Information'.
APPEND objtxt.
CONCATENATE 'Attachment : <<' w_fname1 '>>' INTO objtxt.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
READ TABLE objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
doc_chng-obj_langu = sy-langu.
doc_chng-sensitivty = 'F'.
* Creating 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.
* Creating the document attachment
* Get column names for Barcode Data
CLEAR objbin.
CONCATENATE text-h23
text-h24
text-h25
text-h26
text-h27
INTO objbin SEPARATED BY con_tab .
CONCATENATE objbin con_cret INTO objbin.
APPEND objbin.
CLEAR objbin.
LOOP AT it_excel2 INTO wa_excel2.
CONCATENATE wa_excel2-zz_date
wa_excel2-zz_delivery
wa_excel2-zz_barcode
wa_excel2-blank1
wa_excel2-blank2
INTO objbin SEPARATED BY con_tab.
CONCATENATE objbin con_cret INTO objbin.
APPEND objbin.
CLEAR objbin.
ENDLOOP.
DESCRIBE TABLE objbin LINES tab_lines.
objhead = w_fname1.
APPEND objhead.
* Creating 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 = 'XLS'.
objpack-obj_name = 'Barcode Information'.
objpack-obj_descr = 'Barcode Information'.
objpack-doc_size = tab_lines * 255.
APPEND objpack.
* Entering names in the distribution list
reclist-receiver = p_email.
reclist-rec_type = 'U'.
APPEND reclist.
* Sending the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = ' '
commit_work = 'X'
IMPORTING
sent_to_all = l_sent_to_all
TABLES
packing_list = objpack
object_header = objhead
contents_bin = objbin
contents_txt = objtxt
receivers = 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.
MESSAGE i000(z65f_msgclass) WITH text-211.
WHEN 1.
WRITE: / 'no authorization to send to the specified number of'.
WHEN 2.
WRITE: / 'document could not be sent to any of the recipients!'.
WHEN 4.
WRITE: / 'no authorization to send !'.
WHEN OTHERS.
WRITE: / 'error occurred during sending !'.
ENDCASE.
ENDFORM.
Thanks in advance.
Regards
VijaiHi:
Can any one provide me a solution for this?
regards
vijai -
Send EXCEL attachment with garbage russia text
Hello All - Good day!
I have the same problem where non-english text like russian, and will appear garbage in the excel attachment after it was email.
When I test it in english description/text it looks ok.
I have tried the following FM, and got no luck.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
Program is in Unicode.
PLEASE help.Hello,
Check the following SAP note in this regards:
1151258 Error when sending Excel attachments
Also, please check SAP note regarding SO_DOCUMENT_SEND_API1 interface:
190669 Sending lists via SAPconnect
Regards,
David -
Send excel attachment with more than 255 characters in the internal table
Hi,
I need to send an attachment in the form of spreadsheet.
But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
Whereas my spreadsheet requires a greater width than 255 characters .Hi,
I need to send an attachment in the form of spreadsheet.
But the internal table that is being used for sending attachment in mails can have only 255 characters in one row.
Whereas my spreadsheet requires a greater width than 255 characters . -
Problem in sending Excel attachment on the SAI id.
Hi Experts.
i am using one function module to send one alv output in Excel format to sapid.
FORM SEND_MAIL TABLES T_AMS RECEIVERS_TAB.
CALL FUNCTION 'Z_MAIL_ITAB_AS_XLS_ATTACHMENT'
EXPORTING
I_MESSAGE_TITLE = SYST-TITLE
I_ATTACHMENT_TITLE = SYST-TITLE
I_STRUCTURE_NAME = 'ZAMT__ZBCAUTH0001'
I_INCLUDE_HEADER = 'X'
I_RECIPIENT_UNAME = P_UNAME
TABLES
T_MESSAGE = MESSAGE_TAB
T_DATA = I_TABLE
T_RECEIVERS = RECEIVERS_TAB
EXCEPTIONS
NO_DATA_TO_SEND = 01
UNABLE_TO_GET_NAMETAB = 02
UNABLE_TO_GET_DDTEXTS = 03
NO_HEADER_SUPPLIED = 04
MAIL_SENDING_FAILED = 05
OTHERS = 06.
IF SYST-SUBRC NE 0.
MESSAGE ID SYST-MSGID TYPE SYST-MSGTY NUMBER SYST-MSGNO
WITH SYST-MSGV1 SYST-MSGV2 SYST-MSGV3 SYST-MSGV4.
ENDIF.
ENDFORM.
now, my requirement is i had two internal table one for ITAB_FICO & ITAB_SD for FICO and SD module.AND BY CHECKING CONDITON I HAD TO SEND MAIL TO CORRESPONDING DIFFERENT PERSON.
I HAD DONE THE CODING AS GIVEN BELOW.
IF NOT itab_fico[] IS INITIAL.
RECEIVERS_TAB-RECEIVER = 'SAP_00021'.
RECEIVERS_TAB-REC_TYPE = 'B'.
RECEIVERS_TAB-EXPRESS = 'X'.
APPEND RECEIVERS_TAB.
PERFORM SEND_MAIL TABLES T_AMS RECEIVERS_TAB.
endif.
IF NOT itab_sd[] IS INITIAL.
RECEIVERS_TAB-RECEIVER = 'SAP_00022'. <------- its my sap id
RECEIVERS_TAB-REC_TYPE = 'B'.
RECEIVERS_TAB-EXPRESS = 'X'.
APPEND RECEIVERS_TAB.
PERFORM SEND_MAIL TABLES T_AMS RECEIVERS_TAB.
endif.
Now, what is happening is i am getting two mails,
one contains the attachement in Excel for ITAB_FICO. ( 3 ROWS)
SECOND mail contains two attachement one for ITAB_FICO ,second attachment contains the line items of ITAB_FICO + in the same excel the line items of ITAB_SD(2 ROWS).
So, for one time its working fine, but on sending mail second or third them its attaching the previous attachment also...... i tried to refresh everything but its not working....................
please help,,,,or if possible tell me some other SAP FM ...which can fulfil the requirements.
I will reward points for every suggestion.
thanksHi Saurabh,
IF NOT itab_fico[] IS INITIAL.
<b>REFRESH : RECEIVERS_TAB.
CLEAR : RECEIVERS_TAB.</b>
RECEIVERS_TAB-RECEIVER = 'SAP_00021'.
RECEIVERS_TAB-REC_TYPE = 'B'.
RECEIVERS_TAB-EXPRESS = 'X'.
APPEND RECEIVERS_TAB.
PERFORM SEND_MAIL TABLES T_AMS RECEIVERS_TAB.
endif.
IF NOT itab_sd[] IS INITIAL.
<b>REFRESH : RECEIVERS_TAB.
CLEAR : RECEIVERS_TAB.</b>
RECEIVERS_TAB-RECEIVER = 'SAP_00022'. <------- its my sap id
RECEIVERS_TAB-REC_TYPE = 'B'.
RECEIVERS_TAB-EXPRESS = 'X'.
APPEND RECEIVERS_TAB.
PERFORM SEND_MAIL TABLES T_AMS RECEIVERS_TAB.
endif.
Best regards,
Prashant -
Sending excel attachment to the distribution list
Hi ,
I am sending an Excel file attachment in XLS format to the distrubution list using FM :SO_NEW_DOCUMENT_ATT_SEND_API1
I have passed the parameters as follows:
reclist-REC_TYPE = 'C'.
reclist-COM_TYPE = 'INT'.
reclist-NOTIF_DEL = 'X'.
reclist-NOTIF_NDEL = 'X'.
reclist-RECEIVER = p_DLIST.
APPEND reclist.
but i am receiving error message :
Exception from the class CX_SEND_REQ_BCS was caught
when I am passing the receiver as email address, its working fine.
Please let me know what is the issue?
Tjhanks and regards,
MadhuriHi,
Try
RECLIST-REC_TYPE = 'U'. "internet users
RECLIST-RECEIVER = '<name>@address.com'. " try one like youe first address
RECLIST-REC_TYPE = 'U'.
APPEND RECLIST.
RECLIST-RECEIVER = p_DLIST. " put the list
RECLIST-REC_TYPE = 'P'.
APPEND RECLIST.
Also check this wiki [http://wiki.sdn.sap.com/wiki/display/Snippets/Howtosendmailtoadistributionlistoragroup+ID]
Ben -
Issue while opening Excel attachment send through FM
Hi All,
I had program in which i am sending mail along with Excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1. Mail is going fine with data in Excel attachment. But when i try to open the Excel it gives an Info message saying that "<b>You are trying to open (attachment name),is in different format than specified file extension Verify that file is not corrupted and is from a trusted source before opening file. Do you want to open file now</b>". Then when i presses YES, Excel opens up with all data. I want to know how to avoid that info popup. Is there something has to be passed to FM or something has to be done to Excel like settings in EXCEL so that i can avoid that Info message coming.
Document type of attachment is gw_packing_list-doc_type = 'XLS'.
Thanks in advance,
ShyamHi Shyam,
Have you build your Excel Data table to get attachement in Mail? If no then please find the Eg. code for your reference to send Excel attachment..
* End of Selection Event : Displaying the selected data *
END-OF-SELECTION.
PERFORM EMAIL_EXCEL_ATTACHMENT.
******///form
FORM EMAIL_EXCEL_ATTACHMENT .
* Populate table with detaisl to be entered into .xls file
PERFORM BUILD_XLS_DATA_TABLE.
* 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 S_EMAIL
TEXT-042
C_XLS
'filename'
CHANGING GD_ERROR
GD_RECIEVER.
* Instructs mail send program for SAPCONNECT to send email(rsconn01)
PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
ENDFORM. " EMAIL_EXCEL_ATTACHMENT
********///form BUILD_XLS_DATA_TABLE
FORM BUILD_XLS_DATA_TABLE .
DATA : LV_NETWR(20) TYPE C,
LV_BOL_DATE(20) TYPE C,
LV_KAWRT(20) TYPE C,
LV_FKDAT(20) TYPE C,
LV_WAERK(20) TYPE C,
LV_KURRF(20) TYPE C,
LV_SHIPDATE(20) TYPE C,
LV_DEPTDATE(20) TYPE C.
CONSTANTS:
CON_TAB TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF. "#EC *
DATA STR TYPE STRING.
**********/ this parameter concatenate to get headers
CONCATENATE STR
'SLNO'
'OWNER'
'SERIAL NO'
'FROM'
'DESTINATION'
'INVOICE VALUE'
'DESCRIPTION'
'CUSTOMER NAME'
'BL NUMBER'
'BL DATE'
'VESSEL NAME/AIRLINE DETAILS'
'MODE OF TRANSIT'
'SHIPPING MARKS'
'DUTY SUM INSURED'
'FLAG'
'OPEN COVERNO'
'INVOICE DATE'
'INVOICE NO'
'LC WORDING'
'QUANTITY'
'PACKAGING DETAILS'
'BASIS OF VALUATION'
'EXCLUDE WAR SRCC'
'CURRENCY'
'EXCHANGE RATE'
'ADDRESS'
'VESSEL BUILT YEAR'
'VESSEL FLAG'
'VOYAGE NO'
'SHIPMENT DATE'
'DEPARTURE DATE'
'SURVEYOR COUNTRY'
'SURVEYOR CITY'
'SURVEYOR AGENT'
'SURVEYOR ADDRESS'
'EXPORT CONSIGNMENT'
'CONTAINER DETAILS'
CL_ABAP_CHAR_UTILITIES=>CR_LF INTO STR SEPARATED BY CON_TAB.
LOOP AT IT_FINAL.
*******/ this is to pass body / row data
WRITE : IT_FINAL-NETWR TO LV_NETWR, "#EC UOM_IN_MES
IT_FINAL-BOL_DATE TO LV_BOL_DATE,
IT_FINAL-KAWRT TO LV_KAWRT, "#EC UOM_IN_MES
IT_FINAL-FKDAT TO LV_FKDAT,
IT_FINAL-WAERK TO LV_WAERK,
IT_FINAL-KURRF TO LV_KURRF,
IT_FINAL-SHIPDATE TO LV_SHIPDATE,
IT_FINAL-DEPTDATE TO LV_DEPTDATE.
CONCATENATE
STR
IT_FINAL-SLNO
IT_FINAL-OWNER
IT_FINAL-SRNO
IT_FINAL-PORT_LOAD
IT_FINAL-PORT_DSCHR
LV_NETWR
IT_FINAL-DESCRIP
IT_FINAL-CUSTNAME
IT_FINAL-BOL_NUM
LV_BOL_DATE
IT_FINAL-VESSELNAME
IT_FINAL-SHP_TYPE
IT_FINAL-SHP_MARK
LV_KAWRT
IT_FINAL-FLAG
IT_FINAL-OPEN_CONO
LV_FKDAT
IT_FINAL-VBELN
IT_FINAL-LC_WORD
IT_FINAL-QUANT
IT_FINAL-PACKDETL
IT_FINAL-INCO1
IT_FINAL-EXCWSR
LV_WAERK
LV_KURRF
IT_FINAL-ADDPAY
IT_FINAL-VESSBYR
IT_FINAL-VESSFLG
IT_FINAL-VOY_FLY_NO
LV_SHIPDATE
LV_DEPTDATE
IT_FINAL-SURCOUNT
IT_FINAL-INCO2
IT_FINAL-EXPORT_CON
IT_FINAL-SURAGT
IT_FINAL-SURADD
IT_FINAL-CONTRNO
CL_ABAP_CHAR_UTILITIES=>CR_LF INTO STR SEPARATED BY CON_TAB.
ENDLOOP.
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
EXPORTING
TEXT = STR
TABLES
FTEXT_TAB = IT_ATTACH.
ENDFORM. " BUILD_XLS_DATA_TABLE
******// form POPULATE_EMAIL_MESSAGE_BODY
FORM POPULATE_EMAIL_MESSAGE_BODY .
REFRESH IT_MESSAGE.
IT_MESSAGE = TEXT-043. " Please find attached Insurance Certificate details
APPEND IT_MESSAGE.
ENDFORM. " POPULATE_EMAIL_MESSAGE_BODY
*******'/ form SEND_FILE_AS_EMAIL_ATTACHMENT
*& Form SEND_FILE_AS_EMAIL_ATTACHMENT
* text
* -->PIT_MESSAGE text
* -->PIT_ATTACH text
* -->P_EMAIL text
* -->P_MTITLE text
* -->P_FORMAT text
* -->P_FILENAME text
* -->P_ATTDESCRIPTION text
* -->P_SENDER_ADDRESS text
* -->P_SENDER_ADDRES_TYPE text
* -->P_ERROR text
* -->P_RECIEVER text
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. "#EC *
DATA: LD_ERROR TYPE SY-SUBRC, "#EC *
* 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. "#EC *
* 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.
DESCRIBE TABLE IT_ATTACH LINES W_CNT.
READ TABLE IT_ATTACH INDEX W_CNT.
W_DOC_DATA-DOC_SIZE =
W_CNT * 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.
LOOP AT S_EMAIL.
T_RECEIVERS-RECEIVER = S_EMAIL-LOW.
T_RECEIVERS-REC_TYPE = 'U'.
T_RECEIVERS-COM_TYPE = 'INT'.
T_RECEIVERS-NOTIF_DEL = 'X'.
T_RECEIVERS-NOTIF_NDEL = 'X'.
APPEND T_RECEIVERS.
ENDLOOP.
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. " SEND_FILE_AS_EMAIL_ATTACHMENT
*******/form
*& Form INITIATE_MAIL_EXECUTE_PROGRAM
* text
* --> p1 text
* <-- p2 text
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
*********end of code to trigger mail in excel format....
If any other help please let me know......
I am sure this example code will help you to resolve your problem...
please analyse above code for your requirement...
In my scenario the message you said is not displaying.....
<i>Reward Points</i>
Cheers,
Sagun Desai -
Send Excel as attachment with colors in coloums
Hi,
I need to send Excel as attachment and some particular columns should be coloured.
I am sending Excel attachment using FM SO_DOCUMENT_SEND_API1 when report executed in foreground.
Please help how to make columns coloured.
Thanks,
Phanihi,
This report demonstrates how to send some ABAP data to an EXCEL sheet using OLE automation by this it makes EXCEL columns colorful.
TYPE-POOLS OLE2 .
* handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
H_MAPL TYPE OLE2_OBJECT, " list of workbooks
H_MAP TYPE OLE2_OBJECT, " workbook
H_ZL TYPE OLE2_OBJECT, " cell
H_F TYPE OLE2_OBJECT, " font
H_C TYPE OLE2_OBJECT. " color
DATA: FILENAME LIKE RLGRAP-FILENAME.
TABLES: SPFLI.
DATA H TYPE I.
* table of flights
DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
*& Event START-OF-SELECTION
START-OF-SELECTION.
* read flights
SELECT * FROM SPFLI INTO TABLE IT_SPFLI.
* display header
ULINE (61).
WRITE: / SY-VLINE NO-GAP,
(3) 'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(4) 'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
(8) 'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
ULINE /(61).
* display flights
LOOP AT IT_SPFLI.
WRITE: / SY-VLINE NO-GAP,
IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
ENDLOOP.
ULINE /(61).
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = TEXT-007
EXCEPTIONS
OTHERS = 1.
* start Excel
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
* PERFORM ERR_HDL.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
* CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls' .
* PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = TEXT-008
EXCEPTIONS
OTHERS = 1.
* get list of workbooks, initially empty
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
PERFORM ERR_HDL.
* add a new workbook
CALL METHOD OF H_MAPL 'Add' = H_MAP.
PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = TEXT-009
EXCEPTIONS
OTHERS = 1.
* output column headings to active Excel sheet
PERFORM FILL_CELL USING 1 1 1 200 'Carrier id'(001).
PERFORM FILL_CELL USING 1 2 1 200 'Connection id'(002).
PERFORM FILL_CELL USING 1 3 1 200 'City from'(003).
PERFORM FILL_CELL USING 1 4 1 200 'City to'(004).
PERFORM FILL_CELL USING 1 5 1 200 'Dep. Time'(005).
LOOP AT IT_SPFLI.
* copy flights to active EXCEL sheet
H = SY-TABIX + 1.
IF IT_SPFLI-CARRID CS 'AA'.
PERFORM FILL_CELL USING H 1 0 000255000 IT_SPFLI-CARRID.
ELSEIF IT_SPFLI-CARRID CS 'AZ'.
PERFORM FILL_CELL USING H 1 0 168000000 IT_SPFLI-CARRID.
ELSEIF IT_SPFLI-CARRID CS 'JL'.
PERFORM FILL_CELL USING H 1 0 168168000 IT_SPFLI-CARRID.
ELSEIF IT_SPFLI-CARRID CS 'LH'.
PERFORM FILL_CELL USING H 1 0 111111111 IT_SPFLI-CARRID.
ELSEIF IT_SPFLI-CARRID CS 'SQ'.
PERFORM FILL_CELL USING H 1 0 100100100 IT_SPFLI-CARRID.
ELSE.
PERFORM FILL_CELL USING H 1 0 000145000 IT_SPFLI-CARRID.
ENDIF.
IF IT_SPFLI-CONNID LT 400.
PERFORM FILL_CELL USING H 2 0 255000255 IT_SPFLI-CONNID.
ELSEIF IT_SPFLI-CONNID LT 800.
PERFORM FILL_CELL USING H 2 0 077099088 IT_SPFLI-CONNID.
ELSE.
PERFORM FILL_CELL USING H 2 0 246156138 IT_SPFLI-CONNID.
ENDIF.
IF IT_SPFLI-CITYFROM CP 'S*'.
PERFORM FILL_CELL USING H 3 0 155155155 IT_SPFLI-CITYFROM.
ELSEIF IT_SPFLI-CITYFROM CP 'N*'.
PERFORM FILL_CELL USING H 3 0 189111222 IT_SPFLI-CITYFROM.
ELSE.
PERFORM FILL_CELL USING H 3 0 111230222 IT_SPFLI-CITYFROM.
ENDIF.
IF IT_SPFLI-CITYTO CP 'S*'.
PERFORM FILL_CELL USING H 4 0 200200200 IT_SPFLI-CITYTO.
ELSEIF IT_SPFLI-CITYTO CP 'N*'.
PERFORM FILL_CELL USING H 4 0 000111222 IT_SPFLI-CITYTO.
ELSE.
PERFORM FILL_CELL USING H 4 0 130230230 IT_SPFLI-CITYTO.
ENDIF.
IF IT_SPFLI-DEPTIME LT '020000'.
PERFORM FILL_CELL USING H 5 0 145145145 IT_SPFLI-DEPTIME.
ELSEIF IT_SPFLI-DEPTIME LT '120000' .
PERFORM FILL_CELL USING H 5 0 015215205 IT_SPFLI-DEPTIME.
ELSEIF IT_SPFLI-DEPTIME LT '180000' .
PERFORM FILL_CELL USING H 5 0 000215205 IT_SPFLI-DEPTIME.
ELSE.
PERFORM FILL_CELL USING H 5 0 115115105 IT_SPFLI-DEPTIME.
ENDIF.
ENDLOOP.
* EXCEL FILENAME
CONCATENATE SY-REPID '_' SY-DATUM+6(2) '_' SY-DATUM+4(2) '_'
SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
CALL METHOD OF H_MAP 'SAVEAS' EXPORTING #1 = FILENAME.
FREE OBJECT H_EXCEL.
PERFORM ERR_HDL.
* FORM FILL_CELL *
* sets cell at coordinates i,j to value val boldtype bold *
FORM FILL_CELL USING I J BOLD COL VAL. -
Excel attachment in mailing program
Hi,
I am sending excel attachment in the mailing program.
The attachment contains 56 lines, but the problem is the attachment which is coming with 22 line only in mail .
What may be the problem?
Regards,Please debug and check the internal table before the Mail FM, whether all lines are there.
-
Email Excel attachment with a BOLD row
hi!
My requirement is that data in an internal table should be sent as an attachment in an email. There are a few records in the internal table which needs to be in bold(i have the logic to figure out whichones). I am using the below FM .
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
object_hd_change = wa_object_hd
object_type = 'RAW'
TABLES
objcont = i_text
receivers = i_recv
packing_list = i_packing_list
att_cont = i_att
Does any body have any idea how to bold a few records in the excel attachment?
I appreciate your suggestions.
Thanks,
manasa
Message was edited by:
manasaHi Manasa,
The Code below is for sending Excel attachment in email. Not sure for BOLD...
You can copy and paste the following codes and execute..
Hope this will help you..
TYPE-POOLS: truxs.
DATA t5 LIKE t005t OCCURS 0 WITH HEADER LINE.
START-OF-SELECTION.
SELECT * INTO TABLE t5
FROM t005t
WHERE spras = sy-langu.
DATA wa_data TYPE truxs_t_text_data.
CALL FUNCTION 'SAP_CONVERT_TO_TXT_FORMAT'
EXPORTING
i_line_header = 'X'
TABLES
i_tab_sap_data = t5
CHANGING
i_tab_converted_data = wa_data
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
DATA stmp(4096) TYPE c.
DATA itmp TYPE i.
LOOP AT wa_data INTO stmp.
itmp = STRLEN( stmp ).
stmp+itmp = cl_abap_char_utilities=>cr_lf.
MODIFY wa_data FROM stmp.
ENDLOOP.
PERFORM send_email.
*& Form send_email
FORM send_email .
DATA docs LIKE docs OCCURS 0 WITH HEADER LINE.
DATA excelsize TYPE i.
DATA excel LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA doc LIKE sodocchgi1.
DATA excelln TYPE i.
DATA int_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA int_objhead LIKE solisti1 OCCURS 2 WITH HEADER LINE.
DATA int_objtext LIKE solisti1 OCCURS 0 WITH HEADER LINE.
DATA int_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
DATA bodyln LIKE sy-tabix.
DATA output_data TYPE ssfcrescl.
excel[] = wa_data[].
excel table sizes
DESCRIBE TABLE excel LINES excelln.
Body Email
int_objtext-line = 'Test Body'.
APPEND int_objtext.
DESCRIBE TABLE int_objtext LINES bodyln.
READ TABLE int_objtext INDEX bodyln.
CLEAR doc.
doc-doc_size = ( bodyln - 1 ) * 255 + STRLEN( int_objtext ).
doc-obj_name = ' '.
doc-sensitivty = 'P'.
doc-proc_syst = sy-sysid.
doc-proc_clint = sy-mandt.
CLEAR: int_objpack, int_objpack[].
int_objpack-transf_bin = ' '.
int_objpack-head_start = 1.
int_objpack-head_num = 0.
int_objpack-body_start = 1.
int_objpack-body_num = bodyln.
int_objpack-doc_type = 'RAW'.
int_objpack-obj_descr = 'Test'.
APPEND int_objpack.
CLEAR: int_objhead, int_objhead[].
int_objhead = 'Attachment'.
APPEND int_objhead.
int_objpack-transf_bin = 'X'.
int_objpack-head_start = 1.
int_objpack-head_num = 0.
int_objpack-body_start = 1.
int_objpack-body_num = excelln.
int_objpack-doc_size = excelsize.
int_objpack-doc_type = 'XLS'.
int_objpack-obj_name = 'excel'.
int_objpack-obj_descr = 'test.xls'. "File name
APPEND int_objpack.
Set Receiver
int_reclist-receiver = 'SAPUSER'.
int_reclist-rec_type = 'B'.
int_reclist-notif_del = 'X'.
int_reclist-notif_read = 'X'.
int_reclist-notif_ndel = 'X'.
int_reclist-express = 'X'.
APPEND int_reclist.
doc-obj_descr = 'Report in Excel'.
Sending Email
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = int_objpack
object_header = int_objhead
contents_bin = excel
contents_txt = int_objtext "Body
receivers = int_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.
ENDFORM. " send_email
Note:
- If you are using FM SAP_CONVERT_TO_TXT_FORMAT you will not be able to execute this program in the background.
- dont forget to change 'SAPUSER' to your SAP user ID
- you can check the email by using tcode 'SBWP'.
Reward points if this Helps.
Manish -
Hello,
I have to send an email in a workflow step with a excel attach from an internal table, Does anyone have any sugestion ?
Thanks,
DiegoHi,
Check this [thread1|send excel attachment as email; [thread2|Re: Excel attachment in SO_DOCUMENT_SEND_API1; & [thread3|Help needed for the Excel attachment to mail;.
Regards,
Surjith -
Send an Excel Attachment as mail to a list of recipients
Hello Everyone,
I am trying to send an email with an excel attachment. My code has been activated successfully. But I haven't received any mail.
Kindly help.
My code is as below.
FORM Z_SENDMAIL .
DATA lv_receiver type SOMLRECI1-RECEIVER.
TYPES: BEGIN OF LTS_CHARFINAL,
matnr(18) type c,
maktx(40) type c,
idnlf(35) type c,
ltsnr(6) type c,
werks(4) type c,
ltsbz(20) type c,
ernam(12) type c,
verpr(11) type c,
soh_qty(13) TYPE c,
int_qty(13) TYPE c,
ext_soh(11) TYPE c,
hol_qty(13) TYPE c,
all_qty(13) TYPE c,
bac_qty(13) TYPE c,
ext_ttl(11) TYPE c,
END OF LTS_CHARFINAL.
DATA: WA_CHARFINAL TYPE LTS_CHARFINAL.
lv_receiver = '[email protected]'.
CONCATENATE 'ITEM_TRIM'
'DESCRIPTION'
'VEND_ITEM'
'PLNRCODE'
'LOCATION'
'SITE'
'PLANNER'
'AVERAGE_COST'
'SOH_QTY'
'INTRANS_QTY'
'EXT_COST_SOH'
'HOLD_QTY'
'ALLOC_QTY'
'BACKORD_QTY'
'EXT_COST_TTL_INVEN'
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
LOOP AT GIT_FINAL INTO GWA_FINAL.
wa_charfinal-matnr = gwa_final-matnr.
wa_charfinal-maktx = gwa_final-maktx.
wa_charfinal-idnlf = gwa_final-idnlf.
wa_charfinal-ltsnr = gwa_final-ltsnr.
wa_charfinal-werks = gwa_final-werks.
wa_charfinal-ltsbz = gwa_final-ltsbz.
wa_charfinal-ernam = gwa_final-ernam.
wa_charfinal-verpr = gwa_final-verpr.
wa_charfinal-soh_qty = gwa_final-soh_qty.
wa_charfinal-int_qty = gwa_final-int_qty.
wa_charfinal-ext_soh = gwa_final-ext_soh.
wa_charfinal-hol_qty = gwa_final-hol_qty.
wa_charfinal-all_qty = gwa_final-all_qty.
wa_charfinal-bac_qty = gwa_final-bac_qty.
wa_charfinal-ext_ttl = gwa_final-ext_ttl.
CONCATENATE wa_charfinal-matnr
wa_charfinal-maktx
wa_charfinal-idnlf
wa_charfinal-ltsnr
wa_charfinal-werks
wa_charfinal-ltsbz
wa_charfinal-ernam
wa_charfinal-verpr
wa_charfinal-soh_qty
wa_charfinal-int_qty
wa_charfinal-ext_soh
wa_charfinal-hol_qty
wa_charfinal-all_qty
wa_charfinal-bac_qty
wa_charfinal-ext_ttl
INTO IT_ATTACH SEPARATED BY CON_TAB.
CONCATENATE CON_CRET IT_ATTACH INTO IT_ATTACH.
APPEND IT_ATTACH.
ENDLOOP.
PERFORM Z_BUILD_MESSAGE.
PERFORM Z_SEND_FILE_ATTACHMENT
TABLES IT_MESSAGE
IT_ATTACH
USING lv_receiver
'Example .xls documnet attachment'
'XLS'
'filename'
CHANGING GD_ERROR
GD_RECIEVER.
ENDFORM.
FORM Z_BUILD_MESSAGE .
REFRESH IT_MESSAGE.
IT_MESSAGE = 'Please find the attached document'.
APPEND IT_MESSAGE.
ENDFORM. " Z_BUILD_MESSAGE
FORM Z_SEND_FILE_ATTACHMENT TABLES P_IT_MESSAGE
P_IT_ATTACH STRUCTURE IT_ATTACH
USING P_lv_receiver
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_LV_RECEIVER.
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[] = P_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. " Z_SEND_FILE_ATTACHMENT
-Regards
MonicaHi Monica,
Please check with your BASIS team if all the required configurations are there to send mail.
You can check in SOST transaction if you have an entry there for your mail.
Another relevant transaction in SCOT.
Regards,
Santanu. -
To send output of report to the mails ids as an excel attachment
Hi all,
I have a requirement that I have created a report using classes. Now I have to send output of my report to the particular mailids as an excel attachment.
Can anybody help me?
Regards,
Azra.Hi,
Refer Below links.
Re: Formatting Excel Attachment output in SO_DOCUMENT_SEND_API1
Information Broadcasting with Excel Report as attachment
Zip the excel and send as mail attachment
Regards
Md.MaahboobKhan
Maybe you are looking for
-
Dynamic File name in FTP Communication Channel
Hi All, We have requirement where ,we create a filenames dynamically ( runtime).These filenames whihc do change for every execution needs to be added in FTP communication channel. 1. How can we add the this generated file name in FTP CC Communication
-
Midi not reading A SAMSON 61 CARBON MIDI CONTROLLER HEEN HELP
NEED HELP MIDI WILL READ 61 SAMSON MIDI KEYBOARD BUT IT WILL READ THE 49 KEY VERSION
-
Changing the search help for vbap-aufnr in va01
Hi Folks, Can we change the search help provided for the field Order(vbap-aufnr) in the table Control ALL ITEMS in VA01. 1.go to va01. 2.give the order type. 3.press enter. 4.it will take us to the overview screen. 5.there we will find a table contro
-
Is there a possibility to maintain source list for MRP purposes at storage Location level? We receive requirements from a couple of our subsidaries and we were consolidating this to be a single requirement for our suppliers, however this has changed
-
Has anyone here had experience with a Sony NEX-VG10/E m2ts file?
A recently created file with this video camera, and importing its m2ts file into Permiere Pro CS5 is proving offering disappointing rsults. The images are fuzzy and there is a great deal of what appears to be interlace issues. If it were not for ot