*&---------------------------------------------------------------------*
*& Report  ZP_COUNT_EE                                                       *
*&                                                                     *
*&---------------------------------------------------------------------*
*&   Markus Ebel, 05.11.2009                                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  zp_count_ee                                                       .

*&---------------------------------------------------------------------*
*& This is my first ABAP program
*&---------------------------------------------------------------------*
*& Global Declarations
*&---------------------------------------------------------------------*

CLASS z_tmp DEFINITION.
  PUBLIC SECTION.
    CONSTANTS: dset TYPE string VALUE 'D:\temp\sap.csv'.
    DATA: lt_lines TYPE TABLE OF string.
    DATA: text1 TYPE string,
          text2 TYPE string,
          text3 TYPE string,
          cc TYPE i.

    METHODS: main, storelocal.
ENDCLASS.                    "demo DEFINITION

*----------------------------------------------------------------------*
*       CLASS demo  IMPLEMENTATIO
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS z_tmp IMPLEMENTATION.

  METHOD main.

  data: count type i.

    SELECT
      count( distinct pernr )
      FROM pa0002 INTO count.

      "APPEND text1 TO lt_lines.

      text1 = count.
      write: / text1.

      cc = cc + 1.
    "ENDSELECT.

    storelocal( ).

    text3 = cc.
    CONCATENATE 'Anzahl=' text3 INTO text2.
    write: / text2.

  ENDMETHOD.                    "demo

  METHOD storelocal.

*.. Download
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = dset
      TABLES
        data_tab                = lt_lines
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc <> 0.
        text2 = sy-subrc.
        concatenate 'Kann Datei' dset 'nicht erzeugen:' TEXT2 into text1 SEPARATED BY space.
        write: / text1.
    ENDIF.

  ENDMETHOD.                    "storeLocal

ENDCLASS.                    "demo  IMPLEMENTATIO

*&---------------------------------------------------------------------*
*& Implementations
*&---------------------------------------------------------------------*

START-OF-SELECTION.
  DATA cl TYPE REF TO z_tmp.

  CREATE OBJECT cl.
  cl->main( ).