Adam “Adamlivinlife” Kamal
2022-12-04 14:57:30 UTC
Hello Everyone
I am getting SQL error 8100 on a FETCH in a Cobol program. It's sales history table so it has millions of record. The record has a sequence number as a part of the key, SEQ-NUM = 1 indicate the current month record.
On the beginning of each month, after fetching the record, program will do MAX (SEQ-NUM) and reinsert the record with the highest SEQ-NUM, it.
It looks like these insert while FETCHING causes SQL 8100.
My coworker suggested to close the cursor and reopen it after each read/insert (after saving the position of record).
The table has ~1 million records and just did not think open and close the cursor a million times is the best approach. Any idea how to process these kind of history.
Any idea on how to properly process these records other than close and reopen for each record will be highly appreciated.
Cursor:
EXEC SQL
DECLARE GET_SALES_HISTORY CURSOR FOR
SELECT
WARE
, PART_NUM
, REPORT_DATE
,SALES
FROM =HISTORY
WHERE SEQ_NUM = 1
BROWSE ACCESS
END-EXEC.
/
PROCEDURE DIVISION.
EXEC SQL
FETCH GET_HISTORY
INTO :WARE
,:PART-NUM
,:REPORT-DATE TYPE AS DATETIME YEAR TO MONTH
,:SALES
END-EXEC
IF SQLCODE = 0
MOVE REPORT-DATE O TO HV-REPORT-DATE
IF HV-REPORT-DATE-MM NOT = SYS-MM
EXEC SQL
SELECT MAX(SEQ-NUM)
INTO :HV-MAX-SEQ-NUM
FROM =HISTORY
WHERE WARE = :WARE
AND PART_NUM = :PART-NUM
BROWSE ACCESS
END-EXEC
IF SQLCODE = 0
ADD 1 TO HV-MAX-SEQ-NUM
EXEC SQL
INSERT INTO =HISTORY
( WARE
, PART_NUM
, MAX_SEQ_NUM
, REPORT_DATE
, SALES
)
VALUES
( :WARE
,:PART-NUM
,:HV-MAX-SEQ-NUM
,:REPORT-DATE TYPE AS DATETIME YEAR TO MONTH
,:SALES
)
END-EXEC
END-IF
END-IF
END-IF
EXIT-SECTION
EXIT
I am getting SQL error 8100 on a FETCH in a Cobol program. It's sales history table so it has millions of record. The record has a sequence number as a part of the key, SEQ-NUM = 1 indicate the current month record.
On the beginning of each month, after fetching the record, program will do MAX (SEQ-NUM) and reinsert the record with the highest SEQ-NUM, it.
It looks like these insert while FETCHING causes SQL 8100.
My coworker suggested to close the cursor and reopen it after each read/insert (after saving the position of record).
The table has ~1 million records and just did not think open and close the cursor a million times is the best approach. Any idea how to process these kind of history.
Any idea on how to properly process these records other than close and reopen for each record will be highly appreciated.
Cursor:
EXEC SQL
DECLARE GET_SALES_HISTORY CURSOR FOR
SELECT
WARE
, PART_NUM
, REPORT_DATE
,SALES
FROM =HISTORY
WHERE SEQ_NUM = 1
BROWSE ACCESS
END-EXEC.
/
PROCEDURE DIVISION.
EXEC SQL
FETCH GET_HISTORY
INTO :WARE
,:PART-NUM
,:REPORT-DATE TYPE AS DATETIME YEAR TO MONTH
,:SALES
END-EXEC
IF SQLCODE = 0
MOVE REPORT-DATE O TO HV-REPORT-DATE
IF HV-REPORT-DATE-MM NOT = SYS-MM
EXEC SQL
SELECT MAX(SEQ-NUM)
INTO :HV-MAX-SEQ-NUM
FROM =HISTORY
WHERE WARE = :WARE
AND PART_NUM = :PART-NUM
BROWSE ACCESS
END-EXEC
IF SQLCODE = 0
ADD 1 TO HV-MAX-SEQ-NUM
EXEC SQL
INSERT INTO =HISTORY
( WARE
, PART_NUM
, MAX_SEQ_NUM
, REPORT_DATE
, SALES
)
VALUES
( :WARE
,:PART-NUM
,:HV-MAX-SEQ-NUM
,:REPORT-DATE TYPE AS DATETIME YEAR TO MONTH
,:SALES
)
END-EXEC
END-IF
END-IF
END-IF
EXIT-SECTION
EXIT