0

我有以下正在修改的应用程序引擎程序。我基本上是为在 CSV/文件布局中输入的项目的度量单位 (&UOMResult) 与为同一项目检索到的现有行的值不匹配的情况添加代码,然后我执行 REC .INSERT,否则如果找不到匹配项,那么我将通过不同的 REC1.INSERT 逻辑。

我的理解是 SQL Fetch 函数(&SQL2.Fetch)一次只能获取一行数据并将其存储到一个变量中(如果我错了,请纠正我),因此我必须包含一个 While 循环语句来继续获取所有行,一次一个(如果有 &SQL2.Fetch 的替代方法可以在同一迭代中处理多行,请告诉我)。基于此,我在代码中添加了循环 &SQL2.Fetch 并且如果有匹配的行(到变量 &UOM)然后我做一个 REC.INSERT 处理然后中断循环,否则它继续循环(使用继续功能-不知道是否有必要)通过比较下一行,直到找到匹配项并中断或-(我打算这样做)进入 REC2.Insert 逻辑。我不

现在它的编码方式恐怕在永远不匹配的情况下会是一个无限循环。我希望在整个循环迭代完成后(已读取最后一行)并且没有匹配项,然后转到 REC2.Insert 逻辑。有没有办法让代码知道最后一行已经循环通过,如果是这样,我该如何相应地更改它?

Local SQL &SQL;
Local string &VendorId, &InvItemId, &ItmIdVndr, &UOM, &UOMResult, &ConvRate, &PriceVndr, &Oprid, &PriceStatus, &VendorId_check, &insert_cols, &insert_select, &insert_where, &insert_sql, &Error, &MaxEffdt, &ItmField;
Local date &Effdt;
Local Record &ITM_VNDR_UOM_PR, &REC, &MASTER_ITEM_TBL;

&Oprid = "'BATCH'";
&PriceStatus = "2";
&Error = "N";

MessageBox(0, "", 0, 0, "**** BEGINING OF VALIDATION ERRORS ****");

