应用程序引擎 Peoplecode 绑定变量
Application Engine Peoplecode bind variables
我在应用程序引擎程序中有以下 PeopleCode 步骤,该程序使用文件布局读取 CSV 文件,然后将数据插入 table,我只是想更好地了解如何生成以下脚本中的代码行 (&SQL1 = CreateSQL("%Insert(:1)");
)。看起来 CreateSQL 在 Insert 语句中使用了一个绑定变量 (:1),但我正在努力寻找该变量在程序中定义的位置。
Function EditRecord(&REC As Record) Returns boolean;
Local integer &E;
&REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_OneZero);
If &REC.IsEditError Then
For &E = 1 To &REC.FieldCount
&MYFIELD = &REC.GetField(&E);
If &MYFIELD.EditError Then
&MSGNUM = &MYFIELD.MessageNumber;
&MSGSET = &MYFIELD.MessageSetNumber;
&LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD.Name);
&LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, ""));
End-If;
End-For;
Return False;
Else
Return True;
End-If;
End-Function;
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
rem &SQL1 = CreateSQL("%Insert(:1) Order by COUNT_ORDER");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(@(&RecordName));
&RECP = &RSParent(1).GetRecord(@(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1, &FILE3;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
&FILE1 = GetFile("\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.csv", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.txt", "r", "a", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&LOGFILE.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.GH_ITM_PR_UPDT);
REM &SQL1 = CreateSQL("%Insert(:1)");
&SQL1 = CreateSQL("%Insert(:1)");
/*Skip Header Row: The following line of code reads the first line in the file layout (the header)
and does nothing. Then the pointer goes to the next line in the file and starts using the
file.readrowset*/
&some_boolean = &FILE1.ReadLine(&string);
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;
&FILE1.Close();
&LOGFILE.Close();
:1
来自更下方的线 &SQL1.Execute(&REC2);
&REC2
被分配了一个记录对象,因此行 &SQL1.Execute(&REC2);
的计算结果为 %Insert(your_record_object)
Here is a simple example that's doing basically the same thing
回复因为太长无法评论:
table 的名字很可能是 (PS_)GH_ITM_PR_UPDT。普遍的共识是将 FileLayout 命名为其所基于的记录。
如果没有,则在FileLayout.GH_ITM_PR_UPDT中定义。打开 FileLayout,右键单击该段,然后在 'Selected Node Properties' 下您会找到 'File Record Name'.
在您的代码中,这条记录被转移到 &RS1 中。
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
行集是行的集合。一行由记录组成,一条记录是数据库中的一行数据 table。 (Peoplesoft 对象数据类型很有趣……)
此行集用以下语句中的数据填充:
&RS1 = &FILE1.ReadRowset();
这使用您的文件作为输入并输出一个行集集合,根据您定义 FileLayout 的方式将数据映射到记录。
结果被送入 ImportSegment 函数:
ImportSegment(&RS1, &RS);
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
函数中的 &RS2 是对其余代码中 &RS1 的引用。
table 名称也隐藏在这里:
&RecordName = "RECORD." | &RS2.DBRecordName;
因此,如果您t/don不想检查 FileLayout,您可以使用消息框输出 &RS2.DBRecordName
,您的答案将是进程监视器的消息日志。
最后为此数据库创建了一个记录对象 table 并用行集中的一行填充。这条记录被插入数据库table:
&REC2 = CreateRecord(@(&RecordName));
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
&SQL1 = CreateSQL("%Insert(:1)");
&SQL1.Execute(&REC2);
TLDR:
Table 名称可以在 FileLayout 中找到或在 ImportSegment 函数中输出为 &RS2.DBRecordName
我在应用程序引擎程序中有以下 PeopleCode 步骤,该程序使用文件布局读取 CSV 文件,然后将数据插入 table,我只是想更好地了解如何生成以下脚本中的代码行 (&SQL1 = CreateSQL("%Insert(:1)");
)。看起来 CreateSQL 在 Insert 语句中使用了一个绑定变量 (:1),但我正在努力寻找该变量在程序中定义的位置。
Function EditRecord(&REC As Record) Returns boolean;
Local integer &E;
&REC.ExecuteEdits(%Edit_Required + %Edit_DateRange + %Edit_YesNo + %Edit_OneZero);
If &REC.IsEditError Then
For &E = 1 To &REC.FieldCount
&MYFIELD = &REC.GetField(&E);
If &MYFIELD.EditError Then
&MSGNUM = &MYFIELD.MessageNumber;
&MSGSET = &MYFIELD.MessageSetNumber;
&LOGFILE.WriteLine("****Record:" | &REC.Name | ", Field:" | &MYFIELD.Name);
&LOGFILE.WriteLine("****" | MsgGet(&MSGSET, &MSGNUM, ""));
End-If;
End-For;
Return False;
Else
Return True;
End-If;
End-Function;
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
Local Rowset &RS1, &RSP;
Local string &RecordName;
Local Record &REC2, &RECP;
Local SQL &SQL1;
Local integer &I, &L;
&SQL1 = CreateSQL("%Insert(:1)");
rem &SQL1 = CreateSQL("%Insert(:1) Order by COUNT_ORDER");
&RecordName = "RECORD." | &RS2.DBRecordName;
&REC2 = CreateRecord(@(&RecordName));
&RECP = &RSParent(1).GetRecord(@(&RecordName));
For &I = 1 To &RS2.ActiveRowCount
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
If (EditRecord(&REC2)) Then
&SQL1.Execute(&REC2);
&RS2(&I).GetRecord(1).CopyFieldsTo(&RECP);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&RSP = &RSParent.GetRow(1).GetRowset(&L);
ImportSegment(&RS1, &RSP);
End-If;
End-For;
If &RSParent.ActiveRowCount > 0 Then
&RSParent.DeleteRow(1);
End-If;
Else
&LOGFILE.WriteRowset(&RS);
&LOGFILE.WriteLine("****Correct error in this record and delete all error messages");
&LOGFILE.WriteRecord(&REC2);
For &L = 1 To &RS2.GetRow(&I).ChildCount
&RS1 = &RS2.GetRow(&I).GetRowset(&L);
If (&RS1 <> Null) Then
&LOGFILE.WriteRowset(&RS1);
End-If;
End-For;
End-If;
End-For;
End-Function;
rem *****************************************************************;
rem * PeopleCode to Import Data *;
rem *****************************************************************;
Local File &FILE1, &FILE3;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1, &RS2;
Local integer &M;
&FILE1 = GetFile("\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.csv", "r", "a", %FilePath_Absolute);
&LOGFILE = GetFile("\nt115\apps\interface_prod\interface_in\Item_Loader\ItemPriceFile.txt", "r", "a", %FilePath_Absolute);
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&LOGFILE.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
&RS = CreateRowset(Record.GH_ITM_PR_UPDT);
REM &SQL1 = CreateSQL("%Insert(:1)");
&SQL1 = CreateSQL("%Insert(:1)");
/*Skip Header Row: The following line of code reads the first line in the file layout (the header)
and does nothing. Then the pointer goes to the next line in the file and starts using the
file.readrowset*/
&some_boolean = &FILE1.ReadLine(&string);
&RS1 = &FILE1.ReadRowset();
While &RS1 <> Null
ImportSegment(&RS1, &RS);
&RS1 = &FILE1.ReadRowset();
End-While;
&FILE1.Close();
&LOGFILE.Close();
:1
来自更下方的线 &SQL1.Execute(&REC2);
&REC2
被分配了一个记录对象,因此行 &SQL1.Execute(&REC2);
的计算结果为 %Insert(your_record_object)
Here is a simple example that's doing basically the same thing
回复因为太长无法评论:
table 的名字很可能是 (PS_)GH_ITM_PR_UPDT。普遍的共识是将 FileLayout 命名为其所基于的记录。
如果没有,则在FileLayout.GH_ITM_PR_UPDT中定义。打开 FileLayout,右键单击该段,然后在 'Selected Node Properties' 下您会找到 'File Record Name'.
在您的代码中,这条记录被转移到 &RS1 中。
&FILE1.SetFileLayout(FileLayout.GH_ITM_PR_UPDT);
&RS1 = &FILE1.CreateRowset();
行集是行的集合。一行由记录组成,一条记录是数据库中的一行数据 table。 (Peoplesoft 对象数据类型很有趣……) 此行集用以下语句中的数据填充:
&RS1 = &FILE1.ReadRowset();
这使用您的文件作为输入并输出一个行集集合,根据您定义 FileLayout 的方式将数据映射到记录。 结果被送入 ImportSegment 函数:
ImportSegment(&RS1, &RS);
Function ImportSegment(&RS2 As Rowset, &RSParent As Rowset)
函数中的 &RS2 是对其余代码中 &RS1 的引用。 table 名称也隐藏在这里:
&RecordName = "RECORD." | &RS2.DBRecordName;
因此,如果您t/don不想检查 FileLayout,您可以使用消息框输出 &RS2.DBRecordName
,您的答案将是进程监视器的消息日志。
最后为此数据库创建了一个记录对象 table 并用行集中的一行填充。这条记录被插入数据库table:
&REC2 = CreateRecord(@(&RecordName));
&RS2(&I).GetRecord(1).CopyFieldsTo(&REC2);
&SQL1 = CreateSQL("%Insert(:1)");
&SQL1.Execute(&REC2);
TLDR:
Table 名称可以在 FileLayout 中找到或在 ImportSegment 函数中输出为 &RS2.DBRecordName