-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWG_CUBE_manipulations.pro
375 lines (300 loc) · 8.18 KB
/
WG_CUBE_manipulations.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
601,100
602,"WG_CUBE_manipulations"
562,"NULL"
586,
585,
564,
565,"noR<>AI0oNLSqBaDxm@wh0\b;<W?pnd<Fc;OKr37Ds[FJ_8Kp8Dp@u]L2zS6d>nnBpW]eH>Zq=\Da>C7D^7uC4ChV<w=QN1g]spaeiUS7rsFkq8A2>CDY^HW=D]eKBkDGBkEgkCboCCf\JehuVt0j0KYd=cWsgo;nA@rOof:rY[=AN?7AOYSReG2Rd<98zzREKIZ0:z8"
559,1
928,0
593,
594,
595,
597,
598,
596,
800,
801,
566,0
567,","
588,","
589," "
568,""""
570,
571,
569,0
592,0
599,1000
560,0
561,0
590,0
637,0
577,0
578,0
579,0
580,0
581,0
582,0
603,0
572,284
#****Begin: Generated Statements***
#****End: Generated Statements****
#Region IntroduceThisProcess
####################################################
# Wim Gielis
# March 2024
# https://www.wimgielis.com
####################################################
#EndRegion IntroduceThisProcess
##########################################################
# 1. UNIQUE ALIAS VALUES BY ADDING AN INDEX
##########################################################
vLevel10SOName_NoSO = '';
vLevel10SO = '';
vDim = 'Customer';
vDone = 0;
vOffset = 0;
While( vDone = 0 );
vBasis = vLevel10SOName_NoSO;
vElement = vLevel10SO;
If( vOffset = 0 );
vAttr = vBasis;
Else;
vAttr = vBasis | ' (' | NumberToString( vOffset ) | ')';
EndIf;
If( Dimix( vDim, vAttr ) = 0 );
AttrPutS( vAttr, vDim, vElement, 'Attribute name' );
vDone = 1;
Else;
vOffset = vOffset + 1;
EndIf;
End;
##########################################################
# 2. CHECKING VALIDITY OF ACCOUNT NUMBERS
##########################################################
# Remarks:
# the account should be at least 9 characters
# only numbers can be used in the account
vSrcAccount = '12345678';
vAccount = Trim( vSrcAccount );
vAccountCheck = 'OK';
If( Long( vAccount) >= 9 );
aLoop = 1;
While( aLoop <= Long( vAccount ) & vAccountCheck @= 'OK' );
If( Code( vAccount, aLoop ) < 48 % Code( vAccount, aLoop ) > 57 );
vAccountCheck = 'NOT OK';
EndIf;
# Or:
If( Scan( Subst( vAccount, aLoop, 1 ), '0123456789' ) = 0 );
vAccountCheck = 'NOT OK';
EndIf;
aLoop = aLoop + 1;
End;
Else;
vAccountCheck = 'NOT OK';
EndIf;
If( vAccountCheck @= 'OK' );
#... (other code)
# to test numeric input: vNumber = StringToNumber(vString);
Else;
ItemSkip;
EndIf;
##########################################################
# 3. REWORKING FIGURES WITH BRACKETS FOR THE NEGATIVE VALUES - OPTION 1
##########################################################
# Remarks:
# ( ) is reworked to obtain the negative value
# the TM1 functions StringToNumber and NumberToString use decimal separator for the current user locale!
vAmount = '(123,45)';
vString = Trim( vAmount );
If( Scan( '(', vString ) = 1 & Scan( ')', vString ) = Long( vString ));
vString = '-' | Trim( Subst( vString, 2, Long( vString ) - 2 ));
EndIf;
If( Scan( '(', vString ) > 0 % Scan( ')', vString ) > 0 );
ItemReject( 'Unknown data format for ' | vAmount );
EndIf;
vAmount_N = StringToNumber( vString );
If( vAmount_N <> 0 );
# ...
EndIf;
##########################################################
# 4. REWORKING FIGURES WITH TRAILING MINUS FOR THE NEGATIVE VALUES - OPTION 2
##########################################################
# Remarks:
# 123456,78- is reworked to obtain the negative value by shifting the minus sign to the front
# 123456,78- becomes -123456,78
vAmount = '123,45-';
vAmount = Trim( vAmount );
If( Scan( '-', vAmount ) = Long( vAmount ));
vAmount = '-' | Trim( Delet( vAmount, Long( vAmount ), 1 ));
EndIf;
vAmount_N = StringToNumber( vAmount );
If( vAmount_N <> 0 );
# ...
EndIf;
##########################################################
# 5. REMOVE CHARACTERS FROM A STRING
##########################################################
# Remarks:
# remove certain characters from a string
CreditLimit = 'test$.test';
cRemoveCharacters = '€$£ .';
c = Long( CreditLimit );
While( c >= 1 );
sChar = Subst( CreditLimit, c, 1 );
vScan = Scan( sChar, cRemoveCharacters );
If( vScan > 0 );
CreditLimit = Delet( CreditLimit, c, 1 );
EndIf;
c = c - 1;
End;
# for numeric values:
If( CreditLimit @= '' );
CreditLimit_N = 0;
Else;
CreditLimit_N = StringToNumber( Trim( CreditLimit ));
EndIf;
# - NumberToStringEx can also be useful
##########################################################
# 6. REPLACING CHARACTERS IN A STRING - OPTION 1
##########################################################
# Remarks:
# this is an easy replace, 1 character is replaced with 1 other character
# it is not case-sensitive
# characters are treated as single characters
vActivity = 'test&<>other characters';
cReplaceCharacters = ',';
cReplacedCharacters = '.';
If( cReplaceCharacters @<> cReplacedCharacters );
If( Long( cReplaceCharacters ) = Long( cReplacedCharacters ));
v = vActivity;
r = 1;
While( r <= Long( cReplaceCharacters ));
rChar = Subst( cReplaceCharacters, r, 1 );
c = Long( v );
While( c >= 1 );
sChar = Subst( v, c, 1 );
If( sChar @= rChar );
v = Insrt( Subst( cReplacedCharacters, r, 1 ), Delet( v, c, 1 ), c );
EndIf;
c = c - 1;
End;
r = r + 1;
End;
vActivity = v;
EndIf;
EndIf;
##########################################################
# 7. REPLACING CHARACTERS IN A STRING - OPTION 2
##########################################################
# Remarks:
# similar to OPTION 1 BUT
# it is case-sensitive here
vActivity = 'test&<>other characters';
cReplaceCharacters = ',';
cReplacedCharacters = '.';
If( Long( cReplaceCharacters ) = Long( cReplacedCharacters ));
v = vActivity;
r = 1;
While( r <= Long( cReplaceCharacters ));
rChar = Subst( cReplaceCharacters, r, 1 );
If( Scan( rChar, v ) > 0 );
c = Long( v );
While( c >= 1 );
If( CodeW( v, c ) = CodeW( cReplaceCharacters, r ));
v = Insrt( Subst( cReplacedCharacters, c, 1 ), Delet( v, c, 1 ), c );
EndIf;
c = c - 1;
End;
EndIf;
r = r + 1;
End;
vActivity = v;
EndIf;
##########################################################
# 8. REPLACING CHARACTERS IN A STRING - OPTION 3
##########################################################
# Remarks:
# remove certain characters from a string and replace them with other characters
# example: for XML files, we typically escape:
# & ==> &
# < ==> <
# > ==> >
# Create a dimension called 'XML_Escape_Characters' to contain the characters to be replaced.
# In an attribute called 'Replacement' store the replacement string.
vActivity = 'test&<>other characters';
v = vActivity;
c = Long( v );
While( c >= 1 );
sChar = Subst( v, c, 1 );
If( Dimix( 'XML_Escape_Characters', sChar ) > 0 );
v = Insrt( Attrs( 'XML_Escape_Characters', sChar, 'Replacement' ), Delet( v, c, 1 ), c );
EndIf;
c = c - 1;
End;
vActivity = v;
##########################################################
# 9. REMOVE ALL UNWANTED CHARACTERS FROM A STRING
##########################################################
# Remarks:
#
CreditLimit = 'test$.test';
cKeepCharacters = '€$£ .';
c = Long( CreditLimit );
While( c >= 1 );
sChar = Subst( CreditLimit, c, 1 );
vScan = Scan( sChar, cKeepCharacters );
If( vScan = 0 );
CreditLimit = Delet( CreditLimit, c, 1 );
EndIf;
c = c - 1;
End;
573,3
#****Begin: Generated Statements***
#****End: Generated Statements****
574,3
#****Begin: Generated Statements***
#****End: Generated Statements****
575,3
#****Begin: Generated Statements***
#****End: Generated Statements****
576,CubeAction=1511DataAction=1503CubeLogChanges=0_ParameterConstraints=e30=
930,0
638,1
804,0
1217,1
900,
901,
902,
938,0
937,
936,
935,
934,
932,0
933,0
903,
906,
929,
907,
908,
904,0
905,0
909,0
911,
912,
913,
914,
915,
916,
917,0
918,1
919,0
920,50000
921,""
922,""
923,0
924,""
925,""
926,""
927,""