SAP Tutorials Blog

*&------------------------------------------------------------*
*& Report  ZREPORT_CAPTURE                                    *
*&                                                            *
*&------------------------------------------------------------*
*&                                                            *
*& Demonstrate function module 'LIST_TO_ASCI'                 *
*& ..........................................                 *
*&                                                            *
*& Captures a report displayed using the write statement to an*
*& internal table, this is then downloaded to a PC file       *
*&------------------------------------------------------------* 
REPORT  ZREPORT_CAPTURE  no standard page heading.
TABLES:     ekko.
TYPE-POOLS: slis.                                 "ALV Declarations
*Data Declaration
*----------------
TYPES: BEGIN OF t_ekko,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
  statu TYPE ekpo-statu,
  aedat TYPE ekpo-aedat,
  matnr TYPE ekpo-matnr,
  menge TYPE ekpo-menge,
  meins TYPE ekpo-meins,
  netpr TYPE ekpo-netpr,
  peinh TYPE ekpo-peinh,
 END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
      wa_ekko TYPE t_ekko.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
      gd_tab_group TYPE slis_t_sp_group_alv,
      gd_layout    TYPE slis_layout_alv,
      gd_repid     LIKE sy-repid.
DATA: BEGIN OF it_report OCCURS 0,
      line(300),
      END OF it_report.
************************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
* retrieve data
  PERFORM data_retrieval.
************************************************************************
*END-OF-SELECTION.
END-OF-SELECTION.
* display date on screen
  write: sy-uline(27).
  LOOP AT it_ekko INTO wa_ekko.
    WRITE:/ sy-vline,
            (10)wa_ekko-ebeln, sy-vline,
            (10)wa_ekko-ebelp, sy-vline.
  ENDLOOP.
  write:/ sy-uline(27).
* capture report to internal table, does not work for ALV reports
  CALL FUNCTION 'LIST_TO_ASCI'
    EXPORTING
      LIST_INDEX               = 0
    TABLES
      listasci                 = it_report.
* download report to file
  CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
      filename = 'C:\temp\report.txt'
      filetype = 'ASC'
    TABLES
      data_tab = it_report.
*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data form EKPO table and populate itab it_ekko
*----------------------------------------------------------------------*
FORM data_retrieval.
  SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
   UP TO 10 ROWS
    FROM ekpo
    INTO TABLE it_ekko.
ENDFORM.                    " DATA_RETRIEVAL

Serkan AKKAVAK
Computer Engineer BSc
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com