&SQL = CreateSQL("SELECT VENDOR_ID, INV_ITEM_ID, ITM_ID_VNDR, UNIT_OF_MEASURE, CONVERSION_RATE, PRICE_VNDR, %DateOut(EFFDT), ITEM_FIELD_C10_B FROM PS_GH_ITM_PR_UPDT ORDER BY VENDOR_ID, INV_ITEM_ID, ITM_ID_VNDR", &VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &PriceVndr, &Effdt, &ItmField);
MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField | " " | &Error);
While &SQL.Fetch(&VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &PriceVndr, &Effdt, &ItmField)

   SQLExec("SELECT A.VENDOR_ID FROM PS_ITM_VENDOR A, PS_ITM_VNDR_UOM B WHERE A.SETID = B.SETID AND A.INV_ITEM_ID = B.INV_ITEM_ID AND A.VENDOR_SETID = B.VENDOR_SETID AND A.VENDOR_ID = B.VENDOR_ID AND A.VENDOR_ID = :1 AND A.INV_ITEM_ID = :2 AND A.ITM_ID_VNDR = :3 AND A.ITM_VNDR_PRIORITY = 1 AND B.UNIT_OF_MEASURE = :4 AND B.CONVERSION_RATE = :5", &VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &VendorId_check);

   If None(&VendorId_check) Then;
      &Error = "Y";
      MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField | " " | &Error);
     &CurrentDateTime = %Datetime;
     &Oprid = %OperatorId;
     &RECITEM2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
     SQLExec("SELECT C.EFFDT FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.LAST_DTTM_UPDATE = (SELECT MAX(A_ED.LAST_DTTM_UPDATE) FROM PS_ITM_VNDR_UOM_PR A_ED WHERE C.SETID = A_ED.SETID AND C.INV_ITEM_ID = A_ED.INV_ITEM_ID AND C.VENDOR_SETID = A_ED.VENDOR_SETID AND C.VENDOR_ID = A_ED.VENDOR_ID AND C.VNDR_LOC = A_ED.VNDR_LOC AND C.CURRENCY_CD = A_ED.CURRENCY_CD AND C.QTY_MIN = A_ED.QTY_MIN ) ", &InvItemId, &VendorId, &UOM, &MaxEffdt);
     &SQL2 = CreateSQL("SELECT C.UNIT_OF_MEASURE FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.EFFDT = (SELECT MAX(C1.EFFDT) FROM PS_ITM_VNDR_UOM_PR C1 WHERE C.SETID = C1.SETID AND C.INV_ITEM_ID = C1.INV_ITEM_ID AND C.VENDOR_SETID = C1.VENDOR_SETID AND C.VENDOR_ID = C1.VENDOR_ID AND C.VNDR_LOC = C1.VNDR_LOC AND C.UNIT_OF_MEASURE = C1.UNIT_OF_MEASURE AND C.CURRENCY_CD = C1.CURRENCY_CD AND C.QTY_MIN = C1.QTY_MIN) ", &InvItemId, &VendorId, &UOMResult);
      While &SQL2.Fetch(&UOMResult)
       If &UOM = &UOMResult Then;
       SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM2, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM2);
       /*SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND EFFDT = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM); */
       &new_UNIT_OF_MEASURE = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
       &REC2.SETID.Value = &RECITEM.SETID.Value;
       &REC2.INV_ITEM_ID.Value = &RECITEM2.INV_ITEM_ID.Value;
       &REC2.VENDOR_SETID.Value = &RECITEM2.VENDOR_SETID.Value;
       &REC2.VENDOR_ID.Value = &RECITEM2.VENDOR_ID.Value;
       &REC2.VNDR_LOC.Value = &RECITEM2.VNDR_LOC.Value;
       &REC2.UNIT_OF_MEASURE.Value = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2.CURRENCY_CD.Value = &RECITEM2.CURRENCY_CD.Value;
       &REC2.QTY_MIN.Value = &RECITEM2.QTY_MIN.Value;
       &REC2.EFFDT.Value = &Effdt;
       &REC2.EFF_STATUS.Value = &RECITEM.EFF_STATUS.Value;
       &REC2.PRICE_VNDR.Value = &PriceVndr;
       &REC2.UNIT_PRC_TOL.Value = &RECITEM.UNIT_PRC_TOL.Value;
       &REC2.EXT_PRC_TOL.Value = &RECITEM.EXT_PRC_TOL.Value;
       &REC2.PCT_UNIT_PRC_TOL.Value = &RECITEM.PCT_UNIT_PRC_TOL.Value;
       &REC2.PCT_EXT_PRC_TOL.Value = &RECITEM.PCT_EXT_PRC_TOL.Value;
       &REC2.USE_STD_TOLERANCES.Value = &RECITEM.USE_STD_TOLERANCES.Value;
       &REC2.QTY_RECV_TOL_PCT.Value = &RECITEM.QTY_RECV_TOL_PCT.Value;
       &REC2.UNIT_PRC_TOL_L.Value = &RECITEM.UNIT_PRC_TOL_L.Value;
       &REC2.PCT_UNIT_PRC_TOL_L.Value = &RECITEM.PCT_UNIT_PRC_TOL_L.Value;
       &REC2.EXT_PRC_TOL_L.Value = &RECITEM.EXT_PRC_TOL_L.Value;
       &REC2.PCT_EXT_PRC_TOL_L.Value = &RECITEM.PCT_EXT_PRC_TOL_L.Value;
       &REC2.BU_PRICE_STATUS.Value = "2";
       &REC2.STD_PRICE_STATUS.Value = "2";
       &REC2.LEAD_TIME.Value = &RECITEM.LEAD_TIME.Value;
       &REC2.OPRID_MODIFIED_BY.Value = &Oprid;
       &REC2.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
       &REC2.PRICE_CHANGE.Value = &RECITEM.PRICE_CHANGE.Value;
       &REC2.Insert();
       Break;
       End-While;


       Else;
       Continue;    /* Unless last row has been processed in While - NEED HELP HERE */


      End-If;  /* End-If here or below next code block NEED HELP HERE ?? */

       /* Final Else - If all rows have been looped through and there was not a match found then do the following - NEED HELP HERE */

       SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM3, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM3);
       &new_UNIT_OF_MEASURE = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
       &REC2.SETID.Value = &RECITEM3.SETID.Value;
       &REC2.INV_ITEM_ID.Value = &RECITEM3.INV_ITEM_ID.Value;
       &REC2.VENDOR_SETID.Value = &RECITEM3.VENDOR_SETID.Value;
       &REC2.VENDOR_ID.Value = &RECITEM3.VENDOR_ID.Value;
       &REC2.VNDR_LOC.Value = &RECITEM3.VNDR_LOC.Value;
       &REC2.UNIT_OF_MEASURE.Value = &UOMResult
       &REC2.CURRENCY_CD.Value = &RECITEM3.CURRENCY_CD.Value;
       &REC2.QTY_MIN.Value = &RECITEM3.QTY_MIN.Value;
       &REC2.EFFDT.Value = &Effdt;
       &REC2.EFF_STATUS.Value = &RECITEM3.EFF_STATUS.Value;
       &REC2.PRICE_VNDR.Value = &PriceVndr;
       &REC.UNIT_PRC_TOL.Value = &RECITEM3.UNIT_PRC_TOL.Value;
       &REC2.EXT_PRC_TOL.Value = &RECITEM3.EXT_PRC_TOL.Value;
       &REC2.PCT_UNIT_PRC_TOL.Value = &RECITEM3.PCT_UNIT_PRC_TOL.Value;
       &REC2.PCT_EXT_PRC_TOL.Value = &RECITEM3.PCT_EXT_PRC_TOL.Value;
       &REC2.USE_STD_TOLERANCES.Value = &RECITEM3.USE_STD_TOLERANCES.Value;
       &REC2.QTY_RECV_TOL_PCT.Value = &RECITEM3.QTY_RECV_TOL_PCT.Value;
       &REC2.UNIT_PRC_TOL_L.Value = &RECITEM3.UNIT_PRC_TOL_L.Value;
       &REC2.PCT_UNIT_PRC_TOL_L.Value = &RECITEM3.PCT_UNIT_PRC_TOL_L.Value;
       &REC2.EXT_PRC_TOL_L.Value = &RECITEM3.EXT_PRC_TOL_L.Value;
       &REC2.PCT_EXT_PRC_TOL_L.Value = &RECITEM3.PCT_EXT_PRC_TOL_L.Value;
       &REC2.BU_PRICE_STATUS.Value = "2";
       &REC2.STD_PRICE_STATUS.Value = "2";
       &REC2.LEAD_TIME.Value = &RECITEM3.LEAD_TIME.Value;
       &REC2.OPRID_MODIFIED_BY.Value = &Oprid;
       &REC2.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
       &REC2.PRICE_CHANGE.Value = &RECITEM3.PRICE_CHANGE.Value;
       &REC2.Insert();
     End-If;  
    End-While;
   Else;
      &CurrentDateTime = %Datetime;
      &Oprid = %OperatorId;
      &RECITEM = CreateRecord(Record.ITM_VNDR_UOM_PR);

      /*GETTING MAX EFFECTIVE DATED ROW TO COPY EXISTING ROW VALUES FROM INTO NEW ROW */
      SQLExec("SELECT C.EFFDT FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.UNIT_OF_MEASURE = :3 AND C.EFFDT = (SELECT MAX(C1.EFFDT) FROM PS_ITM_VNDR_UOM_PR C1 WHERE C.SETID = C1.SETID AND C.INV_ITEM_ID = C1.INV_ITEM_ID AND C.VENDOR_SETID = C1.VENDOR_SETID AND C.VENDOR_ID = C1.VENDOR_ID AND C.VNDR_LOC = C1.VNDR_LOC AND C.UNIT_OF_MEASURE = C1.UNIT_OF_MEASURE AND C.CURRENCY_CD = C1.CURRENCY_CD AND C.QTY_MIN = C1.QTY_MIN)  ", &InvItemId, &VendorId, &UOM, &MaxEffdt);

      SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM);
      /*SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND EFFDT = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM); */
      &new_UNIT_OF_MEASURE = &RECITEM.UNIT_OF_MEASURE.Value;
      &REC = CreateRecord(Record.ITM_VNDR_UOM_PR);
      &REC.SETID.Value = &RECITEM.SETID.Value;
      &REC.INV_ITEM_ID.Value = &RECITEM.INV_ITEM_ID.Value;
      &REC.VENDOR_SETID.Value = &RECITEM.VENDOR_SETID.Value;
      &REC.VENDOR_ID.Value = &RECITEM.VENDOR_ID.Value;
      &REC.VNDR_LOC.Value = &RECITEM.VNDR_LOC.Value;
      &REC.UNIT_OF_MEASURE.Value = &RECITEM.UNIT_OF_MEASURE.Value;
      &REC.CURRENCY_CD.Value = &RECITEM.CURRENCY_CD.Value;
      &REC.QTY_MIN.Value = &RECITEM.QTY_MIN.Value;
      &REC.EFFDT.Value = &Effdt;
      &REC.EFF_STATUS.Value = &RECITEM.EFF_STATUS.Value;
      &REC.PRICE_VNDR.Value = &PriceVndr;
      &REC.UNIT_PRC_TOL.Value = &RECITEM.UNIT_PRC_TOL.Value;
      &REC.EXT_PRC_TOL.Value = &RECITEM.EXT_PRC_TOL.Value;
      &REC.PCT_UNIT_PRC_TOL.Value = &RECITEM.PCT_UNIT_PRC_TOL.Value;
      &REC.PCT_EXT_PRC_TOL.Value = &RECITEM.PCT_EXT_PRC_TOL.Value;
      &REC.USE_STD_TOLERANCES.Value = &RECITEM.USE_STD_TOLERANCES.Value;
      &REC.QTY_RECV_TOL_PCT.Value = &RECITEM.QTY_RECV_TOL_PCT.Value;
      &REC.UNIT_PRC_TOL_L.Value = &RECITEM.UNIT_PRC_TOL_L.Value;
      &REC.PCT_UNIT_PRC_TOL_L.Value = &RECITEM.PCT_UNIT_PRC_TOL_L.Value;
      &REC.EXT_PRC_TOL_L.Value = &RECITEM.EXT_PRC_TOL_L.Value;
      &REC.PCT_EXT_PRC_TOL_L.Value = &RECITEM.PCT_EXT_PRC_TOL_L.Value;
      &REC.BU_PRICE_STATUS.Value = "2";
      &REC.STD_PRICE_STATUS.Value = "2";
      &REC.LEAD_TIME.Value = &RECITEM.LEAD_TIME.Value;
      &REC.OPRID_MODIFIED_BY.Value = &Oprid;
      &REC.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
      &REC.PRICE_CHANGE.Value = &RECITEM.PRICE_CHANGE.Value;
      &REC.Insert();

   End-If;

     If None(&ItmField) Then;
      &Error = "Y";
      MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField);
   Else;
      SQLExec("UPDATE PS_MASTER_ITEM_TBL SET ITEM_FIELD_C10_B = :1 WHERE INV_ITEM_ID = :2 AND SETID = 'SHARE' ", &ItmField, &InvItemId);
      /* Else;
       &REC1 = CreateRecord(Record.MASTER_ITEM_TBL);
       &REC1.ITEM_FIELD_C10_B.Value = &ItmField;
       &REC1.SETID.Value = "SHARE";
       &REC1.INV_ITEM_ID.Value = &InvItemId;
       &REC1.Update();
    End-If;  */

   End-If;

