如何仅在 App Engine PeopleCode 的日期时间字段中评估日期

How to evaluate date only in Datetime field in App Engine PeopleCode

首先我想说我是 PeopleSoft AppEngine 和 PeopleCode 开发的新手。

我在 PeopleSoft App Engine 程序中执行以下步骤(OnExecute 步骤),该程序检索 table 中的记录,然后获取这些现有值并使用新的商品价格创建新行。

程序正在执行 table 'PS_ITM_VNDR_UOM_PR' 中的 SQLExec 语句,并使用 EFFDT 作为 WHERE 子句标准的一部分。对于 EFFDT,它正在填充变量值,格式为 'YYYY-MM-DD'。问题是 table PS_ITM_VNDR_UOM_PR 中的某些行对于 EFFDT 具有日期和时间:(即 2018-03-19 10:04:03.040),而不仅仅是日期默认空白时间:(即 2018-03-16 00:00:00.000)。

这是另一种看待问题的方式,这是 SQL 程序是 运行,它的结果是:

SQL 在 WHERE 子句中使用标准 EFFDT 的代码/结果(不选取任何行):

与 EFFDT 日期转换逻辑相同的 SQL 代码/结果(选取一行):

有没有办法修改代码中的 SQL 语句,类似于我在上面的本机 SQL 服务器中所做的,或者我可以定义一个仅日期程序变量的方法我可以在 SQLExec code?

中使用

我在下面的代码中发表了评论,我认为该行包含需要修改的 SQL 语句。

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

&Oprid = "'SYSUSER'";
&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) FROM 
PS_GH_ITM_PR_UPDT ORDER BY VENDOR_ID, INV_ITEM_ID, ITM_ID_VNDR", &VendorId, 
&InvItemId, &ItmIdVndr, &UOM, &ConvRate, &PriceVndr, &Effdt);

While &SQL.Fetch(&VendorId, &InvItemId, &ItmIdVndr, &UOM, &ConvRate, 
&PriceVndr, &Effdt)

   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);
   Else;
      &CurrentDateTime = %Datetime;
      &Oprid = %OperatorId;
      &RECITEM = 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.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);
/* **NEXT SECTION OF CODE IS WHERE THE ISSUE IS OCCURING I BELIEVE** */
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);
/* **** END OF ISSUE CODE IN QUESTION **** */
      &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.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;
End-While;
MessageBox(0, "", 0, 0, "**** END OF VALIDATION ERRORS ****");
MessageBox(0, "", 0, 0, " ");

非常感谢您提供的任何意见!

如果这是一个 Oracle 数据库,您也许可以在 EFFDT 字段上使用 TRUNC。

...UNIT_OF_MEASURE = :4 AND TRUNC(EFFDT) = :5

不确定 SQLServer 或其他数据库上的等效项是什么。我认为那样会忽略时间而只是加入约会。尽管您随后可能会遇到返回多行的问题,或其他重复行问题。 EFFDT 字段通常不应包含时间组件,因此该环境可能存在数据问题。

将 &MaxEffdt 定义为日期。

您已将其定义为字符串,但您 select 将日期放入其中,从而强制进行隐式转换。