*&---------------------------------------------------------------------*
*&  Include           ZSOFTCOPY_SYSTEM                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*& 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       *
*&                                                                     *
*&---------------------------------------------------------------------*


*-----------------------------------------------------------------------
* system
*-----------------------------------------------------------------------
FORM system.
*System: Component Information
  PERFORM system_component.
*System: Kernel Information
  PERFORM system_kernel.
*System: Status
  PERFORM system_status.

ENDFORM.                    "system


*-----------------------------------------------------------------------
* component                                     System Component Info
*-----------------------------------------------------------------------
FORM system_component.

  DATA:
  lt_component TYPE it_component,
  ls_component TYPE st_component,
  lt_cvers TYPE STANDARD TABLE OF cvers,
  lt_html TYPE it_string.

  FIELD-SYMBOLS:
  <ls_cvers> TYPE cvers.

  SELECT * FROM cvers INTO TABLE lt_cvers.
  LOOP AT lt_cvers ASSIGNING <ls_cvers>.
    CLEAR ls_component.
    ls_component-component = <ls_cvers>-component.
    ls_component-release = <ls_cvers>-release.
    CALL FUNCTION 'OCS_GET_COMPONENT_STATE'
      EXPORTING
        iv_component  = <ls_cvers>-component
      IMPORTING
        ev_comp_level = ls_component-level
        ev_last_patch = ls_component-high_package
      EXCEPTIONS
        OTHERS        = 1.
    SELECT SINGLE desc_text FROM cvers_ref INTO ls_component-desc_text
        WHERE component = <ls_cvers>-component
        AND langu = sy-langu.
    APPEND ls_component TO lt_component.
  ENDLOOP.

*HTML
  PERFORM html_main_popupheader
    USING
      txt_component_information
    CHANGING
      lt_html.
* Content
  PERFORM html_add_tablenodiv
    USING
      'MENU_COMPO'
      lt_component
      lt_component
    CHANGING
      lt_html.
* Footer
  PERFORM html_main_popupfooter
    CHANGING lt_html.
*Download
  PERFORM download
    USING
      lt_html
      'MENU'
      'SYSTEM'
      'COMPONENT'
      gc_extension_htm
      abap_false.

ENDFORM.                    "system_component


*-----------------------------------------------------------------------
* kernel                                        System Kernel Info
*-----------------------------------------------------------------------
FORM system_kernel.

  DATA:
  ls_textinput TYPE st_textinput,
  lt_kernel TYPE it_textinput,
  lt_database TYPE it_textinput,
  lt_system TYPE it_textinput,
  lt_html TYPE it_string,
  ls_dbinfo TYPE dbrelinfo.

  FIELD-SYMBOLS:
  <l_patchlevel> TYPE ANY.

  CALL FUNCTION 'DB_DBRELINFO'
    IMPORTING
      dbinfo = ls_dbinfo.

*Kernel information
* Kernel release
  CLEAR ls_textinput.
  ls_textinput-name = txt_kernel_release.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'kernel release'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* Compilation
  CLEAR ls_textinput.
  ls_textinput-name = txt_compilation.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'kernel compiled'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* Sup.Pkg lvl.
  CLEAR ls_textinput.
  ls_textinput-name = txt_sup_pkg_lvl.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'kernel patch level'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* ABAP Load
  CLEAR ls_textinput.
  ls_textinput-name = txt_abap_load.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'ABAP load version'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* CUA load
  CLEAR ls_textinput.
  ls_textinput-name = txt_cua_load.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'CUA load version'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* Mode
  CLEAR ls_textinput.
  ls_textinput-name = txt_mode.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'kernel kind'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.
* Rsyn file
  CLEAR ls_textinput.
  ls_textinput-name = txt_rsyn_file.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'rsyn'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_kernel.

*Database information
* DB client lib.
  CLEAR ls_textinput.
  ls_textinput-name = txt_db_client_lib.
  ls_textinput-input = abap_true.
  ls_textinput-value = ls_dbinfo-clirel.
  APPEND ls_textinput TO lt_database.
