Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8653

Re: Excel Download Top of Page

$
0
0

Hi Monica Hu,

 

Simple see this code...

 

TABLES : sflight.
TYPE-POOLS : slis.

**INTERNAL TABLE DECLARTION
DATA : wa_sflight TYPE sflight,
        it_sflight TYPE TABLE OF sflight.

DATA : it_header TYPE string OCCURS 0.

**DATA DECLARTION
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
       gd_layout    TYPE slis_layout_alv,
       gd_repid     LIKE sy-repid,
       g_save TYPE c VALUE 'X',
       g_variant TYPE disvariant,
       gx_variant TYPE disvariant,
       g_exit TYPE c,
       ispfli TYPE TABLE OF spfli.

* To understand the importance of the following parameter, click here.
**SELECTION SCREEN DETAILS
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002 .
PARAMETERS: variant LIKE disvariant-variant.
SELECTION-SCREEN END OF BLOCK b1.
**GETTING DEFAULT VARIANT
INITIALIZATION.
   gx_variant-report = sy-repid.
   CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
     EXPORTING
       i_save     = g_save
     CHANGING
       cs_variant = gx_variant
     EXCEPTIONS
       not_found  = 2.
   IF sy-subrc = 0.
     variant = gx_variant-variant.
   ENDIF.

**PERFORM DECLARATIONS
START-OF-SELECTION.
   PERFORM data_retrivel.
   PERFORM build_fieldcatalog.
   PERFORM display_alv_report.
   PERFORM gui_download.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog .

   fieldcatalog-fieldname   = 'CARRID'.
   fieldcatalog-seltext_m   = 'Airline Code'.
   fieldcatalog-col_pos     = 0.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'CONNID'.
   fieldcatalog-seltext_m   = 'Flight Connection Number'.
   fieldcatalog-col_pos     = 1.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'FLDATE'.
   fieldcatalog-seltext_m   = 'Flight date'.
   fieldcatalog-col_pos     = 2.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.

   fieldcatalog-fieldname   = 'PRICE'.
   fieldcatalog-seltext_m   = 'Airfare'.
   fieldcatalog-col_pos     = 3.
   fieldcatalog-outputlen   = 20.
   APPEND fieldcatalog TO fieldcatalog.
   CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG


*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_alv_report .
   gd_repid = sy-repid.
   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
       i_callback_program      = gd_repid
       i_callback_top_of_page  = 'TOP-OF-PAGE'  "see FORM
       i_callback_user_command = 'USER_COMMAND'
       it_fieldcat             = fieldcatalog[]
       i_save                  = 'X'
       is_variant              = g_variant
     TABLES
       t_outtab                = it_sflight
     EXCEPTIONS
       program_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.
ENDFORM.                    "DISPLAY_ALV_REPORT

" DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIVEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_retrivel .
   SELECT * FROM sflight INTO TABLE it_sflight UP TO 10 ROWS.
ENDFORM.                    " DATA_RETRIVEL

*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*
FORM top-of-page.
*ALV Header declarations
   DATA: t_header TYPE slis_t_listheader,
         wa_header TYPE slis_listheader,
         t_line LIKE wa_header-info,
         ld_lines TYPE i,
         ld_linesc(10) TYPE c.

* Title
   wa_header-typ  = 'H'.
   wa_header-info = 'SFLIGHT Table Report'.
   APPEND wa_header TO t_header.
  APPEND wa_header-info TO it_header.
   CLEAR wa_header.


* Date
   wa_header-typ  = 'S'.
   wa_header-key = 'Date: '.
   CONCATENATE  sy-datum+6(2) '.'
                sy-datum+4(2) '.'
                sy-datum(4) INTO wa_header-info.   "todays date
   APPEND wa_header TO t_header.
   APPEND wa_header-info TO it_header.
   CLEAR: wa_header.

   CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
     EXPORTING
       it_list_commentary = t_header.
ENDFORM.                    "top-of-page
*&---------------------------------------------------------------------*
*&      Form  gui_download
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM gui_download .
  CALL FUNCTION 'GUI_DOWNLOAD'
     EXPORTING
       filename = 'D:/sflight.xls'
     TABLES
       data_tab = it_header.
   CALL FUNCTION 'GUI_DOWNLOAD'
     EXPORTING
       filename              = 'D:/sflight.xls'
       filetype              = 'ASC'
       append                = 'X'
       write_field_separator = 'X'
     TABLES
       data_tab              = it_sflight.

ENDFORM.                    " gui_download

 

 



Viewing all articles
Browse latest Browse all 8653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>