-
Notifications
You must be signed in to change notification settings - Fork 0
/
db2-tp42.cbl
452 lines (360 loc) · 32.7 KB
/
db2-tp42.cbl
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
IDENTIFICATION DIVISION.
*------------------------*
PROGRAM-ID. PGMDB215.
********************************************************
* *
* TP 42 - CHECK-POINT 33 BATCH DB2 *
* 16-11-2022 *
* *
********************************************************
ENVIRONMENT DIVISION.
*---------------------*
CONFIGURATION SECTION.
SPECIAL-NAMES.
DECIMAL-POINT IS COMMA.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT SALIDA ASSIGN TO DDSALID
FILE STATUS IS FS-SAL.
DATA DIVISION.
FILE SECTION.
FD SALIDA
BLOCK CONTAINS 0 RECORDS
RECORDING MODE IS F.
01 REG-SALIDA PIC X(132).
WORKING-STORAGE SECTION.
*------------------------*
01 FS-SAL PIC X(02).
88 FS-OK VALUE '00'.
88 FS-EOF VALUE '10'.
88 FS-NOK VALUE '01' THRU '09'
'11' THRU '99'.
01 FS-SQL PIC X(02).
88 SQL-OK VALUE '00'.
88 SQL-EOF VALUE '10'.
88 SQL-NOK VALUE '01' THRU '09'
'11' THRU '99'.
77 WS-SQLCODE PIC +++999 USAGE DISPLAY VALUE ZEROS.
EXEC SQL
INCLUDE SQLCA
END-EXEC.
EXEC SQL
INCLUDE TBCURCTA
END-EXEC.
EXEC SQL
INCLUDE TBCURCLI
END-EXEC.
EXEC SQL
DECLARE CURSOR1 CURSOR FOR
SELECT A.TIPCUEN,
A.NROCUEN,
A.SUCUEN,
A.NROCLI,
A.SALDO,
B.TIPDOC,
B.NRODOC,
B.NROCLI,
B.NOMAPE
FROM ITPARUT.TBCURCTA A
INNER JOIN ITPARUT.TBCURCLI B
ON A.NROCLI = B.NROCLI
ORDER BY A.SUCUEN ASC,
A.TIPCUEN ASC
END-EXEC.
* VARIABLES *
01 WS-SUCUEN-ANT PIC 99.
01 WS-TIPCUEN-ANT PIC 99.
* ACUMULADORES *
01 AC-SALCUEN PIC S9(7)V9(2) USAGE COMP-3 VALUE ZEROS.
01 AC-SALSUC PIC S9(7)V9(2) USAGE COMP-3 VALUE ZEROS.
01 AC-SALCLI PIC S9(7)V9(2) USAGE COMP-3 VALUE ZEROS.
* CONTADORES *
01 CN-TOT-CLI PIC 9(03) VALUE ZEROS.
01 CN-TOT-SUC PIC 9(03) VALUE ZEROS.
01 CN-TOT-TIPO PIC 9(03) VALUE ZEROS.
77 CN-LINEA PIC 9(02) VALUE 63.
77 CN-PAGINA PIC 9(02) VALUE ZEROS.
* IMPRESION *
01 WS-SEPARADOR PIC X(132) VALUE ALL '*'.
01 WS-SEPARADOR2 PIC X(132) VALUE SPACES.
01 WS-TITULO.
03 FILLER PIC X(11) VALUE 'TIPO CUENTA'.
03 FILLER PIC X(2) VALUE SPACES.
03 FILLER PIC X(10) VALUE 'NRO CUENTA'.
03 FILLER PIC X(2) VALUE SPACES.
03 FILLER PIC X(30) VALUE 'NOMBRE Y APELLIDO'.
03 FILLER PIC X(2) VALUE SPACES.
03 FILLER PIC X(11) VALUE 'NRO CLIENTE'.
03 FILLER PIC X(16) VALUE SPACES.
03 FILLER PIC X(5) VALUE 'SALDO'.
03 FILLER PIC X(57) VALUE SPACES.
01 WS-REG-CLIENTE.
03 FILLER PIC X(4) VALUE SPACES.
03 WS-TIPCUEN PIC 99 VALUE ZEROS.
03 FILLER PIC X(10) VALUE SPACES.
03 WS-NROCUEN PIC ZZZZ9 VALUE ZEROS.
03 FILLER PIC X(4) VALUE SPACES.
03 WS-NOMYAPEL PIC X(30) VALUE SPACES.
03 FILLER PIC X(6) VALUE SPACES.
03 WS-NROCLI PIC ZZ9 VALUE ZEROS.
03 FILLER PIC X(6) VALUE SPACES.
03 WS-SALDO PIC ZZZ.ZZZ.ZZZ.ZZZ.ZZ9,99- VALUE ZEROS.
01 WS-TIT-SUCURSAL.
03 FILLER PIC X(57) VALUE ALL '*'.
03 FILLER PIC X(12) VALUE ' SUCURSAL '.
03 WS-SUCNAME PIC Z9 VALUE SPACES.
03 FILLER PIC X(3) VALUE SPACES.
03 FILLER PIC X(38) VALUE ALL '*'.
03 FILLER PIC X(3) VALUE SPACES.
03 FILLER PIC X(8) VALUE 'PAGINA: '.
03 WS-PAGINA PIC Z9 VALUE ZEROS.
03 FILLER PIC X(3) VALUE SPACES.
03 FILLER PIC X(4) VALUE ALL '*'.
01 WS-TOT-CUENTA.
03 FILLER PIC X(45) VALUE SPACES.
03 FILLER PIC X(25) VALUE
'CANTIDAD DE CUENTAS TIPO '.
03 WS-CUETIPO PIC XX VALUE SPACES.
03 FILLER PIC X(3) VALUE ' = '.
03 WS-CUETOTAL PIC Z9 VALUE SPACES.
03 FILLER PIC X(13) VALUE SPACES.
03 FILLER PIC X(15) VALUE 'TOTAL SALDOS = '.
03 WS-SUCSALDO PIC ZZZ.ZZZ.ZZZ.ZZZ.999,99-.
01 WS-TOT-SUCURSAL.
03 FILLER PIC X(45) VALUE SPACES.
03 FILLER PIC X(32) VALUE
'CANTIDAD DE CUENTAS EN SUCURSAL '.
03 WS-SUCNAME2 PIC Z9 VALUE SPACES.
03 FILLER PIC X(3) VALUE ' = '.
03 WS-SUCTOTAL PIC Z9 VALUE SPACES.
03 FILLER PIC X(6) VALUE SPACES.
03 FILLER PIC X(15) VALUE 'TOTAL SALDOS = '.
03 WS-SUCSALDO2 PIC ZZZ.ZZZ.ZZZ.ZZZ.999,99-.
PROCEDURE DIVISION.
*-------------------*
**************************************
* CUERPO PRINCIPAL DEL PROGRAMA *
**************************************
MAIN-PROGRAM.
*-------------*
PERFORM 1000-I-INICIO
THRU 1000-F-INICIO
PERFORM 2000-I-PROCESO
THRU 2000-F-PROCESO
PERFORM 9999-I-FINAL
THRU 9999-F-FINAL
GOBACK
.
**************************************
* CUERPO INICIO APERTURA ARCHIVOS *
**************************************
1000-I-INICIO.
*--------------*
OPEN OUTPUT SALIDA
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN OPEN SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
EXEC SQL
OPEN CURSOR1
END-EXEC.
IF SQLCODE NOT EQUAL ZEROS
MOVE SQLCODE TO WS-SQLCODE
DISPLAY '* ERROR OPEN CURSOR 1 = ' WS-SQLCODE
MOVE '99' TO FS-SQL
ELSE
EXEC SQL
FETCH CURSOR1
INTO :DB-CU-TIPCUEN,
:DB-CU-NROCUEN,
:DB-CU-SUCUEN,
:DB-CU-NROCLI,
:DB-CU-SALDO,
:DB-CL-TIPDOC,
:DB-CL-NRODOC,
:DB-CL-NROCLI,
:DB-CL-NOMAPE
END-EXEC
EVALUATE TRUE
WHEN SQLCODE EQUAL ZEROS
MOVE '00' TO FS-SQL
WHEN SQLCODE EQUAL +100
MOVE '10' TO FS-SQL
WHEN OTHER
MOVE SQLCODE TO WS-SQLCODE
DISPLAY 'ERROR FETCH CURSOR: ' WS-SQLCODE
MOVE '99' TO FS-SQL
END-EVALUATE
END-IF
.
1000-F-INICIO.
EXIT.
**************************************
* CUERPO PRINCIPAL DE PROCESOS *
**************************************
2000-I-PROCESO.
*---------------*
PERFORM UNTIL SQL-EOF OR SQL-NOK
OR FS-EOF OR FS-NOK
MOVE DB-CU-SUCUEN TO WS-SUCUEN-ANT
MOVE 0 TO CN-TOT-SUC
MOVE 0 TO AC-SALSUC
PERFORM 4100-IMPRIMIR-TIT-SUC
THRU 4100-F-IMPRIMIR-TIT-SUC
* CORTE A *
PERFORM UNTIL SQL-EOF OR SQL-NOK
OR FS-EOF OR FS-NOK
OR DB-CU-SUCUEN NOT = WS-SUCUEN-ANT
MOVE DB-CU-TIPCUEN TO WS-TIPCUEN-ANT
MOVE 0 TO CN-TOT-TIPO
MOVE 0 TO AC-SALCUEN
* CORTE B *
PERFORM UNTIL SQL-EOF OR SQL-NOK
OR FS-EOF OR FS-NOK
OR DB-CU-SUCUEN NOT = WS-SUCUEN-ANT
OR DB-CU-TIPCUEN NOT = WS-TIPCUEN-ANT
ADD 1 TO CN-TOT-TIPO
ADD DB-CU-SALDO TO AC-SALCUEN
PERFORM 3000-IMPRIMIR-CUENTA
THRU 3000-F-IMPRIMIR-CUENTA
EXEC SQL
FETCH CURSOR1
INTO :DB-CU-TIPCUEN,
:DB-CU-NROCUEN,
:DB-CU-SUCUEN,
:DB-CU-NROCLI,
:DB-CU-SALDO,
:DB-CL-TIPDOC,
:DB-CL-NRODOC,
:DB-CL-NROCLI,
:DB-CL-NOMAPE
END-EXEC
EVALUATE TRUE
WHEN SQLCODE EQUAL ZEROS
CONTINUE
WHEN SQLCODE EQUAL +100
MOVE '10' TO FS-SQL
WHEN OTHER
MOVE SQLCODE TO WS-SQLCODE
DISPLAY 'ERROR FETCH CURSOR: ' WS-SQLCODE
MOVE '99' TO FS-SQL
END-EVALUATE
END-PERFORM
PERFORM 3100-IMPRIMIR-CORTE-TIPO
THRU 3100-F-IMPRIMIR-CORTE-TIPO
ADD CN-TOT-TIPO TO CN-TOT-SUC
ADD AC-SALCUEN TO AC-SALSUC
END-PERFORM
PERFORM 3200-IMPRIMIR-CORTE-SUC
THRU 3200-F-IMPRIMIR-CORTE-SUC
ADD CN-TOT-SUC TO CN-TOT-CLI
ADD AC-SALSUC TO AC-SALCLI
END-PERFORM
.
2000-F-PROCESO.
EXIT.
3000-IMPRIMIR-CUENTA.
*---------------------*
IF CN-LINEA GREATER 29
PERFORM 4100-IMPRIMIR-TIT-SUC
THRU 4100-F-IMPRIMIR-TIT-SUC
END-IF.
MOVE SPACES TO WS-REG-CLIENTE
MOVE DB-CU-TIPCUEN TO WS-TIPCUEN
MOVE DB-CU-NROCUEN TO WS-NROCUEN
MOVE DB-CL-NOMAPE TO WS-NOMYAPEL
MOVE DB-CL-NROCLI TO WS-NROCLI
MOVE DB-CU-SALDO TO WS-SALDO
WRITE REG-SALIDA FROM WS-REG-CLIENTE AFTER 1.
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
ADD 1 TO CN-LINEA.
3000-F-IMPRIMIR-CUENTA.
EXIT.
3100-IMPRIMIR-CORTE-TIPO.
*-------------------------*
IF CN-LINEA GREATER 29
PERFORM 4100-IMPRIMIR-TIT-SUC
THRU 4100-F-IMPRIMIR-TIT-SUC
END-IF.
MOVE WS-TIPCUEN-ANT TO WS-CUETIPO
MOVE CN-TOT-TIPO TO WS-CUETOTAL
MOVE AC-SALCUEN TO WS-SUCSALDO
WRITE REG-SALIDA FROM WS-TOT-CUENTA AFTER 1.
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
ADD 1 TO CN-LINEA.
3100-F-IMPRIMIR-CORTE-TIPO.
EXIT.
3200-IMPRIMIR-CORTE-SUC.
*------------------------*
IF CN-LINEA GREATER 29
PERFORM 4100-IMPRIMIR-TIT-SUC
THRU 4100-F-IMPRIMIR-TIT-SUC
END-IF.
MOVE WS-SUCUEN-ANT TO WS-SUCNAME2
MOVE CN-TOT-SUC TO WS-SUCTOTAL
MOVE AC-SALSUC TO WS-SUCSALDO2
WRITE REG-SALIDA FROM WS-TOT-SUCURSAL AFTER 1.
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
ADD 1 TO CN-LINEA.
3200-F-IMPRIMIR-CORTE-SUC.
EXIT.
4000-IMPRIMIR-TIT-CLI.
*----------------------*
MOVE SPACES TO WS-REG-CLIENTE
MOVE DB-CL-NOMAPE TO WS-NOMYAPEL
MOVE DB-CL-NROCLI TO WS-NROCLI
ADD 1 TO CN-LINEA
WRITE REG-SALIDA FROM WS-TITULO AFTER 1
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
4000-F-IMPRIMIR-TIT-CLI.
EXIT.
4100-IMPRIMIR-TIT-SUC.
*----------------------*
MOVE DB-CU-SUCUEN TO WS-SUCNAME
ADD 1 TO CN-PAGINA
MOVE CN-PAGINA TO WS-PAGINA
WRITE REG-SALIDA FROM WS-TIT-SUCURSAL AFTER PAGE.
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
WRITE REG-SALIDA FROM WS-SEPARADOR AFTER 1.
IF FS-SAL IS NOT EQUAL '00'
DISPLAY '* ERROR EN WRITE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF.
MOVE 2 TO CN-LINEA.
PERFORM 4000-IMPRIMIR-TIT-CLI
THRU 4000-F-IMPRIMIR-TIT-CLI.
4100-F-IMPRIMIR-TIT-SUC.
EXIT.
9999-I-FINAL.
*-------------*
EXEC SQL
CLOSE CURSOR1
END-EXEC.
IF SQLCODE NOT EQUAL ZEROS
MOVE SQLCODE TO WS-SQLCODE
DISPLAY '* ERROR CLOSE CURSOR = ' WS-SQLCODE
MOVE 9999 TO RETURN-CODE
END-IF.
CLOSE SALIDA
IF FS-SAL NOT EQUAL '00'
DISPLAY '* ERROR EN CLOSE SALIDA = ' FS-SAL
MOVE 9999 TO RETURN-CODE
END-IF
.
9999-F-FINAL.
EXIT.