* DB releases
  CLEAR ls_textinput.
  ls_textinput-name = txt_db_releases.
  ls_textinput-input = abap_true.
  ls_textinput-value = ls_dbinfo-releases.
  APPEND ls_textinput TO lt_database.
* DBSL version
  CLEAR ls_textinput.
  ls_textinput-name = txt_dbsl_version.
  ls_textinput-input = abap_true.
  ls_textinput-value = ls_dbinfo-dbsl_vers.
  APPEND ls_textinput TO lt_database.
* DBSL Patch Level
  ASSIGN COMPONENT 'PATCHLEVEL' OF STRUCTURE ls_dbinfo
    TO <l_patchlevel>.
  IF <l_patchlevel> IS ASSIGNED.
    CLEAR ls_textinput.
    ls_textinput-name = txt_dbsl_patch_level.
    ls_textinput-input = abap_true.
    ls_textinput-value = <l_patchlevel>.
    APPEND ls_textinput TO lt_database.
  ENDIF.

*System information
* IP address
  CLEAR ls_textinput.
  ls_textinput-name = txt_ip_address.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'IP address'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_system.
* SAP versions
  CLEAR ls_textinput.
  ls_textinput-name = txt_sap_versions.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'supported SAP vers.'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_system.
* Operating System
  CLEAR ls_textinput.
  ls_textinput-name = txt_operating_system.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'valid OP system'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_system.
* OP release
  CLEAR ls_textinput.
  ls_textinput-name = txt_op_release.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'OP system release'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_system.

*HTML
  PERFORM html_main_popupheader
    USING
      txt_component_information
    CHANGING
      lt_html.
* Content
  PERFORM html_add_box1ti_2tivernodiv
    USING
      txt_kernel_information___2
      lt_kernel
      txt_database_information
      lt_database
      txt_system_information
      lt_system
    CHANGING
      lt_html.
* Footer
  PERFORM html_main_popupfooter
    CHANGING lt_html.
*Download
  PERFORM download
    USING
      lt_html
      'MENU'
      'SYSTEM'
      'KERNEL'
      gc_extension_htm
      abap_false.

ENDFORM.                    "system_kernel


*-----------------------------------------------------------------------
* status                                        System Status
*-----------------------------------------------------------------------
FORM system_status.

  DATA:
  ls_textinput TYPE st_textinput,
  lt_usage_data_r TYPE it_textinput,
  lt_usage_data_l TYPE it_textinput,
  lt_repository_data TYPE it_textinput,
  lt_sap_system_data TYPE it_textinput,
  lt_host_data TYPE it_textinput,
  lt_database_data TYPE it_textinput,
  lt_html TYPE it_string,
  ls_last_logon TYPE st_last_logon,
  l_name TYPE ad_namtext,
  l_laiso TYPE laiso,
  l_sptxt TYPE sptxt,
  l_title TYPE rs38m-repti,
  l_date TYPE sydatum,
  l_db_release(10) TYPE c,
  l_servername(40) TYPE c,
  l_unicode TYPE c,
  l_exists TYPE flag,
  l_ttext TYPE ttext_stct,
  l_stext(40) TYPE c,
  l_repid TYPE syrepid,
  lt_list TYPE STANDARD TABLE OF msxxlist.

  FIELD-SYMBOLS:
  <ls_list> TYPE msxxlist.

*Last logon
  GET PARAMETER ID 'US2' FIELD ls_last_logon.

*Usage data
* Client
  CLEAR ls_textinput.
  ls_textinput-name = txt_client.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-mandt.
  APPEND ls_textinput TO lt_usage_data_l.
* User
  CLEAR ls_textinput.
  ls_textinput-name = txt_user.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-uname.
  PERFORM get_user
    USING sy-uname
    CHANGING l_name.
  ls_textinput-value_text = l_name.
  APPEND ls_textinput TO lt_usage_data_l.
* Language
  CLEAR ls_textinput.
  ls_textinput-name = txt_language.
  ls_textinput-input = abap_true.
  PERFORM get_spras
    USING sy-langu
    CHANGING l_laiso l_sptxt.
  ls_textinput-value = l_laiso.
  ls_textinput-value_text = l_sptxt.
  APPEND ls_textinput TO lt_usage_data_l.
