02-03-2014 5:11 AM
Hello,
I have got a request from user to develope a report where he want to download the report displayed in excel sheet. I know about the export button available on grid and also the WS_DOWNLOAD FM which exports the internal table to spreadsheet.
My requirement is when user downloads the data displayed in grid, he want to do some operations on the data in background for some selective fields , so even it is showing value 'X' for particular field, it will process and download value 'Z' for that field. Out of 20 columns he can hide any number of columns as per his requirement and should be able to download only those visible columns on grid on button press.
Please let me know if anybody has worked on such requirement.
Thanks,
Shriniwas
02-03-2014 5:21 AM
HI,
First of all create a button in the ALV toolbar to export to excel sheet.
In the user command, for the function code for this export button, say &EXP, implement it like this.
(Assuming you are using classic ALV)
DATA: file_path TYPE string,
ret_var TYPE i.
file_path = p_file.
IF r_ucomm = '&EXP'.
DATA ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.
* Delete if file already exists in the system.
CALL METHOD cl_gui_frontend_services=>file_delete
EXPORTING
filename = file_path
CHANGING
rc = ret_var
EXCEPTIONS
file_delete_failed = 1
cntl_error = 2
error_no_gui = 3
file_not_found = 4
access_denied = 5
unknown_error = 6
not_supported_by_gui = 7
wrong_parameter = 8
OTHERS = 9.
IF sy-subrc = 5.
MESSAGE i398(00) WITH text-013 text-014. "Check if file is already open or locked.
EXIT.
ENDIF.
CLEAR i_export.
* Populate header data
* Populate line details.
LOOP AT i_data INTO wa_data.
* Do formatting as required with the data.
................
MOVE-CORRESPONDING wa_data TO wa_export.
ENDLOOP.
* Convert to excel file and send it to the local system
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
i_filename = p_file
TABLES
i_tab_sap_data = i_export.
ENDIF.
02-03-2014 5:44 AM
Hi Shriniwas,
what i understand is based on selection the records will be download in excel format.
i have done like this kind of requirement i think it is help full for u..
declare the data types like this..
data w_no type sy_linno.
data a type c.
data v2 type c.
parameter p_file like ibipparms-path.
data w_file type string.
and declare the work area an internal tables.. fetch the data.. and display the data in ur grid format..
then after..
w_no = sy_linno.
set pf_status 'stat'.
at user_command.
if sy_ucomm = 'DOWNLOAD'.
do w_no times.
*reading the fields... and moving to another internal table to download that fields..
read line sy_index field value a into v2 wa_table-field into wa_field
wa_table-field into wa_field.
if v2 = 'X'.
append wa to it.
clear wa.
endif.
enddo.
at selection-screen on value-request for p_file.
call fm'f4_file'.
imp
file_name = p_file.
start-of-selection.
w_file = p_file.
call fm 'gui_download'
exp
file name = w_file
write_field_separater = 'X"
table
tata_tab = internal table.
refresh intrenal table.
i think this is help full to u..
02-06-2014 10:35 AM
Thanks Sushmitha and Shrini for your response.
My requirement was to download only those columns which are not hidden from gridview report.
I used GET_FRONTEND_FIELDCATALOG to create field catalog and then created a dybnamic table using
cl_alv_table_create=>create_dynamic_table(
EXPORTING
it_fieldcatalog = INT_FIELDCAT1
IMPORTING
ep_table = IT_DTAB ).
It hase resolved my problem.
THanks again.