Properties SourceCde
txt
1
*&---------------------------------------------------------------------*
2
*&  Include           ZUTIL_SRC_COMPRESS                               *
3
*&                                                                     *
4
*&---------------------------------------------------------------------*
5
*&                                                                     *
6
*& This file is part of ZUTIL.                                         *
7
*&                                                                     *
8
*& ZUTIL is free software: you can redistribute it and/or modify       *
9
*& it under the terms of the GNU General Public License as published   *
10
*& by the Free Software Foundation, either version 3 of the License,   *
11
*& or any later version.                                               *
12
*&                                                                     *
13
*& ZUTIL 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 ZUTIL. 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
* get_src_compressed
31
*-----------------------------------------------------------------------
32
FORM get_src_compressed
33
  USING
34
    it_src TYPE table
35
    value(i_compress_better) TYPE flag
36
  CHANGING
37
    ct_compressed TYPE table.
38
 
39
  DATA:
40
  ls_src TYPE string,
41
  l_is_header TYPE flag VALUE abap_true,
42
  l_length TYPE i,
43
  l_pos TYPE i,
44
  l_is_string TYPE flag,
45
  l_chars(72) TYPE c,
46
  l_str TYPE string,
47
  l_str2 TYPE string,
48
  l_srclen TYPE i,
49
  l_strlen TYPE i,
50
  l_line TYPE string,
51
  l_linelen TYPE i.
52
 
53
  REFRESH ct_compressed.
54
 
55
* drop header for better compression
56
  IF i_compress_better = abap_true.
57
    l_is_header = abap_false.
58
  ENDIF.
59
 
60
  LOOP AT it_src INTO ls_src.
61
* drop empty rows
62
    IF ls_src IS INITIAL.
63
      l_is_header = abap_false.
64
      CONTINUE.
65
    ENDIF.
66
* drop comments if not head information
67
    IF ls_src+0(1) = '*'.
68
      IF l_is_header = abap_true.
69
        APPEND ls_src TO ct_compressed.
70
      ENDIF.
71
      CONTINUE.
72
    ENDIF.
73
* remove comments from row
74
    IF ls_src CA '"'.
75
      PERFORM split_src_string
76
        USING
77
          ls_src
78
          '"'
79
        CHANGING
80
          l_str
81
          l_str2.
82
      ls_src = l_str.
83
    ENDIF.
84
* condense line
85
    PERFORM get_src_line_compressed
86
      CHANGING ls_src.
87
* add line
88
    IF NOT l_line IS INITIAL.
89
      l_srclen = strlen( ls_src ).
90
      l_linelen = strlen( l_line ).
91
      l_length = l_srclen + l_linelen.
92
      IF l_length < 71.
93
        CONCATENATE l_line ls_src INTO l_line SEPARATED BY space.
94
        CONTINUE.
95
      ELSE.
96
        DO.
97
          PERFORM split_src_string
98
            USING
99
              ls_src
100
              space
101
            CHANGING
102
              l_str
103
              l_str2.
104
          l_strlen = strlen( l_str ).
105
          l_linelen = strlen( l_line ).
106
          l_length = l_strlen + l_linelen.
107
          IF l_length < 71.
108
            CONCATENATE l_line l_str INTO l_line
109
                SEPARATED BY space.
110
            IF NOT l_str2 IS INITIAL AND l_str2+0(1) = '*'.
111
              CLEAR l_chars.
112
              CLEAR ls_src.
113
              l_chars+1 = l_str2.
114
              ls_src = l_chars.
115
            ELSE.
116
              ls_src = l_str2.
117
            ENDIF.
118
          ELSE.
119
            EXIT.
120
          ENDIF.
121
          IF ls_src IS INITIAL.
122
            EXIT.
123
          ENDIF.
124
        ENDDO.
125
      ENDIF.
126
    ENDIF.
127
    IF NOT l_line IS INITIAL.
128
      APPEND l_line TO ct_compressed.
129
    ENDIF.
130
    l_line = ls_src.
131
    l_is_header = abap_false.
132
  ENDLOOP.
133
  IF NOT l_line IS INITIAL.
134
    APPEND l_line TO ct_compressed.
135
  ENDIF.
136
 
137
ENDFORM.                    "get_src_compressed
138
 
139
 
140
*-----------------------------------------------------------------------
141
* get_src_line_compressed
142
*-----------------------------------------------------------------------
143
FORM get_src_line_compressed
144
  CHANGING
145
    c_line TYPE string.
146
 
147
  DATA:
148
  l_str TYPE string,
149
  l_str1 TYPE string,
150
  l_str2 TYPE string,
151
  l_line_new TYPE string.
152
 
153
  l_str = c_line.
154
 
155
  DO.
156
    PERFORM split_src_string
157
      USING
158
        l_str
159
        space
160
      CHANGING
161
        l_str1
162
        l_str2.
163
 
164
    IF l_line_new IS INITIAL.
165
      l_line_new = l_str1.
166
    ELSE.
167
      CONCATENATE l_line_new l_str1 INTO l_line_new SEPARATED BY space.
168
    ENDIF.
169
 
170
    IF l_str2 IS INITIAL.
171
      EXIT.
172
    ENDIF.
173
    l_str = l_str2.
174
  ENDDO.
175
 
176
  c_line = l_line_new.
177
 
178
ENDFORM.                    "get_src_line_compressed
179
 
180
 
181
*-----------------------------------------------------------------------
182
* split_src_string
183
*-----------------------------------------------------------------------
184
FORM split_src_string
185
  USING
186
    value(i_src) TYPE string
187
    value(i_sep) TYPE char1
188
  CHANGING
189
    c_str1 TYPE string
190
    c_str2 TYPE string.
191
 
192
  DATA:
193
  l_src TYPE string,
194
  l_is_string TYPE flag VALUE abap_false,
195
  l_pos TYPE i VALUE 0,
196
  l_char TYPE char1,
197
  l_srclen TYPE i.
198
 
199
 
200
  CLEAR:
201
  c_str1,
202
  c_str2.
203
 
204
  l_src = i_src.
205
 
206
  SHIFT l_src LEFT DELETING LEADING space.
207
 
208
  SPLIT l_src AT i_sep INTO c_str1 c_str2.
209
 
210
  IF c_str1 CA '''' AND c_str2 CA ''''.
211
    CLEAR: c_str1, c_str2.
212
    l_srclen = strlen( l_src ).
213
    DO.
214
      l_char = l_src+l_pos(1).
215
      CONDENSE l_char.
216
      CASE l_char.
217
        WHEN ''''.
218
          IF l_is_string = abap_true.
219
            l_is_string = abap_false.
220
          ELSE.
221
            l_is_string = abap_true.
222
          ENDIF.
223
        WHEN i_sep.
224
          IF l_is_string = abap_false.
225
            c_str1 = l_src+0(l_pos).
226
            ADD 1 TO l_pos.
227
            c_str2 = l_src+l_pos.
228
            EXIT.
229
          ENDIF.
230
      ENDCASE.
231
      ADD 1 TO l_pos.
232
      IF l_pos = l_srclen.
233
        c_str1 = l_src.
234
        EXIT.
235
      ENDIF.
236
    ENDDO.
237
  ENDIF.
238
 
239
  SHIFT c_str2 LEFT DELETING LEADING space.
240
  IF c_str1 NA ''''.
241
    CONDENSE c_str1.
242
  ENDIF.
243
  IF c_str2 NA ''''.
244
    CONDENSE c_str2.
245
  ENDIF.
246
 
247
ENDFORM.                    "split_src_string