daily pastebin goal
82%
SHARE
TWEET

Untitled

a guest Jul 1st, 2018 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.        IDENTIFICATION DIVISION.
  2.         PROGRAM-ID. connection.
  3.        
  4.        ENVIRONMENT DIVISION.        
  5.         Input-output section.
  6.          file-control.
  7.  
  8.           select parameterfile
  9.            assign to "parbest.txt"
  10.            organization is line sequential
  11.            access mode is sequential.
  12.        
  13.           select logfile assign to "logfile.txt"
  14.            organization is sequential
  15.            access mode is sequential.
  16.        
  17.        DATA DIVISION.
  18.         File section.
  19.          FD logfile.
  20.       *   linage 60
  21.       *   with footing at 56
  22.       *   lines at bottom 3.    
  23.       *   linage mag gebruikt worden in UC 2, maar is hier niet nodig.  
  24.          01 logMessage   pic x(100).
  25.        
  26.         FD parameterfile.
  27.          01 viewingRecord.
  28.           88 end-file    value low-values.
  29.           02 readline    pic x(1000).
  30.          
  31.          
  32.         EXEC SQL BEGIN DECLARE SECTION END-EXEC
  33.           77 SQLCODE     pic S9(3).
  34.           77 SQLSTATE    pic x(5).      
  35.         EXEC SQL END DECLARE SECTION END-EXEC
  36.       * SQLCODE is 0 for success, 100 for no data, -1 for failure
  37.         01 SQLCODE       pic S9(3).
  38.       * SQLSTATE is a 5 character communication code; 00xxx is success.
  39.         01 SQLSTATE      pic x(5).
  40.        
  41.        
  42.         Working-storage section.
  43.          01 inputString  pic x(255).
  44.          01 email        pic x(100).
  45.          01 name         pic x(50).
  46.          01 firstName    pic x(50).
  47.          01 pass         pic x(100).
  48.          01 sqlCount     pic 999 value 0.
  49.    
  50.        
  51.        PROCEDURE DIVISION.
  52.         Pgm.
  53.          display "PMES Database Creator"
  54.          display "====================="
  55.          display ""
  56.      
  57.          open output logfile      
  58.          open input parameterfile  
  59.                
  60.       * Initial read of parameterfile
  61.          display "STATUS: Reading parameters"
  62.          read parameterfile next at end
  63.           move high-values to viewingRecord
  64.           perform LOG-EMPTYFILE
  65.           perform EXITPROGRAM
  66.          end-read.
  67.          move readline to inputString
  68.              
  69.          perform CONNECT        
  70.          if SQLCODE = 0
  71.           display "STATUS: Successfully connected to the database"
  72.           perform LOG-CONNECTION
  73.       *  Read email, name, firstName & pass
  74.           display "STATUS: Reading e-mail, name, first name & password"
  75.           perform READPARAMETERFILE
  76.           unstring readline delimited by " " into
  77.            email name firstName pass
  78.           end-unstring  
  79.       *  Read & execute SQL instructions  
  80.           display "STATUS: Reading & executing SQL statements"    
  81.           perform until end-file
  82.            perform READPARAMETERFILE
  83.            move readline to inputString
  84.            EXEC SQL
  85.             EXECUTE IMMEDIATE :inputString
  86.            END-EXEC
  87.            if SQLCODE = 0
  88.             add 1 to sqlCount
  89.             perform LOG-SQLSTATEMENT
  90.            else
  91.             string
  92.              "ERROR : Problem while executing SQL statement " delimited
  93.               by size
  94.              sqlCount delimited by size
  95.              into inputString
  96.             end-string
  97.             display inputString
  98.             move -1 to sqlCount
  99.             perform EXITPROGRAM
  100.            end-if
  101.           end-perform  
  102.           EXEC SQL
  103.             COMMIT
  104.           END-EXEC  
  105.            if SQLCODE = 0
  106.             display "COMMIT OK"
  107.            else
  108.             perform LOG-COMMIT
  109.             display "ERROR: Problem while commiting to database"
  110.             move -1 to sqlCount
  111.             perform EXITPROGRAM
  112.            end-if    
  113.           EXEC SQL
  114.            DISCONNECT
  115.           END-EXEC  
  116.          else
  117.       *  TODO: Specifieke fouten loggen.
  118.           move -1 to sqlCount
  119.           perform LOG-CONNECTIONERROR
  120.          end-if.        
  121.        
  122.         perform EXITPROGRAM.
  123.        
  124.       * PROCEDURES  
  125.         READPARAMETERFILE.
  126.          read parameterfile next at end
  127.           move high-values to viewingRecord
  128.           perform LOG-ENDOFFILE
  129.          end-read.        
  130.        
  131.         CONNECT.  
  132.          display "STATUS: Connecting to database"    
  133.          EXEC SQL
  134.           CONNECT TO :inputString      
  135.           DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver"                
  136.          END-EXEC.
  137.          
  138.         EXITPROGRAM.
  139.          close logfile
  140.          close parameterfile
  141.          if sqlCount = -1
  142.           display "The program has terminated due to errors, please ref"
  143.            "er to the logfile for more infomation."
  144.          else
  145.           display "The program has successfully completed."
  146.          end-if
  147.          exit program.
  148.        
  149.          
  150.       * LOG PROCEDURES    
  151.         LOG-EMPTYFILE.
  152.          move "ERROR FILE      : Read file is empty" to logMessage
  153.          write logMessage.
  154.          
  155.         LOG-CONNECTION.
  156.          move "STATUS DATABASE : Connection was made" to logMessage
  157.          write logMessage      
  158.          move "STATUS FILE     : Parameterfile is being read.."
  159.           to logMessage
  160.          write logMessage.
  161.        
  162.         LOG-CONNECTIONERROR.
  163.          move "ERROR DATABASE  : Connection could not be made."
  164.           to logMessage
  165.          write logMessage.      
  166.        
  167.         LOG-ENDOFFILE.
  168.          move "STATUS FILE     : End of file." to logMessage
  169.          write logMessage.
  170.          
  171.         LOG-SQLSTATEMENT.
  172.          string
  173.           "STATUS DATABASE : SQL statement " delimited by size
  174.           sqlCount delimited by size
  175.           " > " delimited by size
  176.           inputString delimited by size
  177.           into logMessage
  178.          end-string
  179.          write logMessage.
  180.          
  181.         LOG-COMMIT.
  182.          move "ERROR DATABASE  : Problem while commiting to database" to
  183.           logMessage
  184.          write logMessage.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top