IDENTIFICATION DIVISION.
PROGRAM-ID. DB2TOPS.
AUTHOR. SRIRAM.
*Use cursor to fetch all rows and move to
different PS
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT BI001-OUTPUT-PS ASSIGN TO
DD1
ORGANIZATION SEQUENTIAL
ACCESS SEQUENTIAL
FILE STATUS
WS01-OUTPUT-PS.
SELECT BI001-OUTPUT-PS1 ASSIGN
TO DD2
ORGANIZATION SEQUENTIAL
ACCESS SEQUENTIAL
FILE STATUS WS01-OUTPUT-PS1.
DATA DIVISION.
FILE SECTION.
FD BI001-OUTPUT-PS RECORD CONTAINS 80
CHARACTERS .
01 BI001-OUTPUT-PS-REC .
02 ID-PS PIC 9(4).
02 FILLER PIC X.
02 NAME-PS PIC X(17).
02 FILLER PIC X.
02 COUNTRY-PS PIC X(5).
02 FILLER PIC X.
02 STATE-PS PIC X(13).
FD BI001-OUTPUT-PS1 RECORD CONTAINS 80
CHARACTERS.
01 BI001-OUTPUT-PS1-REC .
02 ID-PS1 PIC 9(4).
02 FILLER PIC X.
02 NAME-PS1 PIC X(17).
02 FILLER PIC X.
02 COUNTRY-PS1 PIC X(5).
02 FILLER PIC X.
02 STATE-PS1 PIC X(13).
WORKING-STORAGE SECTION.
01 VARIABLES .
05 WS01-OUTPUT-PS PIC 9(2).
88 C01-OUTPUT-PS-SUCCESS VALUE 00.
05 WS01-OUTPUT-PS1 PIC 9(2).
88 C01-OUTPUT-PS1-SUCCESS VALUE 00.
01 ERROR-MSG .
05 WS-ERR-MSG .
10 WS-ERR-LEN PIC S9(4) COMP VALUE 800.
10 WS-ERR-TEXT PIC X(80) OCCURS 10 TIMES.
05 WS-ERR-LRECL PIC S9(9) COMP VALUE 80.
05 WS-SQLCODE-CODE PIC S9(3)
SIGN LEADING SEPARATE .
01 WS-SQLCODE-ERR PIC S9(03)
SIGN LEADING SEPARATE.
88 C01-IND-EM-SUCCESS VALUE +000.
88 C01-IND-EM-DUPTABLE VALUE -601.
88 C01-IND-EM-DB-NOT-FND VALUE -204.
88 C01-IND-EM-ILLEGAL-SYMBOL VALUE -104.
88 C01-IND-EM-ILLEGAL-KEYWORD VALUE -199.
EXEC SQL
INCLUDE SQLCA
END-EXEC
EXEC SQL
INCLUDE LOCATION
END-EXEC
EXEC SQL
DECLARE CS_TB_LOCATION
CURSOR FOR
SELECT
EMPLOY_ID,
EMPLOY_FNAME,
EMPLOY_COUNTRY,
EMPLOY_STATE
FROM
TB_LOCATION
END-EXEC
PROCEDURE DIVISION.
0000-MAIN-PARA.
PERFORM 1000-INITIALIZATION-PARA
THRU 1000-INITIALIZATION-PARA-EXIT
PERFORM 2000-PROCESS-PARA
THRU 2000-PROCESS-PARA-EXIT
PERFORM 9000-TERMINATION-PARA
THRU 9000-TERMINATION-PARA-EXIT
.
0000-MAIN-PARA-EXIT.
EXIT
.
1000-INITIALIZATION-PARA.
.
1000-INITIALIZATION-PARA-EXIT.
EXIT
.
2000-PROCESS-PARA.
PERFORM 2100-OPEN-PARA
THRU 2100-OPEN-PARA-EXIT
PERFORM 2100-CURSOR-OPEN-PARA
THRU
2100-CURSOR-OPEN-PARA-EXIT
PERFORM 2100-FETCH-PARA
THRU 2100-FETCH-PARA-EXIT
UNTIL SQLCODE=+100
PERFORM 2100-CLOSE-PARA
THRU 2100-CLOSE-PARA-EXIT
.
2000-PROCESS-PARA-EXIT.
EXIT
.
2100-OPEN-PARA.
OPEN OUTPUT BI001-OUTPUT-PS
EVALUATE TRUE
WHEN C01-OUTPUT-PS-SUCCESS
DISPLAY 'PS OPENED'
WHEN OTHER
DISPLAY 'PS NOT OPENED'
PERFORM
9000-TERMINATION-PARA
THRU 9000-TERMINATION-PARA-EXIT
END-EVALUATE
OPEN OUTPUT BI001-OUTPUT-PS1
EVALUATE TRUE
WHEN C01-OUTPUT-PS1-SUCCESS
DISPLAY 'PS1 OPENED'
WHEN OTHER
DISPLAY 'PS1 NOT
OPENED'
CLOSE BI001-OUTPUT-PS
PERFORM
9000-TERMINATION-PARA
THRU 9000-TERMINATION-PARA-EXIT
END-EVALUATE
.
2100-OPEN-PARA-EXIT.
EXIT
.
2100-CURSOR-OPEN-PARA.
EXEC SQL
OPEN CS_TB_LOCATION
END-EXEC
MOVE SQLCODE TO WS-SQLCODE-ERR.
MOVE SQLCODE TO WS-SQLCODE-CODE.
EVALUATE TRUE
WHEN C01-IND-EM-SUCCESS
DISPLAY 'CURSOR OPENED
SUCCESSFULLY'
DISPLAY WS-SQLCODE-CODE
WHEN C01-IND-EM-ILLEGAL-SYMBOL
DISPLAY 'CHECK THE
BRACES,COMMA,AND SPELLINGS.INVALID'
DISPLAY WS-SQLCODE-CODE
WHEN C01-IND-EM-ILLEGAL-KEYWORD
DISPLAY 'CHECK SPLELLINGS OF
THE KEYWORDS.ITS INVALID'
DISPLAY WS-SQLCODE-CODE
WHEN OTHER
CALL 'DSNTIAR' USING SQLCA,
WS-ERR-MSG
WS-ERR-LRECL
DISPLAY WS-ERR-MSG
END-EVALUATE
.
2100-CURSOR-OPEN-PARA-EXIT.
EXIT
.
2100-FETCH-PARA.
EXEC SQL
FETCH CS_TB_LOCATION
INTO
:HV-EMPLOY-ID,
:HV-EMPLOY-NAME,
:HV-EMPLOY-COUNTRY,
:HV-EMPLOY-STATE
END-EXEC
MOVE SQLCODE TO WS-SQLCODE-ERR.
MOVE SQLCODE TO WS-SQLCODE-CODE.
EVALUATE TRUE
WHEN C01-IND-EM-SUCCESS
IF HV-EMPLOY-STATE = 'CHENNAI'
MOVE HV-EMPLOY-ID TO ID-PS
MOVE HV-EMPLOY-NAME TO NAME-PS
MOVE HV-EMPLOY-COUNTRY TO
COUNTRY-PS
MOVE HV-EMPLOY-STATE TO STATE-PS
WRITE BI001-OUTPUT-PS-REC
ELSE IF HV-EMPLOY-STATE =
'BANGALORE'
MOVE HV-EMPLOY-ID TO ID-PS1
MOVE HV-EMPLOY-NAME TO NAME-PS1
MOVE HV-EMPLOY-COUNTRY TO
COUNTRY-PS1
MOVE HV-EMPLOY-STATE TO STATE-PS1
WRITE BI001-OUTPUT-PS1-REC
END-IF
END-IF
WHEN C01-IND-EM-ILLEGAL-SYMBOL
DISPLAY 'CHECK THE BRACES,COMMA,AND
SPELLINGS.INVALID'
DISPLAY WS-SQLCODE-CODE
WHEN C01-IND-EM-ILLEGAL-KEYWORD
DISPLAY 'CHECK SPLELLINGS OF
THE KEYWORDS.ITS INVALID'
DISPLAY WS-SQLCODE-CODE
WHEN SQLCODE=+100
DISPLAY 'END REACHED'
CONTINUE
WHEN OTHER
CALL 'DSNTIAR' USING SQLCA,
WS-ERR-MSG
WS-ERR-LRECL
DISPLAY WS-ERR-MSG
END-EVALUATE
.
.
2100-FETCH-PARA-EXIT.
EXIT
.
2100-CLOSE-PARA.
CLOSE BI001-OUTPUT-PS
CLOSE BI001-OUTPUT-PS1
DISPLAY 'PS CLOSED SUCCESS'
.
2100-CLOSE-PARA-EXIT.
EXIT
.
9000-TERMINATION-PARA.
STOP RUN
.
9000-TERMINATION-PARA-EXIT.
EXIT
.
No comments:
Post a Comment