I have 2 VSAM files(KSDS).One contains the Policy details and the other contains the customer details, BOTH HAVING THE POLICY NUMBER AS KEY. I need to compare the 2 files and write the matching records into another VSAM file.
How can i achieve it?
I tried this code. but dunno if it would work.
Please help me.
IDENTIFICATION DIVISION
PROGRAM-ID. POLICY.
DATE-WRITTEN. OCT 2011.
***************END OF IDENTIFICATION DIVISION****
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT VSAM-INP-FILE1 ASSIGN TO VSAM1.
ORGANIZATION IS INDEXED
ACCESS IS SEQUENTIAL
RECORD KEY IS POL-NUM
FILE STATUS IS KEY-STATUS1.
SELECT VSAM-INP-FILE2 ASSIGN TO VSAM2.
ORGANIZATION IS INDEXED
ACCESS IS RANDOM
RECORD KEY IS KEY-POL-NUM
FILE STATUS IS KEY-STATUS2.
SELECT OUT-FILE ASSIGN TO VSAM3.
ORGANIZATION IS INDEXED
ACCESS IS RANDOM
RECORD KEY IS O-KEY-POL-NUM
FILE STATUS IS KEY-STATUS3.
************END OF ENVIRONMENT DIVISION***************
DATA DIVISION.
FILE SECTION.
FD VSAM-INP-FILE1.
01 POLICY-DET-REC.
05 POL-NUM PIC 9(10).
05 START-DATE PIC 9(6).
05 END-DATE PIC 9(6).
05 AMOUNT PIC 9(6)V99.
FD VSAM-INP-FILE2.
01 CUST-DET-REC.
05 KEY-POL-NUM PIC 9(10).
05 FIRST-NAME PIC X(20).
05 LAST-NAME PIC X(20).
05 CUST-ADDR PIC X(20).
FD OUTPUT-FILE.
01 OUTPUT-REC.
05 O-KEY-POL-NUM PIC 9(10).
05 O-FIRST-NAME PIC X(20).
05 O-LAST-NAME PIC X(20).
05 O-START-DATE PIC 9(6).
05 O-END-DATE PIC 9(6).
05 O-AMOUNT PIC 9(6)V99.
05 O-CUST-ADDR PIC X(20).
***************END-OF-DATA DIVISION*
WORKING-STORAGE SECTION.
01 WS-VSAM-INP-FILE1.
05 WS-POL-NUM PIC 9(10).
05 WS-START-DATE PIC 9(6).
05 WS-END-DATE PIC 9(6).
05 WS-AMOUNT PIC 9(6)V99.
01 WS-END-REC.
88 END-REC VALUE HIGH-VALUES.
01 WS-VSAM-INP-FILE2.
05 WS-KEY-POL-NUM PIC 9(10).
05 WS-FIRST-NAME PIC X(20).
05 WS-LAST-NAME PIC X(20).
05 WS-CUST-ADDR PIC X(20).
01 WS-STATUS-KEY.
05 KEY-STATUS1 PIC X(2).
05 KEY-STATUS2 PIC X(2).
01 WS-OUTPUT-REC.
05 WS-O-KEY-POL-NUM PIC 9(10).
05 WS-O-FIRST-NAME PIC X(20).
05 WS-O-LAST-NAME PIC X(20).
05 WS-O-START-DATE PIC 9(6).
05 WS-O-END-DATE PIC 9(6).
05 WS-O-AMOUNT PIC 9(6)V99
05 WS-O-CUST-ADDR PIC X(20).
**********END-OF WORKING STORAGE SECTION*
PROCEDURE DIVISION.
*****************************************
OBTAIN THE INPUT VALUES AND OPEN THE FIL
CHECK THE POLICY NUMBER AND IF IT MATCHE
FILE
*****************************************
PERFORM 100-INITIALIZATION
THRU 100-EXIT.
PERFORM 200-PROCESS
THRU 200-EXIT UNTIL END-REC.
PERFORM 300-TERMINATE
THRU 300-EXIT.
STOP RUN.
100-INITIALIZATION.
OPEN INPUT VSAM-INP-FILE1.
OPEN INPUT VSAM-INP-FILE2.
OPEN OUTPUT OUTPUT-FILE.
100-EXIT.
EXIT.
200-PROCESS.
READ VSAM-INP-FILE1
AT END MOVE END-REC TO TRUE.
IF KEY-STATUS1 IS '00' OR '97'
MOVE POL-NUM TO WS-POL-NUM
MOVE START-DATE TO WS-START-DATE
MOVE END-DATE TO WS-END-DATE
MOVE AMOUNT TO WS-AMOUNT
MOVE WS-POL-NUM TO WS-KEY-POL-NUM
READ VSAM-INP-FILE2
MOVE KEY-POL-NUM TO WS-KEY-POL-NUM
MOVE FIRST-NAME TO WS-FIRST-NAME
MOVE LAST-NAME TO WS-LAST-NAME
MOVE CUST-ADDR TO WS-CUST-ADDR
IF KEY-STATUS2 IS '00' OR '97'
DISPLAY "POLICY IS PRESENT"
PERFORM 210-POLICY-PRESENT
THRU 210-POLICY-EXIT
ELSE
DISPLAY "POLICY IS NOT PRESENT"
PERFORM 220-POLICY-NOT-PRESENT
THRU 220-POLICY-EXIT
END-IF.
WRITE OUTPUT-FILE FROM WS-OUT-REC.
ELSE
DISPLAY "ERROR WHILE READING INPUT FILE1"
END-IF.
200-EXIT.
EXIT.
300-TERMINATE.
CLOSE VSAM-INP-FILE1.
CLOSE VSAM-INP-FILE2.
CLOSE OUTPUT-FILE.
300-EXIT.
EXIT.
210-POLICY-PRESENT.
MOVE WS-KEY-POL-NUM TO WS-O-KEY-POL-NUM.
MOVE WS-FIRST-NAME TO WS-O-FIRST-NAME.
MOVE WS-LAST-NAME TO WS-O-LAST-NAME.
MOVE WS-START-DATE TO WS-O-START-DATE.
MOVE WS-END-DATE TO WS-O-END-DATE.
MOVE WS-AMOUNT TO WS-O-AMOUNT.
MOVE WS-CUST-ADDR TO WS-O-CUST-ADDR.
210-POLICY-EXIT.
EXIT.
220-POLICY-NOT-PRESENT.
MOVE WS-KEY-POL-NUM TO WS-O-KEY-POL-NUM.
MOVE SPACES TO WS-O-FIRST-NAME.
MOVE SPACES TO WS-O-LAST-NAME.
MOVE WS-START-DATE TO WS-O-START-DATE.
MOVE WS-END-DATE TO WS-O-END-DATE..
MOVE WS-AMOUNT TO WS-O-AMOUNT.
MOVE SPACES TO WS-O-CUST-ADDR.
220-POLICY-EXIT.
EXIT.
PROGRAM-ID. POLICY.
DATE-WRITTEN. OCT 2011.
***************END OF IDENTIFICATION DIVISION****
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT VSAM-INP-FILE1 ASSIGN TO VSAM1.
ORGANIZATION IS INDEXED
ACCESS IS SEQUENTIAL
RECORD KEY IS POL-NUM
FILE STATUS IS KEY-STATUS1.
SELECT VSAM-INP-FILE2 ASSIGN TO VSAM2.
ORGANIZATION IS INDEXED
ACCESS IS RANDOM
RECORD KEY IS KEY-POL-NUM
FILE STATUS IS KEY-STATUS2.
SELECT OUT-FILE ASSIGN TO VSAM3.
ORGANIZATION IS INDEXED
ACCESS IS RANDOM
RECORD KEY IS O-KEY-POL-NUM
FILE STATUS IS KEY-STATUS3.
************END OF ENVIRONMENT DIVISION***************
DATA DIVISION.
FILE SECTION.
FD VSAM-INP-FILE1.
01 POLICY-DET-REC.
05 POL-NUM PIC 9(10).
05 START-DATE PIC 9(6).
05 END-DATE PIC 9(6).
05 AMOUNT PIC 9(6)V99.
FD VSAM-INP-FILE2.
01 CUST-DET-REC.
05 KEY-POL-NUM PIC 9(10).
05 FIRST-NAME PIC X(20).
05 LAST-NAME PIC X(20).
05 CUST-ADDR PIC X(20).
FD OUTPUT-FILE.
01 OUTPUT-REC.
05 O-KEY-POL-NUM PIC 9(10).
05 O-FIRST-NAME PIC X(20).
05 O-LAST-NAME PIC X(20).
05 O-START-DATE PIC 9(6).
05 O-END-DATE PIC 9(6).
05 O-AMOUNT PIC 9(6)V99.
05 O-CUST-ADDR PIC X(20).
***************END-OF-DATA DIVISION*
WORKING-STORAGE SECTION.
01 WS-VSAM-INP-FILE1.
05 WS-POL-NUM PIC 9(10).
05 WS-START-DATE PIC 9(6).
05 WS-END-DATE PIC 9(6).
05 WS-AMOUNT PIC 9(6)V99.
01 WS-END-REC.
88 END-REC VALUE HIGH-VALUES.
01 WS-VSAM-INP-FILE2.
05 WS-KEY-POL-NUM PIC 9(10).
05 WS-FIRST-NAME PIC X(20).
05 WS-LAST-NAME PIC X(20).
05 WS-CUST-ADDR PIC X(20).
01 WS-STATUS-KEY.
05 KEY-STATUS1 PIC X(2).
05 KEY-STATUS2 PIC X(2).
01 WS-OUTPUT-REC.
05 WS-O-KEY-POL-NUM PIC 9(10).
05 WS-O-FIRST-NAME PIC X(20).
05 WS-O-LAST-NAME PIC X(20).
05 WS-O-START-DATE PIC 9(6).
05 WS-O-END-DATE PIC 9(6).
05 WS-O-AMOUNT PIC 9(6)V99
05 WS-O-CUST-ADDR PIC X(20).
**********END-OF WORKING STORAGE SECTION*
PROCEDURE DIVISION.
*****************************************
OBTAIN THE INPUT VALUES AND OPEN THE FIL
CHECK THE POLICY NUMBER AND IF IT MATCHE
FILE
*****************************************
PERFORM 100-INITIALIZATION
THRU 100-EXIT.
PERFORM 200-PROCESS
THRU 200-EXIT UNTIL END-REC.
PERFORM 300-TERMINATE
THRU 300-EXIT.
STOP RUN.
100-INITIALIZATION.
OPEN INPUT VSAM-INP-FILE1.
OPEN INPUT VSAM-INP-FILE2.
OPEN OUTPUT OUTPUT-FILE.
100-EXIT.
EXIT.
200-PROCESS.
READ VSAM-INP-FILE1
AT END MOVE END-REC TO TRUE.
IF KEY-STATUS1 IS '00' OR '97'
MOVE POL-NUM TO WS-POL-NUM
MOVE START-DATE TO WS-START-DATE
MOVE END-DATE TO WS-END-DATE
MOVE AMOUNT TO WS-AMOUNT
MOVE WS-POL-NUM TO WS-KEY-POL-NUM
READ VSAM-INP-FILE2
MOVE KEY-POL-NUM TO WS-KEY-POL-NUM
MOVE FIRST-NAME TO WS-FIRST-NAME
MOVE LAST-NAME TO WS-LAST-NAME
MOVE CUST-ADDR TO WS-CUST-ADDR
IF KEY-STATUS2 IS '00' OR '97'
DISPLAY "POLICY IS PRESENT"
PERFORM 210-POLICY-PRESENT
THRU 210-POLICY-EXIT
ELSE
DISPLAY "POLICY IS NOT PRESENT"
PERFORM 220-POLICY-NOT-PRESENT
THRU 220-POLICY-EXIT
END-IF.
WRITE OUTPUT-FILE FROM WS-OUT-REC.
ELSE
DISPLAY "ERROR WHILE READING INPUT FILE1"
END-IF.
200-EXIT.
EXIT.
300-TERMINATE.
CLOSE VSAM-INP-FILE1.
CLOSE VSAM-INP-FILE2.
CLOSE OUTPUT-FILE.
300-EXIT.
EXIT.
210-POLICY-PRESENT.
MOVE WS-KEY-POL-NUM TO WS-O-KEY-POL-NUM.
MOVE WS-FIRST-NAME TO WS-O-FIRST-NAME.
MOVE WS-LAST-NAME TO WS-O-LAST-NAME.
MOVE WS-START-DATE TO WS-O-START-DATE.
MOVE WS-END-DATE TO WS-O-END-DATE.
MOVE WS-AMOUNT TO WS-O-AMOUNT.
MOVE WS-CUST-ADDR TO WS-O-CUST-ADDR.
210-POLICY-EXIT.
EXIT.
220-POLICY-NOT-PRESENT.
MOVE WS-KEY-POL-NUM TO WS-O-KEY-POL-NUM.
MOVE SPACES TO WS-O-FIRST-NAME.
MOVE SPACES TO WS-O-LAST-NAME.
MOVE WS-START-DATE TO WS-O-START-DATE.
MOVE WS-END-DATE TO WS-O-END-DATE..
MOVE WS-AMOUNT TO WS-O-AMOUNT.
MOVE SPACES TO WS-O-CUST-ADDR.
220-POLICY-EXIT.
EXIT.