Peoplecode SQL更新设置值在其他变量上

时间:2018-10-11 18:45:03

标签: peoplesoft peoplesoft-app-engine peoplecode

我修改了下面的Application Engine程序,在程序读取的CSV文件布局中添加了一个附加字段(&ItmField)。它正在正确更新(SQL UPDATE)字段ITEM_FIELD_C10_B,但是我在跟踪文件中注意到,SQL UPDATE语句已编写脚本来更新SETIDINV_ITEM_IDITEM_FIELD_C10_B(而不仅仅是ITEM_FIELD_C10_B字段)INV_ITEM_ID等于&InvItemId,而SETID等于“ SHARE”。 SQL更新应该仅将ITEM_FIELD_C10_B字段设置为&ItmField,其中INV_ITEM_ID等于&InvItemId并且SETID等于“分享”。

更新后的代码位于以“ KDR-18/11/11”开头的底部附近 跟踪代码也在下面。

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, &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);

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);
   Else;
      &CurrentDateTime = %Datetime;
      &Oprid = %OperatorId;
      &RECITEM = CreateRecord(Record.ITM_VNDR_UOM_PR);
      /*CHC Modification - Denise Smith - 8/8/2012 - CHC_PO_96588 - Begin */
      /*SQLExec("SELECT TO_CHAR(C.EFFDT,'DD-MON-YYYY') 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("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);
      /*CHC Modification - Denise Smith - 8/8/2012 - CHC_PO_96588 - End */
      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.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;

   /* KDR - 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;
      &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-While;
MessageBox(0, "", 0, 0, "**** END OF VALIDATION ERRORS ****");
MessageBox(0, "", 0, 0, " ");

跟踪代码:

131074   14:14:51.915     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 COM Stmt=UPDATE PS_MASTER_ITEM_TBL SET SETID=:1,INV_ITEM_ID=:2,ITEM_FIELD_C10_B=:3 WHERE SETID=:4 AND INV_ITEM_ID=:5
131075   14:14:51.915     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 Bind-1 type=2 length=5 value=SHARE
131076   14:14:51.916     0.001000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 Bind-2 type=2 length=5 value=68776
131077   14:14:51.916     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 Bind-3 type=2 length=8 value=86753090
131078   14:14:51.916     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 Bind-4 type=2 length=5 value=SHARE
131079   14:14:51.917     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 Bind-5 type=2 length=5 value=68776
131080   14:14:51.924     0.007000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.007000 EXE
131081   14:14:51.924     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 ROW #rows=1
131082   14:14:51.925     0.000000 Cur#5.37988.FSYS92T3 RC=1 Dur=0.000000 Fetch
131083   14:14:51.925     0.000000 Cur#5.37988.FSYS92T3 RC=0 Dur=0.000000 Disconnect

18/10/12编辑:

如果我按如下所示添加SelectByKey:

 /* KDR/TGC - 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;
      &REC1 = CreateRecord(Record.MASTER_ITEM_TBL);
      &REC1.ITEM_FIELD_C10_B.Value = &ItmField;
      &REC1.SETID.Value = "SHARE";
      &REC1.INV_ITEM_ID.Value = &InvItemId;
      If &REC1.SelectByKey() Then;
         &REC1.Update();
      End-If;
   End-If;

然后在跟踪文件中,我看到以下内容似乎正在设置要更新的表中的每个字段:

132424   07:41:59.930     0.000000 Cur#1.37988.FSYS92T3 RC=0 Dur=0.000000 COM Stmt=UPDATE PS_MASTER_ITEM_TBL SET SETID=:1,INV_ITEM_ID=:2,ITM_STATUS_EFFDT=:3,ITM_STATUS_CURRENT=:4,ITM_STAT_DT_FUTURE=NULL,ITM_STATUS_FUTURE=:5,DESCR=:6,DESCR60=:7,DESCRSHORT=:8,UNIT_MEASURE_STD=:9,INV_ITEM_GROUP=:10,INV_PROD_FAM_CD=:11,CATEGORY_ID=:12,DATE_ADDED=:13,ORIG_OPRID=:14,APPROVAL_OPRID=:15,APPROVAL_DATE=:16,LAST_MAINT_OPRID=:17,LAST_DTTM_UPDATE=:18,CHANGE_FIELD=:19,INVENTORY_ITEM=:20,LOT_CONTROL=:21,SERIAL_CONTROL=:22,SHIP_SERIAL_CNTRL=:23,NON_OWN_FLAG=:24,APPROV_REQUIRED=:25,APPROV_SUBMITTED=:26,DENIAL_REASON=:27,STAGED_DATE_FLAG=:28,DIST_CFG_FLAG=:29,PRDN_CFG_FLAG=:30,CFG_CODE_OPT=:31,CFG_COST_OPT=:32,CFG_LOT_OPT=:33,CP_TEMPLATE_ID=:34,CP_TREE_DIST=:35,CP_TREE_PRDN=:36,CM_GROUP=:37,MATERIAL_RECON_FLG=:38,USG_TRCKNG_METHOD=:39,CONSIGNED_FLAG=:40,PL_PRIO_FAMILY=:41,ITEM_FIELD_C30_A=:42,ITEM_FIELD_C30_B=:43,ITEM_FIELD_C30_C=:44,ITEM_FIELD_C30_D=:45,ITEM_FIELD_C1_A=:46,ITEM_FIELD_C1_B=:47,ITEM_FIELD_C1_C=:48,ITEM_FIELD_C1_D=:49,ITEM_FIELD_C10_A=:50,ITEM_FIELD_C10_B=:51,ITEM_FIELD_C10_C=:52,ITEM_FIELD_C10_D=:53,ITEM_FIELD_C2=:54,ITEM_FIELD_C4=:55,ITEM_FIELD_C6=:56,ITEM_FIELD_C8=:57,ITEM_FIELD_N12_A=:58,ITEM_FIELD_N12_B=:59,ITEM_FIELD_N12_C=:60,ITEM_FIELD_N12_D=:61,ITEM_FIELD_N15_A=:62,ITEM_FIELD_N15_B=:63,ITEM_FIELD_N15_C=:64,ITEM_FIELD_N15_D=:65,PROMISE_OPTION=:66,DEVICE_TRACKING=:67,SERIAL_IN_PRDN=:68,TRACE_USAGE=:69,TRACE_CHANGE=:70,PHYSICAL_NATURE=:71 WHERE SETID=:72 AND INV_ITEM_ID=:73

1 个答案:

答案 0 :(得分:0)

  

SQL更新仅应将ITEM_FIELD_C10_B字段设置为&ItmField,其中INV_ITEM_ID等于&InvItemId且SETID等于“ SHARE”。

这实际上是UPDATE语句正在执行的操作,因为绑定1等于绑定4,绑定2等于绑定5。

现在,由于您从其他表中选择了&InvItemId,因此您可以添加以下完整性检查以确保其存在于MASTER_ITEM_TBL中:SelectByKey

If &REC1.SelectByKey() Then
    &REC1.Update();
End-if;

这些字段出现在您的update语句中的原因可能是因为实现Record Class Update()方法的最简单方法是:(推测)

UPDATE TABLE SET (ALL SET FIELDS) WHERE (KEYS);

因为您使用的是独立记录定义,而不是从缓冲区中选择,所以组件处理器不知道SETID和INV_ITEM_ID已经存在,因此必须对其进行设置。

未经测试:在&REC1.SelectByKey()之前添加&REC1.Update()可能会阻止此操作,因为它会导致数据库访问。