Sending a formatted Excel sheet as an attachment in a mail.
Hi ,
I have been using following code to to send formatted excel sheet as attachment in email.
in the below code I want to change the format of cell from Bold to Underline.
I have replaced Bold with Underline for below code but it is not working can anyone suggest on this.
Department
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ).
r_data = l_document->create_simple_element( name = 'Data' value = 'MATNR' parent = r_cell ).
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ).
Creating a ixml Factory
l_ixml = cl_ixml=>create( ).
Creating the DOM Object Model
l_document = l_ixml->create_document( ).
Create Root Node 'Workbook'
l_element_root = l_document->create_simple_element( name = 'Workbook' parent = l_document ). l_element_root->set_attribute( name = 'xmlns' value = 'urn:schemas-microsoft-com:office:spreadsheet' ). ns_attribute = l_document->create_namespace_decl( name = 'ss' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:spreadsheet' ). l_element_root->set_attribute_node( ns_attribute ). ns_attribute = l_document->create_namespace_decl( name = 'x' prefix = 'xmlns' uri = 'urn:schemas-microsoft-com:office:excel' ). l_element_root->set_attribute_node( ns_attribute ).
Create node for document properties.
r_element_properties = l_document->create_simple_element( name = 'TEST_REPORT' parent = l_element_root ). l_value = sy-uname. l_document->create_simple_element( name = 'Author' value = l_value parent = r_element_properties ).
Styles
r_styles = l_document->create_simple_element( name = 'Styles' parent = l_element_root ).
Style for Header
r_style = l_document->create_simple_element( name = 'Style' parent = r_styles ). r_style->set_attribute_ns( name = 'ID' prefix = 'ss' value = 'Header' ). r_format = l_document->create_simple_element( name = 'Font' parent = r_style ).
Worksheet
r_worksheet = l_document->create_simple_element( name = 'Worksheet' parent = l_element_root ). r_worksheet->set_attribute_ns( name = 'Name' prefix = 'ss' value = 'PO Details' ).
Table
r_table = l_document->create_simple_element( name = 'Table' parent = r_worksheet ). r_table->set_attribute_ns( name = 'FullColumns' prefix = 'x' value = '1' ). r_table->set_attribute_ns( name = 'FullRows' prefix = 'x' value = '1' ).
Column Formatting
r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '70' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '70' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '70' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '70' ). r_column = l_document->create_simple_element( name = 'Column' parent = r_table ). r_column->set_attribute_ns( name = 'Width' prefix = 'ss' value = '70' ).
Blank Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
Column Headers Row
r_row = l_document->create_simple_element( name = 'Row' parent = r_table ). r_row->set_attribute_ns( name = 'AutoFitHeight' prefix = 'ss' value = '1' ).
Sr. No.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'EBELN' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
User Name
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'EBELP' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
Full Name
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'AEDAT' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ).
Department
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Header' ). r_data = l_document->create_simple_element( name = 'Data' value = 'MATNR' parent = r_cell ). r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). r_format->set_attribute_ns( name = 'Bold' prefix = 'ss' value = '1' ). r_format = l_document->create_simple_element( name = 'Interior' parent = r_style ). r_format->set_attribute_ns( name = 'Color' prefix = 'ss' value = '#C0C0C0' ). r_format->set_attribute_ns( name = 'Pattern' prefix = 'ss' value = 'Solid' ). r_format = l_document->create_simple_element( name = 'Alignment' parent = r_style ). r_format->set_attribute_ns( name = 'Vertical' prefix = 'ss' value = 'Center' ). r_format->set_attribute_ns( name = 'WrapText' prefix = 'ss' value = '1' ).
Data Table
LOOP AT it_ekpo INTO wa_ekpo. r_row = l_document->create_simple_element( name = 'Row' parent = r_table ).
Sr. No.
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ).
r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ).
l_value = sy-tabix.
CONDENSE l_value NO-GAPS.
r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data
r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'Number' ). " Cell format
EBELN
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_ekpo-ebeln. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
EBELP
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_ekpo-ebelp. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
AEDAT
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_ekpo-aedat. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format
MATNR
r_cell = l_document->create_simple_element( name = 'Cell' parent = r_row ). r_cell->set_attribute_ns( name = 'StyleID' prefix = 'ss' value = 'Data' ). l_value = wa_ekpo-matnr. r_data = l_document->create_simple_element( name = 'Data' value = l_value parent = r_cell ). " Data r_data->set_attribute_ns( name = 'Type' prefix = 'ss' value = 'String' ). " Cell format ENDLOOP.
Creating a Stream Factory
l_streamfactory = l_ixml->create_stream_factory( ).
Connect Internal XML Table to Stream Factory
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).
Rendering the Document
l_renderer = l_ixml->create_renderer( ostream = l_ostream document = l_document ). l_rc = l_renderer->render( ).
Saving the XML Document
l_xml_size = l_ostream->get_num_written_raw( ).
Before sending the mail,
LOOP AT l_xml_table INTO wa_xml.
CLEAR objbin.
objbin-line = wa_xml-data.
APPEND objbin to BINARY_CONTENT.
ENDLOOP.
Here, objbin is of type SOLIX and BINARY_CONTENT is of type SOLIX_TAB.
Now, call the method,
CALL METHOD DOCUMENT->ADD_ATTACHMENT
EXPORTING I_ATTACHMENT_TYPE = 'XLS'
I_ATTACHMENT_SUBJECT = 'My attachment'
I_ATT_CONTENT_HEX = BINARY_CONTENT .
Try this..
r_format->set_attribute_ns( name = 'Underline' prefix = 'ss' value = 'Single' ).
Similar Messages
-
Excel sheet as an attachment to the mail box
Hi,
i need to send an excel sheet as an attachement to the outlook mail box..
is any function module is there which serves my requirement? or if any other way is there pls let me know.
thanks..Here is some sample code.
report zrich_0001.
parameters: p_email type somlreci1-receiver
default [email protected]'.
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.
Regards,
Rich Heilman -
Need to send email with excel sheet as attachment: URGENT
Hi all....i have a requirement where i should extract data from SAP. These datas has to be sent to a mail id entered in the selection screen in excel sheet as an attachment.Can you suggest me any function module that meets the requirement...
For kind information...there is only one selection field for entering the mail id.
Thanks in advance
NandaHi all....i have a requirement where i should extract data from SAP. These datas has to be sent to a mail id entered in the selection screen in excel sheet as an attachment.Can you suggest me any function module that meets the requirement...
For kind information...there is only one selection field for entering the mail id.
Thanks in advance
Nanda -
Adapter Module Error-Sending excel file as an attachment of the mail
Hi ,
My scenario is as follows
1)I am sending an excel file as an attachment of the mail.I need to read that excel attachment as a payload.
So mail adapter is used in sender side.
To configure this, have used standard PayloadSwapBean module with proper module key.
Next to convert excel to XML another custom adapter module is being used.
Both this adapter module , I configured into the CC of sender mail adapter.
The order in which adapter modules are being used in the sender CC are as follows
1)localejbs/AF_Modules/PayloadSwapBean
2)localejbs/MDPExcelToXMLConversion
3)sap.com/com.sap.aii.adapter.mail.app/XIMailAdapterBean
MDPExcelToXMLConversion-Custom adapter module written to convert excel to xml.
I am getting the following error
exception caught during processing mail message [4899]com.sap.aii.af.lib.mp.module.ModuleException
And also,
no messages in coming MONI of PI.
Pls suggest what to do.
Thanks
AyanShabarish,
Will the ordering in which the adapter modules(In this case there are two-PayloadSwapBean & MDPExcelToXML) are appearing into Module tab of sender adapter matter?
Firstly, what is happenning
1)If I take out the custom adapter module MDPExcelToXML and put only PayloadSwapBean then it is successfully converting mail attachment into the main Payload i.e PayloadSwapBean module is working.
2)Nextly, my local code( i.e java code without including standard Module specific method like ejbActivate(),ejbPassivate(),process() etc etc.)) for MDPExcelToXML is successfuly converting the excel file into the XML file.Then I am making the local code into adapter module specific code and deploying that.
A few question arises here,
Do I need to do any specific configurations here in PI for this particular things.Maybe both the adapter module is clashing with each other.
And also using tracing and logging into my custom adapter module code.Getting the following error,
java.io.IOException: Unable to read entire header; 116 bytes read; expected 512 bytes#
Thanks
Ayan -
VF05 report screent to be copied into formated excel sheet
I would like to copy the VF05 Report screen into formatted excel sheet.
on the output screen of VF05 report, I tried settings-> Display variants: here i have selected the layout, but the data could not copied into this layout
Please help me how this can be done.
VERY URGENThello, friend.
as i understand, you want to export the data from VF05 to an excel file. if this is correct, do the following...
first exectue VF05. input the necessary data (payer, material, date ranges, billing type, etc.)
on the next screen, on the menu go to LIST > SAVE > FILE. chosse "Spreadsheet" and ENTER. specify where you want to save the file, the title and the file type (EXCEL file). click "Generate".
now, on your PC, click on the file that you saved. you will now get your report in Excel format.
hope this helped you.
regards.
jty -
Format Excel sheet - Oracle COM Automation
Dear gentlemen,
I would like to get your help to generate a formatted excel sheet using Oracle COM Automation, I may don’t know the correct properties to use, or don’t know how to use it.
For example:
To set a cell value I use this line:
hresult:=Ordcom.SetProperty(RangeHandle, 'Value', data, 'BSTR');
and when I tried to fill the same cell with a yello color I used this line:
hresult:=Ordcom.SetProperty(RangeHandle, 'Interior.Color', 65535, 'BSTR');
but that has no effect at all, so please advise what is wrong, this may apply also for the most properties such as “Font.Bold”.
I appreciate so much any help from you.
Best regards,
NabilHere is another version of my package ORDExcelSB. It includes almost all the formatting needs in Excel.
Package Specification:_
CREATE OR REPLACE PACKAGE ORDExcelSB AS
/* Saubhik: These constants are added */
BorderEdgeLeft CONSTANT BINARY_INTEGER:= 7;
BorderEdgeTop CONSTANT BINARY_INTEGER:=8;
BorderEdgeBottom CONSTANT BINARY_INTEGER:=9;
BorderEdgeRight CONSTANT BINARY_INTEGER:=10;
BorderInsideVertical CONSTANT BINARY_INTEGER:=11;
BorderInsideHorizontal CONSTANT BINARY_INTEGER:=12;
/* Declare externally callable subprograms. */
/* Start: These functions are newly aded by Saubhik Banerjee */
FUNCTION CreateExcelApplication(servername VARCHAR2) RETURN binary_integer;
FUNCTION OpenExcelFile(filename VARCHAR2, sheetname VARCHAR2)
RETURN binary_integer;
FUNCTION SetCellColor(range varchar2, style INTEGER)
return binary_integer;
FUNCTION SetCellBorder(range varchar2, BordersIndex BINARY_INTEGER, BorderStyle BINARY_INTEGER)
return binary_integer;
FUNCTION FormatFontStyle(range varchar2, fontstyle varchar2)
return binary_integer;
FUNCTION FormatFontColor(range varchar2, fontcolor INTEGER)
return binary_integer;
FUNCTION FormatFontName(range varchar2, fontname varchar2)
return binary_integer;
FUNCTION FormatFontSize(range varchar2, fontsize INTEGER)
return binary_integer ;
/* End: These functions are newly aded by Saubhik Banerjee */
FUNCTION CreateExcelWorkSheet(servername varchar2) return binary_integer;
FUNCTION InsertData(range varchar2, data binary_integer, type varchar2)
return binary_integer;
FUNCTION InsertDataReal(range varchar2,
data double precision,
type varchar2) return binary_integer;
FUNCTION GetDataNum(range varchar2) return binary_integer;
FUNCTION GetDataStr(range varchar2) return varchar2;
FUNCTION GetDataReal(range varchar2) return double precision;
FUNCTION GetDataDate(range varchar2) return date;
FUNCTION InsertData(range varchar2, data varchar2, type varchar2)
return binary_integer;
FUNCTION InsertData(range varchar2, data Date, type varchar2)
return binary_integer;
FUNCTION InsertChart(xpos binary_integer,
ypos binary_integer,
width binary_integer,
height binary_integer,
range varchar2,
type varchar2) return binary_integer;
FUNCTION SaveExcelFile(filename varchar2) return binary_integer;
FUNCTION ExitExcel return binary_integer;
END ORDExcelSB;
Package Body:_
CREATE OR REPLACE PACKAGE BODY ORDExcelSB AS
DummyToken binary_integer;
applicationToken binary_integer := -1;
WorkBooksToken binary_integer := -1;
WorkBookToken binary_integer := -1;
WorkSheetToken binary_integer := -1;
WorkSheetToken1 binary_integer := -1;
RangeToken binary_integer := -1;
ChartObjectToken binary_integer := -1;
ChartObject1 binary_integer := -1;
Chart1Token binary_integer := -1;
i binary_integer;
retNum binary_integer;
retReal double precision;
retStr varchar2(255);
retDate DATE;
error_src varchar2(255);
error_description varchar2(255);
error_helpfile varchar2(255);
error_helpID binary_integer;
FUNCTION CreateExcelApplication(servername VARCHAR2) RETURN binary_integer IS
BEGIN
dbms_output.put_line('Creating Excel application...');
i := OrdCOM.CreateObject('Excel.Application',
0,
servername,
applicationToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking Workbooks...');
i := ORDCOM.GetProperty(applicationToken,
'WorkBooks',
0,
WorkBooksToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
RETURN i;
END CreateExcelApplication;
FUNCTION OpenExcelFile(filename VARCHAR2, sheetname VARCHAR2)
RETURN binary_integer IS
BEGIN
dbms_output.put_line('Opening Excel file ' || filename || ' ...');
ORDCOM.InitArg();
ORDCOM.SetArg(filename, 'BSTR');
i := ORDCOM.Invoke(WorkBooksToken, 'Open', 1, DummyToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Opening WorkBook');
i := ORDCOM.GetProperty(applicationToken,
'ActiveWorkbook',
0,
WorkBookToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking WorkSheets..');
i := ORDCOM.GetProperty(applicationToken,
'WorkSheets',
0,
WorkSheetToken1);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking WorkSheet');
ORDCOM.InitArg();
ORDCOM.SetArg(sheetname, 'BSTR');
i := ORDCOM.GetProperty(WorkBookToken, 'Sheets', 1, WorkSheetToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Opened ');
RETURN i;
END OpenExcelFile;
* Invoke the Excel Automation Server and create a Workbook object as
* well as a worksheet object
FUNCTION CreateExcelWorkSheet(servername varchar2) return binary_integer IS
BEGIN
dbms_output.put_line('Creating Excel application...');
i := ORDCOM.CreateObject('Excel.Application',
0,
servername,
applicationToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking Workbooks...');
/*i:=ORDCOM.Invoke(applicationToken, 'WorkBooks',0, WorkBooksToken);*/
i := ORDCOM.GetProperty(applicationToken,
'WorkBooks',
0,
WorkBooksToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking Add to WorkBooks...');
ORDCOM.InitArg();
ORDCOM.SetArg(-4167, 'I4');
i := ORDCOM.Invoke(WorkBooksToken, 'Add', 1, WorkBookToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
dbms_output.put_line('Invoking WorkSheets..');
ORDCOM.InitArg();
ORDCOM.SetArg('Sheet 1', 'BSTR');
/* i:=ORDCOM.Invoke(applicationToken, 'WorkSheets', 1, WorkSheetToken);*/
i := ORDCOM.GetProperty(applicationToken,
'WorkSheets',
0,
WorkSheetToken1);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.Invoke(WorkSheetToken1, 'Add', 0, WorkSheetToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
return i;
END CreateExcelWorkSheet;
* Invoke the Range method to obtain a range token. Then set the property value
* at the specified range to the data required
FUNCTION InsertData(range varchar2, data binary_integer, type varchar2)
RETURN binary_integer IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.SetProperty(RangeToken, 'Value', data, type);
IF (i = 0) THEN
i := ORDCOM.SetProperty(RangeToken, 'ColumnWidth', 15, 'I2');
END IF;
i := ORDCOM.DestroyObject(RangeToken);
RETURN i;
END InsertData;
/* Saubhik: This function is added to set the cell Border */
FUNCTION SetCellBorder(range varchar2, BordersIndex BINARY_INTEGER, BorderStyle BINARY_INTEGER)
return binary_integer IS
--fontToken binary_integer;
BorderToken BINARY_INTEGER;
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
ORDCOM.InitArg();
ORDCOM.SetArg(BordersIndex, 'I2');
i := ORDCOM.GetProperty(RangeToken, 'Borders', 1, BorderToken);
i := ORDCOM.SetProperty(BorderToken, 'weight', BorderStyle, 'I2');
i := ORDCOM.DestroyObject(BorderToken);
i := ORDCOM.DestroyObject(RangeToken);
return i;
END SetCellBorder;
/* Saubhik: This function is added to set the cell background color */
FUNCTION SetCellColor(range varchar2, style INTEGER)
return binary_integer IS
--fontToken binary_integer;
DummyToken BINARY_INTEGER;
SelectionToken BINARY_INTEGER;
InteriorToken BINARY_INTEGER;
--applicationToken
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.Invoke(RangeToken,'SELECT',0,DummyToken);
i := ORDCOM.GetProperty(applicationToken,'Selection',0,SelectionToken);
i := ORDCOM.GetProperty(SelectionToken, 'Interior', 0, InteriorToken);
i := ORDCOM.SetProperty(InteriorToken, 'ColorIndex', style, 'I2');
i := ORDCOM.DestroyObject(RangeToken);
return i;
END SetCellColor;
/* Saubhik: This function is added to change the font style like Bold, Italic etc. */
FUNCTION FormatFontStyle(range varchar2, fontstyle varchar2)
return binary_integer IS
fontToken binary_integer;
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.GetProperty(RangeToken, 'Font', 0, FontToken);
IF fontstyle = 'Bold' OR fontstyle = 'Italic' OR
fontstyle = 'Underline' THEN
i := ORDCOM.SetProperty(FontToken, fontstyle, True, 'BOOL');
END IF;
i := ORDCOM.DestroyObject(FontToken);
i := ORDCOM.DestroyObject(RangeToken);
return i;
END FormatFontStyle;
/* Saubhik: This function is added to change the font style like Arial, Bookman, Century etc. */
FUNCTION FormatFontName(range varchar2, fontname varchar2)
return binary_integer IS
fontToken binary_integer;
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.GetProperty(RangeToken, 'Font', 0, FontToken);
i := ORDCOM.SetProperty(FontToken, 'Name', fontname, 'BSTR');
i := ORDCOM.DestroyObject(FontToken);
i := ORDCOM.DestroyObject(RangeToken);
return i;
END FormatFontName;
/* Saubhik: This function is added to change the font style like Arial, Bookman, Century etc. */
FUNCTION FormatFontSize(range varchar2, fontsize INTEGER)
return binary_integer IS
fontToken binary_integer;
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.GetProperty(RangeToken, 'Font', 0, FontToken);
i := ORDCOM.SetProperty(FontToken, 'Size', fontsize, 'I2');
i := ORDCOM.DestroyObject(FontToken);
i := ORDCOM.DestroyObject(RangeToken);
return i;
END FormatFontSize;
/* Saubhik: This function is added to change the font color like Black, Blue etc. */
FUNCTION FormatFontColor(range varchar2, fontcolor INTEGER)
return binary_integer IS
fontToken binary_integer;
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.GetProperty(RangeToken, 'Font', 0, FontToken);
i := ORDCOM.SetProperty(FontToken, 'ColorIndex', fontcolor, 'I2');
i := ORDCOM.DestroyObject(FontToken);
i := ORDCOM.DestroyObject(RangeToken);
return i;
END FormatFontColor;
* Invoke the Range method to obtain a range token. Then set the property value
* at the specified range to the data required
FUNCTION GetDataNum(range varchar2) RETURN binary_integer IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.GetProperty(RangeToken, 'Value', 0, retNum);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(RangeToken);
RETURN retNum;
END GetDataNum;
FUNCTION GetDataReal(range varchar2) RETURN double precision IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.GetProperty(RangeToken, 'Value', 0, retReal);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(RangeToken);
RETURN retReal;
END GetDataReal;
FUNCTION GetDataStr(range varchar2) RETURN varchar2 IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.GetProperty(RangeToken, 'Value', 0, retStr);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(RangeToken);
RETURN retStr;
END GetDataStr;
FUNCTION GetDataDate(range varchar2) RETURN Date IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.GetProperty(RangeToken, 'Value', 0, retDate);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(RangeToken);
RETURN retDate;
END GetDataDate;
FUNCTION InsertData(range varchar2, data DATE, type varchar2)
RETURN binary_integer IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.SetProperty(RangeToken, 'Value', data, type);
i := ORDCOM.DestroyObject(RangeToken);
RETURN i;
END InsertData;
FUNCTION InsertDataReal(range varchar2,
data double precision,
type varchar2) RETURN binary_integer IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.SetProperty(RangeToken, 'Value', data, type);
i := ORDCOM.DestroyObject(RangeToken);
RETURN i;
END InsertDataReal;
FUNCTION InsertData(range varchar2, data varchar2, type varchar2)
RETURN binary_integer IS
BEGIN
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
i := ORDCOM.SetProperty(RangeToken, 'Value', data, type);
i := ORDCOM.DestroyObject(RangeToken);
RETURN i;
END InsertData;
* Insert a chart at the x and y position of the spreadsheet with the desired
* height and width. Then also uses the ChartWizard to draw the graph with data
* in a specified range area with a specified charting type.
FUNCTION InsertChart(xpos binary_integer,
ypos binary_integer,
width binary_integer,
height binary_integer,
range varchar2,
type varchar2) RETURN binary_integer IS
charttype binary_integer := -4099;
BEGIN
ORDCOM.InitArg();
i := ORDCOM.GetProperty(WorkSheetToken,
'ChartObjects',
0,
ChartObjectToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
ORDCOM.InitArg();
ORDCOM.SetArg(xpos, 'I2');
ORDCOM.SetArg(ypos, 'I2');
ORDCOM.SetArg(width, 'I2');
ORDCOM.SetArg(height, 'I2');
i := ORDCOM.Invoke(ChartObjectToken, 'Add', 4, ChartObject1);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.GetProperty(ChartObject1, 'Chart', 0, Chart1Token);
ORDCOM.InitArg();
ORDCOM.SetArg(range, 'BSTR');
i := ORDCOM.GetProperty(WorkSheetToken, 'Range', 1, RangeToken);
ORDCOM.InitArg();
ORDCOM.SetArg(RangeToken, 'DISPATCH');
IF type = 'xlPie' THEN
charttype := -4102;
ELSIF type = 'xl3DBar' THEN
charttype := -4099;
ELSIF type = 'xlBar' THEN
charttype := 2;
ELSIF type = 'xl3dLine' THEN
charttype := -4101;
END IF;
ORDCOM.SetArg(charttype, 'I4');
i := ORDCOM.Invoke(Chart1Token, 'ChartWizard', 2, DummyToken);
i := ORDCOM.DestroyObject(RangeToken);
i := ORDCOM.DestroyObject(ChartObjectToken);
i := ORDCOM.DestroyObject(ChartObject1);
i := ORDCOM.DestroyObject(Chart1Token);
RETURN i;
END InsertChart;
* Save the Excel File. WARNING: Do not specify a filename that already exist
* since there is no graphical context, Oracle would not be able to pop
* out a warning message for existing file. This causes Excel to hang
FUNCTION SaveExcelFile(filename varchar2) return binary_integer IS
BEGIN
dbms_output.put_line('Saving Excel file...');
ORDCOM.InitArg();
ORDCOM.SetArg(filename, 'BSTR');
i := ORDCOM.Invoke(WorkBookToken, 'SaveAs', 1, DummyToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
RETURN i;
END SaveExcelFile;
* Close the Excel spreadsheet and exit from it
FUNCTION ExitExcel return binary_integer is
BEGIN
dbms_output.put_line('Closing workbook and quitting...');
ORDCOM.InitArg();
ORDCOM.InitArg();
ORDCOM.SetArg(FALSE, 'BOOL');
dbms_output.put_line('Closing workbook...');
i := ORDCOM.Invoke(WorkBookToken, 'Close', 0, DummyToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(WorkBookToken);
ORDCOM.InitArg();
dbms_output.put_line('Closing workbooks...');
i := ORDCOM.Invoke(WorkBooksToken, 'Close', 0, DummyToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(WorkBooksToken);
i := ORDCOM.Invoke(applicationToken, 'Quit', 0, DummyToken);
IF (i != 0) THEN
ORDCOM.GetLastError(error_src,
error_description,
error_helpfile,
error_helpID);
dbms_output.put_line(error_src);
dbms_output.put_line(error_description);
dbms_output.put_line(error_helpfile);
END IF;
i := ORDCOM.DestroyObject(WorkSheetToken);
i := ORDCOM.DestroyObject(WorkSheetToken1);
i := ORDCOM.DestroyObject(applicationToken);
i := ORDCOM.DestroyObject(ChartObjectToken);
i := ORDCOM.DestroyObject(Chart1Token);
i := ORDCOM.DestroyObject(ChartObject1);
i := ORDCOM.DestroyObject(dummyToken);
RETURN i;
END ExitExcel;
END ORDExcelSB; -
Regarding excel sheet as an attachment to mail
hi
am using the follwing code, it works finely upto sending excel as attachment. But the problem came in data of excel sheet.
the data in excel sheet is appearing like this one.
Butxt data is occupying all columns
BUKRS BUTXT
01 New York Insurance Company
The code am developed is....
parameters: p_email type somlreci1-receiver
default '[email protected]'.
types: begin of sol,
text(35),
end of sol.
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 sol 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 details 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 spreadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
if sy-subrc = 0.
message i000(zsai).
endif.
Form BUILD_XLS_DATA
form build_xls_data .
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 then 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.
iattach = iattach(30).
append iattach.
endloop.
endform.
Form SEND_EMAIL_WITH_XLS
Send file by email as .xls spreadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
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.
IF SY-SUBRC = 0.
SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN.
COMMIT WORK .
ENDIF.
endform.hi
am using the follwing code, it works finely upto sending excel as attachment. But the problem came in data of excel sheet.
the data in excel sheet is appearing like this one.
Butxt data is occupying all columns
BUKRS BUTXT
01 New York Insurance Company
The code am developed is....
parameters: p_email type somlreci1-receiver
default '[email protected]'.
types: begin of sol,
text(35),
end of sol.
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 sol 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 details 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 spreadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
if sy-subrc = 0.
message i000(zsai).
endif.
Form BUILD_XLS_DATA
form build_xls_data .
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 then 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.
iattach = iattach(30).
append iattach.
endloop.
endform.
Form SEND_EMAIL_WITH_XLS
Send file by email as .xls spreadsheet
perform send_email_with_xls tables imessage
iattach
using p_email
'Example Excel Attachment'
'XLS'
'TestFileName'
'CompanyCodes'.
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.
IF SY-SUBRC = 0.
SUBMIT rsconn01 WITH mode EQ 'INT' AND RETURN.
COMMIT WORK .
ENDIF.
endform. -
Send An Internal Table Via Excel File As An Attachment of E-mail
Hi,
I've sent my internal table via Excel file as an attachment of email but all records of internal table are in a row of sended excel file.
How can i send an internal table via excel file , records of internal table for each rows of excel file,as an attachment of email correctly?
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 " t_packing_list-doc_type = 'XLS'.
contents_bin = pit_attach " this is a normal internal table.
contents_txt = pit_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.Hi,
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.
LOOP AT T_FINAL INTO WA_T_FINAL.
CONCATENATE WA_T_FINAL-PERNR
WA_T_FINAL-NAME
WA_T_FINAL-LEVEL
WA_T_FINAL-POS
WA_T_FINAL-JOB
WA_T_FINAL-SECTION
WA_T_FINAL-DEPT
WA_T_FINAL-GROUP
WA_T_FINAL-EX_HEAD
WA_T_FINAL-SUPID
WA_T_FINAL-SUPNM
WA_T_FINAL-FHRNM
WA_T_FINAL-VACID
WA_T_FINAL-VAC_SECTION
WA_T_FINAL-VAC_DEPT
WA_T_FINAL-VAC_GROUP
WA_T_FINAL-VAC_EX_HEAD
WA_T_FINAL-VAC_FHRNM
INTO T_FINAL3 SEPARATED BY CON_TAB.
CONCATENATE CON_CRET T_FINAL3 INTO T_FINAL3.
APPEND T_FINAL3.
ENDLOOP.
*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 = 'REPORT'.
W_DOC_DATA-OBJ_DESCR = LD_MTITLE . "mail description
W_DOC_DATA-SENSITIVTY = 'F'.
*Fill the document data and get size of attachment
CLEAR W_DOC_DATA.
READ TABLE T_FINAL1 INDEX W_CNT.
W_DOC_DATA-DOC_SIZE =
( W_CNT - 1 ) * 255 + STRLEN( T_FINAL1 ).
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[] = PT_FINAL1[].
*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 1st 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 = 'Application 1'.
T_PACKING_LIST-OBJ_NAME = 'Application 1'.
T_PACKING_LIST-DOC_SIZE = T_PACKING_LIST-BODY_NUM * 255.
APPEND T_PACKING_LIST.
CLEAR 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.
Edited by: Rahul Ghosh on Apr 6, 2009 6:42 AM -
Sending email with excel file as an attachment
Hi,
In my procedure I am creating one excel file and keeping that excel file in one location as specified in UTL_FILE_DIR.Now my requirement is to pick that excel file from that path and send it as an attachment through an Email.
Can anyone please give me the code to do that and what are the required set up to be done before sending the mail.
Please help me in this regard. This is an urgent requirement.
Thanks
SubhabrataHi,
Please refer the following link:
http://www.dbasupport.com/oracle/ora10g/10g_PLSQL02.shtml
There is para headed Sending E-Mail and Attachments with UTL_MAIL will clarify all your doubts. Link Listing 2.6
is good example.
If you get stuck while coding, get back to us.
Twinkle -
Sending Smart forms O/P as an attachment thru e-mail...
Hi friends...
I have dveloped a new Smartform for PO reminder letter..
and I am trying to send it as an attachment thru mail...
the code I wrote for that is given...
but I am getting a runtime error like
In program "CL_TRACE_BCS==================CP ", the following syntax error
occurred
in the Include "CL_TRACE_BCS==================CU " in line 85:
"Implementation missing for method "END_FUNC". "END_FUNC"."
Plz help me....
*******CODE********
REPORT zmm_vendor_reminder_mail.
TABLES : ekko,ekpo,eket,makt,adrc,adr6,lfa1.
DATA: fm_name TYPE rs38l_fnam.
DATA: BEGIN OF itab1 OCCURS 0.
INCLUDE STRUCTURE lfa1.
DATA: END OF itab1.
DATA : BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE zmm_podetails.
DATA: END OF itab.
DATA : BEGIN OF it_pos OCCURS 0 ,
bukrs LIKE ekpo-bukrs,
werks LIKE ekpo-werks,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
etenr LIKE eket-etenr,
bedat LIKE eket-bedat,
matnr LIKE ekpo-matnr,
meins LIKE ekpo-meins,
menge LIKE eket-menge,
wemng LIKE eket-wemng,
eindt LIKE eket-eindt,
lifnr LIKE ekko-lifnr,
END OF it_pos.
DATA : BEGIN OF it_vendor OCCURS 0 ,
lifnr LIKE lfa1-lifnr,
name1 LIKE adrc-name1,
street LIKE adrc-street,
str_suppl1 LIKE adrc-str_suppl1,
str_suppl2 LIKE adrc-str_suppl2,
city1 LIKE adrc-city1,
post_code1 LIKE adrc-post_code1,
smtp_addr LIKE adr6-smtp_addr,
adrnr LIKE lfa1-adrnr,
telf1 LIKE lfa1-telf1,
telf2 LIKE lfa1-telf2,
END OF it_vendor.
*RAMESH **********
tables: soud.
data: control_parameters TYPE ssfctrlop,
output_options TYPE ssfcompop,
EMail_Subject(50) TYPE c value 'abc'.
DATA: email_recipient TYPE SWOTOBJID,
email_sender TYPE SWOTOBJID,
g_mail_app_obj type SWOTOBJID.
*concatenate text-004 '400000124' into EMail_Subject.
control_parameters-device = 'MAIL'.
control_parameters-no_dialog = 'X'.
control_parameters-preview = space.
output_options-tdnewid = 'X'.
output_options-tdtitle = EMail_Subject.
SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_bukrs FOR ekpo-bukrs,
s_werks FOR ekpo-werks,
s_ekgrp FOR ekko-ekgrp,
s_lifnr FOR ekko-lifnr,
s_ebeln FOR ekko-ebeln,
s_eindt FOR eket-eindt,
s_mtart FOR ekpo-mtart,
s_matkl FOR ekpo-matkl,
s_matnr FOR ekpo-matnr.
SELECTION-SCREEN : END OF BLOCK b1.
PERFORM mail_recipient_object.
PERFORM mail_sender_object.
PERFORM mail_appl_object changing g_mail_app_obj.
*RAMESH **********
*******************************SELECTION-SCREEN************
AT SELECTION-SCREEN.
Validate test for Plant in selections
LOOP AT s_werks.
IF NOT s_werks-high IS INITIAL.
SELECT SINGLE * FROM ekpo
WHERE werks = s_werks-high.
IF sy-subrc NE 0.
MESSAGE e600(fr) WITH 'This Plant'
s_werks-high ' does not exist.'
ENDIF.
ENDIF.
IF NOT s_werks-low IS INITIAL.
SELECT SINGLE * FROM ekpo
WHERE werks = s_werks-low.
IF sy-subrc NE 0.
MESSAGE e600(fr) WITH 'This Plant'
s_werks-low ' does not exist.'
ENDIF.
ENDIF.
ENDLOOP.
START-OF-SELECTION.
PERFORM get_data.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZMM_VENDOR_REMINDER_MAIL'
VARIANT = ' '
DIRECT_CALL = ' '
IMPORTING
fm_name = fm_name
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'ERROR 1'.
ENDIF.
CALL FUNCTION fm_name
EXPORTING
ARCHIVE_INDEX =
ARCHIVE_INDEX_TAB =
ARCHIVE_PARAMETERS =
CONTROL_PARAMETERS = control_parameters
MAIL_APPL_OBJ = g_mail_app_obj
MAIL_RECIPIENT = email_recipient
MAIL_SENDER = email_sender
OUTPUT_OPTIONS = output_options
USER_SETTINGS = 'X'
IMPORTING
DOCUMENT_OUTPUT_INFO =
JOB_OUTPUT_INFO =
JOB_OUTPUT_OPTIONS =
TABLES
itab1 = itab1
itab = itab
EXCEPTIONS
FORMATTING_ERROR = 1
INTERNAL_ERROR = 2
SEND_ERROR = 3
USER_CANCELED = 4
OTHERS = 5
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*& Form get_data
text
FORM get_data.
SELECT a~bukrs a~werks a~ebeln a~ebelp
b~bedat a~matnr a~meins b~menge
b~wemng b~eindt c~lifnr b~etenr
FROM ekpo AS a
INNER JOIN eket AS b
ON a~ebeln = b~ebeln AND
a~ebelp = b~ebelp
INNER JOIN ekko AS c
ON a~ebeln = c~ebeln AND
a~bukrs = c~bukrs
INTO CORRESPONDING FIELDS OF TABLE it_pos
WHERE a~bukrs IN s_bukrs
AND a~werks IN s_werks
AND b~eindt IN s_eindt
AND c~lifnr IN s_lifnr
AND c~ekgrp IN s_ekgrp
AND c~ebeln IN s_ebeln
AND a~mtart IN s_mtart
AND a~matkl IN s_matkl
AND a~matnr IN s_matnr
AND c~bstyp EQ 'F'
AND c~loekz EQ space
AND a~loekz EQ space
AND b~menge > b~wemng.
SELECT DISTINCT a~lifnr b~name1 b~street b~str_suppl1 b~str_suppl2
b~city1 b~post_code1 a~adrnr a~telf1 a~telf2
FROM lfa1 AS a
INNER JOIN adrc AS b
ON a~adrnr = b~addrnumber
INTO CORRESPONDING FIELDS OF TABLE it_vendor
FOR ALL ENTRIES IN it_pos
WHERE a~lifnr = it_pos-lifnr.
LOOP AT it_vendor.
SELECT SINGLE * FROM adr6
WHERE addrnumber = it_vendor-adrnr
AND persnumber EQ space.
IF sy-subrc = 0.
it_vendor-smtp_addr = adr6-smtp_addr.
ENDIF.
MODIFY it_vendor.
SELECT SINGLE * FROM lfa1
WHERE lifnr = it_vendor-lifnr.
IF sy-subrc EQ 0.
MOVE-CORRESPONDING lfa1 TO itab1.
APPEND itab1.
ENDIF.
ENDLOOP.
LOOP AT it_pos.
itab-bukrs = it_pos-bukrs.
itab-ebeln = it_pos-ebeln.
itab-ebelp = it_pos-ebelp.
itab-matnr = it_pos-matnr.
itab-bedat = it_pos-bedat.
itab-meins = it_pos-meins.
itab-eindt = it_pos-eindt.
itab-lifnr = it_pos-lifnr.
itab-etenr = it_pos-etenr.
APPEND itab.
CLEAR itab.
ENDLOOP.
ENDFORM. "get_data
*& Form mail_recipient_object
text
--> p1 text
<-- p2 text
form mail_recipient_object .
data: email_address TYPE SO_NAME.
email_address = '[email protected]'.
CALL FUNCTION 'CREATE_RECIPIENT_OBJ_PPF'
EXPORTING
IP_COUNTRY =
IP_FAXNO =
IP_MAILADDR = email_address
IP_TYPE_ID = 'U'
IMPORTING
EP_RECIPIENT_ID = email_recipient
EP_ADDRESS =
ET_RECIPIENT =
EXCEPTIONS
INVALID_RECIPIENT = 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. " mail_recipient_object
*& Form mail_sender_object
text
--> p1 text
<-- p2 text
form mail_sender_object .
CALL FUNCTION 'CREATE_SENDER_OBJECT_PPF'
EXPORTING
IP_SENDER = sy-uname
IMPORTING
EP_SENDER_ID = email_sender
EXCEPTIONS
INVALID_SENDER = 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. " mail_sender_object
*& Form mail_appl_object
text
<--P_G_MAIL_APP_OBJ text
form mail_appl_object changing p_g_mail_app_obj.
include <cntn01>.
DATA: FOLDER TYPE swc_object,
BEGIN OF SOFMFOL_KEY,
FOLDERTYPE LIKE SOFM-FOLTP,
FOLDERYEAR LIKE SOFM-FOLYR,
FOLDERNUMBER LIKE SOFM-FOLNO,
TYPE LIKE SOFM-DOCTP,
YEAR LIKE SOFM-DOCYR,
NUMBER LIKE SOFM-DOCNO,
FORWARDER LIKE SOUB-USRNAM,
END OF SOFMFOL_KEY,
BOR_KEY LIKE SWOTOBJID-OBJKEY.
SELECT single * FROM soud WHERE sapnam LIKE sy-uname AND deleted = ' '.
IF sy-subrc NE 0.
CALL FUNCTION 'SO_USER_AUTOMATIC_INSERT'
EXPORTING
SAPNAME = SY-UNAME
SO_KEY = ' '
SEND_MAIL_IF_NO_ADDRESS = 'X'
IMPORTING
USRADR =
EXCEPTIONS
NO_INSERT = 1
SAP_NAME_EXIST = 2
X_ERROR = 3
SAP_NAME_NOT_EXIST = 4
OTHERS = 5
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
clear sofmfol_key.
sofmfol_key-type = 'FOL'.
sofmfol_key-year = soud-inbyr.
sofmfol_key-number = soud-inbno.
bor_key = sofmfol_key.
IF not bor_key is initial.
swc_create_object folder 'SOFMFOL' bor_key.
IF sy-subrc = 0.
swc_object_to_persistent folder g_mail_app_obj.
IF sy-subrc ne 0.
clear g_mail_app_obj.
ENDIF.
ENDIF.
ELSE.
clear g_mail_app_obj.
ENDIF.
endform. " mail_appl_objectHi Ramesh
Just checkout the FORM interface whether you are passing the proper parameters or not. Also, check their datatypes....
I couldnot find any error in your code by seeing it....
Regards -
Can we send the documents in oracle portal as attachment to a mail ?
Hi,
Our Client using Oracle APPlication Server Portal 10.1.2 for data management and employee portal purpose.
our users used to attach or store the files/documents in Portal i.e. like a file item.
They want to send some selected files/documents as attachments to a group of people via email
Is there any possiblity to achieve this please let me know.
Regards,
RajeshHi Rajesh,
If you are just have one email procedure which you want to use to send files from both your desktop and from the Portal repository, you could consider to connect the Portal repository to your desktop through WebDAV. I assume however that you are looking for a sort of 'Email This' button next to file items.
I have not programmed this before but I guess you can do this with a custom item based on file item. Add an attribute based on PL/SQL which will do the email for you. The PL/SQL procedure in the custom attribute can use wwsbr_all_items view to retrieve the content of the item and send it with utl_smtp. Easier said than done - have not programmed it myself. But then, I am not a programmer, so I reckon Portal developers on this forum would be able to help.
Regards,
Erik -
Problem in Sending mail with attachment (Excel sheet)
Hi
Iam using this FM SO_NEW_DOCUMENT_ATT_SEND_API1 for sending mail with an attachment (excel sheet).
the application is running fine , mail is going to other system . but the excel sheet attachment contain only few rows not all.
and the body of the mail is not displaying .
Can any one help me. Thanks in advance.Hi,
you can use cl_bcs classes for the same. I am using below code for same thng
CONSTANTS:c_tab TYPE c VALUE cl_bcs_convert=>gc_tab.
CONSTANTS:c_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf.
DATA o_send_request TYPE REF TO cl_bcs.
DATA o_document TYPE REF TO cl_document_bcs.
DATA o_recipient TYPE REF TO if_recipient_bcs.
DATA o_bcs_exception TYPE REF TO cx_bcs.
TRY.
o_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = is_mail_text
i_subject = text-005 ).
ENDTRY.
*create file header
CONCATENATE
text-h00 c_tab text-h01 c_tab text-h02 c_tab text-h03 c_tab text-h04 c_tab
text-h52 c_tab text-h05 c_tab text-h06 c_tab text-h07 c_tab text-h08 c_tab text-h09 c_tab
c_crlf INTO w_data_string.
Loop at itab which contains data to be send as attachment
concatenate field1 field2 field3 c_crlf into your_string separated by c_tab
conatenate final string your_string into final_string.
endloop.
*Convert data into suitable excel format
TRY.
CALL METHOD cl_bcs_convert=>string_to_solix
EXPORTING
iv_string = w_data_string
iv_codepage = '4103'
iv_add_bom = 'X'
IMPORTING
et_solix = w_binary_content.
CATCH cx_bcs INTO o_bcs_exception.
IF o_bcs_exception IS NOT INITIAL.
w_exec_txt = o_bcs_exception->get_text( ).
MESSAGE w_exec_txt TYPE 'S'.
ENDIF.
ENDTRY.
add the spread sheet as attachment to document object
CONCATENATE text-006 sy-datum INTO w_attach_name SEPARATED BY space.
o_document->add_attachment(
i_attachment_type = 'xls'
i_attachment_subject = w_attach_name
i_att_content_hex = w_binary_content ).
*create persistent send request
o_send_request = cl_bcs=>create_persistent( ).
add document object to send request
o_send_request->set_document( o_document ).
create recipient object for external mail id
w_mlrec = iw_recipent.
TRY.
o_recipient = cl_distributionlist_bcs=>getu_persistent(
i_dliname = w_mlrec
i_private = space ).
CATCH cx_bcs INTO o_bcs_exception.
IF o_bcs_exception IS NOT INITIAL.
w_exec_txt = o_bcs_exception->get_text( ).
MESSAGE w_exec_txt TYPE 'S'.
ENDIF.
ENDTRY.
add recipient object to send request
o_send_request->add_recipient( o_recipient ).
---------- send document ---------------------------------------
w_sent_to_all = o_send_request->send( i_with_error_screen = 'X' ).
IF w_sent_to_all EQ abap_true.
COMMIT WORK.
ENDIF. -
Excel-sheet attachment having encoding issues
Hi Everyone,
I have an abap report that upon execution, needs to send pricing alerts to the customer through email. The details of the pricing order are there in the excel sheet that is attached to the email sent to the customer. The excel sheet that is received at the other end, shows the error message "The file is corrupt and cannot be opened", if the excel file is generated from systems using SolarisX86 OS. I suppose this is related to the encoding format of the excel sheet getting generated. Please assist me as to how can I solve this problem. Thanks for your help.Can you provide any coding?
Maybe this is helpful to you:
http://wiki.sdn.sap.com/wiki/display/ABAP/Excelfiles-CSVformat -
How to Convert Report into Excel Sheet when Sending Mail.
Dear Friends,
i want to send mail to HOD of Product with an Excel Sheet .
i want to send Pending Issue details to HOD in Excel Sheet attachment .
here i have pending issue report now i need to send it in Excel Sheet attachment .
i have table where i have manage Product ID and HOD OF PRODUCT.
CREATE TABLE "MAP_USER_PRODUCT_DTL"
( "ID" NUMBER NOT NULL ENABLE,
"PRODUCT_ID"NUMBER,
"USER_ID" VARCHAR2(5) NOT NULL ENABLE,
"HOD_PROD" VARCHAR2(100)========================================Value is Y OR N IF HOD then Y else N
CONSTRAINT "MAP_USER_PRODUCT_DTL_PK" PRIMARY KEY ("ID") ENABLE
/i have one more table where all complete issue detail insert.
CREATE TABLE "CRM_ISSUE_PROBLEM"
( "ID" NUMBER,
"SUBJECT" VARCHAR2(255) NOT NULL ENABLE,
"CLIENT_ID" NUMBER,
"ASSIGNED_TO_ID" VARCHAR2(100),
"ASSIGNED_ON" DATE,
"DESCRIPTION" VARCHAR2(4000),
"PRODUCT_ID" NUMBER NOT NULL ENABLE,
"STATUS_ID" NUMBER NOT NULL ENABLE,
CONSTRAINT "CRM_ISSUE_PROBLEM_PK" PRIMARY KEY ("ID") ENABLE
Here STATUS_ID is Like Pending ISsue,Open Issue and Close Issue .i want to send mail to HOD with Pending Issue Report convert into Excel Sheet and send to HOD?
How can i do this.
Thanks
Edited by: Vedant on Oct 12, 2011 12:36 AM
Edited by: Vedant on Oct 12, 2011 2:22 AMHello Vedant,
Would it suffice if you send a CSV file?
If yes, then see following code.. run the code under APEX > Home > SQL Workshop > SQL Commands
DECLARE
ln_id NUMBER;
lc_clob CLOB;
lb_blob BLOB;
li_in PLS_INTEGER := 1;
li_out PLS_INTEGER := 1;
li_lang PLS_INTEGER := 0;
li_warning PLS_INTEGER := 0;
lv_mail_rcpts VARCHAR2(2000) := '[email protected]';
lv_mail_from VARCHAR2(100) := '[email protected]';
lv_clmn_separator VARCHAR2(1) := ',';
BEGIN
-- Build file content as CLOB
-- Replace with your query
FOR i IN (select object_id A, object_name B, object_type C, status D, temporary E, generated F, secondary G,namespace H from user_objects where rownum < 10)
LOOP
IF lc_clob IS NULL THEN
lc_clob := i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
ELSE
lc_clob := lc_clob||CHR(10)||i.A||lv_clmn_separator||i.B||lv_clmn_separator||i.C||lv_clmn_separator||i.D||lv_clmn_separator||i.E||lv_clmn_separator||i.F||lv_clmn_separator||i.G||lv_clmn_separator||i.H;
END IF;
END LOOP;
-- Convert CLOB to BLOB
DBMS_LOB.CREATETEMPORARY(lb_blob,TRUE);
DBMS_LOB.convertToBlob(lb_blob,lc_clob,DBMS_LOB.LOBMAXSIZE,li_in,li_out,DBMS_LOB.DEFAULT_CSID,li_lang,li_warning);
-- Send mail
ln_id:= APEX_MAIL.SEND(
p_to => lv_mail_rcpts,
p_from => lv_mail_from,
p_subj => 'Subject Goes here',
p_body => 'Body goes here'
-- add CSV file as attachment
APEX_MAIL.ADD_ATTACHMENT
p_mail_id => ln_id,
p_attachment => lb_blob,
p_filename => 'filename.csv',
p_mime_type => 'application/csv'
-- push mail queue
APEX_MAIL.PUSH_QUEUE;
-- empty temporary space
DBMS_LOB.FREETEMPORARY ( lob_loc => lb_blob);
COMMIT;
END;Regards,
Hari -
Formatting of EXCEL Sheets during download
Hi all,
There is a requirement for Formatting EXCEL Sheets when downloaded into an FTP site in background.
The internal table is saved in application server with .xls extension and transferred to FTP thru RFC.
is there any way to format this EXCEL file and get it formatted in FTP when it is seen.
The report will run in background daily and every day the report has to be in same format.
Thanks in Advance..
Vivek ..Hi
You can not format EL file that is uploaded. You have to format the internal table before generation XL file from the internal table. Internal table should have all fields in char type. set char length for each field like
data: begin of itab..
field1(20) type c,
field2(20) type c,
Append header record if u want into this itab as first record.
Append all records into this itab.
Generate XL file from this itab.
I suggest you that..
Upload this itab in to application server as 'DAT' format then generate XL file from this file. Dont set .xls when you upload itab to appl. server.
Bala
Note: Award points if helpful
Maybe you are looking for
-
In my labview program, I open, edit, and close multiple excel sheet one at a time. It used to work, but I am getting a -41106 error. It said that the possible reason is "Report Generation Toolkit: Microsoft Word or Excel did not open. Make sure Mi
-
When I go to access my albums from any app on my phone or iPad, I cannot access the iCloud albums, only the albums synced with iTunes/iPhoto manually. This is frustrating because I cannot add to those albums from mobile device, I have to add to them
-
Can't access multiple webpages at the same time
here's an example of what i want to do... go to a news website and open three stories in three new webpages before i go into airplane mode... reading those three distinct stories on the plane (offline). it seems once you navigate away from a page it
-
Can I change the default settings for Paragraph Rules?
Hello I need to apply the same 'Rule Below' to a lot of separate lines of text in InDesign CS5, but the settings I want differ from the default ones in the Paragraph Rules dialogue box. Is there a way to change the default settings so I can just clic
-
Full-text search broken in Simplified Chinese?
Hello, Can anyone confirm whether full-text search works in Simplified Chinese CHM files produced with Robohelp 7? It looks to me like the answer is no. When I compile a help system that has been localized into Chinese, the compiler produces this err