【问题标题】:How can I create SQL output to a CSV file in Application Engine?如何在 Application Engine 中创建 SQL 输出到 CSV 文件?
【发布时间】:2021-03-28 04:39:41
【问题描述】:

我是 Peopletools 和 Peoplecode 的新手。

我有一条 SQL 语句,我想收集输出(来自 SQL 的所有数据)并创建一个 CSV 文件。

您能否提供一个示例 CSV 文件代码?

我需要为应用引擎进程创建文件布局吗?enter image description here

【问题讨论】:

标签: peoplesoft peoplecode


【解决方案1】:

您不一定需要文件布局来创建 csv - 您只需小心放入 CSV 中的数据,因为数据中带有逗号的任何列都会开始一个新列等。

&filename = "YourFilePath";
&newFile = GetFile(&filename, "w", "a", %FilePath_Absolute);
&newFile.WriteLine("id" | "," | "type" | "," | "streetAddress" | "," | "addressLine2" | "," | "addressLine3" | "," | "locality" | "," | "postalCode" | "," | "region" | "," | "country" | "," | "source" | "," | "requester");
&rsActiveEmp = CreateRowset(Record.RECORD_TO_PROCESS);
&rsActiveEmp.Fill("where processed = 'N'");

For &i = 1 To &rsActiveEmp.ActiveRowCount
   &emplid = &rsActiveEmp.GetRow(&i).RECORD_TO_PROCESS.EMPLID.Value;
   Local TST_PERSON:PERSON &person = create TST_PERSON:PERSON(&emplid);
   Local array of string &address = &person.getMaxEdAddress();
   &newFile.WriteLine(&person.id_ | "," | "Mailing Address" | "," | &address [1] | "," | &address [2] | "," | "" | "," | &address [4] | "," | &address [5] | "," | &address [6] | "," | &address [7] | "," | "1111111" | "," | "FictitiousPerson");
End-For;
&newFile.Close();

您需要手动编写标题行,然后遍历数据集以编写其余行。在我的示例中,TST_PERSON 是一个自定义应用程序类,我使用它来为常用的生物演示数据检索创建“人”对象。在您的情况下,您可以只使用 SqlExec 语句来收集每一行的数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2015-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2016-09-27
    相关资源
    最近更新 更多