End-While;
MessageBox(0, "", 0, 0, "**** END OF VALIDATION ERRORS ****");
MessageBox(0, "", 0, 0, " ");

您将在上面的代码中看到对 &SQL2 和 While 语句的引用,以及我在比较最后一行后如何处理的“需要帮助”注释。也欢迎任何有关整体程序流程的建议。谢谢!

10/23/18 编辑:

Local SQL &SQL;
Local string &VendorId, &InvItemId, &ItmIdVndr, &UOM, &UOMResult, &ConvRate, &PriceVndr, &Oprid, &PriceStatus, &VendorId_check, &insert_cols, &insert_select, &insert_where, &insert_sql, &Error, &MaxEffdt, &ItmField;
Local boolean &RowFound;
Local date &Effdt;
Local Record &ITM_VNDR_UOM_PR, &REC, &MASTER_ITEM_TBL;

&Oprid = "'BATCH'";
&PriceStatus = "2";
&Error = "N";

MessageBox(0, "", 0, 0, "**** BEGINING OF VALIDATION ERRORS ****");

&SQL = CreateSQL("SELECT VENDOR_ID, INV_ITEM_ID, ITM_ID_VNDR, UNIT_OF_MEASURE, CONVERSION_RATE, PRICE_VNDR, %DateOut(EFFDT), ITEM_FIELD_C10_B FROM PS_GH_ITM_PR_UPDT ORDER BY VENDOR_ID, INV_ITEM_ID, ITM_ID_VNDR", &VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &PriceVndr, &Effdt, &ItmField);
MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField | " " | &Error);
While &SQL.Fetch(&VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &PriceVndr, &Effdt, &ItmField)

   SQLExec("SELECT A.VENDOR_ID FROM PS_ITM_VENDOR A, PS_ITM_VNDR_UOM B WHERE A.SETID = B.SETID AND A.INV_ITEM_ID = B.INV_ITEM_ID AND A.VENDOR_SETID = B.VENDOR_SETID AND A.VENDOR_ID = B.VENDOR_ID AND A.VENDOR_ID = :1 AND A.INV_ITEM_ID = :2 AND A.ITM_ID_VNDR = :3 AND A.ITM_VNDR_PRIORITY = 1 AND B.UNIT_OF_MEASURE = :4 AND B.CONVERSION_RATE = :5", &VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, &VendorId_check);

   If None(&VendorId_check) Then;
     MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField | " " | &Error);
     &CurrentDateTime = %Datetime;
     &Oprid = %OperatorId;
     &RECITEM2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
     SQLExec("SELECT C.EFFDT FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.LAST_DTTM_UPDATE = (SELECT MAX(A_ED.LAST_DTTM_UPDATE) FROM PS_ITM_VNDR_UOM_PR A_ED WHERE C.SETID = A_ED.SETID AND C.INV_ITEM_ID = A_ED.INV_ITEM_ID AND C.VENDOR_SETID = A_ED.VENDOR_SETID AND C.VENDOR_ID = A_ED.VENDOR_ID AND C.VNDR_LOC = A_ED.VNDR_LOC AND C.CURRENCY_CD = A_ED.CURRENCY_CD AND C.QTY_MIN = A_ED.QTY_MIN ) ", &InvItemId, &VendorId, &UOM, &MaxEffdt);
     &SQL2 = CreateSQL("SELECT C.UNIT_OF_MEASURE FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.EFFDT = (SELECT MAX(C1.EFFDT) FROM PS_ITM_VNDR_UOM_PR C1 WHERE C.SETID = C1.SETID AND C.INV_ITEM_ID = C1.INV_ITEM_ID AND C.VENDOR_SETID = C1.VENDOR_SETID AND C.VENDOR_ID = C1.VENDOR_ID AND C.VNDR_LOC = C1.VNDR_LOC AND C.UNIT_OF_MEASURE = C1.UNIT_OF_MEASURE AND C.CURRENCY_CD = C1.CURRENCY_CD AND C.QTY_MIN = C1.QTY_MIN) ", &InvItemId, &VendorId, &UOMResult);
     &RowFound = False;
     While &SQL2.Fetch(&UOMResult)
       If &UOM = &UOMResult Then;
       &RowFound = True;
       SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM2, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM2);
       /*SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND EFFDT = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM); */
       &new_UNIT_OF_MEASURE = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
       &REC2.SETID.Value = &RECITEM.SETID.Value;
       &REC2.INV_ITEM_ID.Value = &RECITEM2.INV_ITEM_ID.Value;
       &REC2.VENDOR_SETID.Value = &RECITEM2.VENDOR_SETID.Value;
       &REC2.VENDOR_ID.Value = &RECITEM2.VENDOR_ID.Value;
       &REC2.VNDR_LOC.Value = &RECITEM2.VNDR_LOC.Value;
       &REC2.UNIT_OF_MEASURE.Value = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2.CURRENCY_CD.Value = &RECITEM2.CURRENCY_CD.Value;
       &REC2.QTY_MIN.Value = &RECITEM2.QTY_MIN.Value;
       &REC2.EFFDT.Value = &Effdt;
       &REC2.EFF_STATUS.Value = &RECITEM.EFF_STATUS.Value;
       &REC2.PRICE_VNDR.Value = &PriceVndr;
       &REC2.UNIT_PRC_TOL.Value = &RECITEM.UNIT_PRC_TOL.Value;
       &REC2.EXT_PRC_TOL.Value = &RECITEM.EXT_PRC_TOL.Value;
       &REC2.PCT_UNIT_PRC_TOL.Value = &RECITEM.PCT_UNIT_PRC_TOL.Value;
       &REC2.PCT_EXT_PRC_TOL.Value = &RECITEM.PCT_EXT_PRC_TOL.Value;
       &REC2.USE_STD_TOLERANCES.Value = &RECITEM.USE_STD_TOLERANCES.Value;
       &REC2.QTY_RECV_TOL_PCT.Value = &RECITEM.QTY_RECV_TOL_PCT.Value;
       &REC2.UNIT_PRC_TOL_L.Value = &RECITEM.UNIT_PRC_TOL_L.Value;
       &REC2.PCT_UNIT_PRC_TOL_L.Value = &RECITEM.PCT_UNIT_PRC_TOL_L.Value;
       &REC2.EXT_PRC_TOL_L.Value = &RECITEM.EXT_PRC_TOL_L.Value;
       &REC2.PCT_EXT_PRC_TOL_L.Value = &RECITEM.PCT_EXT_PRC_TOL_L.Value;
       &REC2.BU_PRICE_STATUS.Value = "2";
       &REC2.STD_PRICE_STATUS.Value = "2";
       &REC2.LEAD_TIME.Value = &RECITEM.LEAD_TIME.Value;
       &REC2.OPRID_MODIFIED_BY.Value = &Oprid;
       &REC2.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
       &REC2.PRICE_CHANGE.Value = &RECITEM.PRICE_CHANGE.Value;
       &REC2.Insert();
       Break;
       End-If;  /*Kevin added this on 10/22 3:55PM */
      End-While;

       /* Else;  */
       /* Continue; */   

       /* Final Else - If all rows have been looped through and there was not a match found then do the following  */
      If Not &RowFound Then;
       SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM3, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM3);
       &REC3 = CreateRecord(Record.ITM_VNDR_UOM_PR);
       &new_UNIT_OF_MEASURE = &RECITEM2.UNIT_OF_MEASURE.Value;
       &REC2 = CreateRecord(Record.ITM_VNDR_UOM_PR);
       &REC2.SETID.Value = &RECITEM3.SETID.Value;
       &REC2.INV_ITEM_ID.Value = &RECITEM3.INV_ITEM_ID.Value;
       &REC2.VENDOR_SETID.Value = &RECITEM3.VENDOR_SETID.Value;
       &REC2.VENDOR_ID.Value = &RECITEM3.VENDOR_ID.Value;
       &REC2.VNDR_LOC.Value = &RECITEM3.VNDR_LOC.Value;
       &REC2.UNIT_OF_MEASURE.Value = &UOMResult
       &REC2.CURRENCY_CD.Value = &RECITEM3.CURRENCY_CD.Value;
       &REC2.QTY_MIN.Value = &RECITEM3.QTY_MIN.Value;
       &REC2.EFFDT.Value = &Effdt;
       &REC2.EFF_STATUS.Value = &RECITEM3.EFF_STATUS.Value;
       &REC2.PRICE_VNDR.Value = &PriceVndr;
       &REC.UNIT_PRC_TOL.Value = &RECITEM3.UNIT_PRC_TOL.Value;
       &REC2.EXT_PRC_TOL.Value = &RECITEM3.EXT_PRC_TOL.Value;
       &REC2.PCT_UNIT_PRC_TOL.Value = &RECITEM3.PCT_UNIT_PRC_TOL.Value;
       &REC2.PCT_EXT_PRC_TOL.Value = &RECITEM3.PCT_EXT_PRC_TOL.Value;
       &REC2.USE_STD_TOLERANCES.Value = &RECITEM3.USE_STD_TOLERANCES.Value;
       &REC2.QTY_RECV_TOL_PCT.Value = &RECITEM3.QTY_RECV_TOL_PCT.Value;
       &REC2.UNIT_PRC_TOL_L.Value = &RECITEM3.UNIT_PRC_TOL_L.Value;
       &REC2.PCT_UNIT_PRC_TOL_L.Value = &RECITEM3.PCT_UNIT_PRC_TOL_L.Value;
       &REC2.EXT_PRC_TOL_L.Value = &RECITEM3.EXT_PRC_TOL_L.Value;
       &REC2.PCT_EXT_PRC_TOL_L.Value = &RECITEM3.PCT_EXT_PRC_TOL_L.Value;
       &REC2.BU_PRICE_STATUS.Value = "2";
       &REC2.STD_PRICE_STATUS.Value = "2";
       &REC2.LEAD_TIME.Value = &RECITEM3.LEAD_TIME.Value;
       &REC2.OPRID_MODIFIED_BY.Value = &Oprid;
       &REC2.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
       &REC2.PRICE_CHANGE.Value = &RECITEM3.PRICE_CHANGE.Value;
       &REC2.Insert();
     End-If;

    /* End-While; */
   Else;
      &CurrentDateTime = %Datetime;
      &Oprid = %OperatorId;
      &RECITEM = CreateRecord(Record.ITM_VNDR_UOM_PR);

      /*GETTING MAX EFFECTIVE DATED ROW TO COPY EXISTING ROW VALUES FROM INTO NEW ROW */
      SQLExec("SELECT C.EFFDT FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.UNIT_OF_MEASURE = :3 AND C.EFFDT = (SELECT MAX(C1.EFFDT) FROM PS_ITM_VNDR_UOM_PR C1 WHERE C.SETID = C1.SETID AND C.INV_ITEM_ID = C1.INV_ITEM_ID AND C.VENDOR_SETID = C1.VENDOR_SETID AND C.VENDOR_ID = C1.VENDOR_ID AND C.VNDR_LOC = C1.VNDR_LOC AND C.UNIT_OF_MEASURE = C1.UNIT_OF_MEASURE AND C.CURRENCY_CD = C1.CURRENCY_CD AND C.QTY_MIN = C1.QTY_MIN)  ", &InvItemId, &VendorId, &UOM, &MaxEffdt);

      SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND (CONVERT(CHAR(10),EFFDT,121)) = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM);
      /*SQLExec("%SelectAll(:1) WHERE INV_ITEM_ID = :2 AND VENDOR_ID = :3 AND UNIT_OF_MEASURE = :4 AND EFFDT = :5", &RECITEM, &InvItemId, &VendorId, &UOM, &MaxEffdt, &RECITEM); */
      &new_UNIT_OF_MEASURE = &RECITEM.UNIT_OF_MEASURE.Value;
      &REC = CreateRecord(Record.ITM_VNDR_UOM_PR);
      &REC.SETID.Value = &RECITEM.SETID.Value;
      &REC.INV_ITEM_ID.Value = &RECITEM.INV_ITEM_ID.Value;
      &REC.VENDOR_SETID.Value = &RECITEM.VENDOR_SETID.Value;
      &REC.VENDOR_ID.Value = &RECITEM.VENDOR_ID.Value;
      &REC.VNDR_LOC.Value = &RECITEM.VNDR_LOC.Value;
      &REC.UNIT_OF_MEASURE.Value = &RECITEM.UNIT_OF_MEASURE.Value;
      &REC.CURRENCY_CD.Value = &RECITEM.CURRENCY_CD.Value;
      &REC.QTY_MIN.Value = &RECITEM.QTY_MIN.Value;
      &REC.EFFDT.Value = &Effdt;
      &REC.EFF_STATUS.Value = &RECITEM.EFF_STATUS.Value;
      &REC.PRICE_VNDR.Value = &PriceVndr;
      &REC.UNIT_PRC_TOL.Value = &RECITEM.UNIT_PRC_TOL.Value;
      &REC.EXT_PRC_TOL.Value = &RECITEM.EXT_PRC_TOL.Value;
      &REC.PCT_UNIT_PRC_TOL.Value = &RECITEM.PCT_UNIT_PRC_TOL.Value;
      &REC.PCT_EXT_PRC_TOL.Value = &RECITEM.PCT_EXT_PRC_TOL.Value;
      &REC.USE_STD_TOLERANCES.Value = &RECITEM.USE_STD_TOLERANCES.Value;
      &REC.QTY_RECV_TOL_PCT.Value = &RECITEM.QTY_RECV_TOL_PCT.Value;
      &REC.UNIT_PRC_TOL_L.Value = &RECITEM.UNIT_PRC_TOL_L.Value;
      &REC.PCT_UNIT_PRC_TOL_L.Value = &RECITEM.PCT_UNIT_PRC_TOL_L.Value;
      &REC.EXT_PRC_TOL_L.Value = &RECITEM.EXT_PRC_TOL_L.Value;
      &REC.PCT_EXT_PRC_TOL_L.Value = &RECITEM.PCT_EXT_PRC_TOL_L.Value;
      &REC.BU_PRICE_STATUS.Value = "2";
      &REC.STD_PRICE_STATUS.Value = "2";
      &REC.LEAD_TIME.Value = &RECITEM.LEAD_TIME.Value;
      &REC.OPRID_MODIFIED_BY.Value = &Oprid;
      &REC.LAST_DTTM_UPDATE.Value = &CurrentDateTime;
      &REC.PRICE_CHANGE.Value = &RECITEM.PRICE_CHANGE.Value;
      &REC.Insert();

      /*MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt);*/

   End-If;

   /* 10/11/2018 - Added field ITEM_FIELD_C10_B (&ItmField) to CSV file layout and insert into PS_MASTER_ITEM_TBL (&MASTER_ITEM_TBL) */
   If None(&ItmField) Then;
      &Error = "Y";
      MessageBox(0, "", 0, 0, &VendorId | " " | &InvItemId | " " | &ItmIdVndr | " " | &UOM | " " | &ConvRate | " " | &PriceVndr | " " | &Effdt | " " | &ItmField);
   Else;
      SQLExec("UPDATE PS_MASTER_ITEM_TBL SET ITEM_FIELD_C10_B = :1 WHERE INV_ITEM_ID = :2 AND SETID = 'SHARE' ", &ItmField, &InvItemId);
      /* Else;
       &REC1 = CreateRecord(Record.MASTER_ITEM_TBL);
       &REC1.ITEM_FIELD_C10_B.Value = &ItmField;
       &REC1.SETID.Value = "SHARE";
       &REC1.INV_ITEM_ID.Value = &InvItemId;
       &REC1.Update();
    End-If;  */

   End-If;

