2012-04-26

[PeopleSoft] Get output file directory using PeopleCode

In PT8.2x, simply add (on the bottom of this blog I’ll discuss about the file path separator) :

&FileStr = GetEnv("PSPRCSLOGDIR")|"\yourFile.txt";

&POSI_FILE = GetFile(&FileStr, "W", %FilePath_Absolute);

 

Use %FilePath_Absolute (instead of %FilePath_Relative) .

As per Oracle:

With Application Engine only .log, .trc, .AET, .out can be used. No other extensions work other than these 4 extensions, none of the files will make it to the Report Repository (.err is another story, though). Please note that there must not be multiple “.” in file names.

As some developer mentioned it is possible with PT 8.4x which allows user to picked up other extensions by process types, for example, .txt - Couple things to look into:

  1. Make sure the txt file is 'relative' with %FilePath_Relative' while opening the file.
  2. Make sure the .txt file is setup to be carried over. Here is the navigation (PT 8.48): PeopleTools>Process Scheduler>System Setting .
    Check the third tab Process Output Format and the 5th tab Distribution File Option, make sure the .txt is set or checked.
  3. Make sure the 'Type' is 'Web' and the format is TXT after you click the Run button.

At runtime by running this query it will get the current output directory where “.out” is going, and create the file here.

Struggling with finding the output directory? May the SQL below help:

select PRCSOUTPUTDIR from PSPRCSPARMS where PRCSINSTANCE = {SOMETABLE_AET}.PROCESS_INSTANCE

Below is the code example:

SQLExec("SELECT PRCSOUTPUTDIR FROM PSPRCSPARMS WHERE PRCSINSTANCE = :1", {SOMETABLE_AET}.PROCESS_INSTANCE, &path);

/* Assume that the NT server’s name is "PSNT". */

SQLExec("SELECT A.SERVERNAMERUN FROM PSPRCSRQST A WHERE A.PRCSINSTANCE = :1", {SOMETABLE_AET}.PROCESS_INSTANCE, &serverrun);

If &serverrun = "PSNT" Then

   &DirSep = "\";

Else

   &DirSep = "/";

End-If;

&outputFileName = RTrim(&path | &DirSep | {OUTPUTFILENAME} | ".txt");

&fileHandler = GetFile(&outputFileName, "W", %FilePath_Absolute);

Note that when open file in 'A' - append mode it may not generate any output file. But 'W' - write mode works in my case.

Another way to get the file path separator character is:

/* Get Env Specific directory separator */
&FilePath = GetEnv("PS_SERVDIR");
&DirSep = "/";
If Substring(&FilePath, 1, 1) <> "/" Then
   &DirSep = "\";
End-If;

If Right(&FilePath, 1) <> "/" Or
      Right(&FilePath, 1) <> "\" Then
   &FilePath = &FilePath | &DirSep;
End-If;
&FilePath = &FilePath | "files" | &DirSep;

No comments: