人员代码很简单,实例化记录对象,从XML文件读取,将值分配给rec.fields,然后执行插入,然后执行commitwork()。
我唯一能看到的是无法插入XML数据的原因是它是文件中相同SSN的第二次使用。它要插入的表具有BRANCH_ID,CREATION_DT和SSN作为键结构。对于整个文件,BRANCH_ID和CREATION_DT是静态的。
这是代码。...
您将在下面看到我试图使用TRY / CATCH(它无法正常工作,因为它从未找到要捕获的异常),并且仅测试了insert和commitwork的布尔返回值。如您所见,布尔方法会引发异常,但是它没有正当理由来解释插入失败的原因。
由于代码在下面,您将看到我只是在遍历,而不是使用insert / commitwork的布尔值或try / catch的布尔值来确定错误。由于这种独特的约束错误,程序不会停止,这很奇怪。它只是继续前进到下一行。
自然,我需要能够登录到错误表中,由于唯一的约束,未插入行。有什么建议么?
&REC1 = CreateRecord(Record.D2_PLFS_TBL);
&REC1.SetDefault();
&Node1 = &rootNode.GetElementsByTagName("LocatorData");
&Mega1File.WriteLine("THERE ARE >" | &Node1.Len | " rows in this file.");
&cDate = Substring(&cDate, 8, 2) | Substring(&cDate, 3, 5) | Substring(&cDate, 1, 2);
For &Cnt1 = 1 To &Node1.Len
rem try;
&xmlDoc1 = CreateXmlDoc(&Node1 [&Cnt1].GenXmlString());
&Mega1File.WriteLine(%This.GetElementData(&xmlDoc1, "SocialSecurityAccountNumber"));
&REC1.GetField(Field.IBTRANSACTIONID).Value = &IBTransactionId;
&REC1.GetField(Field.TRANSACTION_NBR).Value = &Cnt1;
&REC1.GetField(Field.BRANCH_ID).Value = &Branch_CD1;
&REC1.GetField(Field.CREATION_DT).Value = &cDate;
&REC1.GetField(Field.SSN).Value = %This.GetElementData(&xmlDoc1, "SocialSecurityAccountNumber");
&REC1.GetField(Field.SSN1).Value = %This.GetElementData(&xmlDoc1, "XRefSocialSecurityAccountNumber");
&REC1.GetField(Field.D2_ACCT_STATUS).Value = %This.GetElementData(&xmlDoc1, "AccountStatus");
&REC1.GetField(Field.NAME).Value = %This.GetElementData(&xmlDoc1, "MemberName");
&REC1.GetField(Field.NAME1).Value = %This.GetElementData(&xmlDoc1, "OwnerName");
&REC1.GetField(Field.D2_MBR_TYPE).Value = %This.GetElementData(&xmlDoc1, "MemberType");
&REC1.GetField(Field.D2_SPCL_HNDLNG).Value = %This.GetElementData(&xmlDoc1, "SpecialHandling");
&REC1.GetField(Field.D2_DOMFOR_CD).Value = %This.GetElementData(&xmlDoc1, "DomForeignCode");
&REC1.GetField(Field.ADDRESS1).Value = %This.GetElementData(&xmlDoc1, "Address");
&REC1.GetField(Field.COUNTRY_2CHAR).Value = %This.GetElementData(&xmlDoc1, "CountryCode");
&REC1.GetField(Field.CITY).Value = %This.GetElementData(&xmlDoc1, "CityName");
&REC1.GetField(Field.STATE).Value = %This.GetElementData(&xmlDoc1, "StateName");
&REC1.GetField(Field.POSTAL).Value = %This.GetElementData(&xmlDoc1, "ZipSuffix");
&REC1.GetField(Field.POSTAL2).Value = %This.GetElementData(&xmlDoc1, "ZipName");
&REC1.GetField(Field.BRANCH_FLAG).Value = %This.GetElementData(&xmlDoc1, "BranchOfService");
&REC1.GetField(Field.D2_RANK_RATE).Value = %This.GetElementData(&xmlDoc1, "RankRate");
&REC1.GetField(Field.UNIT_CD).Value = %This.GetElementData(&xmlDoc1, "UIC");
&REC1.GetField(Field.RETIREMENT_DT).Value = %This.GetElementData(&xmlDoc1, "RetirementTransferDate");
&REC1.Insert();
CommitWork();
/* If &REC1.Insert() Then
&Mega1File.WriteLine("INSERTED");
CommitWork();
Else
&Mega1File.WriteLine("NOT !!!!!! INSERTED");
throw CreateException(0, 0, "exception here");
End-If;
catch Exception &ex
Local Record &recError = CreateRecord(Record.D2_DRAS2_ERROR);
&Mega1File.WriteLine("Caught the ERROR >" | &ex.ToString() | "<");
&recError.IBTRANSACTIONID.Value = &IBTransactionId;
&recError.TRANSACTION_NBR.Value = &Cnt1;
&recError.SSN.Value = %This.GetElementData(&xmlDoc1, "SocialSecurityAccountNumber");
&recError.MESSAGE_NBR.Value = 0;
&recError.MESSAGE_TEXT_254.Value = "IGS-PLFS - " | &ex.ToString();
&recError.FIELDNAME.Value = "SSN";
&recError.VALUE_TEXT.Value = "Duplicate Row, Unique Constraint on SSN";
&recError.Insert();
CommitWork();
end-try;*/
End-For;
答案 0 :(得分:0)
阅读PeopleBooks时说,如果这些键已经存在,则insert方法将返回false值。任何其他原因都会导致程序终止。
因此您可以编写如下内容:
if not &REC1.insert() then
throw CreateException(0, 0, "Duplicate Insert");
End-If;