* Previous logon
  CLEAR ls_textinput.
  ls_textinput-name = txt_previous_logon.
  ls_textinput-input = abap_true.
  ls_textinput-has_value_ext = abap_true.
  PERFORM get_date
    USING ls_last_logon-date
    CHANGING ls_textinput-value.
  PERFORM get_time
    USING ls_last_logon-time
    CHANGING ls_textinput-value_ext.
  APPEND ls_textinput TO lt_usage_data_r.
* Logon
  CLEAR ls_textinput.
  ls_textinput-name = txt_logon.
  ls_textinput-input = abap_true.
  ls_textinput-has_value_ext = abap_true.
  PERFORM get_date
    USING ls_last_logon-date_now
    CHANGING ls_textinput-value.
  PERFORM get_time
    USING ls_last_logon-time_now
    CHANGING ls_textinput-value_ext.
  APPEND ls_textinput TO lt_usage_data_r.
* System time
  CLEAR ls_textinput.
  ls_textinput-name = txt_system_time.
  ls_textinput-input = abap_true.
  ls_textinput-has_value_ext = abap_true.
  PERFORM get_date
    USING sy-datum
    CHANGING ls_textinput-value.
  PERFORM get_time
    USING sy-uzeit
    CHANGING ls_textinput-value_ext.
  APPEND ls_textinput TO lt_usage_data_r.

*SAP data - Repository data
  l_repid = sy-repid.
* Transition
  CLEAR ls_textinput.
  ls_textinput-name = txt_transaction.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-tcode.
  SELECT SINGLE ttext FROM tstct INTO l_ttext
    WHERE sprsl = sy-langu
    AND tcode = sy-tcode.
  ls_textinput-value_text = l_ttext.
  APPEND ls_textinput TO lt_repository_data.
* Program (screen)
  CLEAR ls_textinput.
  ls_textinput-name = txt_program_screen.
  ls_textinput-input = abap_true.
  ls_textinput-value = l_repid.
  CALL FUNCTION 'PROGRAM_TITLE'
    EXPORTING
      program  = l_repid
      language = sy-langu
    IMPORTING
      title    = l_title.
  ls_textinput-value_text = l_title.
  APPEND ls_textinput TO lt_repository_data.
* Screen number
  CLEAR ls_textinput.
  ls_textinput-name = txt_screen_number.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-dynnr.
  APPEND ls_textinput TO lt_repository_data.
* Program (GUI)
  CLEAR ls_textinput.
  ls_textinput-name = txt_program_gui.
  ls_textinput-input = abap_true.
  ls_textinput-value = l_repid.
  CALL FUNCTION 'PROGRAM_TITLE'
    EXPORTING
      program  = l_repid
      language = sy-langu
    IMPORTING
      title    = l_title.
  ls_textinput-value_text = l_title.
  APPEND ls_textinput TO lt_repository_data.
* GUI status
  CLEAR ls_textinput.
  ls_textinput-name = txt_gui_status.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-pfkey.
  APPEND ls_textinput TO lt_repository_data.

*SAP data - SAP System data
* Component version
  CLEAR ls_textinput.
  ls_textinput-name = txt_component_version.
  ls_textinput-input = abap_true.
  SELECT SINGLE stext FROM cvers_txt INTO l_stext
    WHERE langu = sy-langu.
  IF sy-subrc <> 0.
    SELECT SINGLE stext FROM cvers_txt INTO l_stext
      WHERE langu = 'EN'.
  ENDIF.
  ls_textinput-value = l_stext.
  APPEND ls_textinput TO lt_sap_system_data.
* Space row
  CLEAR ls_textinput.
  ls_textinput-space = abap_true.
  APPEND ls_textinput TO lt_sap_system_data.
* Installation number
  CLEAR ls_textinput.
  ls_textinput-name = txt_installation_number.
  ls_textinput-input = abap_true.
  CALL FUNCTION 'SLIC_GET_LICENCE_NUMBER'
    IMPORTING
      license_number = ls_textinput-value.
  APPEND ls_textinput TO lt_sap_system_data.
