I am getting this error when a program executing, when it is trying to update data in the table. Is this because of duplicate record ? what will be the condition to avoid sql error for duplicate record. below error:
Description = [IBM][CLI Driver][DB2/NT64] SQL0803N One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "1" constrains table "FH.Product" from having duplicate values for the index key. SQLSTATE=23505 Code here:
request = [
UPDATE FH.product
SET numchassis='%3',mtoc='%4'
WHERE numchassis='%1' AND mtoc='%2'
]
query=Constructed String(query,sChassis,sMTOC,sVin,sNewMTOC)
SQLChangeConnection(nCnx_DWH)
bRes = SQLExec(query,"REQUPD3")
IF NOT bRes THEN
SQLInfoGene("REQUPD3")
gsError=SQL. MyError+RC+Request
sSQLState is a string = SQL. MyError
sNativeErrorCode is a string = Spaceless(ExtractString(sSQLState,2,"Native Error Code ="))
sSQLState = WithoutSpace(ExtractString(ExtractString(sSQLState,2,"SQL State ="),1,RC))
//If update error because duplicate
IF sNativeErrorCode = "-803" AND sSQLState = "23505" THEN
Delete
ECRIRE_TRACE("calling If condition ")
deleteDepot(sChassis,sMTOC)
OTHERWISE
FIN_ERREUR()
END
END
Problem is in IF condition, it is not calling the deleteDepot()method.