Executing Excel Macros from SAP
Hi all Experts,
I have created a program which tranfers data from different internal tables into Different Worksheets of a single workbook.
Now, Can some one please tell me how to Execute macros from SAP.
Regards,
AJ
To execute an Excel macro follow these steps.
1. Create macro inside Excel Workbook where you transferred your information.
2. Use following instruction to execute the desired macro you create:
DATA: EXCEL TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.
CALL METHOD OF EXCEL 'Run' EXPORTING #1 = 'WRITE_SHEET_CELL'
#2 = 'VALUE1'
#3 = 'VALUE2'
#4 = 'VALUE3'.
In previous example, macro WRITE_SHEET_CELL was created first. The macro name must be in uppercase.
Regards.
Rafael Rojas.
Similar Messages
-
How to execute Excel Marco from SAP using Office Integration Classes
Is there a way to trigger Excel Macro from SAP? I tried using method CALL METHOD document->execute_macro
of i_oi_document_proxy but it does not work.
Thanks
VivekTry this:
If you are using OLE to populate the Excel Sheet then, then yes you can run a macro.
CALL METHOD OF OBJ_EX_APP 'Run'
EXPORTING #1 = MACROSTR.
Adding a Field Exit
To add a field exit first find the data element that is linked to the screen field- the screen number and program
Run program RSMODPRF. You will need to create two function modules one FIELD_EXIT_MEPO_VENDOR and
FIELD_EXIT_MEPO_VENDOR_A
FIELD_EXIT_MEPO_VENDOR should have code simply of input = ouput.
FIELD_EXIT_MEPO_VENDOR_A should have the code for whatever the functionality is required
Go back to RSMODPRF and run the program without parameters. Use the push buttons to assign the screen, 'A' and program. Use the drop down to activate the field list.
This should now work, but there is no way of debugging. For further information look at OSS 29377
program zzdirlist.
for AIX this method also works.
DATA: BEGIN OF TABL OCCURS 0,
TEXT(80) TYPE C,
END OF TABL.
DATA: COMMAND(256) TYPE C.
COMMAND = 'ls'.
CALL FUNCTION 'RFC_REMOTE_PIPE' DESTINATION 'SERVER_EXEC'
EXPORTING COMMAND = COMMAND
READ = 'X'
TABLES PIPEDATA = TABL.
LOOP AT TABL.
WRITE:/ TABL-text.
ENDLOOP. -
Running Excel macros from ABAP
Hello everyone,
I am trying to execute an Excel macro from an ABAP program. We are currently on a 46C system. While doing some research on help.sap.com I came across the method execute_macro in class i_oi_document_proxy. Ive never used methods in ABAP before and Im not really sure what Im doing. Has anyone got this to work? When I try to run the program it dumps with error OBJECTS_OBJREF_NOT_ASSIGNED.
Thanks,
Becky
Here is the program:
REPORT ztest_program.
INCLUDE ole2incl.
DATA gs_excel TYPE ole2_object .
DATA gs_wbooks TYPE ole2_object .
DATA gs_wbook TYPE ole2_object .
DATA gs_application TYPE ole2_object .
DATA: h_sheet TYPE ole2_object.
DATA: document TYPE REF TO i_oi_document_proxy.
*Name of the macro in Excel
DATA: macro_string(50) TYPE c
VALUE 'FB03process.FromTheBeginning',
no_flush TYPE c,
param_count TYPE i VALUE 0,
script_name TYPE c VALUE 'X',
error TYPE REF TO i_oi_error
OCCURS 0 WITH HEADER LINE,
retcode TYPE soi_ret_string,
error_string(50) TYPE c,
retvalue(30) TYPE c.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = text-007
EXCEPTIONS
OTHERS = 1.
CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF gs_excel 'Visible' = 1 .
GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
GET PROPERTY OF gs_wbooks 'Application' = gs_application .
*--Opening the existing document
CALL METHOD OF gs_wbooks 'Open' = gs_wbook
EXPORTING #1 = 'D:\temp\FB03process.xls' .
tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = 0
text = text-009
EXCEPTIONS
OTHERS = 1.
GET PROPERTY OF gs_excel 'ACTIVESHEET' = h_sheet.
CALL METHOD document->execute_macro
EXPORTING macro_string = macro_string
param_count = param_count
script_name = script_name
no_flush = no_flush
IMPORTING error = error
retcode = retcode
CHANGING error_string = error_string
retvalue = retvalue.
disconnect from Excel
FREE OBJECT gs_excel.
PERFORM err_hdl.
FORM err_hdl.
IF sy-subrc <> 0.
WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
STOP.
ENDIF.
ENDFORM. " ERR_HDLHi,
Please correct me if I am wrong but it seems that you have not fetched a handle to the document object before issuing the statement CALL METHOD document->execute_macro. Hence the error OBJECTS_OBJREF_NOT_ASSIGNED is being dislayed. If you want to use SAP Desktop Office Integration using ABAP Objects, take a look at this article at http://www.intelligenterp.com/feature/archive/ or http://www.sapinfo.net/public/en/index.php4/article/comvArticle-193333c63b4bd807d2/en/articleStatistic
Hope this helps.
Regards
Message was edited by: Shehryar Khan -
Unable to export report to excel file from SAP
Hi all,
I have a problem to download data from a report. The XL gets downloaded in a different format than my colleague.
We are using the same XL version but two weeks back the SAP GUI 730 got reinstalled to my machine and since then the problem
started.
Can you please confirm is there is any particular user settings for this?
I have login in any different working ( SAP Export ) machine with my login ID and Password and try to export the report to excel file from SAP, and I have same issue . Same we have requested another user to login in my machine with their ID and Password and check the same, They have tried and its working for then in my machine.
see screenshots attached.
Thanks.Execute report>
Right click anywhere in the report output and select Spreadsheet.
A pop up box will appear, select which export option you would like to use and click green check.
NOTE: If you don't see this option then goto Settings>Switch List then try above said.
Thanks,
Kumar -
Execute Excel Macro Through DIAdem
Hi All,
I am currently trying to run a script in DIAdem which exports certain material properties to an Excel Macro-enabled workbook. Inside the Excel workbook the user executes a macro to perform some calculations. The results of that calculation will then be re-imported into a DIAdem report. I have the import/export data part down, but the million dollar question is how can I execute an Excel macro from DIAdem's VBScript?
I know some are going to say this makes no sense, just do the calculation in DIAdem. I know this, but the file/calculations are an industry accepted toolbox and it must be done this way.
Thanks in advance and here is some dumbed down code to showcase the example:
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim excel
Dim excelbook
Dim a
Set Excel = CreateObject("Excel.Application")
Excel.Visible = True
Set excelbook=Excel.Workbooks.Open("My File")
excelbook.Sheets("InputResults").range("B5").value = Data.Root.ChannelGroups(ChanGrp#).Properties("myProp").Value
'Call 'My_Macro' !!!!!!!!!!!!!!!!!!!!
Msgbox("Result is: " & excelbook.Sheets("InputResults").range("B5").value)
Solved!
Go to Solution.Hi GT_Mark
You simply can use the methode Run
Call Excel.Run("MyMacro")
Of course you have to make sure that you refer only to data that are available in Excel.
To obtain CodeCompletion for Excel in the script editor select Microsoft Excel x.x Objects Library in the "Registed Type Libraries" dialog box. The x.x value depends on your installed Excel version. To open this dialog box, select Script»Type Libraries in DIAdem SCRIPT.
Hope this helps
Winfried -
Executing Sabrix Reports from SAP CPS
Does anyone know if we can executing Sabrix Reports from SAP CPS?
Thanks,
BhushanNo. That was the first option I could think of. Executing it with ABAP Program.
I dont have much information about Sabrix System but what I understand is that automated tax reporting solution which runs batch processes in background during
night and email report with desired data in an excel spreadsheet format. Sabrix doesn’t have a custom solution to generate reports. They have suggested leveraging 3rd party tools for such requirement. -
How to extract the data into Excel / PDF from SAP
Hi,
We have spool number of a report output.
We want to extract the data into Excel / PDF from SAP directly...
Plz guide...Hi ,
Please check this [Thread|HOW TO DOWNLOAD SAP OUTPUT TO EXCEL FILE;. Hope your problem will be solved.
You can check [this also.|http://wiki.sdn.sap.com/wiki/display/sandbox/ToConvertSpoolDataintoPDFandExcelFormatandSenditinto+Mail]
Thanks,
Abhijit -
hi experts ,
i need to execute DOS command from SAP .
earlier we have 'GUI_EXEC' WS_EXECUTE , 'WS_DOWNLOAD' etc which are Obsolete now.
as we are using ECC6.0. kindly guide how to do this.
best regards,
RahulTry out...
DSVAS_DOC_WS_EXECUTE_50
or
CL_GUI_FRONTEND_SERVICES=>EXECUTE
<b><REMOVED BY MODERATOR></b>
Thanks & Regards
ilesh 24x7
Message was edited by:
Alvaro Tejada Galindo -
How to run excel macro from ole
hi to all experts.
i need to run excel macro from oleHi,
*& Report ZKC_TEST
*& Description: Fancy report output in XL
*&Programmer: Krishna Chauhan
*&Date: 20 Feb 09
REPORT ZKC_TEST.
* INCLUDES *
INCLUDE ole2incl.
*& TYPES *
TYPES: BEGIN OF ty_marc,
matnr TYPE marc-matnr,
werks TYPE marc-werks,
pstat TYPE marc-pstat,
lvorm TYPE marc-lvorm,
ekgrp TYPE marc-ekgrp,
END OF ty_marc.
TYPES: BEGIN OF ty_titles,
title(20) TYPE c,
field(20) TYPE c,
END OF ty_titles.
*& INTERNAL TABLES *
DATA: t_marc TYPE STANDARD TABLE OF ty_marc,
t_titles TYPE STANDARD TABLE OF ty_titles.
*& FIELD-SYMBOLS *
FIELD-SYMBOLS: <fs_marc> LIKE LINE OF t_marc,
<fs_titles> LIKE LINE OF t_titles,
<fs> TYPE ANY.
*& VARIABLES *
DATA: w_tabix TYPE sy-tabix,
w_titles TYPE sy-tabix,
w_line TYPE sy-tabix,
w_field TYPE string,
filename TYPE string,
path TYPE string,
fullpath TYPE string.
DATA: data_titles TYPE REF TO data.
DATA: e_sheet TYPE ole2_object,
e_activesheet TYPE ole2_object,
e_newsheet TYPE ole2_object,
e_appl TYPE ole2_object,
e_work TYPE ole2_object,
e_cell TYPE ole2_object,
e_color TYPE ole2_object,
e_bold TYPE ole2_object.
*& SELECTION-SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
*& START-OF-SELECTION *
START-OF-SELECTION.
PERFORM get_titles.
PERFORM get_data.
PERFORM create_excel.
*& AT SELECTION-SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Select archivo'
default_extension = 'xls'
file_filter = '*.xls'
CHANGING
filename = filename
path = path
fullpath = fullpath.
IF sy-subrc EQ 0.
p_file = fullpath.
ENDIF.
*& Form get_titles *
FORM get_titles.
CREATE DATA data_titles TYPE ty_titles.
ASSIGN data_titles->* TO <fs_titles>.
<fs_titles>-title = 'Material'.
<fs_titles>-field = 'MATNR'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Plant'.
<fs_titles>-field = 'WERKS'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'PSTAT'.
<fs_titles>-field = 'PSTAT'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Deletion Flag'.
<fs_titles>-field = 'LVORM'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'EKGRP'.
<fs_titles>-field = 'EKGRP'.
APPEND <fs_titles> TO t_titles.
ENDFORM. "get_titles
*& Form get_data *
FORM get_data.
SELECT matnr werks pstat lvorm ekgrp
INTO TABLE t_marc
FROM marc
WHERE matnr = '000000000001013351'.
ENDFORM. " get_data
*& Form create_excel *
FORM create_excel.
w_line = 1.
CREATE OBJECT e_appl 'EXCEL.APPLICATION'.
SET PROPERTY OF e_appl 'VISIBLE' = 1.
CALL METHOD OF e_appl 'WORKBOOKS' = e_work.
CALL METHOD OF e_work 'Add' = e_work.
GET PROPERTY OF e_appl 'ActiveSheet' = e_activesheet.
SET PROPERTY OF e_activesheet 'Name' = 'Material Plants'.
LOOP AT t_marc ASSIGNING <fs_marc>.
w_tabix = sy-tabix.
w_line = w_line + 1.
LOOP AT t_titles ASSIGNING <fs_titles>.
w_titles = sy-tabix.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = 1
#2 = w_titles.
SET PROPERTY OF e_cell 'Value' = <fs_titles>-title.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_color 'ColorIndex' = 35.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 1.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = w_line
#2 = w_titles.
CONCATENATE '<fs_marc>-' <fs_titles>-field
INTO w_field.
ASSIGN (w_field) TO <fs>.
SET PROPERTY OF e_cell 'Value' = <fs>.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_cell 'ColumnWidth' = 20.
SET PROPERTY OF e_color 'ColorIndex' = 0.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 0.
ENDLOOP.
ENDLOOP.
CALL METHOD OF e_work 'SAVEAS'
EXPORTING
#1 = p_file.
CALL METHOD OF e_work 'close'.
CALL METHOD OF e_appl 'QUIT'.
FREE OBJECT e_appl.
ENDFORM. " create_excel -
How does execute PHP Script from SAP?
I've already installed SAPRFC and run SAP Function from PHP successfully. But failed when tried execute PHP script from SAP (SM59). Anyone can help me for a clear instruction for this problem?
ThanksHi Max,
here is the Source:
[code]
#!/usr/bin/php -q
<?php
// SAPRFC - Server example
// PHP server function RFC_READ_REPORT
// Require: CGI version PHP, RFC destination defined in SAP R/3 (SM59)
// http://saprfc.sourceforge.net
// Interface definiton for RFC_READ_REPORT
// (generated by saprfc.php - option Generate PHP)
$DEF_RFC_READ_REPORT = array (
array (
"name"=>"SYSTEM",
"type"=>"EXPORT",
"optional"=>"0",
"def"=> array (
array ("name"=>"","abap"=>"C","len"=>8,"dec"=>0)
array (
"name"=>"TRDIR",
"type"=>"EXPORT",
"optional"=>"0",
"def"=> array (
array ("name"=>"NAME","abap"=>"C","len"=>40,"dec"=>0),
array ("name"=>"SQLX","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"EDTX","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"VARCL","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"DBAPL","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"DBNA","abap"=>"C","len"=>2,"dec"=>0),
array ("name"=>"CLAS","abap"=>"C","len"=>4,"dec"=>0),
array ("name"=>"TYPE","abap"=>"C","len"=>3,"dec"=>0),
array ("name"=>"OCCURS","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"SUBC","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"APPL","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"SECU","abap"=>"C","len"=>8,"dec"=>0),
array ("name"=>"CNAM","abap"=>"C","len"=>12,"dec"=>0),
array ("name"=>"CDAT","abap"=>"D","len"=>8,"dec"=>0),
array ("name"=>"UNAM","abap"=>"C","len"=>12,"dec"=>0),
array ("name"=>"UDAT","abap"=>"D","len"=>8,"dec"=>0),
array ("name"=>"VERN","abap"=>"C","len"=>6,"dec"=>0),
array ("name"=>"LEVL","abap"=>"C","len"=>4,"dec"=>0),
array ("name"=>"RSTAT","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"RMAND","abap"=>"C","len"=>3,"dec"=>0),
array ("name"=>"RLOAD","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"FIXPT","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"SSET","abap"=>"C","len"=>1,"dec"=>0),
array ("name"=>"SDATE","abap"=>"D","len"=>8,"dec"=>0),
array ("name"=>"STIME","abap"=>"C","len"=>6,"dec"=>0),
array ("name"=>"IDATE","abap"=>"D","len"=>8,"dec"=>0),
array ("name"=>"ITIME","abap"=>"C","len"=>6,"dec"=>0),
array ("name"=>"LDBNAME","abap"=>"C","len"=>20,"dec"=>0)
array (
"name"=>"PROGRAM",
"type"=>"IMPORT",
"optional"=>"0",
"def"=> array (
array ("name"=>"","abap"=>"C","len"=>40,"dec"=>0)
array (
"name"=>"QTAB",
"type"=>"TABLE",
"optional"=>"0",
"def"=> array (
array ("name"=>"LINE","abap"=>"C","len"=>72,"dec"=>0)
// Create list of PHP server functions
$GLOBAL_FCE_LIST[RFC_READ_REPORT] = saprfc_function_define(0,"RFC_READ_REPORT",$DEF_RFC_READ_REPORT);
// PHP server function
function RFC_READ_REPORT ($fce)
$REPORT = saprfc_server_import ($fce,"PROGRAM");
saprfc_table_init ($fce,"QTAB");
$fd = fopen ($REPORT,"r");
if (!$fd)
return ("NOTFOUND"); // raise exception "NOTFOUND"
while (!feof($fd))
$LINE = fgets ($fd,73);
saprfc_table_append ($fce,"QTAB",array("LINE"=>$LINE));
fclose ($fd);
saprfc_server_export ($fce,"SYSTEM","PHP");
return (true);
// Call script with: ./server.php -a phpgw -g hostname -x sapgw00
$rfc = saprfc_server_accept ($argv);
// Dispatch one function call
$rc = saprfc_server_dispatch ($rfc,$GLOBAL_FCE_LIST);
saprfc_close ($rfc);
?>
[/code]
Regards
Gregor
Message was edited by: Gregor Wolf -
Export Excel Documents from SAP Business One
Hello Guys,
I have been having a problem with one of our customers regarding the export of documents from SAP Business One to Excel, Whenever a user tries to export a list to Excell SBO first exports it to a txt file. I found a thread where some of you had recommended to follow the steps of this procedure in order to allow the system to export the file directly into Excel:
1. On your desktop go To: "Start -> Programs -> Microsoft Office ->
Microsof Excel
2. In Excel go to:"Tools #> Options #> General" Tab.
3. De-select the tick-box "Ignore Other Applications"
In order to de-select the "Portection from Macro Viruses"
1. In Excel go to:"Tools -> Macro -> Security"
2. Set the security level to "Medium".
Change path from 'Local' to 'Server'
1. Define the path:
a) Choose "Administration"
b) Choose "System Initialization"
c) Choose "General Settings"
d) Select the "Path" tab
e) Define a path for the Excel folder by using the Browse (...)
option
Press 'Export to Excel' to open the 'AutoOpen.xls
Make sure you change / remove the 'Local;=True' Statement accordingly,
meaning:
Excel is Starting from the server: remove the statement.
Excel is Starting from the client: add the statement.
The Excel folder should be located in a shared Folder in the server and
it should contain the "AutoOpen.xls" file.
I followed all the steps up until the step where it tells me to press "Export to Excel" to open the "AutoOpen.xls" ( I believe it refers to the Excel Export Command) however when I click the icon it does not open the 'AutoOpen.xls. Does anybody know what the problem might be?? ( I checked the AutoOpen.xls" file and it does exist in the excel folder located in the shaerd folder)
I`d sure appreciate your help guys!!Hi Manuel,
Can you make sure your path is :
C:\Program Files\SAP\SAP Business One Server\B1_SHR\ExclDocs\
Test with this and see what is your result ..make sure you are exporting with folder with Sharing folder B1_SHR .
Hope this helps
Bishal
Edited by: BIshal Adhikari on Sep 17, 2009 11:19 AM -
How to send ALV Report in excel format from SAP
Hi Gurus,
We are using SAP 4.7 and using different SAP reports.Now I want to send SAP ALV report in excel format directly from SAP in background.Now we send these reports in background weekly by using autimetic scheduling but this is PDF format.Now I want to change this pdf format to excel format.In SCOT T.Code I am able to find any excel format.Please help me out.
I am waiting for your reply.
Advance Thanks
NirmalHi Nirmal,
I have done the same in my previous organisation.For this particular solution you need to ask your basis guys to upgrade the support package so that BCS classes could be available in the system.
API interafces five some problem with attachemnts and SAP has recommended to use BCS classes.
Currently BCS classes won't be availbale in 4.7.
Once the BCS classes are available
use below code
CONSTANTS:
lc_tab TYPE c VALUE cl_bcs_convert=>gc_tab,
lc_crlf TYPE c VALUE cl_bcs_convert=>gc_crlf,
lc_codepage TYPE abap_encod VALUE '4103',
data :
lv_string TYPE string,
binary_content TYPE solix_tab,
size TYPE so_obj_len,
*" Set Heading of Excel File
CONCATENATE 'Employee DATA'
lc_crlf lc_crlf
INTO lv_string.
*" Set Header for Excel Fields
CONCATENATE lv_string
lc_header1 lc_tab
lc_header2 lc_tab
lc_header3 lc_tab
lc_header4 lc_tab
lc_header5 lc_tab
lc_header6 lc_tab
lc_header7 lc_tab
lc_header8 lc_tab
lc_header9 lc_tab
lc_header10 lc_crlf
INTO lv_string.
"lc_header1 to 10 could be your field headers
"Move Internal table data
LOOP AT gt_final1 INTO gwa_final1.
CONCATENATE lv_string
gwa_final1-field1 lc_tab
gwa_final1-field2 lc_tab
gwa_final1-field3 lc_crlf
INTO lv_string.
ENDLOOP.
*" convert the text string into UTF-16LE binary data including
*" byte-order-mark. Mircosoft Excel prefers these settings
*" all this is done by new class cl_bcs_convert (see note 1151257)
TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = lv_string
iv_codepage = lc_codepage "suitable for MS Excel, leave empty
iv_add_bom = abap_true "for other doc types
IMPORTING
et_solix = binary_content
ev_size = size ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
TRY.
*" create persistent send request
send_request = cl_bcs=>create_persistent( ).
document = cl_document_bcs=>create_document(
i_type = lc_doc
i_text = main_text
i_subject = lc_sub ).
document->add_attachment(
i_attachment_type = lc_attach "#EC NOTEXT
i_attachment_subject = lc_sub "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
send_request->set_document( document ).
recipient = cl_cam_address_bcs=>create_internet_address( email ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient.
IF recipient IS NOT INITIAL.
sent_to_all = send_request->send( i_with_error_screen = abap_true ).
COMMIT WORK.
* MESSAGE text-014 TYPE gc_succ .
ENDIF.
CATCH cx_bcs INTO bcs_exception.
MESSAGE i865(so) WITH bcs_exception->error_type.
ENDTRY.
For BCS decalartion u can go to se 38 and see program BCS_EXAMPLE_1 to BCS_EXAMPLE_7.
Rewrads if helpful.
Cheers
Ramesh Bhatt -
Sending external mail with excel attachment from SAP
Hi All,
I am trying to send a external mail from SAP. Mail is getting posted correctly with attachment having type excel. If attach file has more than 1 records then in mail it is coming in a single lines. it is not getting wrap.
e.g. my attach internal table has records like LINE1
LINE2
LINE3
output in attach excel file is : LINE1 LINE2 LINE3
in attach file it should come line by line.
source code of my function module is as follows :
FUNCTION ZXI_SEND_MAIL_WITH_ATTACHMENT.
""Local Interface:
*" IMPORTING
*" REFERENCE(SUBJECT) TYPE SO_OBJ_DES OPTIONAL
*" REFERENCE(ATTACH_NAME1) TYPE SOOD-OBJDES
*" REFERENCE(EXT1) TYPE SOODK-OBJTP
*" REFERENCE(MAIL_ID) TYPE ADR6-SMTP_ADDR
*" TABLES
*" IT_CONTENT TYPE SOLI_TAB OPTIONAL
*" IT_ATTACH TYPE SOLI_TAB OPTIONAL
DATA: send_request TYPE REF TO cl_bcs.
DATA: document TYPE REF TO cl_document_bcs.
DATA: sender TYPE REF TO cl_sapuser_bcs.
DATA: recipient TYPE REF TO if_recipient_bcs.
DATA: exception_info TYPE REF TO if_os_exception_info,
bcs_exception TYPE REF TO cx_document_bcs.
DATA i_attachment_size TYPE sood-objlen.
Creates persistent send request
send_request = cl_bcs=>create_persistent( ).
TRY.
*****Create txt mail document**************************
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = it_content[]
i_subject = subject ).
**************Creates Attachment 1***********************
CALL METHOD document->add_attachment
EXPORTING
i_attachment_type = ext1
i_attachment_subject = attach_name1
i_att_content_text = it_attach[].
Add document to send request
CALL METHOD send_request->set_document( document ).
Get sender object
sender = cl_sapuser_bcs=>create( sy-uname ).
Add sender
CALL METHOD send_request->set_sender
EXPORTING
i_sender = sender.
recipient = cl_cam_address_bcs=>create_internet_address(
i_address_string = mail_id ).
CALL METHOD send_request->add_recipient
EXPORTING
i_recipient = recipient
i_express = 'U'
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
**********Trigger e-mails immediately****************************
send_request->set_send_immediately( 'X' ).
CALL METHOD send_request->send( ).
COMMIT WORK.
CATCH cx_document_bcs INTO bcs_exception.
ENDTRY.
ENDFUNCTION.
please suggest me a solution and thanks in advance.
Thanks&Regards,
SachinSee the sample code for sending attachment as Mail
Mailing with Attachment by ABAP Coding
Refer this link:
Mail with attachment.
FORM send_list_to_basis .
DATA: w_path LIKE rlgrap OCCURS 0 WITH HEADER LINE,
lt_index TYPE sy-tabix,
doc_type(3) TYPE c,
descr LIKE it_objpack_basis-obj_descr,
temp_data LIKE w_path,
temp1 TYPE string,
tab_lines TYPE i,
langu(15) TYPE c,
expirydate TYPE so_obj_edt,
L_FILE1(100).
CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.
W_PATH-FILENAME = L_FILE1.
APPEND w_path.
CLEAR w_path.
wa_doc_chng-obj_descr = 'User List not logged on for 180 days'.
wa_doc_chng-obj_langu = 'E'.
wa_doc_chng-obj_expdat = sy-datum.
CLEAR w_subject.
CONCATENATE 'Please find attached document with list of users'
'not logged on for 180 days for client' sy-mandt
INTO w_subject SEPARATED BY space.
it_objtxt_basis-line = w_subject.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
it_objtxt_basis-line = text-004.
APPEND it_objtxt_basis.
CLEAR it_objtxt_basis.
CLEAR w_tab_line.
DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.
READ TABLE it_objtxt_basis INDEX w_tab_line INTO l_cline.
wa_doc_chng-doc_size =
( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).
CLEAR it_objpack_basis-transf_bin.
it_objpack_basis-head_start = 1.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = 1.
it_objpack_basis-body_num = w_tab_line.
it_objpack_basis-doc_type = 'RAW'.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
LOOP AT w_path.
temp1 = w_path.
descr = w_path.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '\'
string = descr
IMPORTING
head = descr
tail = temp_data.
CALL FUNCTION 'STRING_REVERSE'
EXPORTING
string = descr
lang = 'E'
IMPORTING
rstring = descr.
CALL FUNCTION 'STRING_SPLIT'
EXPORTING
delimiter = '.'
string = descr
IMPORTING
head = temp_data
tail = doc_type.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = temp1
filetype = 'BIN'
header_length = 0
read_by_line = 'X'
replacement = '#'
TABLES
data_tab = it_upload.
DESCRIBE TABLE it_upload LINES tab_lines.
DESCRIBE TABLE it_objbin_basis LINES lt_index.
lt_index = lt_index + 1.
LOOP AT it_upload.
wa_objbin_basis-line = it_upload-line.
APPEND wa_objbin_basis TO it_objbin_basis.
CLEAR wa_objbin_basis.
ENDLOOP.
it_objpack_basis-transf_bin = 'X'.
it_objpack_basis-head_start = 0.
it_objpack_basis-head_num = 0.
it_objpack_basis-body_start = lt_index.
it_objpack_basis-body_num = tab_lines.
it_objpack_basis-doc_type = doc_type.
it_objpack_basis-obj_descr = descr.
it_objpack_basis-doc_size = tab_lines * 255.
APPEND it_objpack_basis.
CLEAR it_objpack_basis.
ENDLOOP.
it_reclist_basis-receiver = '[email protected]'.
it_reclist_basis-rec_type = 'U'.
APPEND it_reclist_basis.
CLEAR it_reclist_basis.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = wa_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack_basis
contents_txt = it_objtxt_basis
contents_bin = it_objbin_basis
receivers = it_reclist_basis
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
IF sy-subrc EQ 0.
SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
ENDIF.
ENDFORM. " send_list_to_basis
Reward points if useful
Regards
Anji -
Have a pushbutton on downloaded excel sheet from SAP
Hello
Is it possible to have a Pushbutton on downloaded excel sheet from SAPCheck OLE for this.
-
Hi SAP gurus,
I have a requirement where in we have a DOS exe Program but Dont have source code of it. The Program takes some input values, Calculates and Gives the output result. We need that Program to be called from SAP so that we can pass the input values from SAP and get the results back into SAP.
It would be great if you can help me out in this. Answers will be rewarded.
Thanks,Check FM WS_EXECUTE.
REPORT ZEXAMPLE.
DATA: V_PGM(100) VALUE 'C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\WINWORD.EXE',
V_FNAME LIKE RLGRAP-FILENAME VALUE 'C:\DOCUMENT.DOC'.
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
COMMANDLINE = V_FNAME
PROGRAM = V_PGM
EXCEPTIONS
FRONTEND_ERROR = 1
NO_BATCH = 2
PROG_NOT_FOUND = 3
ILLEGAL_OPTION = 4
GUI_REFUSE_EXECUTE = 5
OTHERS = 6.
IF SY-SUBRC NE 0.
WRITE:/ V_FNAME, 'NOT OPENED WITH', V_PGM.
ELSE.
WRITE:/ 'EXTERNAL APPLICATION CALLED SUCCESSFULLY'.
ENDIF.
Maybe you are looking for
-
Suppose there are 50 dedicated packages for top 50 table and 25 SAPXXXX package in total. I want to: Load them order by size (seems this is the default setting in migtion monitor) For those 50 tables, I need specify both DDL file and loadArgs 8 paral
-
How to tell which pages are linked to a template
How can you tell, from a template, all of the pages which it affects. I have some "junk" templates that are from previous experiments which I am trying to remove, I wouldn't want them to be a part of something important.
-
Multicast sessions page of server properties
I am using ZEN 4.0.1 ir7, Netware 6.5sp4, ConsoleOne 1.3.6e. I was creating multicast sessions on the multicast sessions page of server properties for later use by my technician. I had created 5 sessions, then closed the property page. Then later I w
-
Adobe Download Assistant give me (Error 100) when i try to sign in
I downloaded the Adobe Dreamweaver trial but i can't get past the Adobe Download Assistant. Every time i try to sign in it says "Error communicationg with Adobe.com (Error 100). I can log in at www.adobe.com. Whats the problem here?
-
Hi all, I am using adaptive web service model in CE7.2 Server. every time i made some change to the web service, it is not well recognized, for example, i add one more field in the input request. i reimported the model, compile and deploy. the server