Eigenschaften | Quelltext
Titel | Database - download convert data |
Originalsprache | DE | Deutsch
Erstellt | 24.08.2012 |  | CREYTZ |
Letzte Änderung | 23.02.2021 |  | CREYTZ |
Status | aktiv |
Attribute
Typ | Include-Programm |
Status | Produktives Kundenprogramm |
Anwendung |  |
Berechtigungsgruppe |  |
Paket | ZDB | Datenbank
| Editorsperre
txt
    1
    *&---------------------------------------------------------------------*
    2
    *&  Include           ZDB_DOWNLOAD_CONVERT_DATA                        *
    3
    *&                                                                     *
    4
    *&---------------------------------------------------------------------*
    5
    *&                                                                     *
    6
    *& This file is part of ZDB.                                           *
    7
    *&                                                                     *
    8
    *& ZDB_DOWNLOAD is free software: you can redistribute it and/or       *
    9
    *& modify it under the terms of the GNU General Public License as      *
    10
    *& published by the Free Software Foundation, either version 3 of the  *
    11
    *& License, or any later version.                                      *
    12
    *&                                                                     *
    13
    *& ZDB_DOWNLOAD is distributed in the hope that it will be useful,     *
    14
    *& but WITHOUT ANY WARRANTY; without even the implied warranty of      *
    15
    *& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the       *
    16
    *& GNU General Public License for more details.                        *
    17
    *&                                                                     *
    18
    *& You should have received a copy of the GNU General Public License   *
    19
    *& along with ZDOWNLOAD. If not, see <http://www.gnu.org/licenses/>.   *
    20
    *&                                                                     *
    21
    *&---------------------------------------------------------------------*
    22
    *&                                                                     *
    23
    *&  Author:     Ruediger von Creytz     ruediger.creytz@globalbit.net  *
    24
    *&  Copyright:  globalBIT, LLC          http://www.globalbit.net       *
    25
    *&                                                                     *
    26
    *&---------------------------------------------------------------------*
    27
    28
    29
    *-----------------------------------------------------------------------
    30
    * form: data2csv
    31
    *-----------------------------------------------------------------------
    32
    FORM data2csv USING
    33
                    value(i_tabname)
    34
                  CHANGING
    35
                    ct_csv TYPE it_string.
    36
      DATA:
    37
      lt_dd03l TYPE STANDARD TABLE OF dd03l,
    38
      ls_dd02l TYPE dd02l,
    39
      l_fieldname TYPE fieldname,
    40
      l_position TYPE tabfdpos,
    41
      l_value TYPE string,
    42
      l_csv TYPE string,
    43
      l_len TYPE i,
    44
      l_length TYPE string,
    45
      ls_fs TYPE REF TO data.
    46
    47
      FIELD-SYMBOLS:
    48
      <ls_dd03l> TYPE dd03l,
    49
      <ls_fs> TYPE ANY,
    50
      <l_value> TYPE ANY.
    51
    52
      REFRESH ct_csv.
    53
    54
      SELECT * FROM dd03l INTO TABLE lt_dd03l
    55
          WHERE tabname = i_tabname
    56
          AND as4local = 'A'
    57
          ORDER BY position.
    58
    59
      SELECT SINGLE * FROM dd02l INTO ls_dd02l
    60
          WHERE tabname = i_tabname
    61
          AND as4local = 'A'.
    62
    63
      LOOP AT lt_dd03l ASSIGNING <ls_dd03l>.
    64
        IF <ls_dd03l>-fieldname+0(1) = '.'.
    65
          CONTINUE.
    66
        ENDIF.
    67
        IF NOT l_csv IS INITIAL.
    68
          CONCATENATE l_csv ';' INTO l_csv.
    69
        ENDIF.
    70
        l_len = <ls_dd03l>-intlen.
    71
        l_length = l_len.
    72
        CONDENSE l_length.
    73
        CONCATENATE l_csv '"' <ls_dd03l>-fieldname
    74
          '(' <ls_dd03l>-inttype l_length ')"'
    75
          INTO l_csv.
    76
      ENDLOOP.
    77
      APPEND l_csv TO ct_csv.
    78
    79
    *content
    80
      CREATE DATA ls_fs TYPE (i_tabname).
    81
      ASSIGN ls_fs->* TO <ls_fs>.
    82
      SELECT * FROM (i_tabname) INTO <ls_fs>.
    83
        CLEAR l_csv.
    84
        LOOP AT lt_dd03l ASSIGNING <ls_dd03l>.
    85
          CLEAR l_value.
    86
          IF <ls_dd03l>-fieldname+0(1) = '.'.
    87
            CONTINUE.
    88
          ENDIF.
    89
    90
          IF NOT <ls_dd03l>-datatype = 'RAWSTRING'.
    91
            ASSIGN COMPONENT <ls_dd03l>-fieldname OF STRUCTURE <ls_fs>
    92
                TO <l_value>.
    93
            l_value = <l_value>.
    94
          ENDIF.
    95
    96
          IF NOT l_csv IS INITIAL.
    97
            CONCATENATE l_csv ';' INTO l_csv.
    98
          ENDIF.
    99
          CONCATENATE l_csv '"' l_value '"' INTO l_csv.
    100
        ENDLOOP.
    101
        APPEND l_csv TO ct_csv.
    102
        IF sy-dbcnt = g_add_db_max_lines.
    103
          EXIT.
    104
        ENDIF.
    105
      ENDSELECT.
    106
    107
    ENDFORM.                    "select_data2csv
    108
    109
    110
    *-----------------------------------------------------------------------
    111
    * form: data2xml
    112
    *-----------------------------------------------------------------------
    113
    FORM data2xml USING
    114
                    value(i_tabname)
    115
                  CHANGING
    116
                    ct_xml TYPE it_string.
    117
      DATA:
    118
      lt_dd03l TYPE STANDARD TABLE OF dd03l,
    119
      ls_dd03t TYPE dd03t,
    120
      ls_dd02l TYPE dd02l,
    121
      ls_dd02t TYPE dd02t,
    122
      l_fieldname(30) TYPE c,
    123
      l_position TYPE tabfdpos,
    124
      l_value TYPE string,
    125
      l_xml TYPE string,
    126
      ls_fs TYPE REF TO data.
    127
    128
      FIELD-SYMBOLS:
    129
      <ls_dd03l> TYPE dd03l,
    130
      <ls_fs> TYPE ANY,
    131
      <l_value> TYPE ANY.
    132
    133
      REFRESH ct_xml.
    134
    135
      SELECT * FROM dd03l INTO TABLE lt_dd03l
    136
          WHERE tabname = i_tabname
    137
          AND as4local = 'A'
    138
          ORDER BY position.
    139
    140
      APPEND '<?xml version="1.0" encoding="UTF-8" ?>' TO ct_xml.
    141
      APPEND '<db>' TO ct_xml.
    142
      APPEND '<definition><table>' TO ct_xml.
    143
      SELECT SINGLE * FROM dd02l INTO ls_dd02l
    144
        WHERE tabname = i_tabname
    145
        AND as4local = 'A'.
    146
      SELECT fieldname position FROM dd03l INTO (l_fieldname, l_position)
    147
          WHERE tabname = 'DD02L'
    148
          ORDER BY position.
    149
        ASSIGN COMPONENT l_fieldname OF STRUCTURE ls_dd02l
    150
            TO <l_value>.
    151
        IF NOT <l_value> IS INITIAL.
    152
          l_value = <l_value>.
    153
          PERFORM encode_html CHANGING l_value.
    154
          TRANSLATE l_fieldname TO LOWER CASE.
    155
          CONCATENATE
    156
            '<' l_fieldname ' value="' l_value '"/>'
    157
            INTO l_xml.
    158
          APPEND l_xml TO ct_xml.
    159
        ENDIF.
    160
      ENDSELECT.
    161
    162
      SELECT * FROM dd02t INTO ls_dd02t
    163
          WHERE tabname = i_tabname
    164
          AND as4local = 'A'.
    165
        CONCATENATE
    166
          '<text language="' ls_dd02t-ddlanguage '">'
    167
          ls_dd02t-ddtext
    168
          '</text>'
    169
          INTO l_xml.
    170
        APPEND l_xml TO ct_xml.
    171
      ENDSELECT.
    172
    173
      APPEND '</table>' TO ct_xml.
    174
    175
      LOOP AT lt_dd03l ASSIGNING <ls_dd03l>.
    176
        IF <ls_dd03l>-fieldname+0(1) = '.'.
    177
          CONTINUE.
    178
        ENDIF.
    179
        APPEND '<col>' TO ct_xml.
    180
        SELECT fieldname position FROM dd03l INTO (l_fieldname, l_position)
    181
            WHERE tabname = 'DD03L'
    182
            AND fieldname <> 'TABNAME'
    183
            ORDER BY position.
    184
          ASSIGN COMPONENT l_fieldname OF STRUCTURE <ls_dd03l>
    185
            TO <l_value>.
    186
          l_value = <l_value>.
    187
          IF NOT <l_value> IS INITIAL.
    188
            PERFORM encode_html CHANGING l_value.
    189
            TRANSLATE l_fieldname TO LOWER CASE.
    190
            CONCATENATE
    191
                '<' l_fieldname '>' l_value '</' l_fieldname '>'
    192
                INTO l_xml.
    193
            APPEND l_xml TO ct_xml.
    194
          ENDIF.
    195
        ENDSELECT.
    196
        SELECT * FROM dd03t INTO ls_dd03t
    197
            WHERE tabname = <ls_dd03l>-tabname
    198
            AND fieldname = <ls_dd03l>-fieldname
    199
            AND as4local = 'A'.
    200
          CONCATENATE
    201
            '<text language="' ls_dd03t-ddlanguage '">'
    202
            ls_dd03t-ddtext
    203
            '</text>'
    204
            INTO l_xml.
    205
          APPEND l_xml TO ct_xml.
    206
        ENDSELECT.
    207
        APPEND '</col>' TO ct_xml.
    208
      ENDLOOP.
    209
    210
      APPEND '</definition>' TO ct_xml.
    211
    212
    *content
    213
      APPEND '<lines>' TO ct_xml.
    214
    215
      CREATE DATA ls_fs TYPE (i_tabname).
    216
      ASSIGN ls_fs->* TO <ls_fs>.
    217
      SELECT * FROM (i_tabname) INTO <ls_fs>.
    218
        CLEAR l_xml.
    219
    220
        APPEND '<line>' TO ct_xml.
    221
    222
        LOOP AT lt_dd03l ASSIGNING <ls_dd03l>.
    223
          IF <ls_dd03l>-fieldname+0(1) = '.'.
    224
            CONTINUE.
    225
          ENDIF.
    226
          CLEAR l_value.
    227
          IF NOT <ls_dd03l>-datatype = 'RAWSTRING'.
    228
            ASSIGN COMPONENT <ls_dd03l>-fieldname OF STRUCTURE <ls_fs>
    229
                TO <l_value>.
    230
            l_value = <l_value>.
    231
            PERFORM encode_html CHANGING l_value.
    232
          ENDIF.
    233
    234
          IF NOT <l_value> IS INITIAL.
    235
            IF <ls_dd03l>-fieldname(1) = '.'.
    236
              <ls_dd03l>-fieldname(1) = '_'.
    237
            ENDIF.
    238
            CONCATENATE
    239
                '<cell name="' <ls_dd03l>-fieldname '">'
    240
                l_value
    241
                '</cell>' INTO l_xml.
    242
            APPEND l_xml TO ct_xml.
    243
          ENDIF.
    244
        ENDLOOP.
    245
        APPEND '</line>' TO ct_xml.
    246
        IF sy-dbcnt = g_add_db_max_lines.
    247
          EXIT.
    248
        ENDIF.
    249
      ENDSELECT.
    250
      APPEND '</lines></db>' TO ct_xml.
    251
    252
    ENDFORM.                    "select_data2xml