on 04-29-2008 4:45 PM
Hi,
i am using ALV table display.for that i used the standard component SALV_WDR_TABLE.
so we get standard buttons like Print and Export to Excelsheet.
my requirement is when i click on the button 'Export to Excelsheet' i need to export the selected records from the ALV list display to the ExcelSheet.How to do this.and where to write the method code for this?
Hi Lakshmi
I think instead of using standard button . you can hide standard button and create new button on ALV and write your own functionality for that.
Here is the code for creating new button and hiding standard buttons.
data: l_ref_cmp_usage type ref to if_wd_component_usage,
lr_std TYPE REF TO if_salv_wd_std_functions.
DATA: l_ref_INTERFACECONTROLLER TYPE REF TO IWCI_SALV_WD_TABLE .
DATA : lr_table_settings TYPE REF TO if_salv_wd_table_settings.
l_ref_cmp_usage = wd_This->wd_CpUse_Appr( ).
if l_ref_cmp_usage->has_active_component( ) is initial.
l_ref_cmp_usage->create_component( ).
endif.
l_ref_INTERFACECONTROLLER = wd_This->wd_CpIfc_Appr( ).
data:
l_VALUE type ref to Cl_Salv_Wd_Config_Table.
l_VALUE = l_ref_INTERFACECONTROLLER->Get_Model(
).
lr_table_settings ?= l_value.
lr_std ?= l_value.
lr_table_settings->set_read_only( abap_false ).
lr_table_settings->set_width( '100%').
lr_std->set_edit_check_available( abap_false ).
lr_std->set_edit_append_row_allowed( abap_false ).
lr_std->set_edit_check_available( abap_false ).
lr_std->set_edit_delete_row_allowed( abap_false ).
lr_std->set_EXCEL_INPLACE_ALLOWED( abap_true ).
lr_std->set_edit_insert_row_allowed( abap_false ).
lr_std->SET_EXPORT_ALLOWED( abap_false ).
lr_std->SET_PDF_ALLOWED( abap_false ).
data: lr_user_function1 type ref to cl_salv_wd_function.
data:lr_user_function1 = l_value->if_salv_wd_function_settings~create_function_right( id = 'DISA' ).
data: lr_disp_button type ref to cl_salv_wd_fe_button.
lv_button_text type string.
create object lr_disp_button.
lv_button_text = 'Display'.
lr_disp_button->set_text( lv_button_text ).
lr_disp_button->SET_IMAGE_SOURCE( 'ICON_DISPLAY' ).
lr_user_function1->set_editor( lr_disp_button ).
l_VALUE = l_ref_INTERFACECONTROLLER->Get_Model(
).
Regards
Naresh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for the reply.
I know how to create self defined buttons.but i need to use the standard button.So for this i think we can use ON_STD_FUNCTION_AFTE event handler.
but i need to export the selected rows from ALV list display to the Microsoft Excel Sheet.can any one give me the sample code or an idea ?
Hi Lakshmi
You can use the following code
data : lr_conv type ref to CL_ABAP_CONV_OUT_CE,
xml_out type string,
lv_content type xstring.
tab_sub is the internal table
CALL TRANSFORMATION ('ID')
SOURCE tab2 = tab_sub
RESULT XML xml_out.
lr_conv = cl_abap_conv_out_ce=>create( encoding = 'UTF-8' ).
CALL FUNCTION 'CRM_IC_XML_STRING2XSTRING'
EXPORTING
INSTRING = xml_out
*
IMPORTING
OUTXSTRING = lv_content.
cl_wd_runtime_services=>attach_file_to_response(
i_filename = 'file.xls'
i_content = lv_content
i_mime_type = 'x-excel/application'
i_in_new_window = abap_true ).
Regards
Naresh
Hi,
I worked the same functionality. I will give you the logic, Please implement it.
1. Create Custom Button for Export instead of Standard button
2. Write the code for this button as follow
- Get the all selected records, I hope you may have one of the field is Primary field which is unique for each record
- You already uploaded the data into your ALV Corresponding node. so get the data and filter with selected records using primary key field.
- Now you got the selected records information in your internal table
Do the following code to download the file
data: converter TYPE REF TO cl_rpe_convert.
CREATE OBJECT converter.
CALL METHOD CONVERTER->TRANSFORM_TO_XML
EXPORTING
DATA = lt_employees
TAGNAME = 'XMLSTR' "'ZPDS_ALL_EMPLOYEES'
IGNORE_INIT_VALUE =
CHANGING
XML = XMLSTR
EXCEPTIONS
XML_WRITE_ERROR = 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.
Concatenate 'C:\PDS export' sy-datum '.xls' into lv_file_name separated by space.
cl_wd_runtime_services=>attach_file_to_response(
EXPORTING
i_filename = lv_file_name
i_content = XMLSTR
i_mime_type = 'application/vnd.ms-excel' ).
3. I hope this solve your problem.
Please let me know if you face any other problem. i will try to help you.
All the best,
Bye
Vijay
Hi Naresh,
The Export to Spreadsheet standar button functionality in the ALV is working properly, you dont need to write seperate code for that, Once you get the data in the ALV, check off the popup blocker and try to download it from the standard button in the ALV. it will open a dialog box asking whether you want to save the file or open it.
Check it and see..
Cheers
Mary
User | Count |
---|---|
78 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.