Download data from internal table to excel sheet from the background
Hello Experts,
I have written a code where the data is stored in the internal table . Now when i run this code in the background i want this internal table data to get downloaded in the excel sheet. The function module GUI_DOWNLAOD is not supported in the background. So is there any other function module that can be used or is there any other way to do this
Thanks in advance
Hi Aditya,
I would provide you 2 advice:
1. save the file on the application server as text file and the fileds in it separated by TAB,you can download the file whenever you want and open it with excel.
2.generate excel files and send it to the email address whatever you specify in the selection-screen.
Thanks,
Sam
Similar Messages
-
Gui_download for transferring the data from internal table to excel sheet.
hi all,
i am using gui_download for transferring the data from internal table to excel sheet.
I have a internal table with 3 columns col1,col2,col3 and I am getting the file at the specified path,but my problem is that,in the excel sheet(path specified) all the 3 columns values are printed in one column.Please help me.
Thanks in advance.Hi Venkata,
plz use FM 'SAP_CONVERT_TO_XLS_FORMAT' :
call function 'SAP_CONVERT_TO_XLS_FORMAT'
exporting
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_filename = p_file
* I_APPL_KEEP = ' '
tables
i_tab_sap_data = t_mbew
* CHANGING
* I_TAB_CONVERTED_DATA =
* EXCEPTIONS
* CONVERSION_FAILED = 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.
Hope this helps,
Erwan -
How to download internal table to excel sheet
I have a requirement to download nearly 8 to 10 internal tables to excel sheets(for each internal table one excel sheet) without displaying the diolog box showing open and save buttons.
scenario :
I will enter the path name like this - C:\myfolder\Custom_programs.xls.
C:\myfolder\Custom_tables.xls.
(File name does not exit..it has to created inside the
specified folder)
in submit button I populate 2 internal tables say it1 and it2. then I need to move the tables contents to the path I have specified above.
attach_file_to_response method is not working for the above reqt since it is showing the dialog box.
Please provide a suitable solution...Please ignore all the responders that are stating that you can use GUI_DOWNLOAD from Web Dynpro ABAP. As you found out, this absolutely will not work, since this function module and other download logic like it depends upon a connection to the SAPGUI. People posting to use the GUI_DOWNLOAD from WDA need to learn a little more about the architecture of WDA before they go posting incorrect repsonses in the forum. I have little tollerance for people posting outright incorrect information in the WDA Forum.
What you want to do - download silent - is not easily done from WDA. There are rules about how web applications must behave in a browser. Normal HTML/JavaScript does not allow silent downloads for security reasons. Obviously there are many untrustworthy websites on the internet that you wouldn't want to allow to directly access your local machine. WDA must live within these same browser limitations.
SAP has done some work using a Java Applet to get around some of these security issues. This funcitonality comes in NetWeaver 7.01. It is the AcfUpDownload UI element:
http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/b9157c878a2d67e10000000a42189c/frameset.htm
However it is designer for usage with the Content or KPro server - so even it might not meet your needs. -
Downloding from internal table to excel
Hi All,
I am using ole concept to download data from internal table to excel because i want to fill few records with colors and few with bold etc.
But this ole concept is downloading to excel line by line and taking much time.
How can i improve the performance in this concept or is there any other concept please let me know.
i am using fallowng logic to download to excel.
*Generating the Excel report in the foreground
data: h_excel type ole2_object, " Excel object
h_mapl type ole2_object, " list of workbooks
h_map type ole2_object, " workbook
start Excel
create object h_excel 'EXCEL.APPLICATION'.
set property of h_excel 'Visible' = 1.
get list of workbooks, initially empty
call method of h_excel 'Workbooks' = h_mapl.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map.
perform err_hdl.
output column headings to active Excel sheet
perform fill_cell using 1 1 1 000 'Job Name'(001).
perform fill_cell using 1 2 1 000 'Variant'(002).
perform fill_cell using 1 3 1 000 'Description'(003).
perform fill_cell using 1 4 1 000 'Run Date'(004).
perform fill_cell using 1 5 1 000 'Run Time'(005).
perform fill_cell using 1 6 1 000 'Duration'(006).
perform fill_cell using 1 7 1 000 'Spool'(007).
perform fill_cell using 1 8 1 000 'Records Upl'(008).
perform fill_cell using 1 9 1 000 'Error'(009).
perform fill_cell using 1 10 1 000 'Total'(010).
perform fill_cell using 1 11 1 000 'Action'(011).
perform fill_cell using 1 12 1 000 'ReRun'(012).
loop at t_final.
copy datato active EXCEL sheet
h = sy-tabix + 1.
perform fill_cell using h 1 0 000 t_final-jobname.
perform fill_cell using h 2 0 000 t_final-variant.
perform fill_cell using h 3 0 000 t_final-description.
perform fill_cell using h 4 0 000 t_final-strtdate.
perform fill_cell using h 5 0 000 t_final-strttime.
perform fill_cell using h 6 0 000 t_final-duration.
perform fill_cell using h 7 0 000 t_final-listident.
perform fill_cell using h 8 0 000 t_final-rec_upl.
perform fill_cell using h 9 0 000 t_final-rec_err.
perform fill_cell using h 10 0 000 t_final-rec_tot.
if t_final-comment eq 'job did not run'.
perform fill_cell using h 11 0 200 t_final-comment.
elseif t_final-rec_err eq 0.
perform fill_cell using h 11 0 000 t_final-comment.
else.
perform fill_cell using h 11 0 200 t_final-comment.
endif.
perform fill_cell using h 12 0 000 t_final-rerun.
endloop.
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
call method of h_excel 'Worksheets' = h_mapl." EXPORTIN G #1 = 2.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map exporting #1 = 2.
perform err_hdl.
tell user what is going on
set property of h_map 'NAME' = 'COPY'.
loop at t_final.
copy flights to active EXCEL sheet
h = sy-tabix + 1.
perform fill_cell using h 1 0 000 t_final-jobname.
perform fill_cell using h 2 0 000 t_final-variant.
perform fill_cell using h 3 0 000 t_final-description.
perform fill_cell using h 4 0 000 t_final-strtdate.
perform fill_cell using h 5 0 000 t_final-strttime.
perform fill_cell using h 6 0 000 t_final-duration.
perform fill_cell using h 7 0 000 t_final-listident.
perform fill_cell using h 8 0 000 t_final-rec_upl.
perform fill_cell using h 9 0 000 t_final-rec_err.
perform fill_cell using h 10 0 000 t_final-rec_tot.
if t_final-comment eq 'job did not run'.
perform fill_cell using h 11 0 200 t_final-comment.
elseif t_final-rec_err eq 0.
perform fill_cell using h 11 0 000 t_final-comment.
else.
perform fill_cell using h 11 0 200 t_final-comment.
endif.
perform fill_cell using h 12 0 000 t_final-rerun.
endloop.
free object h_excel.
perform err_hdl.
*& Form ERR_HDL
outputs OLE error if any *
form err_hdl.
if sy-subrc <> 0.
write: / 'Batch Job Automation Carried Out Succesfully'.
stop.
endif.
endform. " ERR_HDL .
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
form fill_cell using i j bold col val.
call method of h_excel 'Cells' = h_zl exporting #1 = i #2 = j.
perform err_hdl.
set property of h_zl 'Value' = val .
perform err_hdl.
get property of h_zl 'Font' = h_f.
perform err_hdl.
set property of h_f 'Bold' = bold .
perform err_hdl.
set property of h_f 'Color' = col.
perform err_hdl.
endform. "FILL_CELLHi,
You are populating the Cells one by one from the internal table, and all of them are coloured and font is bold. the method is OK, but when the amount of data is huge - it is going to take a longer time. May be the performance will improve a little if you turn the visibility off.
I ll suggest you to use ALV_XXL_CALL, it can color the key columns, at the same time you can have colored headings - and the performance is good. It is the same function module called when you do a "Export to Excel" from an ALV grid. But you can compain about the Font characteristics - as this does not change the Font size etc.
Your code has got a lot of freedom as long as the formatting is concerned - for bigger data - i ll suggest you to use a WS_DOWNLOAD kind of a function module to get the data at once in the presentation server and then call Excel methods and do the formatting. -
Download internal table to Excel sheet
Hi,
I am trying a sampole program to download an internal table to excel and am
uisng the Fm GUI_DOWNLOAD for the same. But how do I ensure that each column
of internal will be aligned as columns in the excel sheet to. I a trying to do
that with a separator but I am not able to figure out.
Below is my code.
REPORT z_excel_download.
DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
DATA : BEGIN OF it_file OCCURS 0,
data(2000),
END OF it_file.
SELECT * FROM mara INTO TABLE it_mara UP TO 100 ROWS.
LOOP AT it_mara.
CONCATENATE it_mara-matnr
it_mara-ersda
it_mara-ernam
it_mara-pstat
it_mara-mtart
it_mara-mbrsh INTO it_file-data SEPARATED BY '/t'.
APPEND it_file.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = 'C:\Documents and Settings\XXXXXX\Desktop\test.xls'
TABLES
data_tab = it_file
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Thanks.Hi Varun,
On SDN are plenty of post where you can find the answer to your problem.
Please try the following code that I found here several years ago to resolve your problem.
Regards,
Eric
REPORT Excel.
TABLES:
sflight.
* header data................................
DATA :
header1 LIKE gxxlt_p-text VALUE 'Suresh',
header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.
* Internal table for holding the SFLIGHT data
DATA BEGIN OF t_sflight OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA END OF t_sflight.
* Internal table for holding the horizontal key.
DATA BEGIN OF t_hkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_h.
DATA END OF t_hkey .
* Internal table for holding the vertical key.
DATA BEGIN OF t_vkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_v.
DATA END OF t_vkey .
* Internal table for holding the online text....
DATA BEGIN OF t_online OCCURS 0.
INCLUDE STRUCTURE gxxlt_o.
DATA END OF t_online.
* Internal table to hold print text.............
DATA BEGIN OF t_print OCCURS 0.
INCLUDE STRUCTURE gxxlt_p.
DATA END OF t_print.
* Internal table to hold SEMA data..............
DATA BEGIN OF t_sema OCCURS 0.
INCLUDE STRUCTURE gxxlt_s.
DATA END OF t_sema.
* Retreiving data from sflight.
SELECT * FROM sflight
INTO TABLE t_sflight.
* Text which will be displayed online is declared here....
t_online-line_no = '1'.
t_online-info_name = 'Created by'.
t_online-info_value = 'SURESH KUMAR PARVATHANENI'.
APPEND t_online.
* Text which will be printed out..........................
t_print-hf = 'H'.
t_print-lcr = 'L'.
t_print-line_no = '1'.
t_print-text = 'This is the header'.
APPEND t_print.
t_print-hf = 'F'.
t_print-lcr = 'C'.
t_print-line_no = '1'.
t_print-text = 'This is the footer'.
APPEND t_print.
* Defining the vertical key columns.......
t_vkey-col_no = '1'.
t_vkey-col_name = 'MANDT'.
APPEND t_vkey.
t_vkey-col_no = '2'.
t_vkey-col_name = 'CARRID'.
APPEND t_vkey.
t_vkey-col_no = '3'.
t_vkey-col_name = 'CONNID'.
APPEND t_vkey.
t_vkey-col_no = '4'.
t_vkey-col_name = 'FLDATE'.
APPEND t_vkey.
* Header text for the data columns................
t_hkey-row_no = '1'.
t_hkey-col_no = 1.
t_hkey-col_name = 'PRICE'.
APPEND t_hkey.
t_hkey-col_no = 2.
t_hkey-col_name = 'CURRENCY'.
APPEND t_hkey.
t_hkey-col_no = 3.
t_hkey-col_name = 'PLANETYPE'.
APPEND t_hkey.
t_hkey-col_no = 4.
t_hkey-col_name = 'SEATSMAX'.
APPEND t_hkey.
t_hkey-col_no = 5.
t_hkey-col_name = 'SEATSOCC'.
APPEND t_hkey.
t_hkey-col_no = 6.
t_hkey-col_name = 'PAYMENTSUM'.
APPEND t_hkey.
* populating the SEMA data..........................
t_sema-col_no = 1.
t_sema-col_typ = 'STR'.
t_sema-col_ops = 'DFT'.
APPEND t_sema.
t_sema-col_no = 2.
APPEND t_sema.
t_sema-col_no = 3.
APPEND t_sema.
t_sema-col_no = 4.
APPEND t_sema.
t_sema-col_no = 5.
APPEND t_sema.
t_sema-col_no = 6.
APPEND t_sema.
t_sema-col_no = 7.
APPEND t_sema.
t_sema-col_no = 8.
APPEND t_sema.
t_sema-col_no = 9.
APPEND t_sema.
t_sema-col_no = 10.
t_sema-col_typ = 'NUM'.
t_sema-col_ops = 'ADD'.
APPEND t_sema.
CALL FUNCTION 'XXL_FULL_API'
EXPORTING
* DATA_ENDING_AT = 54
* DATA_STARTING_AT = 5
filename = 'TESTFILE'
header_1 = header1
header_2 = header2
no_dialog = 'X'
no_start = ' '
n_att_cols = 6
n_hrz_keys = 1
n_vrt_keys = 4
sema_type = 'X'
* SO_TITLE = ' '
TABLES
data = t_sflight
hkey = t_hkey
online_text = t_online
print_text = t_print
sema = t_sema
vkey = t_vkey
EXCEPTIONS
cancelled_by_user = 1
data_too_big = 2
dim_mismatch_data = 3
dim_mismatch_sema = 4
dim_mismatch_vkey = 5
error_in_hkey = 6
error_in_sema = 7
file_open_error = 8
file_write_error = 9
inv_data_range = 10
inv_winsys = 11
inv_xxl = 12
OTHERS = 13
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF. -
Urgent:download data in differnt tabs of excel sheet
Hi,
I want to save data from internal table to different worksheet of an excel sheet file without using ole. I am having thousands of record in my internal table. Currently I am doing this by using OLE but its response time is very high. Plz suggest any other method with which we can do it fast.
rely will be suitably rewarded
Edited by: amit manglik on Jan 28, 2008 10:23 AM
Edited by: amit manglik on Jan 29, 2008 10:18 AMhi,
Refer sample code:
Multiple excel sheets generation in a workbook
CREATE OBJECT EXCEL 'EXCEL.SHEET'.
GET PROPERTY OF EXCEL 'Application' = APPLICATION.
SET PROPERTY OF APPLICATION 'Visible' = 1.
CALL METHOD OF APPLICATION 'Workbooks' = BOOKS.
CALL METHOD OF BOOKS 'Add' = BOOK.
CALL METHOD OF BOOK 'WORKSHEETS' = SHEET.
CALL METHOD OF SHEET 'ADD'.
Fill all the sheets with relavant data
PERFORM SHEET1 TABLES ITAB1.
PERFORM SHEET2 TABLES ITAB2.
PERFORM SHEET3 TABLES ITAB3.
PERFORM SHEET4 TABLES ITAB4.
Quit the excel after use
CALL METHOD OF EXCEL 'QUIT'.
FREE OBJECT: COLUMN,SHEET,BOOK,BOOKS,APPLICATION,EXCEL. "NO FLUSH.
CLEAR V_SHEET.
FORM FILL_CELL USING ROW COL VAL.
CALL METHOD OF SHEET 'cells' = CELL NO FLUSH
EXPORTING #1 = ROW #2 = COL.
SET PROPERTY OF CELL 'value' = VAL.
FREE OBJECT CELL NO FLUSH.
ENDFORM. " FILL_CELL
FORM SHEET1 TABLES ITAB1 STRUCTURE ITAB1.
V_SHEET = Sheet Name.
V_NO = V_NO + 1.
CALL METHOD OF BOOK 'worksheets' = SHEET NO FLUSH EXPORTING #1 = V_NO.
SET PROPERTY OF SHEET 'Name' = V_SHEET NO FLUSH.
PERFORM FILL_SHEET1 TABLES ITAB1 USING V_NO V_SHEET.
CALL METHOD OF SHEET 'Columns' = COLUMN.
FREE OBJECT SHEET.
CALL METHOD OF COLUMN 'Autofit'.
FREE OBJECT COLUMN.
ENDFORM.
Repeat above procedure for all sheets you want to add
FORM FILL_SHEET1
TABLES ITAB1 STRUCTURE ITAB1
USING V_NO V_SHEET.
ROW = 1.
PERFORM FILL_CELL USING ROW 1 'Column1 Name'.
PERFORM FILL_CELL USING ROW 2 'Column2 Name'.
PERFORM FILL_CELL USING ROW 3 'Column3 Name'.
ROW = ROW + 1.
LOOP AT ITAB1.
PERFORM FILL_CELL USING ROW 1 ITAB1-Column1.
PERFORM FILL_CELL USING ROW 2 ITAB1-Column2.
PERFORM FILL_CELL USING ROW 3 ITAB1-Column3.
ROW = ROW + 1.
ENDLOOP.
ENDFORM.
Repeat above procedure for all sheets you want to add
Also follow this link, for a simillar kind of download program.
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/c05db2ca-569e-2910-0784-fc06cc3be31d
Hope this helps, Do reward. -
Need to download data of many tables in excel.
Hi
I have a requirement to download the data of more then one database tables into one excel sheet.
Can any one let me know how i can doe this?
WBRS,
AmarAmar,
(1) First get the data of different tables into seperate internal table.
(2) Move the all internal table in one final internl table.
(3) Using 'WS_DOWNLOAD' Fm you can download the final internal table in excel format.
I will have send if you need a sample code.
You can search lots of stuff in SDN, before posting ....
Thanks,
Veera -
Downloading from Internal table to Excel
Hi All,
My requirement is download to Excel sheet, but in my internal table i have more than 95,000 record
(max limit in Excel sheet is 65535).
Please help me out by providing your solutions.
note: here i know one solution, by splitting into two files but no.of records are mis-macthing.
and one more issue when uploading the file we need to mention two file names.
hope this is not suggesstable.
Thanks in Advance
Madhavi.hi,
try this
Parameters: P_file like RLGRAP-FILENAME.
data : begin of int_head occurs 0,
Filed1(20) type c, " Header Data
end of int_head.
data : begin of int_data occurs 0,
Field1(20) type c, " Data
Field2(20) type c,
Field3(20) type c,
Field4(20) type c,
end of int_data.
int_head-Filed1 = 'Sales Ord'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Sold-to-Party'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Purchase Ord'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Ship-to-Party'.
APPEND int_head.
CLEAR int_head.
int_data-field1 = '1JOHN'.
int_data-field2 = '2TOM'.
int_data-field3 = '3BRAD'.
int_data-field4 = '4PETER'.
Append int_data.
Clear int_data.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = p_file " path offile where u need to download
CREATE_PIVOT = 0
DATA_SHEET_NAME = ' '
PIVOT_SHEET_NAME = ' '
PASSWORD = ' '
PASSWORD_OPTION = 0
TABLES
PIVOT_FIELD_TAB =
data_tab = int_data "internal table with data
fieldnames = int_head "internal table with header
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
OTHERS = 9
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
Store data from a table into excel sheet and email
Hi all,
I am just wondering, i m not sure where to start. I want to insert data from a table into an excel spread sheet.
I'm working on a stored procedure with 3 input parameters:
1. the actual query
2. userid
3. the column headers (comma separated) - these will be in the same order as the outer select statement in the query itself. I will use the column headers for the respective columns in Excel worksheet.
When the proc is executed, the excel is populated. If the record count is > 65536, then I need to create multiple worksheets in the same excel file.
How can i do that? Can any body please help with this..?We are doing like this ( Not sure whether it is the best method available)
--Get the output of the query (Since the number of columns is not fixed you would have to use dbms_sql package)
--loop through the output and write into a file, for example test.csv, using UTL_FILE package
--load the file into a blob variable(we are doing it by loading it into a table)
--For mailing You can use the below package
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
Mailing code we are using is given below:
CREATE OR REPLACE procedure xls_mail(
p_sender varchar2, -- sender, example: 'Me <[email protected]>'
p_recipients varchar2, -- recipients, example: 'Someone <[email protected]>'
p_subject varchar2, -- subject
p_text varchar2, -- text
p_filename varchar2, -- name of xls file
p_blob blob -- xls file
) is
conn utl_smtp.connection;
i number;
len number;
BEGIN
conn := demo_mail.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => demo_mail.MULTIPART_MIME_TYPE);
demo_mail.begin_attachment(
conn => conn,
mime_type => 'application/xls',
inline => TRUE,
filename => p_filename,
transfer_enc => 'base64');
-- split the Base64 encoded attachment into multiple lines
i := 1;
len := DBMS_LOB.getLength(p_blob);
WHILE (i < len) LOOP
IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
ELSE
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, (len - i)+1, i)));
END IF;
UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
END LOOP;
demo_mail.end_attachment(conn => conn);
demo_mail.attach_text(
conn => conn,
data => p_text,
mime_type => 'text/html');
demo_mail.end_mail( conn => conn );
END; -
Uploading internal table to Excel sheet
Hi Experts,
I am downloading data from Excel file which is saved on local desktop i.e. Presentation server into internal table.
Changing internal table data and uploading it back to same Excel sheet
Tried using FM 'MS_EXCEL_OLE_STANDARD_DAT'.
Issues faced:
1) New file is getting generated and existing one is not getting edited.
2) While executing the program the newly created Excel file opens as a pop up. I want to avoid this.
Please help.Hi
PARAMETER P_file like RLGRAP-FILENAME
data : begin of int_head occurs 0,
Filed1(20) type c, " Header Data
end of int_head.
int_head-Filed1 = 'PLTNY'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'WERKS'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'KTEXT'.
APPEND int_head.
CLEAR int_head.
Select plnty werks ktext from plko into CORRESPONDING FIELDS OF TABLE itab
Where plnty = 'Q' .
v_filetype = '.xls'. "I just manipulate the file name using XLS file type.
v_filename = p_file.
CONCATENATE p_file v_filetype INTO lv_filename.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_filename
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = ITAB
FIELDNAMES = int_head
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
ENDIF.
ENDFORM. -
How to save Internal table into Excel Sheet in App. Sever in Background
How can i save my file int excel in application server in background.
i am able to do in fronend but not in back ground.HI
see this example code where i had write EXCEL to INTERNAL TABLE and then TO APPLICATION SERVER
assign this program to background thats all
REPORT ZSD_EXCEL_INT_APP.
parameter: file_nm type localfile.
types : begin of it_tab1,
f1(20),
f2(40),
f3(20),
end of it_tab1.
data : it_tab type table of ALSMEX_TABLINE with header line,
file type rlgrap-filename.
data : it_tab2 type it_tab1 occurs 1,
wa_tab2 type it_tab1,
w_message(100) TYPE c.
at selection-screen on value-request for file_nm.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
* PROGRAM_NAME = SYST-REPID
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
STATIC = 'X'
* MASK = ' '
CHANGING
file_name = file_nm
EXCEPTIONS
MASK_TOO_LONG = 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.
start-of-selection.
refresh it_tab2[].clear wa_tab2.
file = file_nm.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '10'
i_end_row = '35'
tables
intern = it_tab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at it_tab.
case it_tab-col.
when '002'.
wa_tab2-f1 = it_tab-value.
when '004'.
wa_tab2-f2 = it_tab-value.
when '008'.
wa_tab2-f3 = it_tab-value.
endcase.
at end of row.
append wa_tab2 to it_tab2.
clear wa_tab2.
endat.
endloop.
data : p_file TYPE rlgrap-filename value 'TEST3.txt'.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
*--- Display error messages if any.
IF sy-subrc NE 0.
MESSAGE e001(zsd_mes).
EXIT.
ELSE.
*---Data is downloaded to the application server file path
LOOP AT it_tab2 INTO wa_tab2.
TRANSFER wa_tab2 TO p_file.
ENDLOOP.
ENDIF.
*--Close the Application server file (Mandatory).
CLOSE DATASET p_file.
loop at it_tab2 into wa_tab2.
write : / wa_tab2-f1,wa_tab2-f2,wa_tab2-f3.
endloop. -
Hi
I am using ALV Classe concept. I have one requirement in which I need to transfer internal table data to excel sheet. how to implement this requirement. Cud u pls suggest.
regards,
Naseer.You can use the method cl_gui_frontend_services=>gui_download
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
filename = 'C:temptest.xls'
filetype = 'DAT'
CHANGING
data_tab = datatab
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 24.
Regards,
Naimesh Patel -
Regarding downloading data into excel from internal table
hi all ,
i'm using the function module SAP_CONVERT_TO_XLS_FORMAT to download data of internal table into excel . now i need to know . when user presses the button for downlading it should download after downloading if he again tries to download it in the same should not allow him to download or it should refresh the excel of the speecific path and then it should downlaod . please let me know how make it.Hi,
Use below FM
call function 'MS_EXCEL_OLE_STANDARD_DAT'
exporting
file_name = p_file " path offile where u need to download
CREATE_PIVOT = 0
DATA_SHEET_NAME = ' '
PIVOT_SHEET_NAME = ' '
PASSWORD = ' '
PASSWORD_OPTION = 0
tables
PIVOT_FIELD_TAB =
data_tab = <dyn_table> "internal table with data
*fieldnames = int_head "internal table with header
exceptions
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
others = 9
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Regards,
Prashant -
How to export the data from table to excel sheet
hi experts i have some problem am trying to export the data fro table to Excel sheet in the view controller i have created one button wit public void onActionCLEAR(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionCLEAR(ServerEvent)
//wdContext.nodeBapi_Salesorder_Getlist_Input().
//wdContext.nodeBapi_Salesorder_Getlist_Input().invalidate();
//@@end
//@@begin javadoc:onActionExporToExcel(ServerEvent)
/** Declared validating event handler. */
//@@end
public void onActionExporToExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionExporToExcel(ServerEvent)
try{
FileOutputStream fos=new FileOutputStream("Test.xls");
PrintStream ps=new PrintStream(fos);
ps.println("<html><body><table border=1>");
int size=wdContext.nodeBapi_Salesorder_Getlist_Input().size();
Iterator attributes=wdContext.getNodeInfo().iterateAttributes();
ps.println("<tr>");
while(attributes.hasNext()){
ps.println("<th>");
DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
ps.println(attrName.getName());
ps.println("</th>");
ps.println("</tr>");
for(int i=0; i<wdContext.nodeBapi_Salesorder_Getlist_Input().size();i++)
attributes=wdContext.getNodeInfo().iterateAttributes();
ps.println("<tr>");
IWDNodeElement ele=wdContext.getElementAt(i);
while(attributes.hasNext()){
ps.println("<td>");
DataAttributeInfo attrName=(DataAttributeInfo)attributes.next();
ps.println(""+ele.getAttributeAsText(attrName.getName()));
ps.println("</td>");
ps.println("</tr>");
ps.println("</table></body></html>");
ps.flush();
ps.close();
fos.close();
catch(Exception e){
wdComponentAPI.getMessageManager().reportException(e.getMessage(), false);
finally{
//return("Test.xls") ;
//@@end
}h action and i have return the code
its running sucessfully but am not able to perform the action plz help meHi,
You shouldn't use DataAttributeInfo as it is an internal object, if I'm correct.
Use IWDAttributeInfo instead of DataAttributeInfo and it should work
(See also API doc of IWDNodeInfo.iterateAttributes() at http://help.sap.com/javadocs/nwce/ce711sp02/wdr/com.sap.wdr/com/sap/tc/webdynpro/progmodel/api/IWDNodeInfo.html#iterateAttributes())
Cheers,
Robin -
FM to download internal table to excel
Hi all,
I want to download my internal table into excel sheet. For this i am using FM
<b>GUI_DOWNLOAD</b>. But in my internal table each record is of around <b>400</b> char. length. I think because of this the downloaded <b>content is not proper</b> i.e. in junk format. Please sugest some solution for this.
Regards,
Vinod.Hi Vinod,
Try this program.Just copy and paste this program....
REPORT zpck_download_to_excel .
INCLUDE ole2incl.
DATA: w_cell1 TYPE ole2_object,
w_cell2 TYPE ole2_object.
*--- Ole data Declarations
DATA: h_excel TYPE ole2_object, " Excel object
h_mapl TYPE ole2_object, " list of workbooks
h_map TYPE ole2_object, " workbook
h_zl TYPE ole2_object, " cell
h_f TYPE ole2_object, " font
gs_interior TYPE ole2_object, " Pattern
worksheet TYPE ole2_object,
h_cell TYPE ole2_object,
h_cell1 TYPE ole2_object,
range TYPE ole2_object,
h_sheet2 TYPE ole2_object,
h_sheet3 TYPE ole2_object,
gs_font TYPE ole2_object,
flg_stop(1) TYPE c.
Internal table Declaration
DATA : t_excel_t076m LIKE t076m OCCURS 0 WITH HEADER LINE.
TYPES: data1(1500) TYPE c,
ty TYPE TABLE OF data1.
DATA: it TYPE ty WITH HEADER LINE,
it_2 TYPE ty WITH HEADER LINE.
DATA: rec TYPE sy-tfill,
deli(1) TYPE c,
l_amt(18) TYPE c.
DATA: BEGIN OF hex,
tab TYPE x,
END OF hex.
DATA: l_rc TYPE i.
FIELD-SYMBOLS: <fs> .
CONSTANTS cns_09(2) TYPE n VALUE 09.
ASSIGN deli TO <fs> TYPE 'X'.
hex-tab = cns_09.
<fs> = hex-tab.
DATA gv_sheet_name(20) TYPE c .
M A C R O Declaration
DEFINE ole_check_error.
if &1 ne 0.
message e002(zz) with &1.
exit.
endif.
END-OF-DEFINITION.
Fetching Data
SELECT * FROM t076m INTO TABLE t_excel_t076m.
LOOP AT t_excel_t076m.
CONCATENATE
t_excel_t076m-parart
t_excel_t076m-konto
t_excel_t076m-mwart
t_excel_t076m-mwsatz
t_excel_t076m-land1
t_excel_t076m-mwskz
INTO it
SEPARATED BY deli.
APPEND it.
CLEAR it.
ENDLOOP.
IF h_excel-header = space OR h_excel-handle = -1.
start Excel
CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
ENDIF.
*--- get list of workbooks, initially empty
CALL METHOD OF h_excel 'Workbooks' = h_mapl.
SET PROPERTY OF h_excel 'Visible' = 1.
add a new workbook
CALL METHOD OF h_mapl 'Add' = h_map.
Name of the T076
gv_sheet_name = 'T076M'.
GET PROPERTY OF h_excel 'ACTIVESHEET' = worksheet.
SET PROPERTY OF worksheet 'Name' = gv_sheet_name .
CALL METHOD cl_gui_frontend_services=>clipboard_export
IMPORTING
data = it[]
CHANGING
rc = l_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
OTHERS = 4.
Get the First row and col
CALL METHOD OF h_excel 'Cells' = w_cell1
EXPORTING
#1 = 1
#2 = 1.
Get the 255 row and col
CALL METHOD OF h_excel 'Cells' = w_cell2
EXPORTING
#1 = 5000
#2 = 6.
Select the Data
CALL METHOD OF h_excel 'Range' = range
EXPORTING
#1 = w_cell1
#2 = w_cell2.
CALL METHOD OF range 'Select'.
CALL METHOD OF worksheet 'Paste'.
*--- disconnect from Excel
FREE OBJECT h_zl.
FREE OBJECT h_mapl.
FREE OBJECT h_map.
FREE OBJECT h_excel.
Hope it helps you.
Reward points if helpful.
Regards,
Chitra.
Maybe you are looking for
-
HT201210 Itunes will not reconize my 2G Apple TV box why? and how do I fix it?
Why won't itunes reconize my second generation apple tv box?
-
LG monitor not working with iMac
I just bought a LG IPS 226v-PN monitor and am using a mini-dsiplayport to HDMI adapter to connect. The monitor was automatically found and I can see and use it as a dual monitor but I am seen a snow like effect on the screen with pixel randomly activ
-
How do I add a sharp to chords in Notation
How can I add a sharp to the chords for example C7(sharp9)in the notation. I do not have a sharp sign on my Mac keyboard. Somehow the notation program in Logic is not as user friendly as Cubase. Can one change the amount of bars per leger line and is
-
How does one remove a shape?
I have put down a number of retangular SHAPEs in copper. Some went down correctly, some didn't. I seem to be unable to delete, or even edit, the undesirable shapes. The basic problem may be an inability to actually select the shape. The procedures g
-
Smart guides, please fix them adobe
After CS3 smart guides became useless. AN UPDATE IS NEEDED!