[go: up one dir, main page]

Menu

[r37]: / common / analMT.cbl  Maximize  Restore  History

Download this file

1110 lines (1105 with data), 44.6 kB

   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
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
>>source free
*>***********************************************
*> *
*> Analysis *
*> File/Table RDB Handler *
*> *
*>***********************************************
*>
identification division.
Program-Id. analMT.
*>**
*> Author. Vincent B Coen, FBCS, FIDM, FIDPM, CPL
*> for Applewood Computers.
*>**
*> Security. Copyright (C) 2016 and later, Vincent Bryan Coen.
*> Distributed under the GNU General Public License
*> v2.0. Only. See the file COPYING for details.
*>**
*> Remarks. Analysis File RDB Handler using amended JC preSQL.
*> **********************************************
*>
*> This version uses an amended JC pre-Sql processor.
*> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*>
*> This and associated modules relate to ACAS versions v3.02 and later.
*>
*> This modules does all file handling using RDB and is called
*> from the ACAS
*> Analysis file handler acas015
*> which in turn is called
*> from each ACAS application module that requires file/RDB data handling.
*>
*> If RDBMS (Relational DataBase Management Systems) is in use it will be
*> called by the specific module to handle similar processing as a Cobol
*> flat file and will pass the equivelent
*> RDB (Relational DataBase) row as a Cobol file record (01 level) moving
*> row by row to the correct Cobol flat file fields as required.
*>
*> RDB DAL (Data Access Layer) modules are individually modified to handle:
*> MS SQL server, Mysql, DB2, Postgres and Oracle as available and tested.
*> These are contained in seperate directories for each RDB, eg
*> 'MSSQL' (MS SQL Server), 'Mysql', 'DB2', 'Postgres'. 'Oracle'.
*> You need to compile from the correct directory for the specific
*> RDB you will use and have installed along with all of the development
*> libraries and include files etc using the correct pre-compiler tool
*> to process the 'EXEC SQL' code converting to Cobol calls etc.
*> see the RDB specific ACAS notes.
*>
*> For specific SQL servers supported, the pre-compiler system is included
*> where ever possible but for some, copyright reasons may prevent
*> inclusion. In some cases for one specific RDB more than one precompiler
*> is used as an experiment to help find the ideal one to use.
*>
*> In addition:
*> If the system has been set up to (see the System File set up via the
*> main menu module for each sub system), it will also process BOTH flat
*> file AND the correct rdb tables,
*>
*> it will write/delete/update etc to both but read from 1=Flat and be
*> overwritten by the rdb access if data is present.
*> This will help in transferring the Cobol flat files to rdb tables.
*>
*> If you wish to convert a running ACAS system over from Flat files
*> to RDBMS see below. However it is recommended to use the Duplicate
*> processing of files/table as outlined above where no or very low
*> data records exist:
*>
*> Depending on the RDB you wish to use there is
*> also, included LMs (Load Modules) to convert each ISAM
*> (Indexed Sequential) file to the rdb database tables if you wish to
*> convert the system in one hit, without using the Duplicate file/RDB
*> processing procedures. These will also need to be compiled from the
*> specific LM directory that contains the rdb DAL modules.
*> These will be very RDB specific.
*>
*> For a existing running ACAS system using the Load modules AND
*> not using the dup processing process as indicated above is the
*> recommended way to go.
*>**
*> File Handling:
*> Uses the Global Error / Access logging file within the acas0nn module.
*>**
*> Called by Modules:
*> acas015 - Analysis Cobol Handler.
*>
*>**
*> Error Messages Used.
*> SM004 SQL Err no in 'mysql-procedures'
*> SM901 Note error and hit return.
*>**
*> Version. 1.00 17/06/2016.
*>
*>**
*> Changes.
*> 04/08/16 vbc - .01 Removed file action logging to sep. module ditto acas011.
*> 18/07/16 vbc - .02 Insert call for SQL error msg where missing and move
*> spaces / zero to SQL-Msg| Err and other little fixes/cleanups.
*> Remap all changes to the .scb source file.
*> 20/07/16 vbc - .03 Close logger if testing-1 set on table close.
*> branch to 999-end instead of 998-free when EOF on read next.
*> Seems to auto release if end of cursor data reached
*> and causes an abort ??
*> 24/07/16 vbc - Taken from the stockMT sources with same versioning.
*> 30/07/16 vbc - .04 Change Open and Close to also show table name in operation.
*> 31/07/16 vbc - .05 Moved mv spaces/zero in Write to before insert.
*> Remove fhlogger file close in Process-Close.
*> Forgot error 989 so commented.
*> 05/11/16 vbc - .06 Removed all lock/unlock code.
*> 01/03/18 vbc - .11 Renamed error messages to SM901, SM004 as needed.
*> 21/03/18 vbc - .12 Bring coding into line with later ones using sql-state etc.
*> 16/04/24 vbc Copyright notice update superseding all previous notices.
*>**
*> Module USAGE
*>**************
*>
*> On Entry: Set up Linkage areas -
*> ******** Analysis-Record = Contents of data record to be written/read
*> File-Access = File-Function as needed.
*> Access-Type as needed.
*> File-Defs (File-Definitions) = Paths set up.
*>
*> On Exit: Linkage contains:
*> ******* Record = containing a read data record or table row
*> Fs-Reply = 0, 99 or other value where
*> 0 = Operation completed successfully
*> 10 = End of (Cobol) File returned to calling module only.
*> 21 = Invalid key on START OR key not found
*> 22 - Attempt to duplicate a key value.
*> 23 = Key not found. from read indexed
*> 99 = Indicates an error see WE-Error, SQL-ERR/MSG for more info
*> WE-Error 0 = Operation completed successfully
*>
*> 999 = Not used here - Yet.
*> 998* = File-Key-No Out Of Range not 1, 2 or 3.
*> 997* = Access-Type wrong (< 5 or > 8)
*> 996* = File Delete key out of range (not = 1 or 2)
*> 995* = During Delete SQLSTATE not '00000' investigate using MSG-Err/Msg
*> 994* = During Rewrite, ^^ see above ^^
*> 992* = Invalid Function requested in File-Function
*> 990* = Unknown and unexpected error, again ^^ see above ^^
*> 989* = Unexpected error on Read-Indexed, investigate as above.
*> 911* = Rdb Error during initializing,
*> possibly can not connect to database
*> Check connect data and
*> see SQL-Err & SQL-MSG
*> Produced by Mysql-1100-Db-Error in copy
*> module mysql-procedure.
*> 910* = Table locked > 5 seconds
*> 901 = File Def Record size not =< than ws record size
*> Module needs ws definition changing to correct size
*> FATAL, Stop using system, fix source code
*> and recompile before using system again.
*> Other = any other rdbms errors see specific
*> (Rdbms) manual
*> SQL-Err = Error code from RDBMS is set if above 2 are non zero
*> SQL-Msg = Non space providing more info if SQL-Err non '00000'
*> * = FS-Reply = 99.
*>
copy "ACAS-SQLstate-error-list.cob".
*>
*> During testing a log file will be created containing datetime stamp, task and return codes
*> for both FS-Reply and WE-Error and table used - in this case the Stock File.
*> WARNING - This file could get large so needs manually deleting after examination.
*>
*> NOTE that the value in SQL-Err is the standard ANSI RDBMS error code to help keep
*> DAL handler changes to a minimum when reusing code for other RDBs - hopefully
*>
*> SHOULD THIS BE IN THE DAL ONLY ? Only for RDB accessing.
*>
*>********************************************************************************************
*>
*> Copyright Notice.
*> ****************
*>
*> This notice supersedes all prior copyright notices & was updated 2024-04-16.
*>
*> These files and programs are part of the Applewood Computers Accounting
*> System and is Copyright (c) Vincent B Coen. 1976-2025 and later.
*>
*> This program is now free software; you can redistribute it and/or modify it
*> under the terms listed here and of the GNU General Public License as
*> published by the Free Software Foundation; version 3 and later as revised
*> for PERSONAL USAGE ONLY and that includes for use within a business but
*> EXCLUDES repackaging or for Resale, Rental or Hire in ANY way.
*>
*> Persons interested in repackaging, redevelopment for the purpose of resale or
*> distribution in a rental or hire mode must get in touch with the copyright
*> holder with your commercial plans and proposals.
*>
*> ACAS is distributed in the hope that it will be useful, but WITHOUT
*> ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
*> FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
*> for more details. If it breaks, you own both pieces but I will endeavour
*> to fix it, providing you tell me about the problem.
*>
*> You should have received a copy of the GNU General Public License along
*> with ACAS; see the file COPYING. If not, write to the Free Software
*> Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*>
*>**********************************************************************************
*>
environment division.
*> copy "envdiv.cob".
*>
input-output section.
Data Division.
Working-Storage Section.
77 prog-name pic x(17) value "analMT (3.02.12)".
*>
*> JC WS requirements here
*>
77 ws-Where pic x(512).
*>
*> Used within presql generated code
*>
01 WS-Reply pic x value space.
01 WS-MYSQL-I PIC S9(4) COMP.
01 WS-MYSQL-EDIT PIC -Z(18)9.9(9).
*>
*> TESING data
*>
01 ws-temp-ed pic 9(10).
*>
*> The communication area for the MySQL database changed for free/mysql
*>
*> jc preSQL MySQL stuff ends
*>
*> Metadata on primary and alternate keys... from Prima DAL for ANALYSIS-REC
*>
01 Table-Of-Keynames.
03 filler pic x(30) value 'PA-CODE '.
03 filler pic x(8) value '00010003'. *> offset/length
03 filler pic x(3) value 'STR'. *> data type
01 filler redefines table-of-keynames.
03 keyOfReference occurs 1
indexed by KOR-x1.
05 keyname pic x(30).
05 KOR-offset pic 9(4).
05 KOR-length pic 9(4).
05 KOR-Type pic XXX. *> Not used currently
*>
*> The START condition cannot be compounded, and it must use a
*> Key of Reference within the record. (These are COBOL rules...)
*> The interface defines which key and the relation condition.
*>
*>
01 DAL-Data.
05 MOST-Relation pic xxx. *> valid are >=, <=, <, >, =
05 Most-Cursor-Set pic 9 value zero.
88 Cursor-Not-Active value zero.
88 Cursor-Active value 1.
*>
*> Variables common to all DALs
*> ****************************
*>
01 subscripts usage comp-5.
12 J pic s9(4).
12 K pic s9(4).
12 L pic s9(4).
*>
01 work-fields.
03 ws-env-lines pic 999 value zero.
03 ws-lines binary-char unsigned value zero.
03 ws-22-lines binary-char unsigned value zero.
03 ws-23-lines binary-char unsigned value zero.
03 ws-98-lines binary-char unsigned value zero.
03 ws-99-lines binary-char unsigned value zero.
03 ws-Rec-Cnt binary-long unsigned value zero.
*>
01 Error-Messages.
03 SM901 pic x(31) value "SM901 Note error and hit return".
*>
*> /MYSQL VAR\
*> ACASDB
*> TABLE=ANALYSIS-REC,HV
COPY "mysql-variables.cpy".
*>
*> Definitions for the ANALYSIS-REC Table
*>
01 TP-ANALYSIS-REC USAGE POINTER.
01 TD-ANALYSIS-REC.
05 HV-PA-CODE PIC X(3).
05 HV-PA-GL PIC 9(08) COMP.
05 HV-PA-DESC PIC X(24).
05 HV-PA-PRINT PIC X(3).
*> /MYSQL-END\
Linkage Section.
*>**************
*>
*>**********************************************************************
copy "wsfnctn.cob". *> File-Access
*>
*>**********************************************************************
01 ACAS-DAL-Common-data.
*>
*> log file reporting for testing otherwise zero
*>
03 SW-Testing pic 9 value 1. *> zero.
88 Testing-1 value 1.
*>
*> Testing only for displays ws-where etc otherwise zero
*>
03 SW-Testing-2 pic 9 value zero.
88 Testing-2 value 1.
*>
03 Log-File-Rec-Written pic 9(6) value zero. *> in both acas0nn and a DAL.
*>
*> Generated by MOSTGEN from the COPY Book... The record buffer
*> This data buffer was derived from the C:\prim-acas1\SourceSets\PULEDGER.CBF
*> COPY book by MOSTGEN. It is hard coded here so you
*> can see which version of the Source Set was used.
*>
01 Analysis-Rec.
03 Pa-Code pic xxx.
03 Pa-Gl pic 9(6).
03 Pa-Desc pic x(24).
03 Pa-Print pic xxx.
*>
screen section.
*>=============
*>
01 Display-Message-1 foreground-color 2.
03 value "WS-Where=" line 23 col 1.
03 from WS-Where (1:J) pic x(69) col 10.
*>
01 Display-Message-2 foreground-color 2.
03 value "SM004 SQL Err No.=" line 4 col 1. *> size 18 char
03 using Ws-Mysql-Error-Number pic x(4) col 19. *> 4 == 22
03 value " Para=" col 23. *> size 6 char == 28
03 using WS-No-Paragraph pic 9(3) col 29. *> 4 == 32
03 value " SQL Cmd=" col 32. *> 9 == 41
03 using Ws-Mysql-Command pic x(199) col 41.
03 value "SQL Err Msg=" line 7 col 1. *> 12
03 using Ws-Mysql-Error-Message pic x(67) col 13.
*>
*>
PROCEDURE DIVISION using File-Access
ACAS-DAL-Common-data
Analysis-Rec. *> Ws record
*>**********************************************
ba-ACAS-DAL-Process section.
accept ws-env-lines from lines.
if ws-env-lines < 24
move 24 to ws-env-lines ws-lines
else
move ws-env-lines to ws-lines
end-if
*> Force Esc, PgUp, PgDown, PrtSC to be detected
set ENVIRONMENT "COB_SCREEN_EXCEPTIONS" to "Y".
set ENVIRONMENT "COB_SCREEN_ESC" to "Y".
*>
add 2 to ws-lines giving ws-99-lines.
add 1 to ws-lines giving ws-98-lines.
*>
ba010-Initialise.
*>
*> move zero to We-Error
*> Fs-Reply.
*>
move spaces to WS-MYSQL-Error-Message
WS-MYSQL-Error-Number
WS-Log-Where
WS-File-Key
SQL-Msg
SQL-Err
SQL-State.
*>
*> Work out what is being requested and convert to action!!
*>
*> This version uses the JC pre-Sql processor.
*> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*>
evaluate File-Function
when 1
go to ba020-Process-Open
when 2
go to ba030-Process-Close
when 3
go to ba040-Process-Read-Next
when 4
go to ba050-Process-Read-Indexed
when 5
go to ba070-Process-Write
when 7
go to ba090-Process-Rewrite
when 8
go to ba080-Process-Delete
when 9
go to ba060-Process-Start
when other *> 6 is spare / unused
go to ba100-Bad-Function
end-evaluate.
*>
ba020-Process-Open.
*>
*> Manual process MYSQL INIT
*> then perform MYSQL-1000-OPEN THRU MYSQL-1090-EXIT
*>
string DB-Schema delimited by space
X"00" delimited by size
into WS-MYSQL-BASE-NAME
end-string.
string DB-Host delimited by space
X"00" delimited by size
into WS-MYSQL-HOST-NAME
end-string.
string DB-UName delimited by space
X"00" delimited by size
into WS-MYSQL-IMPLEMENTATION
end-string.
string DB-UPass delimited by space
X"00" delimited by size
into WS-MYSQL-PASSWORD
end-string.
string DB-Port delimited by space
X"00" delimited by size
into WS-MYSQL-PORT-NUMBER
end-string.
string DB-Socket delimited by space
X"00" delimited by size
into WS-MYSQL-SOCKET
end-string.
move 1 to ws-No-Paragraph.
PERFORM MYSQL-1000-OPEN THRU MYSQL-1090-EXIT.
if fs-reply not = zero
go to ba999-end.
*>
*> *> /MYSQL INIT\
*> BASE=ACASDB
*> IMPLEMENTATION=dev-prog-001
*> PASSWORD=mysqlpass
*> *> /MYSQL-END\
*>
move "OPEN Analysis" to WS-File-Key
move zero to Most-Cursor-Set
go to ba999-end.
*>
ba030-Process-Close.
if Cursor-Active
perform ba998-Free.
*>
move 2 to ws-No-Paragraph.
move "CLOSE Analysis" to WS-File-Key.
*> /MYSQL CLOSE\
*>
*> Close the Database
*>
PERFORM MYSQL-1980-CLOSE THRU MYSQL-1999-EXIT
*> /MYSQL-END\
*>
go to ba999-end.
*>
ba040-Process-Read-Next.
*>
*> Here a SELECT first then fetch if no cursor active using lowest
*> possible key of "000"
*> [ Pa-Code ]
*>
if Cursor-Not-Active
set KOR-x1 to 1 *> 1 = Primary, 2 = Abrev, 3 = Desc (NOT Delete function as can be dups)
move KOR-offset (KOR-x1) to K
move KOR-length (KOR-x1) to L
*>
move spaces to WS-Where
move 1 to J
string "`" delimited by size
KeyName (KOR-x1) delimited by space
"`" delimited by size
" > " delimited by size
'"000"' delimited by size
' ORDER BY ' delimited by size
"`" delimited by size
keyname (KOR-x1) delimited by space
"`" delimited by size
' ASC' delimited by size
into ws-Where
with pointer J
end-string
*>
move ws-Where (1:J) to WS-Log-Where *> For test logging
move 3 to ws-No-Paragraph
*> /MYSQL SELECT\
*>
*> Select rows
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
STRING "SELECT * FROM "
"`ANALYSIS-REC`"
" WHERE "
ws-Where (1:J) *> Pa-Code > "000" ORDER BY ANALYSIS-REC ASC
";" X"00" INTO WS-MYSQL-COMMAND
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
PERFORM MYSQL-1220-STORE-RESULT THRU MYSQL-1239-EXIT
MOVE WS-MYSQL-RESULT TO TP-ANALYSIS-REC
*> /MYSQL-END\
move "000" to WS-File-Key
if Testing-2
display Display-Message-1 with erase eos
end-if
*>
*> It could be an empty table so test for it
*>
if WS-MYSQL-Count-Rows = zero
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0" *> set non '0' if no rows ?
move WS-MYSQL-Error-Number to SQL-Err
call "MySQL_error" using WS-MYSQL-Error-Message
move WS-MYSQL-Error-Message to SQL-Msg
end-if *> do not really need to do this meaning the above CALL
move 10 to fs-reply
move 10 to WE-Error
move "No Data" to WS-File-Key
go to ba998-Free *> can clear the dup code after testing
end-if
move 1 to Most-Cursor-Set *> should test if select worked first??????
end-if.
*>
*> If here cursor is set, so get the next row
*>
move spaces to WS-Log-Where.
move 4 to ws-No-Paragraph.
move zero to return-code.
*>
*> /MYSQL FETCH\
*>
*> Fetch next record
*>
*> TABLE=ANALYSIS-REC
MOVE TP-ANALYSIS-REC TO WS-MYSQL-RESULT
CALL "MySQL_fetch_record" USING WS-MYSQL-RESULT
HV-PA-CODE
HV-PA-GL
HV-PA-DESC
HV-PA-PRINT
*> /MYSQL-END\
end-call
*>
if return-code = -1 *> no more data so free cursor & return
move 10 to fs-Reply WE-Error
move "EOF" to WS-File-Key
set Cursor-Not-Active to true
go to ba999-End
end-if
*>
if WS-MYSQL-Count-Rows = zero
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
call "MySQL_error" using WS-MYSQL-Error-Message
move 10 to fs-reply *> EOF equivilent !!
move 10 to WE-Error
move WS-MYSQL-Error-Number to SQL-Err *> Not really needed but help for testing
move WS-MYSQL-Error-Message to SQL-Msg *> ditto
initialize Analysis-Rec with filler
move "EOF2" to WS-File-Key
end-if
set Cursor-Not-Active to true
go to ba999-End
end-if.
*>
if fs-reply = 10
set Cursor-Not-Active to true
move "EOF3" to WS-File-Key
go to ba999-End
end-if.
perform bb100-UnloadHVs. *> transfer/move HV vars to Record layout
*>
move HV-Pa-Code to WS-File-Key.
move zero to fs-reply WE-Error.
go to ba999-end.
*>
ba050-Process-Read-Indexed.
*>
*> Now do on correct key within WHERE
*> Sets up key and compare data
*>
set KOR-x1 to 1. *> 1 = only key
move KOR-offset (KOR-x1) to K
move KOR-length (KOR-x1) to L
*>
move spaces to WS-Where
move 1 to J
string "`" delimited by size
KeyName (KOR-x1) delimited by space
"`" delimited by size
'="' delimited by size
Analysis-Rec (K:L) delimited by size
'"' delimited by size
into WS-Where
with pointer J
end-string
move WS-Where (1:J) to WS-Log-Where. *> For test logging
if Testing-2
display Display-Message-1 with erase eos
end-if
move 5 to ws-No-Paragraph
*> /MYSQL SELECT\
*>
*> Select rows
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
STRING "SELECT * FROM "
"`ANALYSIS-REC`"
" WHERE "
WS-Where (1:J)
";" X"00" INTO WS-MYSQL-COMMAND
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
PERFORM MYSQL-1220-STORE-RESULT THRU MYSQL-1239-EXIT
MOVE WS-MYSQL-RESULT TO TP-ANALYSIS-REC
*> /MYSQL-END\
*>
if WS-MYSQL-Count-Rows = zero
move 21 to fs-Reply *> could also be 23 or 14
move zero to WE-Error
go to ba998-Free
end-if
move 6 to ws-No-Paragraph
*> /MYSQL FETCH\
*>
*> Fetch next record
*>
*> TABLE=ANALYSIS-REC
MOVE TP-ANALYSIS-REC TO WS-MYSQL-RESULT
CALL "MySQL_fetch_record" USING WS-MYSQL-RESULT
HV-PA-CODE
HV-PA-GL
HV-PA-DESC
HV-PA-PRINT
*> /MYSQL-END\
end-call
*>
if WS-MYSQL-Count-Rows not > zero
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
move 21 to fs-reply *> from 23
move 990 to WE-Error
call "MySQL_error" using WS-MYSQL-Error-Message
move WS-MYSQL-Error-Number to SQL-Err
move WS-MYSQL-Error-Message to SQL-Msg
move spaces to WS-File-Key
go to ba998-Free
else
move 21 to fs-reply *> from 23
move 989 to WE-Error
move zero to SQL-Err
move spaces to SQL-Msg
move spaces to WS-File-Key
go to ba998-Free
end-if
end-if *> row count zero should show up as a MYSQL error ?
perform bb100-UnloadHVs *> transfer/move HV vars to ws-Record layout
move HV-Pa-Code to WS-File-Key
move zero to FS-Reply WE-Error.
go to ba998-Free.
*>
ba060-Process-Start.
*>
*> Check for Param error 1st on start
*>
if access-type < 5 or > 8 *> not using not < or not >
move 99 to FS-Reply
move 997 to WE-Error *> Invalid calling parameter settings 997
go to ba999-end
end-if
*>
*> First clear any active cursors
*>
if Cursor-Active
perform ba998-Free.
*>
*> Now do Start on correct key before read-next within WHERE
*> Set up MOST-relation for condition test and key
*>
set KOR-x1 to 1.
move KOR-offset (KOR-x1) to K
move KOR-length (KOR-x1) to L
*>
move spaces to MOST-Relation.
move 1 to J.
evaluate Access-Type
when 5 *> fn-equal-to
move "= " to MOST-Relation
when 6 *> fn-less-than
move "< " to MOST-Relation
when 7 *> fn-greater-than
move "> " to MOST-Relation
when 8 *> fn-not-less-than
move ">= " to MOST-Relation
when 9 *> fn-not-greater-than [ not currently used in ACAS ]
move "<= " to MOST-Relation
end-evaluate
*>
move spaces to WS-Where
string "`" delimited by size
KeyName (KOR-x1) delimited by space
"`" delimited by size
MOST-relation delimited by space
'"' delimited by size
Analysis-Rec (K:L) delimited by size
'"' delimited by size
' ORDER BY ' delimited by size
"`" delimited by size
keyname (KOR-x1) delimited by space
"`" delimited by size
' ASC ' delimited by size
into WS-Where
with pointer J
end-string
move WS-Where (1:J) to WS-Log-Where. *> For test logging
move Analysis-Rec (K:L) to WS-File-Key
if Testing-2
display Display-Message-1 with erase eos
end-if
*>
move 8 to ws-No-Paragraph
*> /MYSQL SELECT\
*>
*> Select rows
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
STRING "SELECT * FROM "
"`ANALYSIS-REC`"
" WHERE "
WS-Where (1:J)
";" X"00" INTO WS-MYSQL-COMMAND
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
PERFORM MYSQL-1220-STORE-RESULT THRU MYSQL-1239-EXIT
MOVE WS-MYSQL-RESULT TO TP-ANALYSIS-REC
*> /MYSQL-END\
*>
if WS-MYSQL-Count-Rows not zero
set Cursor-Active to true
end-if
*>
if WS-MYSQL-Count-Rows = zero
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
call "MySQL_error" using WS-MYSQL-Error-Message
move WS-MYSQL-Error-Number to SQL-Err
move WS-MYSQL-Error-Message to SQL-Msg
move 21 to fs-reply *> this may need changing for val in WE-Error!!
move zero to WE-Error
end-if
else
move zero to FS-Reply WE-Error
move WS-MYSQL-Count-Rows to WS-Temp-Ed
string MOST-relation
Analysis-Rec (K:L)
" got =" delimited by size
WS-Temp-ED delimited by size
" recs"
into WS-File-Key
end-string
end-if
go to ba999-end.
*>
*> Now a read next will process a Fetch from cursor
*>
ba070-Process-Write.
perform bb000-HV-Load. *> move Analysis-Rec fields to HV fields
move Pa-Code to WS-File-Key.
move zero to FS-Reply WE-Error SQL-State.
move spaces to SQL-Msg
move zero to SQL-Err
move 10 to ws-No-Paragraph.
perform bb200-Insert.
if WS-MYSQL-COUNT-ROWS not = 1
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
call "MySQL_error" using Ws-Mysql-Error-Message
move WS-MYSQL-Error-Number to SQL-Err
move WS-MYSQL-Error-Message to SQL-Msg
if SQL-Err (1:4) = "1062"
or = "1022" *> Dup key (rec already present)
or Sql-State = "23000" *> Dup key (rec already present)
move 22 to fs-reply
else
move 99 to fs-reply *> this may need changing for val in WE-Error!!
end-if
end-if
end-if
go to ba999-End. *> and log it
*>
ba080-Process-Delete.
*>
set KOR-x1 to 1.
move KOR-offset (KOR-x1) to K
move KOR-length (KOR-x1) to L
*>
move spaces to WS-Where
move 1 to J
string "`" delimited by size
KeyName (KOR-x1) delimited by space
"`" delimited by size
'="' delimited by size
Analysis-Rec (K:L) delimited by size
'"' delimited by size
into WS-Where
with pointer J
end-string
move Analysis-Rec (K:L) to WS-File-Key.
move WS-Where (1:J) to WS-Log-Where. *> For test logging
if Testing-2
display Display-Message-1 with erase eos
end-if
move 13 to ws-No-Paragraph.
*> /MYSQL DELETE\
*>
*> Delete a row
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
STRING "DELETE FROM "
"`ANALYSIS-REC`"
" WHERE "
WS-Where (1:J)
X"00" INTO WS-MYSQL-COMMAND
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
*> /MYSQL-END\
if WS-MYSQL-COUNT-ROWS not = 1
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
call "MySQL_error" using Ws-Mysql-Error-Message
move WS-MYSQL-Error-Number to SQL-Err
move WS-MYSQL-Error-Message to SQL-Msg
move 99 to fs-reply
move 995 to WE-Error
end-if
go to ba999-End
else
move spaces to SQL-Msg
move zero to SQL-Err
end-if.
move zero to FS-Reply WE-Error.
go to ba999-End.
*>
ba090-Process-Rewrite.
*>
perform bb000-HV-Load. *> Load up the HV fields from table record in WS
move 17 to ws-No-Paragraph.
set KOR-x1 to 1 *> 1 = Primary, 2 = Abrev, 3 = Desc (NOT Delete function as can be dups)
move KOR-offset (KOR-x1) to K
move KOR-length (KOR-x1) to L
*>
move Analysis-Rec (K:L) to WS-File-Key.
move spaces to WS-Where
move 1 to J
string "`" delimited by size
KeyName (KOR-x1) delimited by space
"`" delimited by size
'="' delimited by size
Analysis-Rec (K:L) delimited by size
'"' delimited by size
into WS-Where
with pointer J
end-string
move WS-Where (1:J) to WS-Log-Where. *> For test logging
perform bb300-Update.
*>
if Testing-2
display Display-Message-1 with erase eos
end-if
*>
if WS-MYSQL-COUNT-ROWS not = 1
call "MySQL_errno" using WS-MYSQL-Error-Number
call "MySQL_sqlstate" using WS-MYSQL-SQLstate
move WS-MYSQL-SqlState to SQL-State
if WS-MYSQL-Error-Number (1:1) not = "0"
call "MySQL_error" using Ws-Mysql-Error-Message
move WS-MYSQL-Error-Number to SQL-Err
move WS-MYSQL-Error-Message to SQL-Msg
move 99 to fs-reply *> this may need changing for val in WE-Error!!
move 994 to WE-Error
end-if
go to ba999-End
end-if
move zero to FS-Reply WE-Error.
move zero to SQL-Err.
move spaces to SQL-Msg.
go to ba999-exit.
*>
ba100-Bad-Function.
*>
*> Houston; We have a problem
*>
move 990 to WE-Error.
move 99 to Fs-Reply.
go to ba999-end.
*>
*> /MYSQL PRO\
COPY "mysql-procedures.cpy".
*> /MYSQL-END\
*>
ba998-Free.
move 20 to ws-No-Paragraph.
*> /MYSQL FREE\
*>
*> Free result array
*>
*> TABLE=ANALYSIS-REC
MOVE TP-ANALYSIS-REC TO WS-MYSQL-RESULT
CALL "MySQL_free_result" USING WS-MYSQL-RESULT end-call
*> /MYSQL-END\
set Cursor-Not-Active to true.
*>
ba999-end.
*> Any Clean ups before quiting move data record ????? do so at the start as well ??????
*>
if Testing-1
perform Ca-Process-Logs
end-if.
*>
ba999-exit.
exit program.
*>
bb000-HV-Load Section.
*>*************************
*>
*> Load the Host variables with data from the passed record
*>
*> This Method loads the Host Variables for the Base table with
*> the data passed in the data-buffer.
*>
initialize TD-ANALYSIS-REC.
move PA-CODE to HV-Pa-CODE
move PA-GL to HV-PA-GL
move PA-DESC to HV-Pa-Desc
move Pa-Print to HV-Pa-Print.
*>
*> Loading HVs implies a non-Fetch action. RGs are handled separately for
*> all such actions so they must not be loaded here.
*>
bb000-Exit.
exit section.
*>
bb100-UnloadHVs Section.
*>*************************
*>
*> Load the data buffer in the interface with data from the host variables.
*> (init moved lower)
*>
*> NULL fields must not be returned in the buffer. SQL filters each column to
*> ensure it has a proper value. This saves using indicator variables.
*>
initialize Analysis-Rec.
*>
move HV-Pa-Code to PA-CODE
move HV-PA-GL to PA-GL
move HV-Pa-Desc to PA-DESC
move HV-Pa-Print to Pa-Print.
*>
bb100-Exit.
exit section.
*>
bb200-Insert Section.
*>*******************
*>
*> /MYSQL INSERT\
*>
*> Insert a row
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
MOVE 1 TO WS-MYSQL-I
STRING 'INSERT INTO '
'`ANALYSIS-REC` SET '
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-CODE`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-CODE,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-GL`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
MOVE HV-PA-GL
TO WS-MYSQL-EDIT
STRING FUNCTION TRIM (WS-MYSQL-EDIT(13:08))
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING '"' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-DESC`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-DESC,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-PRINT`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-PRINT,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ";" INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING X"00" INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
*> /MYSQL-END\
. *> period here
*>
bb200-Exit.
exit section.
*>
bb300-Update Section.
*>*******************
*>
*> /MYSQL UPDATE\
*>
*> Update a row
*>
*> TABLE=ANALYSIS-REC
INITIALIZE WS-MYSQL-COMMAND
MOVE 1 TO WS-MYSQL-I
STRING 'UPDATE '
'`ANALYSIS-REC` SET '
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-CODE`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-CODE,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-GL`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
MOVE HV-PA-GL
TO WS-MYSQL-EDIT
STRING FUNCTION TRIM (WS-MYSQL-EDIT(13:08))
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING '"' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-DESC`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-DESC,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ', 'INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
*>
STRING '`PA-PRINT`="' INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (HV-PA-PRINT,TRAILING)
'"'
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING " WHERE "
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING FUNCTION TRIM (WS-Where (1:J))
INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
STRING ";" X"00" INTO WS-MYSQL-COMMAND
WITH POINTER WS-MYSQL-I end-string
PERFORM MYSQL-1210-COMMAND THRU MYSQL-1219-EXIT
*> /MYSQL-END\
. *> period here
*>
bb300-Exit.
exit section.
*>
Ca-Process-Logs.
*>**************
*>
call "fhlogger" using File-Access
ACAS-DAL-Common-data.
*>
ca-Exit. exit.
*>
end program analMT.