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


*-----------------------------------------------------------------------
* csv_tools
*-----------------------------------------------------------------------
FORM csv_tools.
  PERFORM csv_tools_text_elements.
  PERFORM text_tools.

  PERFORM csv_tools_table_structure.
  PERFORM csv_tools_tabstrip.
  PERFORM csv_tools_varid_broken.
ENDFORM.                    "csv_tools


*-----------------------------------------------------------------------
* csv_tools_table_structure
*-----------------------------------------------------------------------
FORM csv_tools_table_structure.
  DATA:
  lt_csv TYPE it_string,
  lt_row TYPE it_string,
  ls_row TYPE string,
  ls_table TYPE st_table_structure.

  FIELD-SYMBOLS:
  <ls_csv> TYPE string,
  <l_fs> TYPE ANY.

  REFRESH gt_table_structure.

  PERFORM csv_table_structure CHANGING lt_csv.

  LOOP AT lt_csv ASSIGNING <ls_csv>.
    SPLIT <ls_csv> AT '|' INTO TABLE lt_row.
    LOOP AT lt_row INTO ls_row.
      IF NOT ls_row IS INITIAL.
        CLEAR ls_table.
        SPLIT ls_row AT ';' INTO
            ls_table-id
            ls_table-row_nr
            ls_table-fieldname
            ls_table-title_elem
            ls_table-link_row
            ls_table-row_def
            ls_table-colored_row
            ls_table-comparator
            ls_table-comp_value.
        IF NOT ls_table-title_elem IS INITIAL.
          ASSIGN (ls_table-title_elem) TO <l_fs>.
          ls_table-title = <l_fs>.
          UNASSIGN <l_fs>.
        ENDIF.
        APPEND ls_table TO gt_table_structure.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    "csv_tools_table_structure


*-----------------------------------------------------------------------
* csv_tools_tabstrip
*-----------------------------------------------------------------------
FORM csv_tools_tabstrip.
  DATA:
  lt_csv TYPE it_string,
  lt_row TYPE it_string,
  ls_row TYPE string,
  ls_tabstrip TYPE st_tabstrip.

  FIELD-SYMBOLS:
  <ls_csv> TYPE string,
  <l_fs> TYPE ANY.

  REFRESH gt_tabstrip.

  PERFORM csv_tabstrip CHANGING lt_csv.

  LOOP AT lt_csv ASSIGNING <ls_csv>.
    SPLIT <ls_csv> AT '|' INTO TABLE lt_row.
    LOOP AT lt_row INTO ls_row.
      IF NOT ls_row IS INITIAL.
        CLEAR ls_tabstrip.
        SPLIT ls_row AT ';' INTO
            ls_tabstrip-form
            ls_tabstrip-id
            ls_tabstrip-parent_id
            ls_tabstrip-tab_nr
            ls_tabstrip-firstrow
            ls_tabstrip-active_order
            ls_tabstrip-text_elem
            ls_tabstrip-comparator
            ls_tabstrip-comp_value.
        IF NOT ls_tabstrip-text_elem IS INITIAL.
          ASSIGN (ls_tabstrip-text_elem) TO <l_fs>.
          ls_tabstrip-text = <l_fs>.
          UNASSIGN <l_fs>.
        ENDIF.
        APPEND ls_tabstrip TO gt_tabstrip.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    "csv_tools_tabstrip


*-----------------------------------------------------------------------
* csv_tools_text_elements
*-----------------------------------------------------------------------
FORM csv_tools_text_elements.
  DATA:
  lt_csv TYPE it_string,
  lt_row TYPE it_string,
  ls_row TYPE string,
  ls_text_element TYPE st_text_element,
  ls_text_element_t TYPE st_text_element_t.

  FIELD-SYMBOLS:
  <ls_csv> TYPE string.

*txt
  REFRESH gt_text_element.

  PERFORM csv_text_elements_1 CHANGING lt_csv.

  LOOP AT lt_csv ASSIGNING <ls_csv>.
    SPLIT <ls_csv> AT '|' INTO TABLE lt_row.
    LOOP AT lt_row INTO ls_row.
      IF NOT ls_row IS INITIAL.
        SPLIT ls_row AT ';' INTO
          ls_text_element-fieldname
          ls_text_element-txt_prefix
          ls_text_element-dtel_rollname
          ls_text_element-dtel_field
          ls_text_element-domname
          ls_text_element-domvalue
          ls_text_element-icon_id
          ls_text_element-icon_field
          ls_text_element-conc_v1
          ls_text_element-conc_copula
          ls_text_element-conc_v2
          ls_text_element-conc_sep_space
          ls_text_element-msg_id
          ls_text_element-msg_nr
          ls_text_element-msg_v1
          ls_text_element-msg_v2
          ls_text_element-msg_v3
          ls_text_element-msg_v4.
        APPEND ls_text_element TO gt_text_element.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

*txtt
  REFRESH gt_text_element_t.

  PERFORM csv_text_elements_2 CHANGING lt_csv.

  LOOP AT lt_csv ASSIGNING <ls_csv>.
    SPLIT <ls_csv> AT '|' INTO TABLE lt_row.
    LOOP AT lt_row INTO ls_row.
      IF NOT ls_row IS INITIAL.
        SPLIT ls_row AT ';' INTO
          ls_text_element_t-fieldname
          ls_text_element_t-spras
          ls_text_element_t-text.
        APPEND ls_text_element_t TO gt_text_element_t.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    "csv_tools_text_elements


*-----------------------------------------------------------------------
* csv_tools_varid_broken
*-----------------------------------------------------------------------
FORM csv_tools_varid_broken.
  DATA:
  lt_csv TYPE it_string,
  lt_row TYPE it_string,
  ls_row TYPE string,
  ls_varid TYPE st_varid.

  FIELD-SYMBOLS:
  <ls_csv> TYPE string.

  REFRESH gt_varid_broken.

  PERFORM csv_varid_broken CHANGING lt_csv.

  LOOP AT lt_csv ASSIGNING <ls_csv>.
    SPLIT <ls_csv> AT '|' INTO TABLE lt_row.
    LOOP AT lt_row INTO ls_row.
      IF NOT ls_row IS INITIAL.
        SPLIT ls_row AT ';' INTO ls_varid-report ls_varid-vari.
        APPEND ls_varid TO gt_varid_broken.
      ENDIF.
    ENDLOOP.
  ENDLOOP.
ENDFORM.                    "csv_tools_varid_broken
