*&---------------------------------------------------------------------*
*&  Include           ZSOFTCOPY_ADD                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& This file is part of ZSOFTCOPY.                                     *
*&                                                                     *
*& ZSOFTCOPY is free software: you can redistribute it and/or modify   *
*& it under the terms of the GNU General Public License as published   *
*& by the Free Software Foundation, either version 3 of the License,   *
*& or any later version.                                               *
*&                                                                     *
*& ZSOFTCOPY is distributed in the hope that it will be useful,        *
*& but WITHOUT ANY WARRANTY; without even the implied warranty of      *
*& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
*& GNU General Public License for more details.                        *
*&                                                                     *
*& You should have received a copy of the GNU General Public License   *
*& along with ZDOWNLOAD. If not, see <http://www.gnu.org/licenses/>.   *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&  Author:     Ruediger von Creytz     ruediger.creytz@globalbit.net  *
*&  Copyright:  globalBIT, LLC          http://www.globalbit.net       *
*&                                                                     *
*&---------------------------------------------------------------------*


*-----------------------------------------------------------------------
* add_report_sourceCode
*-----------------------------------------------------------------------
FORM add_report_sourcecode
  USING
    value(i_progname)
    value(i_filename)
    value(i_extension)
    value(i_add_no_includes)
    value(is_ztadir) TYPE st_ztadir
    value(i_id)
    value(i_on) TYPE flag
  CHANGING
    ct_html TYPE it_string.

  DATA:
  lt_initial TYPE it_string,
  lt_src TYPE it_string,
  lt_src_compressed TYPE it_string,
  lt_src_no_includes TYPE it_string,
  l_lines TYPE i,
  l_lines_no_includes TYPE i,
  l_filename TYPE string,
  l_filename_compressed TYPE string,
  l_filename_no_includes TYPE string.

  PERFORM try_read_report
    USING i_progname
    CHANGING lt_src.
  IF g_add_sourcecode = abap_true.
    l_filename = i_filename.
    PERFORM download
      USING
        lt_src
        is_ztadir-pgmid
        is_ztadir-object
        l_filename
        i_extension
        abap_false.
    IF i_add_no_includes = abap_true.
      PERFORM try_create_src_no_includes
        USING
          lt_initial
          i_progname
          i_progname
        CHANGING
          lt_src_no_includes.
      DESCRIBE TABLE lt_src LINES l_lines.
      DESCRIBE TABLE lt_src_no_includes LINES l_lines_no_includes.
      IF l_lines < l_lines_no_includes.
        CONCATENATE l_filename '.complete'
            INTO l_filename_no_includes.
        PERFORM download
          USING
            lt_src_no_includes
            is_ztadir-pgmid
            is_ztadir-object
            l_filename_no_includes
            i_extension
            abap_false.
      ENDIF.
      IF gc_src_max_rows < l_lines_no_includes.
        CONCATENATE l_filename '.compressed'
            INTO l_filename_compressed.
        PERFORM get_src_compressed
          USING lt_src_no_includes abap_false
          CHANGING lt_src_compressed.
        PERFORM download
          USING
            lt_src_compressed
            is_ztadir-pgmid
            is_ztadir-object
            l_filename_compressed
            i_extension
            abap_false.
      ENDIF.
    ENDIF.
  ENDIF.
  PERFORM html_add_sourcecode
    USING
      lt_src
      l_filename
      l_filename_no_includes
      l_filename_compressed
      i_extension
      i_id
      i_on
    CHANGING
      ct_html.
ENDFORM.                    "addReportSrc
