如何使用PeopleCode对文件运行ps/查询

您可以使用PeopleCode调用ps查询。为此,可以在PeopleCode中使用查询类。
PeopleCode中的查询类可用于创建新查询,或修改或删除现有查询。还可以使用查询类中的方法来执行查询,并将结果集作为行集返回,或者将其格式化并将结果集写入文件。
使用会话类/对象可以访问查询类(或API)。
这是您在运行时使用查询时必须遵循的典型步骤。

1.调用PeopleSoft会话对象上的GetQuery方法来获取查询。

在打开现有查询之前,必须获取会话对象。会话控制对查询的访问,提供错误跟踪,使您能够设置运行时环境,等等。下面的代码行检查以验证会话对象是否有效。

/*create a query API object*/
Local ApiObject &aRunQry;
/*create a session API object*/
Local Session &MySession;

/*The current session*/
&MySession = %Session; 
If &MySession <> Null Then 
/*The GetQuery method returns an empty query object. After you have an empty query object, you can use it to open an existing query*/
    &aRunQry= &MySession.GetQuery();
End-If;

  

2.使用Open方法打开所需的特定查询。

&aRunQry.Open("MY_TEST_QUERY", True, False);

Open方法包含表单的3个参数:open(QueryName,Public,Update)
QueryName是特定查询的名称,它接受一个字符串值,第二个参数指定查询是公共的还是私有的,最后一个参数是必需的,您可以说true of false。

 

3.将运行时提示记录作为PeopleCode记录对象的实例添加到查询中(可选)

假设您已经使用PeopleSoft查询管理器创建了一个查询,并且已经为查询定义了提示。为了填充这些提示值,可以使用PromptRecord属性访问记录实例。然后,您可以使用它作为RunToFile方法的第一个输入参数。

/* Obtain the PromptRecord for the query*/
Local Record &aQryPromptRec;
&aQryPromptRec = &aRunQry.PromptRecord;

This instance of the PromptRecord can be passed to the PeopleCode Prompt function to prompt the user for the runtime values, as follows:

&nResult = Prompt(&strQryName | " Prompts", "", &aQryPromptRec);

/* Populate the runtime parameters */
If &aQryPromptRec <> Null Then
&nResult = Prompt(&strQryName | " Prompts", "", &aQryPromptRec); 
End-If;

4.运行对文件的查询

可以使用RunToFile方法执行查询,并将结果返回给指定有目的地的文件。

/* Run the query output for txt in CSV format */ 
If (&aRunQry.RunToFile(&aQryPromptRec, "c:\temp\" | &aRunQry.Name, %Query_TXT, 0) = 0) Then
   MessageBox(0, "", 0, 0, "Resultset saved into file successfully.");
Else
   MessageBox(0, "", 0, 0, "Failed to save Resultset into file.");
End-If;

使用调度查询页(报表工具、查询、计划查询)调度查询时,可以添加提示记录参数。可以编程方式填充提示记录(查询Run_PARM)在“计划查询”页面中,并在“PeopleCode”中使用。如果您想使用应用程序引擎运行查询,这是很有帮助的。

做那件事
步骤1:使用APPEngineSQL操作填充ps_query_run_PARM记录(例如向ps_query_run_PARM记录插入提示记录参数)

步骤2:然后使用以下PeopleCode将提示参数从ps_query_run_PARM分配给&aQryPromptRec(本地提示记录)

&aQryPromptRec = &aRunQry.PromptRecord;
         If &aQryPromptRec <> Null Then        
            &rcdQryRunParms = CreateRecord(Record.QUERY_RUN_PARM);
            &sqlSelectQryParms = CreateSQL("%Selectall(:1) WHERE OPRID = :2 AND RUN_CNTL_ID = :3");
            
            &sqlSelectQryParms.Execute(&rcdQryRunParms, %OperatorId, MY_AET_RECORD.RUN_CNTL_ID);
            
            While &sqlSelectQryParms.Fetch(&rcdQryRunParms)
               For &i = 1 To &rcdQryPrompts.FieldCount
                  If &aQryPromptRec.GetField(&i).Name = &rcdQryRunParms.GetField(Field.FIELDNAME).Value Then
                     &aQryPromptRec.GetField(&i).Value = &rcdQryRunParms.GetField(Field.BNDVALUE).Value;
                     Break;
                  End-If;
               End-For;
            End-While;
            
         &sqlSelectQryParms.Close();
         End-If;

步骤3:现在可以使用RunToFile(),如下所示

/* Run the query output for txt in CSV format */ 
If (&aRunQry.RunToFile(&aQryPromptRec, "c:\temp\" | &aRunQry.Name, %Query_TXT, 0) = 0) Then
   MessageBox(0, "", 0, 0, "Resultset saved into file successfully.");
Else
   MessageBox(0, "", 0, 0, "Failed to save Resultset into file.");
End-If;

猜你喜欢

转载自www.cnblogs.com/ameken/p/10006167.html