Professional Documents
Culture Documents
00010001
000200 PROGRAM-ID. DB2PROG2. 00020001
000300* 00030001
000400 ENVIRONMENT DIVISION. 00040001
000500 INPUT-OUTPUT SECTION. 00050001
000600 FILE-CONTROL. 00060001
000700 SELECT TRAN-FILE ASSIGN TO TRNFILE 00070001
000800 ORGANIZATION IS SEQUENTIAL 00080001
000900 ACCESS MODE IS SEQUENTIAL 00090001
001000 FILE STATUS IS WS-INP-STAT. 00100001
001100* 00110001
001200 SELECT ERROR-FILE ASSIGN TO ERRFILE 00120001
001300 ORGANIZATION IS SEQUENTIAL 00130001
001400 ACCESS MODE IS SEQUENTIAL 00140001
001500 FILE STATUS IS WS-ERR-STAT. 00150001
001600* 00160001
001700 SELECT REPORT-FILE ASSIGN TO REPFILE 00170001
001800 ORGANIZATION IS SEQUENTIAL 00180001
001900 ACCESS MODE IS SEQUENTIAL 00190001
002000 FILE STATUS IS WS-REP-STAT. 00200001
002100* 00210001
002200 DATA DIVISION. 00220001
002300 FILE SECTION. 00230001
002400 FD TRAN-FILE 00240001
002500 RECORDING MODE IS F 00250001
002600 RECORD CONTAINS 51 CHARACTERS. 00260001
002700* 00270001
002800 01 TRANSACTION-RECORD. 00280001
002900 03 TRAN-CODE PIC X(01). 00290001
003000 88 ADD-EMP VALUE 'A'. 00300001
003100 88 UPD-EMP VALUE 'U'. 00310001
003200 88 DEL-EMP VALUE 'D'. 00320001
003300 03 EMP-ID PIC X(05). 00330001
003400 03 EMP-NAME PIC X(15). 00340001
003500 03 EMP-LOC PIC X(03). 00350001
003600 03 EMP-DOB PIC X(08). 00360001
003700 03 EMP-TECH PIC X(05). 00370001
003800 03 EMP-EARN PIC 9(05)V99. 00380001
003900 03 EMP-DEDN PIC 9(05)V99. 00390001
004000* 00400001
004100 FD ERROR-FILE 00410001
004200 RECORDING MODE IS F 00420001
004300 RECORD CONTAINS 51 CHARACTERS. 00430001
004400* 00440001
004500 01 ERROR-RECORD PIC X(51). 00450001
004600* 00460001
004700 FD REPORT-FILE 00470001
004800 RECORDING MODE IS F 00480001
004900 RECORD CONTAINS 80 CHARACTERS. 00490001
005000* 00500001
005100 01 REPORT-RECORD PIC X(80). 00510001
005200* 00520001
005300 WORKING-STORAGE SECTION. 00530001
005400 01 WS-TRN-STAT PIC X(02) VALUE SPACES. 00540001
005500 88 TRN-SUCCESS VALUE '00'. 00550001
005600* 00560001
005700 01 WS-ERR-STAT PIC X(02) VALUE SPACES. 00570001
005800 88 ERR-SUCCESS VALUE '00'. 00580001
005900* 00590001
006000 01 WS-REP-STAT PIC X(02) VALUE SPACES. 00600001
006100 88 REP-SUCCESS VALUE '00'. 00610001
006200* 00620001
006300 01 WS-VALID-FLAG PIC X(02) VALUE 'N'. 00630001
006400 88 VALID-DATA VALUE 'Y'. 00640001
006500* 00650001
006600 01 WS-FILE-FLAG PIC X(02) VALUE 'N'. 00660001
006700 88 END-OF-DATA VALUE 'Y'. 00670001
006800* 00680001
006900 01 WS-EMP-FLAG PIC S9(03) VALUE ZERO. 00690001
007000 88 EMP-EXISTS VALUE ZERO. 00700001
007100 88 EMP-NOTFOUND VALUE +100. 00710001
007200* 00720001
007300 01 WS-TOTAL. 00730001
007400 03 TOTAL-EARN PIC 9(06)V99 VALUE ZERO. 00740001
007500 03 TOTAL-DEDN PIC 9(06)V99 VALUE ZERO. 00750001
007600 03 TOTAL-EMP PIC 9(03) VALUE ZERO. 00760001
007700 03 OUT-EMP PIC ZZ9 VALUE ZERO. 00770001
007800 03 WS-SQLCODE PIC -9(03) VALUE ZERO. 00780001
007900* 00790001
008000 03 LINE-COUNT PIC 9(02) VALUE 99. 00800001
008100 03 PAGE-COUNT PIC 9(02) VALUE ZERO. 00810001
008200 03 WS-DATE PIC X(10) VALUE SPACES. 00820001
008300 03 WS-TIME PIC X(08) VALUE SPACES. 00830001
008400* 00840001
008500 01 LINE-RECORD. 00850001
008600 03 FILLER PIC X(78) VALUE ALL '-'. 00860001
008700* 00870001
008800 01 HEADING-LINE1. 00880001
008900 03 FILLER PIC X(06) VALUE 'DATE: '. 00890001
009000 03 OUT-DATE PIC X(10) VALUE SPACES. 00900001
009100 03 FILLER PIC X(50) VALUE SPACES. 00910001
009200 03 FILLER PIC X(06) VALUE 'TIME: '. 00920001
009300 03 OUT-TIME PIC X(08) VALUE SPACES. 00930001
009400* 00940001
009500 01 HEADING-LINE2. 00950001
009600 03 FILLER PIC X(20) VALUE 00960001
009700 'LISTING OF EMPLOYEES'. 00970001
009800 03 FILLER PIC X(46) VALUE SPACES. 00980001
009900 03 FILLER PIC X(06) VALUE 'PAGE: '. 00990001
010000 03 OUT-PAGE PIC Z9 VALUE ZERO. 01000001
010100* 01010001
010200 01 HEADING-LINE3. 01020001
010300 03 FILLER PIC X(43) VALUE 01030001
010400 'ID TRN MESSAGE DESCRIPTION'. 01040001
010500* 01050001
010600 01 OUT-RECORD. 01060001
010700 03 OUT-ID PIC X(05) VALUE SPACES. 01070001
010800 03 FILLER PIC X(02) VALUE SPACES. 01080001
010900 03 OUT-TRAN PIC X(01) VALUE SPACES. 01090001
011000 03 FILLER PIC X(02) VALUE SPACES. 01100001
011100 03 OUT-MESSAGAE PIC X(70) VALUE SPACES. 01110001
011200* 01120001
011300 01 WS-INDICATOR-VARIABLES. 01130001
011400 03 EMP-NAME-IND PIC S9(4) USAGE COMP. 01140001
011500 03 EMP-LOC-IND PIC S9(4) USAGE COMP. 01150001
011600 03 EMP-DOB-IND PIC S9(4) USAGE COMP. 01160001
011700 03 EMP-TECH-IND PIC S9(4) USAGE COMP. 01170001
011800 03 EMP-EARN-IND PIC S9(4) USAGE COMP. 01180001
011900 03 EMP-DEDN-IND PIC S9(4) USAGE COMP. 01190001
012000* 01200001
012100 01 WSS-ERR-MSG. 01210001
012200 05 WS-ERR-MSG. 01220001
012300 10 WS-ERR-MSG-LEN PIC S9(4) COMP VALUE 800. 01230001
012400 10 WS-ERR-MSG-TEXT PIC X(80) OCCURS 10 TIMES 01240001
012500 INDEXED BY WS-IDX. 01250001
012600 05 WS-ERR-LRECL PIC S9(9) COMP VALUE 80. 01260001
012700 05 WS-SUB PIC 9(2) VALUE ZERO. 01270001
012800* 01280001
012900 EXEC SQL 01290001
013000 INCLUDE EMPLOYEE 01300001
013100 END-EXEC 01310001
013200* 01320001
013300 EXEC SQL 01330001
013400 INCLUDE SQLCA 01340001
013500 END-EXEC. 01350001
013600* 01360001
013700 PROCEDURE DIVISION. 01370001
013800 MAIN-PARA. 01380001
013900 PERFORM INIT-PARA 01390001
014000 PERFORM PROCESS-PARA UNTIL END-OF-DATA 01400001
014100 PERFORM END-PARA 01410001
014200 STOP RUN. 01420001
014300* 01430001
014400 INIT-PARA. 01440001
014500 OPEN INPUT TRAN-FILE 01450001
014600 DISPLAY 'OPEN TRN FS = ', WS-TRN-STAT 01460001
014700 OPEN OUTPUT ERROR-FILE 01470001
014800 DISPLAY 'OPEN ERR FS = ', WS-ERR-STAT 01480001
014900 OPEN OUTPUT REPORT-FILE 01490001
015000 DISPLAY 'OPEN REP FS = ', WS-REP-STAT 01500001
015100* 01510001
015200 IF TRN-SUCCESS AND ERR-SUCCESS AND REP-SUCCESS 01520001
015300 PERFORM READ-INPUT 01530001
015400 PERFORM DATE-TIME-PARA 01540001
015500 ELSE 01550001
015600 DISPLAY 'ERROR OPENING FILE' 01560001
015700 SET END-OF-DATA TO TRUE 01570001
015800 END-IF. 01580001
015900* 01590001
016000 READ-INPUT. 01600001
016100 READ TRAN-FILE 01610001
016200 AT END 01620001
016300 DISPLAY 'READ TRN FS = ', WS-TRN-STAT 01630001
016400 DISPLAY 'END OF FILE REACHED' 01640001
016500 SET END-OF-DATA TO TRUE 01650001
016600 NOT AT END 01660001
016700 ADD 1 TO TOTAL-EMP 01670001
016800 END-READ. 01680001
016900* 01690001
017000 PROCESS-PARA. 01700001
017100 PERFORM SELECT-EMPLOYEE 01710001
017200 EVALUATE TRAN-CODE 01720001
017300 WHEN ADD-EMP 01730001
017400 PERFORM PARA-ADD 01740001
017500 WHEN UPD-EMP 01750001
017600 PERFORM PARA-UPDATE 01760001
017700 WHEN DEL-EMP 01770001
017800 PERFORM PARA-DELETE 01780001
017900 WHEN OTHER 01790001
018000 MOVE 'INVALID TRANSACTION CODE'TO OUT-MESSAGE 01800001
018100 PERFORM ERROR-PARA 01810001
018200 END-EVALUATE 01820001
018300 PERFORM PRINT-PARA 01830001
018400 PERFORM READ-INPUT. 01840001
018500* 01850001
018600 SELECT-EMPLOYEE. 01860001
018700 MOVE EMP-ID TO HV-EMP-ID, OUT-ID 01870001
018800 EXEC SQL 01880001
018900 SELECT EMP_NAME 01890001
019000 ,EMP_LOC 01900001
019100 ,EMP_DOB 01910001
019200 ,EMP_TECH 01920001
019300 ,EMP_EARN 01930001
019400 ,EMP_DEDN 01940001
019500 INTO :HV-EMP-NAME 01950001
019600 ,:HV-EMP-LOC 01960001
019700 ,:HV-EMP-DOB 01970001
019800 ,:HV-EMP-TECH 01980001
019900 ,:HV-EMP-EARN 01990001
020000 ,:HV-EMP-DEDN 02000001
020100 FROM EMPLOYEE_TABLE 02010001
020200 WHERE EMP_ID = :HV-EMP-ID 02020001
020300 END-EXEC 02030001
020400 MOVE SQLCODE TO WS-SQLCODE, WS-EMP-ID 02040001
020500 DISPLAY 'SELECT SQL = ', WS-SQLCODE, ' ', EMP-ID. 02050001
020600* 02060001
020700 PARA-ADD. 02070001
020800 IF EMP-NOTFOUND 02080001
020900 PERFORM VALIDATION-PARA 02090001
021000 IF VALID-DATA 02100001
021100 PERFORM MOVE-FILE-TO-HOST 02110001
021200 PERFORM INSERT-ROW 02120001
021300 MOVE 'EMPLOYEE ADDED SUCCESSFULLY' TO OUT-MESSAGE 02130001
021400 ELSE 02140001
021500 MOVE 'INVALID DATA, CANNOT ADD' TO OUT-MESSAGE 02150001
021600 PERFORM ERROR-PARA 02160001
021700 END-IF 02170001
021800 ELSE 02180001
021900 MOVE 'EMPLOYEE TO ADD, EXISTS' TO OUT-MESSAGE 02190001
022000 PERFORM ERROR-PARA 02200001
022100 END-IF. 02210001
022200* 02220001
022300 PARA-UPDATE. 02230001
022400 IF EMP-EXISTS 02240001
022500 PERFORM VALIDATION-PARA 02250001
022600 IF VALID-DATA 02260001
022700 PERFORM MOVE-FILE-TO-HOST 02270001
022800 PERFORM UPDATE-ROW 02280001
022900 MOVE 'EMPLOYEE UPDATED SUCCESSFULLY' TO OUT-MESSAGE 02290001
023000 ELSE 02300001
023100 MOVE 'INVALID DATA, CANNOT UPDATE' TO OUT-MESSAGE 02310001
023200 PERFORM ERROR-PARA 02320001
023300 END-IF 02330001
023400 ELSE 02340001
023500 MOVE 'EMPLOYEE TO UPDATE DOE NOT EXIST' TO OUT-MESSAGE 02350001
023600 PERFORM ERROR-PARA 02360001
023700 END-IF. 02370001
023800* 02380001
023900 PARA-DELETE. 02390001
024000 IF EMP-EXISTS 02400001
024100 PERFORM DELETE-ROW 02410001
024200 MOVE 'EMPLOYEE DELETED SUCCESSFULLY' TO OUT-MESSAGE 02420001
024300 ELSE 02430001
024400 MOVE 'EMPLOYEE TO DELETE DOES NOT EXIST' TO OUT-MESSAGE 02440001
024500 PERFORM ERROR-PARA 02450001
024600 END-IF. 02460001
024700* 02470001
024800 ERROR-PARA. 02480001
024900 WRITE ERROR-RECORD FROM TRANSACTION-RECORD 02490001
025000 ADD 1 TO TOTAL-ERROR. 02500001
025100* 02510001
025200 VALIDATION-PARA. 02520001
025300 SET VALID-DATA TO TRUE. 02530001
025400* 02540001
025500 PRINT-PARA. 02550001
025600 IF LINE-COUNT > 10 02560001
025700 PERFORM HEADING-PARA 02570001
025800 END-IF 02580001
025900 MOVE TRAN-CODE OUT-CODE 02590001
026000 MOVE EMP-ID OUT-ID 02600001
026100 WRITE REPORT-RECORD FROM OUT-RECORD 02610001
026200 MOVE SPACES TO OUT-RECORD 02620001
026300 ADD 1 TO LINE-COUNT. 02630001
026400* 02640001
026500 HEADING-PARA. 02650001
026600 ADD 1 TO PAGE-COUNT 02660001
026700 MOVE PAGE-COUNT TO OUT-PAGE 02670001
026800 WRITE REPORT-RECORD FROM HEADING-LINE1 AFTER PAGE 02680001
026900 WRITE REPORT-RECORD FROM HEADING-LINE2 02690001
027000 WRITE REPORT-RECORD FROM HEADING-LINE3 AFTER 2 02700001
027100 MOVE ZERO TO LINE-COUNT. 02710001
027200* 02720001
027300 INSERT-ROW. 02730001
027400 EXEC SQL 02740002
027500 INSERT INTO EMPLOYEE_TABLE 02750002
027600 (EMP_ID, EMP_NAME, EMP_LOC, EMP_DOB, EMP_TECH, EMP_EARN,02760002
027700 EMP_DEDN) 02770002
027800 VALUES(:EMP-ID, :EMP-NAME, :EMP-LOC, :EMP-DOB, :EMP-TECH02780002
027900 :EMP-EARN, :EMP_DEDN) 02790002
028000 END-EXEC 02800002
028100 MOVE SQLCODE TO WS-SQLCODE 02810002
028200 DISPLAY 'INSERT SQL: ', WS-SQLCODE. 02820002
028300* 02830002
028400 UPDATE-ROW. 02840001
028500 EXEC SQL 02850002
028600 UPDATE EMPLOYEE_TABLE 02860002
028700 SET (EMP_NAME = :EMP-NAME 02870002
028800 ,EMP_LOC = :EMP-LOC 02880002
028900 ,EMP_DOB = :EMP-DOB 02890002
029000 ,EMP_TECH = :EMP-TECH 02900002
029100 ,EMP_EARN = :EMP-EARN 02910002
029200 ,EMP_DEDN = :EMP-DEDN) 02920002
029300 WHERE EMP_ID = :EMP-ID 02930002
029400 END-EXEC 02940002
029500 MOVE SQLCODE TO WS-SQLCODE 02950002
029600 DISPLAY 'INSERT SQL: ', WS-SQLCODE. 02960002
029700* 02970002
029800 DELETE-ROW. 02980002
029900 EXEC SQL 02990002
030000 DELETE FROM EMPLOYEE_TABLE 03000002
030100 WHERE EMP_ID = :EMP-ID 03010002
030200 END-EXEC 03020002
030300 MOVE SQLCODE TO WS-SQLCODE 03030002
030400 DISPLAY 'INSERT SQL: ', WS-SQLCODE. 03040002
030500* 03050002
030600 MOVE-FILE-TO-HOST. 03060002
030700 MOVE EMP-NAME TO HV-EMP-NAME 03070002
030800 MOVE EMP-LOC TO HV-EMP-LOC 03080002
030900 MOVE EMP-TECH TO HV-EMP-TECH 03090002
031000 MOVE EMP-DOB(1:4) TO HV-EMP-DOB(1:4) 03100002
031100 MOVE EMP-DOB(5:2) TO HV-EMP-DOB(6:2) 03110002
031200 MOVE EMP-DOB(6:2) TO HV-EMP-DOB(9:B) 03120002
031300 MOVE '-' TO HV-EMP-DOB(5:1) 03130002
031400 MOVE '-' TO HV-EMP-DOB(8:1) 03140002
031500* 03150002
031600 MOVE EMP-EARN TO OUT-EARN 03160002
031700 MOVE EMP-DEDN TO OUT-DEDN. 03170002
031800* 03180002
031900 DATE-TIME-PARA. 03190002
032000 EXEC SQL 03200002
032100 SELECT CURRENT DATE, CURRENT TIME 03210002
032200 INTO :WS-DATE, :WS-TIME 03220002
032300 FROM SYSIBM.SYSDUMMY1 03230002
032400 END-EXEC 03240002
032500 MOVE SQLCODE TO WS-SQLCODE 03250002
032600 DISPLAY 'DATE TIME SQL = ', WS-SQLCODE 03260002
032700* 03270002
032800 MOVE WS-DATE(1:4) TO OUT-DATE(7:4) 03280002
032900 MOVE WS-DATE(6:2) TO OUT-DATE(4:2) 03290002
033000 MOVE WS-DATE(9:2) TO OUT-DATE(1:2) 03300002
033100 MOVE '/' TO OUT-DATE(3:1) 03310002
033200 MOVE '/' TO OUT-DATE(6:1) 03320002
033300 MOVE WS-TIME TO OUT-TIME. 03330002
033400* 03340002
033500 END-PARA. 03350002
033600 MOVE SPACES TO HEADING-LINE3 03360002
033700 PERFORM HEADING-PARA 03370002
033800 INITIALIZE OUT-RECORD 03380002
033900* 03390002
034000 MOVE 'TOTALS : ' TO OUT-NAME 03400002
034100 MOVE TOTAL-EARN TO OUT-EARN 03410002
034200 MOVE TOTAL-DEDN TO OUT-DEDN 03420002
034300 MOVE TOTAL-EMP TO OUT-EMP 03430002
034400 MOVE OUT-EMP TO OUT-LOC 03440002
034500* 03450002
034600 SUBTRACT TOTAL-DEDN FROM TOTAL-EARN GIVING OUT-SAL 03460002
034700 WRITE REPORT-RECORD FROM OUT-RECORD 03470002
034800* 03480002
034900 CLOSE TRAN-FILE 03490002
035000 DISPLAY 'CLOSE INP FS = ', WS-INP-STAT 03500002
035100 CLOSE REPORT-FILE 03510002
035200 DISPLAY 'CLOSE REP FS = ', WS-REP-STAT. 03520002
035300* 03530002
035400 ERROR-PARA. 03540002
035500 CALL 'DSNTIAR' USING SQLCA, 03550002
035600 WS-ERR-MSG, 03560002
035700 WS-ERR-LRECL 03570002
035800 DISPLAY '*---*---*---*---*---*---*---*---*---*---*---*' 03580002
035900 PERFORM VARYING WS-SUB FROM 1 BY 1 UNTIL WS-SUB > 10 03590002
036000 DISPLAY WS-ERR-MSG-TEXT(WS-SUB) 03600002
036100 END-PERFORM. 03610002