Eigenschaften | Quelltext
Titel | Database - upload 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_UPLOAD_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: csv2data
    31
    *-----------------------------------------------------------------------
    32
    FORM csv2data USING
    33
                    value(i_tabname) TYPE tabname
    34
                    it_csv TYPE it_string.
    35
      DATA:
    36
      lt_dd03l TYPE STANDARD TABLE OF dd03l,
    37
      ls_dd02l TYPE dd02l,
    38
      l_fieldname TYPE fieldname,
    39
      l_position TYPE tabfdpos,
    40
      lt_value TYPE it_string,
    41
      l_value TYPE string,
    42
      l_csv TYPE string,
    43
      l_len TYPE i,
    44
      l_cnt TYPE i,
    45
      l_length TYPE string,
    46
      l_quot TYPE flag,
    47
      ls_fs TYPE REF TO data.
    48
    49
      FIELD-SYMBOLS:
    50
      <ls_csv> TYPE string,
    51
      <ls_dd03l> TYPE dd03l,
    52
      <ls_fs> TYPE ANY,
    53
      <l_fs> TYPE ANY,
    54
      <l_value> TYPE ANY.
    55
    56
      SELECT * FROM dd03l INTO TABLE lt_dd03l
    57
          WHERE tabname = i_tabname
    58
          AND as4local = 'A'
    59
          ORDER BY position.
    60
    61
      SELECT SINGLE * FROM dd02l INTO ls_dd02l
    62
          WHERE tabname = i_tabname
    63
          AND as4local = 'A'.
    64
    65
    *content
    66
      CREATE DATA ls_fs TYPE (i_tabname).
    67
      ASSIGN ls_fs->* TO <ls_fs>.
    68
    69
      LOOP AT it_csv ASSIGNING <ls_csv>.
    70
        IF sy-tabix = 1.
    71
          CONTINUE.
    72
        ENDIF.
    73
    74
        CLEAR l_cnt.
    75
    76
        SPLIT <ls_csv> AT ';' INTO TABLE lt_value.
    77
        LOOP AT lt_value ASSIGNING <l_value>.
    78
          IF l_quot = abap_true.
    79
            CONCATENATE l_value ';' <l_value> INTO l_value.
    80
          ELSE.
    81
            l_value = <l_value>.
    82
            IF l_value <> space AND l_value+0(1) = '"'.
    83
              l_quot = abap_true.
    84
              l_value = l_value+1.
    85
            ENDIF.
    86
          ENDIF.
    87
    88
          IF l_quot = abap_true.
    89
            l_len = strlen( l_value ).
    90
            IF l_len > 0.
    91
              SUBTRACT 1 FROM l_len.
    92
              IF l_value+l_len(1) = '"'.
    93
                l_value = l_value+0(l_len).
    94
                l_quot = abap_false.
    95
              ENDIF.
    96
            ENDIF.
    97
          ENDIF.
    98
    99
          IF l_quot = abap_false.
    100
            ADD 1 TO l_cnt.
    101
            READ TABLE lt_dd03l ASSIGNING <ls_dd03l> INDEX l_cnt.
    102
            IF sy-subrc <> 0.
    103
    *          message 'Cannot import data'.
    104
              EXIT.
    105
            ENDIF.
    106
    107
            IF <ls_dd03l>-fieldname <> 'MANDT'.
    108
              ASSIGN COMPONENT <ls_dd03l>-fieldname OF STRUCTURE <ls_fs>
    109
                TO <l_fs>.
    110
              <l_fs> = l_value.
    111
            ENDIF.
    112
          ENDIF.
    113
        ENDLOOP.
    114
    115
        MODIFY (i_tabname) FROM <ls_fs>.
    116
        CLEAR <ls_fs>.
    117
    118
      ENDLOOP.
    119
    120
    ENDFORM.                    "select_csv2data