n OVP application, here a list UIBB is shown. Now we have a button like Show Excel.
Once this button is pressed, the list data should appear in an excel.
The table type and the line type.
List UIBB feeder class implemented interfaces.
Created an attribute.
Implemented GTE_DEFINITION method.
Implemented GET_DATA method.
Create an OVP application and application configuration and OVP component configuration.
Add the list UIBB configuration.
In list UIBB we have the below fields. Click on Toolbar Schema.
here ww have button with text as ‘Show Excel’ and event as ‘EXCEL_DISP’.
put the below logic in PROCESS_EVENT method under the event ‘EXCEL_DISP’.
METHOD if_fpm_guibb_list~process_event.
DATA: lt_spfli TYPE spfli_tab,
ls_spfli TYPE spfli,
lt_abap_comp_tab TYPE abap_component_tab,
lt_dfies TYPE ddfields,
lr_struct TYPE REF TO cl_abap_structdescr,
lr_struct_dynamic TYPE REF TO cl_abap_structdescr,
lr_table TYPE REF TO cl_abap_tabledescr,
lr_type TYPE REF TO cl_abap_typedescr,
lr_export TYPE REF TO data,
lv_xml_content TYPE xstring.
DATA: lt_spfli TYPE spfli_tab,
ls_spfli TYPE spfli,
lt_abap_comp_tab TYPE abap_component_tab,
lt_dfies TYPE ddfields,
lr_struct TYPE REF TO cl_abap_structdescr,
lr_struct_dynamic TYPE REF TO cl_abap_structdescr,
lr_table TYPE REF TO cl_abap_tabledescr,
lr_type TYPE REF TO cl_abap_typedescr,
lr_export TYPE REF TO data,
lv_xml_content TYPE xstring.
FIELD-SYMBOLS:
<fs_abap_component> TYPE LINE OF abap_component_tab,
<fs_header> TYPE any,
<fs_column_title> TYPE any,
<fs_item> TYPE any,
<fs_export> TYPE STANDARD TABLE,
<fs_dfies> TYPE LINE OF ddfields,
<fs_column> TYPE any.
<fs_header> TYPE any,
<fs_column_title> TYPE any,
<fs_item> TYPE any,
<fs_export> TYPE STANDARD TABLE,
<fs_dfies> TYPE LINE OF ddfields,
<fs_column> TYPE any.
CASE io_event->mv_event_id.
WHEN ‘EXCEL_DISP’.
lr_struct ?= cl_abap_typedescr=>describe_by_name( ‘SPFLI’ ).
lr_type = cl_abap_typedescr=>describe_by_name( ‘STRING’ ).
lt_dfies = lr_struct->get_ddic_field_list( ).
lr_struct ?= cl_abap_typedescr=>describe_by_name( ‘SPFLI’ ).
lr_type = cl_abap_typedescr=>describe_by_name( ‘STRING’ ).
lt_dfies = lr_struct->get_ddic_field_list( ).
LOOP AT lt_dfies ASSIGNING <fs_dfies>.
APPEND INITIAL LINE TO lt_abap_comp_tab ASSIGNING <fs_abap_component>.
<fs_abap_component>–name = <fs_dfies>–fieldname.
<fs_abap_component>–type ?= lr_type.
ENDLOOP.
lr_struct_dynamic = cl_abap_structdescr=>create( lt_abap_comp_tab ).
lr_table = cl_abap_tabledescr=>create( p_line_type = lr_struct_dynamic ).
CREATE DATA lr_export TYPE HANDLE lr_table.
ASSIGN lr_export->* TO <fs_export>.
APPEND INITIAL LINE TO <fs_export> ASSIGNING <fs_header>.
* Add the column title to the table
LOOP AT lt_dfies ASSIGNING <fs_dfies>.
ASSIGN COMPONENT ‘SCRTEXT_L’ OF STRUCTURE <fs_dfies> TO <fs_column>.
ASSIGN COMPONENT <fs_dfies>-fieldname
APPEND INITIAL LINE TO lt_abap_comp_tab ASSIGNING <fs_abap_component>.
<fs_abap_component>–name = <fs_dfies>–fieldname.
<fs_abap_component>–type ?= lr_type.
ENDLOOP.
lr_struct_dynamic = cl_abap_structdescr=>create( lt_abap_comp_tab ).
lr_table = cl_abap_tabledescr=>create( p_line_type = lr_struct_dynamic ).
CREATE DATA lr_export TYPE HANDLE lr_table.
ASSIGN lr_export->* TO <fs_export>.
APPEND INITIAL LINE TO <fs_export> ASSIGNING <fs_header>.
* Add the column title to the table
LOOP AT lt_dfies ASSIGNING <fs_dfies>.
ASSIGN COMPONENT ‘SCRTEXT_L’ OF STRUCTURE <fs_dfies> TO <fs_column>.
ASSIGN COMPONENT <fs_dfies>-fieldname
OF STRUCTURE <fs_header> TO <fs_column_title>.
<fs_column_title> = <fs_column>.
ENDLOOP.
UNASSIGN <fs_header>.
<fs_column_title> = <fs_column>.
ENDLOOP.
UNASSIGN <fs_header>.
* Add the content to the table
lt_spfli = gt_flight_list_ui.
LOOP AT lt_spfli INTO ls_spfli.
APPEND INITIAL LINE TO <fs_export> ASSIGNING <fs_item>.
MOVE-CORRESPONDING ls_spfli TO <fs_item>.
ENDLOOP.
TRY.
CALL TRANSFORMATION id SOURCE abap = <fs_export>
RESULT XML lv_xml_content.
CATCH cx_transformation_error. “#EC NO_HANDLER
ENDTRY.
CALL METHOD cl_wd_runtime_services=>attach_file_to_response
EXPORTING
i_filename = ‘Flight.xls’
i_content = lv_xml_content
i_mime_type = ‘application/vnd.ms-excel’
i_in_new_window = abap_false
i_inplace = abap_false.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
lt_spfli = gt_flight_list_ui.
LOOP AT lt_spfli INTO ls_spfli.
APPEND INITIAL LINE TO <fs_export> ASSIGNING <fs_item>.
MOVE-CORRESPONDING ls_spfli TO <fs_item>.
ENDLOOP.
TRY.
CALL TRANSFORMATION id SOURCE abap = <fs_export>
RESULT XML lv_xml_content.
CATCH cx_transformation_error. “#EC NO_HANDLER
ENDTRY.
CALL METHOD cl_wd_runtime_services=>attach_file_to_response
EXPORTING
i_filename = ‘Flight.xls’
i_content = lv_xml_content
i_mime_type = ‘application/vnd.ms-excel’
i_in_new_window = abap_false
i_inplace = abap_false.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
TEST the application.
Ok.
Here we have the excel.
-------------------------------------------------------------------------------------------------------------------------