Monday, 29 February 2016

Launching Excel from FPM OVP Application

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.
2.jpg
The table type and the line type.
1
List UIBB feeder class implemented interfaces.
8
Created an attribute.
9
Implemented GTE_DEFINITION method.
10
Implemented GET_DATA method.
11
Create an OVP application and application configuration and OVP component configuration.
3
Add the list UIBB configuration.
4

5
In list UIBB we have the below fields. Click on Toolbar Schema.
6
here ww have button with text as ‘Show Excel’ and event as ‘EXCEL_DISP’.
7
put  the below logic in  PROCESS_EVENT method under the event ‘EXCEL_DISP’.
12.jpg
METHOD if_fpm_guibb_list~process_event.
    DATAlt_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.
    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).
        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=>createlt_abap_comp_tab ).
        lr_table cl_abap_tabledescr=>createp_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>.
* 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.

1314

 TEST the application.17
Ok.
15
Here we have the excel.
16
-------------------------------------------------------------------------------------------------------------------------

Comments system

Disqus Shortname