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.
Similar Messages
-
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. -
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. -
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. -
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 data into xml file?
Hi,
Experts,
I have downloaded internal table data into XLS format using GUI_DOWNLOAD Function module, But i didn't Know how to download internal table data into XML format please post some ideas/inputs on this issue.
Thank you,
Shabeer ahmed.check this
data : gd_repid type sy-repid.
GD_REPID = SY-REPID.
DATA : L_DOM TYPE REF TO IF_IXML_ELEMENT,
M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
G_IXML TYPE REF TO IF_IXML,
W_STRING TYPE XSTRING,
W_SIZE TYPE I,
W_RESULT TYPE I,
W_LINE TYPE STRING,
IT_XML TYPE DCXMLLINES,
S_XML LIKE LINE OF IT_XML,
W_RC LIKE SY-SUBRC.
DATA: XML TYPE DCXMLLINES.
DATA: RC TYPE SY-SUBRC,
BEGIN OF XML_TAB OCCURS 0,
D LIKE LINE OF XML,
END OF XML_TAB.
data : l_element type ref to if_ixml_element,
xml_ns_prefix_sf type string,
xml_ns_uri_sf type string.
CLASS CL_IXML DEFINITION LOAD.
G_IXML = CL_IXML=>CREATE( ).
CHECK NOT G_IXML IS INITIAL.
M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
CHECK NOT M_DOCUMENT IS INITIAL.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'REPAIRDATA'
DATAOBJECT = IT_FINAL_LAST1[]
IMPORTING
DATA_AS_DOM = L_DOM
CHANGING
DOCUMENT = M_DOCUMENT
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
CHECK NOT L_DOM IS INITIAL.
W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
*Start of code for Header
* namespace
t_mnr = sy-datum+4(2).
CALL FUNCTION 'IDWT_READ_MONTH_TEXT'
EXPORTING
LANGU = 'E'
MONTH = t_mnr
IMPORTING
T247 = wa_t247
concatenate sy-datum+6(2)
wa_t247-ktx
sy-datum(4) into t_var1.
concatenate sy-uzeit(2)
sy-uzeit+2(2)
sy-uzeit+4(2) into t_var2.
clear : xml_ns_prefix_sf,
xml_ns_uri_sf.
l_element = m_document->get_root_element( ).
xml_ns_prefix_sf = 'TIMESTAMP'.
concatenate t_var1 t_var2 into xml_ns_uri_sf separated by space.
clear : t_var1,
t_var2,
t_mnr,
wa_t247.
l_element->set_attribute( name = xml_ns_prefix_sf
namespace = ' '
value = xml_ns_uri_sf ).
clear : xml_ns_prefix_sf,
xml_ns_uri_sf.
xml_ns_prefix_sf = 'FILECREATOR'.
xml_ns_uri_sf = 'SAP'.
l_element->set_attribute( name = xml_ns_prefix_sf
namespace = ' '
value = xml_ns_uri_sf ).
clear : xml_ns_prefix_sf,
xml_ns_uri_sf.
xml_ns_prefix_sf = 'CLAIMGROUP'.
xml_ns_uri_sf = '1'.
l_element->set_attribute( name = xml_ns_prefix_sf
namespace = ' '
value = xml_ns_uri_sf ).
clear : xml_ns_prefix_sf,
xml_ns_uri_sf.
xml_ns_prefix_sf = 'CLAIMTYPES'.
xml_ns_uri_sf = 'W'.
l_element->set_attribute( name = xml_ns_prefix_sf
namespace = ' '
value = xml_ns_uri_sf ).
*End of Code for Header
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
DOCUMENT = M_DOCUMENT
IMPORTING
XML_AS_STRING = W_STRING
SIZE = W_SIZE
TABLES
XML_AS_TABLE = IT_XML
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
LOOP AT IT_XML INTO XML_TAB-D.
APPEND XML_TAB.
ENDLOOP.
*Start of Code for File name
concatenate p_file
'\R'
'000_119481'
sy-datum+6(2) sy-datum+4(2) sy-datum+2(2)
sy-uzeit(2) sy-uzeit+2(2) sy-uzeit(2) '.xml' into p_file.
*End of Code for File name
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_SIZE
FILENAME = p_file
FILETYPE = 'BIN'
TABLES
DATA_TAB = XML_TAB
EXCEPTIONS
OTHERS = 10.
IF SY-SUBRC = 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
How to download internal table data to excel in WebUI
Hi everyone,
I am trying to download the contents of an internal table to excel in CRM Web UI.
One way, would be to create a table view and use the export to excel button.
However, wish to avoid this and directly download using code.
Also tried converting to xstring and setting data in the response object. However, this works only when I execute the component directly from BSP_WD_CMPWB. In the UI framework however, when I click on custom button(for download), it navigates to a screen where the contents of string are shown directly on browser.
Is there any other way of doing this?
Thanks in advance.
Regards,
DeepakHi,
there are two ways to download excel from the webclient using table views. The first is a XML stream that is send to Excel directly. Only works for Excel 2003 and later. The second is the fall back to a .csv.
I do not know if for the second option a direct connection is established as mentioned in the last post or there is actually a file stream send to the client.
Anyway the SAP provides the excel download through a seperate webservice. Have a look at CL_CHTMLB_CONFIG_TAB_EXCEL_EXP->IF_HTTP_EXTENSION~HANDLE_REQUEST( ).
I suppose going the same direction with your excel download will work. This service opens a new download stream with the excel content... Maybe it is even possible to copy it and adjust it to your needs...
cheers Carsten -
Download Internal table to Excel with different Tabs - ole2_object
Hi All,
I am using ole2_object to download the data from internal table to Excel file. As per different values in sorting key, data will be downloading in different tab in same Excel file.
In my internal table one field is of character type and some times contains number as value.
e.g. itab-code = 000002.
While downloading to Excel, Excel consider this value as numeric and remove the leading zero.
Any suggestions for how to set format property as Text for this cell, will highly appreciated.
Sample code -
data: gs_excel type ole2_object,
gs_wbooklist type ole2_object,
gs_application type ole2_object,
gs_wbook type ole2_object,
gs_activesheet type ole2_object,
gs_sheets type ole2_object,
gs_newsheet type ole2_object,
gs_cell type ole2_object.
create object gs_excel 'EXCEL.APPLICATION'.
get property of gs_excel 'workbooks' = gs_wbooklist.
get property of gs_wbooklist 'Application' = gs_application.
set property of gs_application 'SheetsInNewWorkbook' = 1.
call method of gs_wbooklist 'Add' = gs_wbook.
get property of gs_application 'ActiveSheet' = gs_activesheet.
set property of gs_activesheet 'Name' = datasheet_name.
call method of gs_excel 'Cells' = gs_cell exporting #1 = v_row
#2 = v_col.
set property of gs_cell 'value' = <f>.
GET PROPERTY OF gs_cell 'Font' = gs_Font.
SET PROPERTY OF gs_Font 'Bold' = 1 .
Thanks.
Regards,
Meenakshi.Hello,
Just concatenate ' infont of the fields, which you want to treat as a text.
Like,
itab-code = '00002'.
concatenate '''' itab-code into itab-code.
modify itab.
You can also set the text properties of the cell by,
SET PROPERTY OF gs_cell 'NumberFormat' = '@' .
but, it will remove the leading zeros and set the format as text.
Regards,
Naimesh -
How to download internal structure in Excel file ?
Hi,
In a ABAP 4.7 program, we need to download internal table/structures in a excel file. Automatically (as manually with breakpoint and Excel export button),
The SAP_CONVERT_TO_XLS_FORMAT doesn't work (empty file) certainly cause non STANDARD TABLE used.
There is various internal tables/structures, see one below
TYPES:
BEGIN OF gty_rup,
kunnr LIKE bsid-kunnr,
xref1 LIKE bsid-xref1,
xref3 LIKE bsid-xref3,
END OF gty_rup.
TYPES:
BEGIN OF gty_rup_tiers,
zztie LIKE bseg-zztie,
zzdat LIKE bseg-zzdat,
zzsea LIKE bseg-zzsea,
END OF gty_rup_tiers.
TYPES:
BEGIN OF gty_data_solde,
wrbtr LIKE bsid-wrbtr,
shkzg LIKE bsid-shkzg,
belnr LIKE bsid-belnr,
hkont LIKE bsid-hkont,
buzei LIKE bsid-buzei,
bldat LIKE bsid-bldat,
gjahr LIKE bsid-gjahr,
blart LIKE bsid-blart,
END OF gty_data_solde,
DATA:
BEGIN OF lt_prps OCCURS 0,
key_client TYPE gty_rup,
key_tiers TYPE gty_rup_tiers,
data TYPE gty_data_solde,
END OF lt_prps.
Does someone know function working with only the table/structure name as parameter ?
Thanks
Hervehere's what I did....I opened the xfile2.txt with Excel 2007 and stepped through the import wizard as a tab-delimited file. You're quite right it seems about the XLS function module.... I couldn't get a file downloaded that I could open with that thing. So I dropped it and just did the following:
TYPES: BEGIN OF gtypx.
INCLUDE TYPE gty_rup.
INCLUDE TYPE gty_rup_tiers.
INCLUDE TYPE gty_data_solde.
TYPES END OF gtypx.
DATA: lt_prps TYPE STANDARD TABLE OF gtypx WITH HEADER LINE.
START-OF-SELECTION.
lt_prps-kunnr = '1234'.
APPEND lt_prps.
LOOP AT lt_prps.
WRITE:/ lt_prps-kunnr.
ENDLOOP.
DATA: lv_filen type string value 'c:\xfile2.txt'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = lv_filen
FILETYPE = 'ASC'
* APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* WRITE_LF = 'X'
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
* NO_AUTH_CHECK = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* IMPORTING
* FILELENGTH =
tables
data_tab = lt_prps
* FIELDNAMES =
* 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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF. -
How to download internal table data to .xlsx file ?
Hello All,
I am using SAP ECC 6.0. I need to download internal table data to .xlsx file.
I tried GUI_DOWNLOAD, all the data are getting transferred to the .xlsx file, but while opening I am getting the below error.
Excel cannot open the file "download.xlsx" because file format or file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.
Though Microsoft office 2007 is installed in my system.
Please help <removed by moderator>.
Edited by: Thomas Zloch on Oct 24, 2011 10:55 AMHi,
Please find the below code to download data into excel file.
DATA: ld_filename TYPE string,
ld_path TYPE string,
ld_fullpath TYPE string,
ld_result TYPE i.
Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = ' '
DEFAULT_EXTENSION = 'XLS'
default_file_name = 'accountsdata'
INITIAL_DIRECTORY = 'c:\temp\'
CHANGING
filename = ld_filename
path = ld_path
fullpath = ld_fullpath
user_action = ld_result.
Check user did not cancel request
CHECK ld_result EQ '0'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = ld_fullpath
filetype = 'ASC'
APPEND = 'X'
write_field_separator = 'X'
CONFIRM_OVERWRITE = 'X'
TABLES
data_tab = it_datatab[] "need to declare and populate
EXCEPTIONS
file_open_error = 1
file_write_error = 2
OTHERS = 3.
Thanks and Regards
Chitra -
Download internal table to excel with header
Hi All,
I have a requirement to download internal table contents to excel with field headings. I tried searching in forums before posting but didn't got much help.
I have used GUI_DOWNLOAD, WS_DOWNLOAD and EXCEL_OLE_STANDARD_DAT.
But unable to download the header in excel..along with data...
EXCEL_OLE_STANDARD_DAT is getting field header in excel but not downloading automatically , need to save manually which is not the requirement.
The data is huge with around 151 columns....I got 2 internal tables.
One for the data and the other with field names.
Many Thanks,
Ravi KHi Ravi,
You need to have 2 different internal tables for achieving the needful. One internal table would be having your data and another would store your table field names i.e., declare a structure of length 100 characters,
TYPES : BEGIN OF GTY_FIELDNAMES,
TITLE(100),
END OF GTY_FIELDNAMES.
DATA: GIT_FIELDNAMES TYPE STANDARD TABLE OF GTY_FIELDNAMES,
GWA_FIELDNAMES TYPE GTY_FIELDNAMES.
DATA : GD_FILENAME TYPE STRING,
GD_PATH TYPE STRING,
GD_FULLPATH TYPE STRING,
GD_RESULT TYPE I.
Now have a subroutine where by you append your headings into the internal table i.e.,GIT_FIELDNAMES
CLEAR GWA_FIELDNAMES.
GWA_FIELDNAMES-TITLE = 'Material Number'.
APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.
CLEAR GWA_FIELDNAMES.
GWA_FIELDNAMES-TITLE = 'Material Description'.
APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.
Once you are done with it you can call up the save dialog
* Display save dialog window
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Save File As...'
DEFAULT_EXTENSION = 'XLS'
DEFAULT_FILE_NAME = 'SalesPlan'
INITIAL_DIRECTORY = 'C:\'
CHANGING
FILENAME = GD_FILENAME
PATH = GD_PATH
FULLPATH = GD_FULLPATH
USER_ACTION = GD_RESULT.
* Check user did not cancel request
CHECK GD_RESULT EQ '0'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = GD_FULLPATH
FILETYPE = 'ASC'
* APPEND = 'X'
WRITE_FIELD_SEPARATOR = 'X'
* CONFIRM_OVERWRITE = 'X'
TABLES
DATA_TAB = GIT_FINAL " Internal table having data
FIELDNAMES = GIT_FIELDNAMES " Internal table having headings
EXCEPTIONS
FILE_OPEN_ERROR = 1 "#EC ARGCHECKED
FILE_WRITE_ERROR = 2
OTHERS = 3.
Hope this gets sorted your problem.
Thanks & Regards,
Varun Kumar Sahu -
Function Module to Download Internal table in EXCEL
Hi All,
I need a Function Module to download the Internal table to Excel File.
I Have used SAP_CONVERT_TO_XLS_FORMAT,
but this function modules are using GUI_Download indirectly.
I dont want to use GUI_DOWNLOAD as i am going to call this Function Module in Portal.
So pls anybody has this type of function module.
Thanks & Regards,
Dhruv ShahHello Dhruv.
In Agreement with Deniz.
It is required to Export the query as an excel file.
[SAP HELP Library - Standard Reference - Exporting as a CSV File / MS Excel 2000 File|http://help.sap.com/saphelp_nw04/helpdata/en/d2/11a28fc26d4042a6d230a9783152f2/content.htm]
[SDN - Reference - Error in "Export to Microsoft Excel" from Portal|Error in "Export to Microsoft Excel" from Portal;
Hope this works out well.
Good Luck & Regards.
Harsh Dave -
Downloading internal table to excel
Hi, i have to download some data from an internal table to an excel file. all the fields in the internal table are strings, some of them look like a number (for example 32,45 or 123,01). Before downloading the internal table to excel i make a "conversion", as i want these fields to appear like "32.45" i replace ',' with '.', but when i download to excel, the fields appears with ','.... My problem is that I need to combine this excel with a Word document and the format with ',' is wrong........
I'm using function MS_EXCEL_OLE_STANDARD_DAT...
thanks in advance...Hi,
The following code will help u to splve the problem.
have a look,
TABLES: VBAK,VBAP.
DATA: BEGIN OF I_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN,
ERDAT LIKE VBAK-ERDAT,
ERNAM LIKE VBAK-ERNAM,
AUDAT LIKE VBAK-AUDAT,
VBTYP LIKE VBAK-VBTYP,
END OF I_VBAK.
DATA: BEGIN OF I_VBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
CHARG LIKE VBAP-CHARG,
MATKL LIKE VBAP-MATKL,
END OF I_VBAP.
DATA: BEGIN OF IT_VBAK OCCURS 0,
VBELN LIKE VBAK-VBELN,
ERDAT LIKE VBAK-ERDAT,
ERNAM LIKE VBAK-ERNAM,
AUDAT LIKE VBAK-AUDAT,
VBTYP LIKE VBAK-VBTYP,
POSNR LIKE VBAP-POSNR,
MATNR LIKE VBAP-MATNR,
CHARG LIKE VBAP-CHARG,
MATKL LIKE VBAP-MATKL,
END OF IT_VBAK.
SELECT VBELN ERDAT ERNAM AUDAT VBTYP FROM VBAK INTO TABLE I_VBAK.
SELECT VBELN POSNR MATNR CHARG MATKL FROM VBAP INTO TABLE I_VBAP.
SORT: I_VBAK BY VBELN,I_VBAP BY VBELN.
LOOP AT I_VBAK.
READ TABLE I_VBAP WITH KEY VBELN = I_VBAK-VBELN BINARY SEARCH.
IF SY-SUBRC = 0.
MOVE I_VBAK-VBELN TO IT_VBAK-VBELN.
MOVE I_VBAK-ERDAT TO IT_VBAK-ERDAT.
MOVE I_VBAK-ERNAM TO IT_VBAK-ERNAM.
MOVE I_VBAK-AUDAT TO IT_VBAK-AUDAT.
MOVE I_VBAK-VBTYP TO IT_VBAK-VBTYP.
MOVE I_VBAP-POSNR TO IT_VBAK-POSNR.
MOVE I_VBAP-MATNR TO IT_VBAK-MATNR.
MOVE I_VBAP-CHARG TO IT_VBAK-CHARG.
MOVE I_VBAP-MATKL TO IT_VBAK-MATKL.
APPEND IT_VBAK.
ENDIF.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = 'D:\C5.DOC'
FILETYPE = 'ASC' "Separate Columns by Tabs in Case of ASCII Download
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = 'X' "Overwrite The File Only After
Confirmation
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = IT_VBAK
FIELDNAMES =
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Reward points,if it is helpful.
Thanks,
chandu. -
Download Internal Table to Excel
Hi All,
I m new to Webdynpro for ABAP and i m trying to download the data as it is in the Internal Table to excel file using FM 'CRM_IC_XML_STRING2XSTRING' ( to convert string to xstring) and CLASS 'cl_wd_runtime_services=>attach_file_to_response' ( to attach the content in excel).
The export is working fine, but it also has some extra rows and columns with data "/asx:abap".
Also the header is appended with data like "/@version/#agg".
The columns were sorted by its name and gets interchanged and sometimes repeated too.
Is there a way to get the header formatted and trim the unwanted rows and columns appearing.
Thanks in advance,
Raju JHi Vankat,
In last thread i have posted that creating an XLST for the xml will solve the problem. But still it was working fine in MS Excel 2007 and not in the older versions in my case.
Again, i thought of following the method adviced by Radhika(in the previous post).
Loop your internal table and concatenate the content to a string variable SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
Then convert the string to XSTRING using the below FM.
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = l_outstream "Concatenated string
IMPORTING
buffer = l_content. "Resulted xstring
Then call the cl_wd_runtime_services as mentioned below.
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'filename.xls'
i_content = l_content "Resulted xstring
i_mime_type = 'EXCEL'
i_in_new_window = abap_true ).
This is one way and the other is,
If you want to do it using
CALL TRANSFORMATION ZXSLT "While creating ZXSLT select the prog. type as XSLT program.
SOURCE tab = internal_table[]
RESULT XML l_outstream.
Then convert the l_outstream to xstring and attach to cl_wd_runtime_services.
ZXSLT will contain code like this,
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:asx="http://www.sap.com/abapxml"
xmlns:x="urn:schemas-microsoft-com:office:excel">
<xsl:strip-space elements="*"/>
<xsl:template match="asx:abap/asx:values/TAB">
<items>
<xsl:for-each select = "item">
<it>
<OBJECT_ID><xsl:value-of select="OBJECT_ID"/></OBJECT_ID>
<DESCRIPTION><xsl:value-of select="DESCRIPTION"/></DESCRIPTION>
</it>
</xsl:for-each>
</items>
</xsl:template>
</xsl:transform>
I think this will solve your problem.
Regards,
Raju J -
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 advanceHi 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
Maybe you are looking for
-
What is tcode to create a credit memo ?
What is tcode to create a credit memo ? please tell me the steps ?
-
Our hard drive recently crashed. Luckily, the files were backed up. When my daughter recently opened Photo Booth, it told her it could not locate the library. If I choose "Choose Existing," it takes me to a few different photo libraries, including o
-
Openscript is supporting SOAP 1.2 protocol. Really?
Hello guys, can you help me with this one? I have an OpenScript project about testing web services and the SOAP protocol's version is 1.2. Even though in the documentation it says that OATS is supporting SOAP 1.2 I'm unable to locate which variable t
-
The Raw Image format from my Canon D7 are not recognised by Elements 6, although they are from my Canon D10, D30 and G10. Canon brush me off by telling me to contact Adobe. Can anyone please advise this 76 y.o. dinosaur of a solution? I certainly
-
Can i add regex to check forbidden words
Hi i want to set the forbidden words to be a regular expression can i? thanks in advance.