End-While;
MessageBox(0, "", 0, 0, "**** END OF VALIDATION ERRORS ****");
MessageBox(0, "", 0, 0, " ");
4

1 回答 1

1

您想在 while 中设置一个变量以确定是否找到记录,如果未找到,则执行您的替代插入逻辑。在这种情况下,我们将使用变量 &rowFound 来确定是否存在匹配项。

Local Boolean &rowFound;
Local SQL &sql;

&sql = createsql("SELECT C.UNIT_OF_MEASURE FROM PS_ITM_VNDR_UOM_PR C WHERE C.INV_ITEM_ID = :1 AND C.VENDOR_ID = :2 AND C.EFFDT = (SELECT MAX(C1.EFFDT) FROM PS_ITM_VNDR_UOM_PR C1 WHERE C.SETID = C1.SETID AND C.INV_ITEM_ID = C1.INV_ITEM_ID AND C.VENDOR_SETID = C1.VENDOR_SETID AND C.VENDOR_ID = C1.VENDOR_ID AND C.VNDR_LOC = C1.VNDR_LOC AND C.UNIT_OF_MEASURE = C1.UNIT_OF_MEASURE AND C.CURRENCY_CD = C1.CURRENCY_CD AND C.QTY_MIN = C1.QTY_MIN)",&InvItemId, &VendorID);

&rowFound = False;
while &sql.fetch(&UOMResult)
    If &UOM = &UOMResult Then
        &rowFound = True;
        /* Do Insert Code here */
        break;
     end-if;
end-while;
&sql.close;

if not &rowFound then 
    /* Insert Logic if it's not found */
end-if
于 2018-10-22T22:12:51.497 回答