* License expiration
  CLEAR ls_textinput.
  ls_textinput-name = txt_license_expiration.
  ls_textinput-input = abap_true.
  CALL FUNCTION 'SLIC_GET_LICENCE_DATE'
    IMPORTING
      licence_date = l_date.
  PERFORM get_date
    USING l_date
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_sap_system_data.
* Unicode System
  PERFORM get_fuba_exists
    USING 'SLDAG_CHECK_FOR_UNICODE'
    CHANGING l_exists.
  IF l_exists = abap_true.
    CLEAR ls_textinput.
    ls_textinput-name = txt_unicode_system.
    ls_textinput-input = abap_true.
    CALL FUNCTION 'SLDAG_CHECK_FOR_UNICODE'
      IMPORTING
        unicode = l_unicode.
    IF l_unicode = 1.
      ls_textinput-value = txt_yes.
    ELSE.
      ls_textinput-value = txt_no.
    ENDIF.
    APPEND ls_textinput TO lt_sap_system_data.
  ENDIF.

*Host data
* Operating system
  CLEAR ls_textinput.
  ls_textinput-name = txt_operating_system.
  ls_textinput-input = abap_true.
  ls_textinput-value = sy-opsys.
  APPEND ls_textinput TO lt_host_data.
* Machine type
  CLEAR ls_textinput.
  ls_textinput-name = txt_machine_type.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'machine type'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_host_data.
* Server name
  CLEAR ls_textinput.
  ls_textinput-name = txt_server_name.
  ls_textinput-input = abap_true.
***
  CALL FUNCTION 'TH_SERVER_LIST'
    TABLES
      list   = lt_list
    EXCEPTIONS
      OTHERS = 1.
  READ TABLE lt_list ASSIGNING <ls_list> INDEX 1.
  IF <ls_list> IS ASSIGNED.
    l_servername = <ls_list>-name.
  ELSE.
*  call 'C_SAPGPARAM'
*    id 'NAME'  field 'rdisp/myname'
*    id 'VALUE' field l_servername.
*  if sy-subrc <> 0.
    CLEAR l_servername.
  ENDIF.
  ls_textinput-value = l_servername.
  APPEND ls_textinput TO lt_host_data.
* Platform ID
  CLEAR ls_textinput.
  ls_textinput-name = txt_platform_id.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'SAP system id'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_host_data.

*Database data
* Database system
  CLEAR ls_textinput.
  ls_textinput-name = txt_database_system.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'database system'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_database_data.
* Release
  CLEAR ls_textinput.
  ls_textinput-name = txt_release.
  ls_textinput-input = abap_true.
  CALL FUNCTION 'DB_GET_RELEASE'
    IMPORTING
      release = l_db_release.
  ls_textinput-value = l_db_release.
  APPEND ls_textinput TO lt_database_data.
* Name
  CLEAR ls_textinput.
  ls_textinput-name = txt_name.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'database name'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_database_data.
* Host
  CLEAR ls_textinput.
  ls_textinput-name = txt_host.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'database host'
    CHANGING ls_textinput-value.
  ls_textinput-value = sy-host.
  TRANSLATE ls_textinput-value TO UPPER CASE.
  APPEND ls_textinput TO lt_database_data.
* Owner
  CLEAR ls_textinput.
  ls_textinput-name = txt_owner.
  ls_textinput-input = abap_true.
  PERFORM get_version_info
    USING 'database owner'
    CHANGING ls_textinput-value.
  APPEND ls_textinput TO lt_database_data.

*HTML
  PERFORM html_main_popupheader
    USING
      txt_status
    CHANGING
      lt_html.
* Content
  PERFORM html_add_box1tidbl_box2ti_2tix
    USING
      txt_usage_data
      lt_usage_data_l
      lt_usage_data_r
      txt_sap_data
      txt_repository_data
      txt_sap_system_data
      lt_repository_data
      lt_sap_system_data
      txt_host_data
      txt_database_data
      lt_host_data
      lt_database_data
    CHANGING
      lt_html.
* Footer
  PERFORM html_main_popupfooter
    CHANGING lt_html.
*Download
  PERFORM download
    USING
      lt_html
      'MENU'
      'SYSTEM'
      'STATUS'
      gc_extension_htm
      abap_false.

ENDFORM.                    "system_status
