I'm attempting to use a MERGE statement to update records in a physical file on an iSeries or AS400 running V7R1.
The issue that I am having is when attempting to use the merge on the test table, I get a Row not found for MERGE. SQLSTATE=02000
warning very similar to this question on SO.
The main difference in my issue is that I started by creating a copy of my test table to preserve the data, and then using the merge to update. The merge worked against the copy created with CPYF
. When I was satisfied the merge was working as expected, I pointed it to the proper test file and upon execution, received the warning below.
SQL State: 02000
Vendor Code: 100 Message: [SQL0100] Row not found for MERGE.
The target table is a membered physical file with an alias over it. For example, DOUG/MYDATA(F901), to create the alias I ran the following:
CREATE ALIAS DOUG.MYDATA901 FOR DOUG.MYDATA(F901);
Query that is not updating is below:
MERGE INTO DOUG.MYDATA901 TGT USING DOUG.TEST01 SRC
ON TGT.PREC = SRC.PREC
WHEN MATCHED THEN
UPDATE SET TGT.PQDS = TGT.PQDS - SRC.TTL_DIST;
However, when I make a copy of the file I'd like to update, the merge works...
CPYF FROMFILE(DOUG/MYDATA) TOFILE(DOUG/BUMYDATA) FROMMBR(F901) MBROPT(*REPLACE) CRTFILE(*YES) OUTFMT(*CHAR)
Merge code yields modified records:
MERGE INTO DOUG.BUMYDATA TGT USING DOUG.TEST01 SRC
ON TGT.PREC = SRC.PREC
WHEN MATCHED THEN
UPDATE SET TGT.PQDS = TGT.PQDS - SRC.TTL_DIST;
I validated that the source and copy, when used in a select with an inner join, does in fact yield results:
SELECT *
FROM DOUG.MYDATA901 TGT
JOIN DOUG.BUMYDATA SRC ON TGT.PREC = SRC.PREC;
Why would the MERGE work for the copied data but not the source table I created the copy from?