Can some one help in resolving the below issue.....
I am trying to update a DB2 table using a flat file.
The Db2 table has got 4 records....
CO_CD POL_SYM POL_NBR POL_MOD POL_EFF_DT ENTR_DT FEE_AMT FEE_PD_CD
----- ------- ------- ------- ---------- ---------- ------- ---------
83 A4I 5600867 02 05/20/2010 07/29/2010 5.00
83 A4I 5600867 02 05/20/2010 06/29/2010 5.00
83 A4I 5616843 02 05/18/2010 07/27/2010 5.00
83 A4I 5616843 02 05/18/2010 06/27/2010 5.00
----- ------- ------- ------- ---------- ---------- ------- ---------
83 A4I 5600867 02 05/20/2010 07/29/2010 5.00
83 A4I 5600867 02 05/20/2010 06/29/2010 5.00
83 A4I 5616843 02 05/18/2010 07/27/2010 5.00
83 A4I 5616843 02 05/18/2010 06/27/2010 5.00
out of 4 records...2 of them are duplicated...So i need to write a program to update a Db2 table with FEE_PD_CD
on a row level...
My input flat file data is given below:
83A4I56008670205/20/2010 00001556{W09/20/2010
83A4I56008670205/20/2010 00001606{P09/20/2010
83A4I56168430205/18/2010 00012920{W09/20/2010
I wanted to check the policy from flat file and check it in DB2 table and if SQL code is ZERO then update DB2 table with
corresponding flag value ---W/P value ...
I was expected a output is:
CO_CD POL_SYM POL_NBR POL_MOD POL_EFF_DT ENTR_DT FEE_AMT FEE_PD_C
----- ------- ------- ------- ---------- ---------- ------- --------
83 A4I 5600867 02 05/20/2010 07/29/2010 5.00 W
83 A4I 5600867 02 05/20/2010 06/29/2010 5.00 P
83 A4I 5616843 02 05/18/2010 07/27/2010 5.00 W
83 A4I 5616843 02 05/18/2010 06/27/2010 5.00
----- ------- ------- ------- ---------- ---------- ------- --------
83 A4I 5600867 02 05/20/2010 07/29/2010 5.00 W
83 A4I 5600867 02 05/20/2010 06/29/2010 5.00 P
83 A4I 5616843 02 05/18/2010 07/27/2010 5.00 W
83 A4I 5616843 02 05/18/2010 06/27/2010 5.00
So I tried several times..but not able to get the expected output.
below is the complete source code and correct me where i am going wrong....to update on row level
*****************************************************************
* CURSOR DECLARATION
*****************************************************************
EXEC SQL
DECLARE T200KT-CSR CURSOR FOR
SELECT FEE_PD_CD, FEE_PD_DT
FROM T200KT_DRCT_BILL_SVC_CHRG
WHERE
CO_CD = :WS-POL-CO AND
POL_SYM = :WS-POL-SYM AND
POL_NBR = :WS-POL-NUM AND
POL_MOD = :WS-POL-MOD AND
POL_EFF_DT = :WS-POL-EFF-DT
FOR UPDATE OF FEE_PD_CD, FEE_PD_DT
END-EXEC.
*
0000-MAIN.
PERFORM 1000-INITIALIZE.
PERFORM 2000-PROCESS-INPUT THRU 2000-EXIT
UNTIL EOF-INPUT-FILE.
CLOSE INPUT-FILE.
STOP RUN.
1000-INITIALIZE.
OPEN INPUT INPUT-FILE.
READ INPUT-FILE INTO WS-INPUT-REC
AT END MOVE 'Y' TO EOF-INPUT-SW.
1300-OPEN-CURSOR.
EXEC SQL
OPEN T200KT-CSR
END-EXEC.
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
CONTINUE
WHEN OTHER
MOVE '1300-OPEN-CURSOR' TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
*
****************************************************************
2000-PROCESS-INPUT.
****************************************************************
PERFORM 1300-OPEN-CURSOR.
PERFORM 2100-FETCH-CURSOR UNTIL WS-END-OF-CURSOR.
PERFORM 3500-CLOSE-CURSOR.
READ INPUT-FILE INTO WS-INPUT-REC
AT END MOVE 'Y' TO EOF-INPUT-SW.
2000-EXIT.
EXIT.
*
2100-FETCH-CURSOR.
**************************************************************
* FETCHES T200KT CURSOR
**************************************************************
INITIALIZE T200KT-TABLE-ORD-STR.
*
EXEC SQL
FETCH T200KT-CSR
INTO :T200KT-FEE-PD-CD, :T200KT-FEE-PD-DT
END-EXEC.
*
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
IF T200KT-FEE-PD-CD = SPACES
MOVE WS-POL-FEE-PD-CD TO T200KT-FEE-PD-CD
MOVE WS-POL-FEE_PD_DT TO T200KT-FEE-PD-DT
PERFORM 3200-UPDT-TABLE
END-IF
WHEN +100 ALSO ANY
SET WS-END-OF-CURSOR TO TRUE
WHEN OTHER
MOVE '2100-FETCH-CURSOR' TO WS-ABEND-PARAGRAPH
MOVE WS-POL-FEE-PD-CD
TO WS-ABEND-HOST-VAR1
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
3200-UPDT-TABLE.
EXEC SQL
UPDATE T200KT_DRCT_BILL_SVC_CHRG
SET FEE_PD_CD = :T200KT-FEE-PD-CD,
FEE_PD_DT = :T200KT-FEE-PD-DT
WHERE CURRENT OF T200KT-CSR
END-EXEC.
EVALUATE SQLCODE
WHEN +0
CONTINUE
WHEN OTHER
MOVE '3200-UPDT-TABLE'
TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
3500-CLOSE-CURSOR.
EXEC SQL
CLOSE T200KT-CSR
END-EXEC.
*
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
EXEC SQL
COMMIT
END-EXEC
WHEN OTHER
MOVE '3500-CLOSE-CURSOR' TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
* CURSOR DECLARATION
*****************************************************************
EXEC SQL
DECLARE T200KT-CSR CURSOR FOR
SELECT FEE_PD_CD, FEE_PD_DT
FROM T200KT_DRCT_BILL_SVC_CHRG
WHERE
CO_CD = :WS-POL-CO AND
POL_SYM = :WS-POL-SYM AND
POL_NBR = :WS-POL-NUM AND
POL_MOD = :WS-POL-MOD AND
POL_EFF_DT = :WS-POL-EFF-DT
FOR UPDATE OF FEE_PD_CD, FEE_PD_DT
END-EXEC.
*
0000-MAIN.
PERFORM 1000-INITIALIZE.
PERFORM 2000-PROCESS-INPUT THRU 2000-EXIT
UNTIL EOF-INPUT-FILE.
CLOSE INPUT-FILE.
STOP RUN.
1000-INITIALIZE.
OPEN INPUT INPUT-FILE.
READ INPUT-FILE INTO WS-INPUT-REC
AT END MOVE 'Y' TO EOF-INPUT-SW.
1300-OPEN-CURSOR.
EXEC SQL
OPEN T200KT-CSR
END-EXEC.
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
CONTINUE
WHEN OTHER
MOVE '1300-OPEN-CURSOR' TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
*
****************************************************************
2000-PROCESS-INPUT.
****************************************************************
PERFORM 1300-OPEN-CURSOR.
PERFORM 2100-FETCH-CURSOR UNTIL WS-END-OF-CURSOR.
PERFORM 3500-CLOSE-CURSOR.
READ INPUT-FILE INTO WS-INPUT-REC
AT END MOVE 'Y' TO EOF-INPUT-SW.
2000-EXIT.
EXIT.
*
2100-FETCH-CURSOR.
**************************************************************
* FETCHES T200KT CURSOR
**************************************************************
INITIALIZE T200KT-TABLE-ORD-STR.
*
EXEC SQL
FETCH T200KT-CSR
INTO :T200KT-FEE-PD-CD, :T200KT-FEE-PD-DT
END-EXEC.
*
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
IF T200KT-FEE-PD-CD = SPACES
MOVE WS-POL-FEE-PD-CD TO T200KT-FEE-PD-CD
MOVE WS-POL-FEE_PD_DT TO T200KT-FEE-PD-DT
PERFORM 3200-UPDT-TABLE
END-IF
WHEN +100 ALSO ANY
SET WS-END-OF-CURSOR TO TRUE
WHEN OTHER
MOVE '2100-FETCH-CURSOR' TO WS-ABEND-PARAGRAPH
MOVE WS-POL-FEE-PD-CD
TO WS-ABEND-HOST-VAR1
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
3200-UPDT-TABLE.
EXEC SQL
UPDATE T200KT_DRCT_BILL_SVC_CHRG
SET FEE_PD_CD = :T200KT-FEE-PD-CD,
FEE_PD_DT = :T200KT-FEE-PD-DT
WHERE CURRENT OF T200KT-CSR
END-EXEC.
EVALUATE SQLCODE
WHEN +0
CONTINUE
WHEN OTHER
MOVE '3200-UPDT-TABLE'
TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.
3500-CLOSE-CURSOR.
EXEC SQL
CLOSE T200KT-CSR
END-EXEC.
*
EVALUATE SQLCODE ALSO SQLWARN0
WHEN +0 ALSO SPACES
EXEC SQL
COMMIT
END-EXEC
WHEN OTHER
MOVE '3500-CLOSE-CURSOR' TO WS-ABEND-PARAGRAPH
PERFORM 9999-SQL-ABEND
END-EVALUATE
.