Problem in sending the attachment using SO_NEW_DOCUMENT_ATT_SEND_API1
Hi,
I have a requirement to send the details of an internal table to External mail as an attachment. I have used fn.module 'SO_NEW_DOCUMENT_ATT_SEND_API1' to do so. I am getting the attachment but the data is stored in only one row when we checked it in SAP outbox. This is irrespective of TXT, XLS etc. I can not check the exact file in my external mail inbox as the connection is not established in dev & Quality systems. This question was raised earlier by other guys and there was no correct answer provided. If any of you encountered this type of problem & got the solution please help.
Thanks,
Ashok
Hi Buddy,
Hope this piece of code will definately help you out, Its working at my end.
Thanks,
Krishna..
FORM p_send_email .
FIELD-SYMBOLS: <field> TYPE ANY.
DATA : BEGIN OF i_dload OCCURS 0 ,
dload(1000) ,
END OF i_dload .
DATA: it_receivers LIKE somlreci1 OCCURS 1 WITH HEADER LINE,
w_object_content LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: w_doc_data LIKE sodocchgi1 OCCURS 0 WITH HEADER LINE.
DATA :w_records TYPE zres_records.
DATA: w_rsnum(10),
w_bdmng(14),
w_meins(4).
DATA: ws_email LIKE adr6-smtp_addr. "for internal e_mail address
DATA: ws_email1 LIKE adr6-smtp_addr. "for external e_mail address
*--Internal table declaration
DATA: it_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
DATA: it_objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE.
DATA: it_objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE.
DATA: it_reclist LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
DATA: doc_chng LIKE sodocchgi1.
DATA: tab_lines LIKE sy-tabix.
DATA: w_longtext(500) TYPE c.
DATA: v_date(10) TYPE c.
DATA: text(200) TYPE c.
DATA: w_text(50) TYPE c.
*--Get receipient address
CLEAR it_reclist.
*--To send error to internal mail
ws_email = p_email.
*--To send error to external mail
ws_email1 = p_email1.
*---setting name of file for csv
CONCATENATE text-003 p_bdoc text-004 INTO w_filename.
CONDENSE w_filename NO-GAPS.
IF flag <> 1.
IF p_email1 IS NOT INITIAL.
build body of message
CONCATENATE 'disply message ' ' ' INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
it_reclist-receiver = ws_email1.
it_reclist-rec_type = c_u.
it_reclist-express = ' '.
it_reclist-com_type = 'INT'.
APPEND it_reclist.
Set title of object and email
CLEAR: w_text.
CONCATENATE 'Greenheck Packing List Data'
INTO w_text SEPARATED BY space.
doc_chng-obj_descr = text-005. "w_text.
doc_chng-obj_name = 'Inbound EDI'.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
*--Move the Report Name as the Heading line for email file
CLEAR: w_longtext.
MOVE: text-012 TO w_longtext.
w_longtext = 'name of report for testing'.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append Blank Lines
APPEND it_objbin. CLEAR it_objbin.
APPEND it_objbin. CLEAR it_objbin.
*User name
CLEAR text.
MOVE: 'User:' TO text,
sy-uname TO text+6.
it_objbin = text.
APPEND it_objbin. CLEAR it_objbin.
---appending heading to Internal table of Email
CLEAR: w_longtext, w_xblnr_1 , w_aubel_1, w_vemng_1,
w_matnr_1, w_harmdesc_1, w_hc_1, w_cooland1_1,
w_brgew_1, w_tknum_1, w_vbeln_1, w_vbeln1_1,
w_exidv_1, w_vhilm_1, w_pack_no_1,
w_brgew1_1, w_laeng_1, w_breit_1,
w_hoehe_1, w_vol_1.
w_xblnr_1 = 'Cust PO No.'.
w_aubel_1 = 'Sal Order'.
w_vemng_1 = 'Pack Qty'.
w_matnr_1 = 'Model no.'.
w_harmdesc_1 = 'Hrm Desc'.
w_hc_1 = 'Hrm Code'.
w_cooland1_1 = 'Country of Origin'.
w_brgew_1 = 'Net Wt.'.
w_tknum_1 = 'Shipment'.
w_vbeln_1 = 'Billing Doc'.
w_vbeln1_1 = 'Delivery'.
w_exidv_1 = 'Pkg ID'.
w_vhilm_1 = 'Pkg Desc'.
w_pack_no_1 = 'Pkg No.'.
w_brgew1_1 = 'Gross Wt'.
w_laeng_1 = 'Length'.
w_breit_1 = 'Width'.
w_hoehe_1 = 'Height'.
w_vol_1 = 'Cubic Mtr'.
CONCATENATE w_xblnr_1 w_aubel_1 w_vemng_1
w_matnr_1 w_harmdesc_1 w_hc_1 w_cooland1_1
w_brgew_1 w_tknum_1 w_vbeln_1 w_vbeln1_1
w_exidv_1 w_vhilm_1 w_pack_no_1
w_brgew1_1 w_laeng_1 w_breit_1
w_hoehe_1 w_vol_1
INTO w_longtext SEPARATED BY ','.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
LOOP AT it_tab.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
Look for Commas in the field value. If it exists, put quotes around
value so that the file opens correctly with all the columns aligned
in Excel.
SEARCH <field> FOR ',' IN CHARACTER MODE.
If search for commas was successful.
IF sy-subrc = 0.
CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
ENDIF.
IF sy-index = 1.
i_dload-dload = <field>.
SHIFT: i_dload-dload LEFT DELETING LEADING space.
ELSE.
Put Comma as a separator for values in IT_DLOAD internal table
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONCATENATE i_dload-dload <field> INTO i_dload-dload
SEPARATED BY ',' IN CHARACTER MODE.
ENDIF.
ENDDO.
it_objbin = i_dload-dload.
APPEND it_objbin. CLEAR it_objbin.
ENDLOOP.
flag = 1.
endif.
ENDIF.
---if to send error file.
IF p_email IS NOT INITIAL.
build body of message
CONCATENATE 'Errors in file ' ' ' INTO it_objtxt
SEPARATED BY space.
APPEND it_objtxt.
CLEAR it_objtxt.
it_reclist-receiver = ws_email.
it_reclist-rec_type = c_u.
it_reclist-express = ' '.
it_reclist-com_type = 'INT'.
APPEND it_reclist.
Set title of object and email
CLEAR: w_text.
CONCATENATE 'Greenheck Packing List Data'
INTO w_text SEPARATED BY space.
doc_chng-obj_descr = text-005.
doc_chng-obj_name = 'Inbound EDI'.
DESCRIBE TABLE it_objtxt LINES tab_lines.
READ TABLE it_objtxt INDEX tab_lines.
doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).
*--Move the Report Name as the Heading line for email file
CLEAR: w_longtext.
MOVE: text-012 TO w_longtext.
w_longtext = 'name of report for testing'.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append Blank Lines
APPEND it_objbin. CLEAR it_objbin.
APPEND it_objbin. CLEAR it_objbin.
*User name
CLEAR text.
MOVE: 'User:' TO text,
sy-uname TO text+6.
it_objbin = text.
APPEND it_objbin. CLEAR it_objbin.
---appending heading to Internal table of Email
CLEAR: w_longtext, w_xblnr_1 , w_aubel_1, w_vemng_1,
w_matnr_1, w_harmdesc_1, w_hc_1, w_cooland1_1,
w_brgew_1, w_tknum_1, w_vbeln_1, w_vbeln1_1,
w_exidv_1, w_vhilm_1, w_pack_no_1,
w_brgew1_1, w_laeng_1, w_breit_1,
w_hoehe_1, w_vol_1, w_error.
w_xblnr_1 = 'Cust PO No.'.
w_aubel_1 = 'Sal Order'.
w_vemng_1 = 'Pack Qty'.
w_matnr_1 = 'Model no.'.
w_harmdesc_1 = 'Hrm Desc'.
w_hc_1 = 'Hrm Code'.
w_cooland1_1 = 'Counrty of Origin'.
w_brgew_1 = 'Net Wt.'.
w_tknum_1 = 'Shipment'.
w_vbeln_1 = 'Billing doc'.
w_vbeln1_1 = 'Delivery'.
w_exidv_1 = 'Pkg ID'.
w_vhilm_1 = 'Pkg Desc'.
w_pack_no_1 = 'Pkg No.'.
w_brgew1_1 = 'Gross Wt'.
w_laeng_1 = 'Length'.
w_breit_1 = 'Width'.
w_hoehe_1 = 'Height'.
w_vol_1 = 'Cubic Mtr'.
w_error = 'Error'.
CONCATENATE w_xblnr_1 w_aubel_1 w_vemng_1
w_matnr_1 w_harmdesc_1 w_hc_1 w_cooland1_1
w_brgew_1 w_tknum_1 w_vbeln_1 w_vbeln1_1
w_exidv_1 w_vhilm_1 w_pack_no_1
w_brgew1_1 w_laeng_1 w_breit_1
w_hoehe_1 w_vol_1 w_error
INTO w_longtext SEPARATED BY ','.
it_objbin = w_longtext.
APPEND it_objbin. CLEAR it_objbin.
*--Append the details to Internal table of Email
LOOP AT it_tab.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE it_tab TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
Look for Commas in the field value. If it exists, put quotes around
value so that the file opens correctly with all the columns aligned
in Excel.
SEARCH <field> FOR ',' IN CHARACTER MODE.
If search for commas was successful.
IF sy-subrc = 0.
CONCATENATE '"' <field> '"' INTO <field> IN CHARACTER MODE.
ENDIF.
IF sy-index = 1.
i_dload-dload = <field>.
SHIFT: i_dload-dload LEFT DELETING LEADING space.
ELSE.
Put Comma as a separator for values in IT_DLOAD internal table
SHIFT: i_dload-dload LEFT DELETING LEADING space.
CONCATENATE i_dload-dload <field> INTO i_dload-dload
SEPARATED BY ',' IN CHARACTER MODE.
ENDIF.
ENDDO.
it_objbin = i_dload-dload.
APPEND it_objbin. CLEAR it_objbin.
ENDLOOP.
flag = 0.
endif.
-Convert to correct format----
CALL FUNCTION 'SO_RAW_TO_RTF'
TABLES
objcont_old = it_objbin
objcont_new = it_objbin.
create the control table entry for the main email
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR it_objpack-transf_bin.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-doc_type = 'RAW'.
APPEND it_objpack.
DESCRIBE TABLE it_objbin LINES tab_lines.
it_objpack-head_start = 1.
it_objpack-head_num = 0.
it_objpack-body_start = 1.
it_objpack-body_num = tab_lines.
it_objpack-transf_bin = c_x.
it_objpack-doc_type = 'CSV'.
it_objpack-obj_descr = w_filename. "'billing doc no.csv'.
it_objpack-obj_name = 'Billing Doc'.
it_objpack-doc_size = tab_lines * 255.
APPEND it_objpack.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
PUT_IN_OUTBOX = c_x
commit_work = c_x
TABLES
packing_list = it_objpack
object_header = it_objhead
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc <> 0.
WRITE: / 'failure in sending mail'.
ELSE.
if flag = 0.
MESSAGE s999(pp) WITH text-007.
endif.
if flag = 1.
MESSAGE s999(pp) WITH text-006.
endif.
WRITE: / 'success in sending mail'.
ENDIF.
ENDFORM. " p_send_email
Similar Messages
-
Problem while sending the message using RWB
Dear All,
I am facing a problem while sending a message from RWB. I sent the message using Test Message in component monitoring, it says message sent but I am not able to see any message in sxi_monitor.
When I send the same message using the http client it successfully processed by XI and I can see the success message in sxi_monitor.
Please let me know if anyone has face similar kind of issue.
Thanks,
Alok
Edited by: Alok Raoka on May 26, 2008 5:08 PMDear All,
I am facing a problem while sending a message from RWB. I sent the message using Test Message in component monitoring, it says message sent but I am not able to see any message in sxi_monitor.
When I send the same message using the http client it successfully processed by XI and I can see the success message in sxi_monitor.
Please let me know if anyone has face similar kind of issue.
Thanks,
Alok
Edited by: Alok Raoka on May 26, 2008 5:08 PM -
Hi ALL,
I HAVE THE REQUIREMENT AS SEND A REPORT AS A MAIL. IAM USING FM 'SO_NEW_DOCUMENT_ATT_SEND_API1' WHILE EXECUTING ITS NOT SHOWING ANY ERROR. BUT IAM NOT GETTING ANY MAIL. I CHECKED IN 'SOST' TCODE. THERE I SEE A MESSAGE LIKE 'CANNOT PROCESS THE MSG TYPE IN SAP SYSTEM'. PLS TELL ME THE WHAT IS THE PROBLE.Hi
Please dont write in Capital letters, it considered as shouting. Hope you are aware of the forum rules.
You can check if you have made anything wrong in coding by referring wiki link.
[Sending Mails |http://wiki.sdn.sap.com/wiki/display/ABAP/SendingMails-HomePage]
Regards
Abhii -
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. -
Logo Problem While sending the smart form as an attachment via Email
Hi ,
I am using the FM SO_NEW_DOCUMENT_ATT_SEND_API1 to send the smartforma as an attachement into the mailbox . it is sent correctly but the COLOR LOGO are not coming correctlly .
I checked the OTF to PDF file is getting converted correctly .i.e. if i am downloading the foem then it is displaying correctly , but in case of sending it to mailbox as an attached PDF file ,the logo are not comming correctly ,
If anybody faced such type of problem can u please clarify .
I am thinking the problem is in FM SO_NEW_DOCUMENT_ATT_SEND_API1 . this FM is not sending the Attached PDF file correctly .
All the TExt/variables are displaying correctly in the PDF file except the LOGO.while opening the PDF file one Warnng message is getting displayed : "An error occured while opening the Image" .
PLease help ..
Thanks,
sachiHi,
Edit your logo as 256 color bit map image and save it and upload into SE78,
And also better to use this FM :SO_DOCUMENT_SEND_API1 it is good for new versions.
thanks,
venkat.
Edited by: Satya venkat Rao.R on Dec 13, 2011 6:02 AM -
Convert internal table to pdf and send the attachment trough bcs method
Hi everyone , I try to send an pdf attachment trough bcs method but I failed. I use scms_text_to_xstring then use method cl_document_bcs=>xstring_to_solix and then add attachment with the bcs method.
Thanks in advance.
Create the attachment
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONCATENATE 'PO' 'PO Line'
INTO lw_attachment SEPARATED BY
cl_abap_char_utilities=>horizontal_tab.
APPEND lw_attachment TO lt_attachment.
CLEAR lw_attachment.
LOOP AT lt_po_data_cons INTO lw_po_data_cons.
CONCATENATE lw_po_data_cons-bukrs lw_po_data_cons-ename lw_po_data_cons-usrid_long
INTO lw_attachment.
SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
CONCATENATE cl_abap_char_utilities=>newline lw_attachment
INTO lw_attachment.
APPEND lw_attachment TO lt_attachment.
ENDLOOP.
CALL FUNCTION 'SCMS_TEXT_TO_XSTRING'
EXPORTING
MIMETYPE = 'text/bin'
IMPORTING
buffer = buf2
TABLES
text_tab = lt_attachment.
l_i_attachment = cl_document_bcs=>xstring_to_solix( ip_xstring = buf2 ).
l_o_document->add_attachment(
i_attachment_type = 'PDF' " add PDF attachment
i_attachment_subject = 'PDF attachment'
i_att_content_hex = l_i_attachment
l_o_send_request->set_document( l_o_document ).
l_v_ret = l_o_send_request->send( ).Hi,
You can send the PDF using OOPS abap classes and methods
for sending it in mail .
Regards
Mansi -
I have to send large files like 5MB or biger via mobile phone, but in that cases phone is telling mi to plug in power. And when I do that, there is no problem to send the file. For smaller files there is no problem. How can I solve the problem? Because when I'm not at home I can't plug in the power.
hi,
I am sending file from server to client i.e client will request for a file and service will send it back....... no socket connection is there...I am using JBOSS and apache axis.
pls help me out.....
Rashi -
Error while sending the data using input schedule
Dear Friends,
I am unable to send the data using input schedule due to following error is occur while sending the data.
The Error Message : Member (H1) of dimension (ENTITY) is not a base member (parent or formula)
Can anyone please help me to resolve the above error.
Thanks and regards,
MD.Hi,
You are trying to send data to a parent/node, you can only send data in BPC to lowest-level children (base mamabers) of any dimension.
"H1" is a parent in the entity dimension so you should try sending to a child.
Tom. -
Problem in downlaoding the attachment from the transaction iw33
Hi experts ,
I am facing problem in downlaoding the attachment from the transaction iw33 where we have attached a presentation.
when i tried to debug it at the function module GUI_DOWNLOAD its returning sy-subrc = 5 which is no authorization .
there is some problem with the user authorizations as the same thing is working fine with other SAP user account .It was an authorisation problem .
-
When I try to send an attachment using Word for MAC people have a hard time opening it with a PC. Can I do anything different?
shldr2thewheel already sent a teach-yourself way. Perhaps you could be more specific: any .doc file written in Mac OS is opened with difficulty? what version of Office on mac and what version in windows? any format, e.g. .doc or .rtf? Even a simple rtext of, say, 2-3 pages? or only long docs, e.g. 100 pages or more? what language is used? English or any other West European, Latin based text, or other scripts too? What do you understand by ‘people have a hard time opening it with a PC?’ takes a very long time? or does not open at all? etc. etc.
-
Hi All,
I have a requirement of sending the data available in an internal table via email. I need to populate this content into excel sheet and send it as an attachment to recipients. I am using the following code for that.
REPORT z51515t_doc_att.
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 : BEGIN OF itab OCCURS 0,
pernr LIKE p0001-pernr,
name LIKE p0002-vorna,
END OF itab.
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 = 'My Content 1 '.
APPEND objtxt.
objtxt = 'My Content2'.
APPEND objtxt.
DESCRIBE TABLE objtxt LINES tab_lines.
Creation of the entry for the document
CLEAR objpack-transf_bin. "Will get content from content_text
objpack-head_start = 1. "Reads given row number in object header
objpack-head_num = 0.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'RAW'.
APPEND objpack.
Prepare content for attachment
DO 3 TIMES.
itab-pernr = 182.
itab-name = 'Prasath'.
APPEND itab.
itab-pernr = 1000.
itab-name = 'Praveen'.
APPEND itab.
ENDDO.
Populate attachment content
LOOP AT itab.
CONCATENATE itab-pernr itab-name INTO objbin-line.
APPEND objbin.
ENDLOOP.
DESCRIBE TABLE objbin LINES tab_lines.
Creation of the entry for the compressed attachment
objpack-transf_bin = 'X'. "Will get content from content_bin
objpack-head_start = 1.
objpack-head_num = 1.
objpack-body_start = 1.
objpack-body_num = tab_lines.
objpack-doc_type = 'EXT'.
objpack-obj_name = 'WEBSITE'.
objpack-obj_descr = 'MyFile.XLS'.
objpack-doc_size = tab_lines * 255.
APPEND objpack.
target recipent
CLEAR reclist.
reclist-receiver = '[email protected]'.
reclist-express = 'X'.
reclist-rec_type = 'U'.
APPEND reclist.
copy recipents
CLEAR reclist.
reclist-receiver = '[email protected]'.
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
put_in_outbox = 'X'
commit_work = 'X'
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.
Now using this code i am able to send out the file but the data in the XL file is not aligned properly. When i open the attachment that i receive the contents of itab appear inside the same cell - A1 of the XL sheet. I want the data to be available in different rows and columns. How do i achieve this?
Thanks,
Prasath NSee the below program it was sending the file as attach in XLS format by column and rows are properly placed ... see the
<b>Code in my program :
CONSTANTS: con_cret TYPE x VALUE '0D', "OK for non Unicode
con_tab TYPE x VALUE '09'. "OK for non Unicode</b>
REPORT ZEMAIL_ATTACH .
TABLES: ekko.
PARAMETERS: p_email TYPE somlreci1-receiver
DEFAULT '[email protected]'.
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 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 '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
reward points if it is usefull ....
Girish -
Problem with attachment using SO_NEW_DOCUMENT_ATT_SEND_API1
Hi,
I'm using function module SO_NEW_DOCUMENT_ATT_SEND_API1 to send emails from SAP (to Outlook - but the problem can already be observed when checking the email attachment in transaction SOST) with attachments.
My attachment is a tab delimited file (so that I can open with MS Excel) with a line size of approx. 1600 characters. I mean, concatenating all fields of the output table into a 1600 character field, separated by tabstops (cl_abap_char_utilities=>horizontal_tab)
I am using function module SCMS_STRING_TO_FTEXT to convert the internal table that I want to send to the line size as accepted by function module SO_NEW_DOCUMENT_ATT_SEND_API1, tables parameter contents_bin. Due to function module SCMS_STRING_TO_FTEXT this happens line by line, using a string variable. I make sure to remove any exess blanks that appear in the process due to not completey filled character fields. And for all rows bar the first the string is prefixed with (cl_abap_char_utilities=>cr_lf). I believe that's required so that SAP knows to put the lines back together. So far so good.
When checking the email's attachment via SOST (and the same happens in Outlook) there are extra blanks in certain fields. Like:
Annual Base
92,928. 00
or
Email
First L ast
In debugging it appears that these excess spaces (sometimes 1, sometimes several) appear where the 1600 character data line is split into the 255 character pieces in 'contents_bin'. But then it happens quite randomly and cannot be observed in all data rows.
Is there a better way of splitting my internal table into 255 character chunks so that what is one field will never get split up into two rows. For the above example, the two fields would show like this in contents_bin
.... 92,928.
00
and
First_L
ast
Or where else lies the problem?
Thanks in advance!
PhilippRon,
Thank you for the suggestion. Just tried but issue remains exactly the same. The function module you have suggested builds the table in the same way.
But, after a few more rounds of debugging and scratching my head it occured to me that my problem is self inflicted. I was using the condense statement in an attempt to get rid of the trailing blanks at the end of a row causing the last column to be filled with lots of spaces at the end. But it wasn't working anyway and I have since inserted a dummy column at the end to take all those trailing blanks. What this condense statement did though was creating trailing blanks in some of those rows with 255 characters fixed length and those trailing blanks then showed up as additional blanks in some columns in the attachment that the emailing function module created by putting those lines back to it's original length of close to 1600 characters.
Problem solved!
Regards,
Philipp -
Problem while sending the *.txt as attachment with mail
Hi All,
I am Using function module (SO_NEW_DOCUMENT_ATT_SEND_API1) to send Mail with attachment in *.TXT format. But This function module is allowing only 255 char for a row. But the length of my Internal table is 700 char. Is there any another way to process the attachment without disturbing the data,that means need to process all 700 char in the field with out splitting.no other way and use mutilple lines as text ( This is possible )
you want to keep text as multiple lines into internal table use FM
SWA_STRING_SPLIT - Pass text and maintain length as 255 Charcters -
Problem in sending the file as an attachment through mail
Hi,
I have developed a Zreport. The functionality is like on executing this report it should send an e-mail with an attachment of the data in the xcel format.
So, while execting this report in background mode in ECC 5.0, it is able to send the mail as an attachment but the file doesn't contain the data in it But, the same report while trying to execute in back ground mode in ECC 6.0, it is able to send the mail with the attachment and the file also has the data.
So, my question is like are there any patches that has to be installed in ECC 5.0 system to get this successfully done.
Thanks in advance for your answers.
RohithHello,
Are you using the standad sap function module or using OLE objects to generate excel?
First try creating the excel file in foreground and see if the data is being populated.
Kind Regards,
Niky. -
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
Maybe you are looking for
-
HT201210 i want to downgrade my iphone 4s from 6.1.3 to 6.1.2
hi i am having an iphone 4s and i want it to be downgrade from ios 6.1.3 to 6.1.2 so i will i do that
-
Cannot insert null into a Primary Key Column using Entity Framework
I have to insert data into UserPreferences Table which has a primary key. This I am doing with Oracle Entity Framework Provider. It is unable to do it though i have set the StoreGeneratedPattern = "Identity". But while saving changes it is saying a n
-
My Ps CS4 stopped giving me the error I was getting, but now it's doing something else. I was trying to create a de stijl piece for a school assignment and as I would use the paint bucket to fill in the squares with color it wouldn't show me what I h
-
hi, i am badly in need of help. i partitioned my mac hd yesterday and now the boot camp is nt working as i was using win 7 on it. i am using macbook pro 13'' 2011. plz help me. anxiously waiting for response... specially from "Christopher murphy"
-
Cannot install fcp studio contents
Hi there, has anyone run into the problem of not being able to install the content DVDs of FCP5? If I select the softwares, fcp, dvdsp, motion, & soundtrack then they installed fine but cannot install their contents DVDs. Pleaes helps. thankx JP