0

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

我在 PeopleSoft App Engine 程序(OnExecute 步骤)中有以下步骤,该程序检索表中的记录,然后获取这些现有值并创建具有新项目价格的新行。

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

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

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

在此处输入图像描述

具有 EFFDT 日期转换逻辑的相同 SQL 代码/结果(选择一行): 在此处输入图像描述

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

我在下面的代码中发表了评论,我认为该行与需要修改的有问题的 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, " ");

我感谢您提供的任何意见!

4

2 回答 2

1

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

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

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

于 2018-07-09T17:31:56.563 回答
0

将 &MaxEffdt 定义为日期。

您将其定义为字符串,但您在其中选择了一个日期,从而强制进行隐式转换。

于 2018-07-18T13:08:46.447 回答