How to Change Grid Column Name of Grid/Scroll level 1 in Peoplecode

How to Change Grid Column Name of Grid/Scroll level 1 in Peoplecode Dynamically

  1. Double Filed Properties in Scroll Area/ Grid and

go to General  Tab and key name of field = ‘LINK’

 How to Change Label Grid/Scroll Column Name in Peoplecode

2. Use PeopleCode at Page Peoplecode

Local Grid &GRID;
Local GridColumn &GRIDCOLUMN;

&GRID = GetGrid(Panel.TEST_MAIN, “COURSE”);

/* Panel.TEST_MAIN = Component,  COURSE = Record Name in Level 1 */

&GRIDCOLUMN = &GRID.GetColumn(“LINK”);
&GRIDCOLUMN.Label = “New Label”

http://www.jointlantic.com/disable-grid-column-page-field-name-using-peoplecode-peoplesoft/

How to Generate XML Publisher from Record Page and Run BI Publisher in PeopleCode

How to Generate XML Publisher from Record Page and Run BI Publisher in PeopleCode

How to select data on scroll area or data grid or data level 0 from page in peoplesoft.

Page for get data for create xml file and run bi publisher by peoplecod.

  1. Create Link or Button and use FieldChange Event : print pdf

 

2. Create PeopleCode for Run BI Publisher.

2.1 Create XML file for Data of RTF Template (Other Template)

               2.1.1 Create Datasource is XML type before create RTF Template go to Reporting tool > BI Publisher > Data Source

Data Source Type =XML

Data Source = Create Name

2.1.2 Upload xml file

2.1.3 Create Report Definition

  

2.2 Generate Report By Peoplecode

 

import PSXP_RPTDEFNMANAGER:*;
import EP_FUNCTIONS:EP_Utilities;

Declare Function GetDirSeparator PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetFileExtension PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;

&EP_Utilities = create EP_FUNCTIONS:EP_Utilities();

Local XmlDoc &xmldocRoot = CreateXmlDoc(“<?xml version=’1.0′ encoding = ‘UTF-8’?><root></root>”);
Local XmlNode &nodeRoot = &xmldocRoot.DocumentElement;
Local XmlNode &nodeCurrent, &nodeParent, &nodeEvaluation, &nodeSection, &nodeItem, &nodeSubItem, &nodeEmployee;
/***********************************************************************************/

/*—- 2.1 Create XML file for Create RTF Template (Other Template) —*/

/*— Selete Data from Page —*/

&nodeCurrent = &nodeRoot.AddElement(“EMPLID”);
&nodeCurrent.NodeValue = TEST_DERIVED.EMPLID;
&nodeCurrent = &nodeRoot.AddElement(“NAME”);
&nodeCurrent.NodeValue = TEST_DERIVED.NAME;
&nodeCurrent = &nodeRoot.AddElement(“NATIONAL_ID”);
&nodeCurrent.NodeValue = TEST_DERIVED.NATIONAL_ID;
&nodeCurrent = &nodeRoot.AddElement(“DEPT_DESCR”);
&nodeCurrent.NodeValue = DEPT_TBL.DESCR254;

/*********Add list Element Scroll Left ***********/
Local Rowset &RS_LEV0, &RS_SECT1, &RS_SECT2;
Local Row &ROW1, &ROW2;

&RS_LEV0 = GetLevel0();
&listNode = &nodeRoot.AddElement(“LIST_ITEM”);

/*—– SCROLL LEFT —-*/
&RS_SECT1 = &RS_LEV0(1).GetRowset(Scroll.TEST_PSVARIABLE);

For &i = 1 To &RS_SECT1.ActiveRowCount

/*– Where condition data in scroll left of page–*/
If (&RS_SECT1(&i).TEST_PSVARIABLE.TEST_PS_FIX.Value = “Y”)  Then

&subNodeCurrent = &listNode.AddElement(“DESCRIPTION” | &i);
&subNodeCurrent.NodeValue = &RS_SECT1(&i).TEST_PSVARIABLE.DESCRIPTION.Value;

&subNodeCurrent = &listNode.AddElement(“DESCR_CALC” | &i);
&subNodeCurrent.NodeValue = &RS_SECT1(&i).TEST_PSVARIABLE.DESCR_CALC.Value;

End-If;

End-For;

/*—– SCROLL RIGHT —-*/

&RS_SECT2 = &RS_LEV0(1).GetRowset(Scroll.TEST_PSVARIABLE2);

For &i = 1 To &RS_SECT2.ActiveRowCount

/*– Where condition data in scroll right of page–*/
If (&RS_SECT2(&i).TEST_PSVARIABLE2.TEST_PS_FIX.Value = “Y”)  Then

&subNodeCurrent = &listNode.AddElement(“DESCRIPTION2” | &i);
&subNodeCurrent.NodeValue = &RS_SECT1(&i).TEST_PSVARIABLE2.DESCRIPTION.Value;

&subNodeCurrent = &listNode.AddElement(“DESCR_CALC2” | &i);
&subNodeCurrent.NodeValue = &RS_SECT2(&i).TEST_PSVARIABLE2.DESCR_CALC.Value;

End-If;

End-For;

&sFormattedXML = &xmldocRoot.GenFormattedXmlString();

/*– WinMessage for Get XML File for Data Source of this report –*/
WinMessage(&sFormattedXML);

 

/***********************************************************************************/
/*— (2.2) Generate Report —*/
Local date &AsOfDate;
Local string &LanguageCd, &MyReportName, &OutFormat, &sTemplateId;
try

/* detect system directory separator */
rem &sDirSep = GetDirSeparator();
/* create process directory */
rem WinMessage(“%FilePath_Relative : ” | %FilePath_Relative, 0);
CreateDirectory(“XMLP”, %FilePath_Relative);

/* Set XML Publisher report required parameters */
&LanguageCd = %Language_User;
&AsOfDate = %Date;
&MyReportName = “COACHING”;

/* create report defn object */
&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&MyReportName);
&oRptDefn.Get();

&oRptDefn.SetRuntimeDataXMLDoc(&xmldocRoot);
&oRptDefn.ProcessReport(&sTemplateId, &LanguageCd, &AsOfDate, “”);
&sFileExt = GetFileExtension(&sOutputFormat);
CommitWork();

/* display the output */
&oRptDefn.DisplayOutput();

catch Exception &Err
Local string &sSub1, &sSub2, &sSub3, &sSub4, &sSub5;
Evaluate &Err.SubstitutionCount
When > 4
&sSub5 = &Err.GetSubstitution(5);
When > 3
&sSub4 = &Err.GetSubstitution(4);
When > 2
&sSub3 = &Err.GetSubstitution(3);
When > 1
&sSub2 = &Err.GetSubstitution(2);
When > 0
&sSub1 = &Err.GetSubstitution(1);
End-Evaluate;
Error MsgGet(&Err.MessageSetNumber, &Err.MessageNumber, &Err.ToString(), &sSub1, &sSub2, &sSub3, &sSub4, &sSub5);
end-try;

Scrollselect Level 1

Scrollselect Level 1

You can populate data from record or view to grid or scroll on page peoplesoft by use syntax scrollselect level 1 at below

ScrollFlush(Record.COURSE);
ScrollSelect(1, Scroll.COURSE, Record.COURSE, “Where emplid = :1 and To_Char(DATE,’yyyymmdd’) = :2 “,  %EmployeeId&DATE);

How to Create Function PeopleCode of PeopleSoft

How to Create Function PeopleCode of PeopleSoft

Create Function in Record Field Formula (Record.Field)

/********************************************************************
Create Function
********************************************************************/
Function Set_DATE_Format_Number(&DATE_IN, &DATE_OUT)

&DATE_OUT = Right(to_char(&DATE_IN,’dd/mm/’)|to_char(to_number(to_char(&DATE_IN,’yyyy’))+543));

End-Function;

 

How to Call Function in PeopleCode

Declare Function Set_DATE_Format_Number PeopleCode Record.Field FieldFormula;

Set_DATE_Format_Number(sysdate,&DATE_OUT);

Replace ENTER SQL/Peoplecode

Replace ENTER SQL/Peoplecode

PeopleCode: How to Replace ENTER in Peoplecode for write file in csv for report and other.

&NEW = SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(&COMMENTS_2000, CHAR(13), ” “),CHAR(10),” “),”,”,” “);

 

SQL: How to Replace ENTER in SQL

REPLACE(REPLACE(REPLACE(TEXT, CHR(10), ”), CHR(13), ”) , CHR(09), ”)

/* Character
CHR(9) — Horizontal tab
CHR(10) — Line feed
CHR(13) — Carriage return.
*/

 

How to Retrieve Image URL Using Java In PeopleCode

How to Retrieve Image URL Using Java In PeopleCode ( FieldChange event)

Local JavaObject &joCertString, &joUrl, &joUrlConnection, &joInputStream, &joImageIO, &joBufferedImage, &joFile;
Local JavaObject &joCertificateFactoryClass, &joCertificateFactory, &joCertInputStream, &joCertificate;
Local JavaObject &joKeystoreClass, &joKeystore, &joTrustManagerFactoryClass, &joTrustManagerFactory;
Local JavaObject &joSSLContextClass, &joSSLContext, &joSSLFactory, &joCastObjectClass;
Local any &anyFileData;
Local Record &recTest;
Local string &sPhotosCert;
Local number &nPutResult;

/*Setup CertificateFactory*/
&sPhotosCert = GetHTMLText(HTML.PHOTOS_CERT);
&joCertString = CreateJavaObject(“java.lang.String”, &sPhotosCert);
&joCertificateFactoryClass = GetJavaClass(“java.security.cert.CertificateFactory”);
&joCertificateFactory = &joCertificateFactoryClass.getInstance(“X.509”);
&joCertInputStream = CreateJavaObject(“java.io.ByteArrayInputStream”, &joCertString.getBytes(“UTF-8”));
&joCertificate = &joCertificateFactory.generateCertificate(&joCertInputStream);

/*Create Keystore*/
&joKeystoreClass = GetJavaClass(“java.security.KeyStore”);
&joKeystore = &joKeystoreClass.getInstance(“JKS”);
&joKeystore.load( Null, Null);
&joKeystore.setCertificateEntry(“photos”, &joCertificate);

/*Create TrustManagerFactory*/
&joTrustManagerFactoryClass = GetJavaClass(“javax.net.ssl.TrustManagerFactory”);
&joTrustManagerFactory = &joTrustManagerFactoryClass.getInstance(&joTrustManagerFactoryClass.getDefaultAlgorithm());
&joTrustManagerFactory.init(&joKeystore);

/*Create SSLContext and get SSLSocketFactory*/
&joSSLContextClass = GetJavaClass(“javax.net.ssl.SSLContext”);
&joSSLContext = &joSSLContextClass.getInstance(“TLS”);
&joSSLContext.init( Null, &joTrustManagerFactory.getTrustManagers(), Null);
&joSSLFactory = &joSSLContext.getSocketFactory();

/*Create URL*/
&joUrl = CreateJavaObject(“java.net.URL”, “https://domain.com/handler.ashx?id=123456”);

/*Get URLConnection*/
&joUrlConnection = &joUrl.openConnection();

/*Cast to HttpsURLConnection*/
&joCastObjectClass = GetJavaClass(“com.domain.CastObject”);
&joUrlConnection = &joCastObjectClass.objectToHttpsURLConnection(&joUrlConnection);

/*Set connection properties*/
&joUrlConnection.setSSLSocketFactory(&joSSLFactory);
&joUrlConnection.setRequestMethod(“GET”);

/*Get InputStream*/
&joInputStream = GetJavaClass(“java.io.InputStream”);
&joInputStream = &joUrlConnection.getInputStream();

/*Get Image From Stream*/
&joImageIO = GetJavaClass(“javax.imageio.ImageIO”);
&joBufferedImage = CreateJavaObject(“java.awt.image.BufferedImage”, 1, 1, 1);
&joBufferedImage = &joImageIO.read(&joInputStream);

/*Write Image to File*/
&joFile = CreateJavaObject(“java.io.File”, “/temp/URLImage2.jpg”);
&joImageIO.write(&joBufferedImage, “jpg”, &joFile);

/*Put the File into a PS record so we can get a BLOB of it*/
&nPutResult = PutAttachment(“record://PSFILE_ATTDET”, “013505.jpg”, “/temp/URLImage2.jpg”);

/*Grab that BLOB*/
SQLExec(“SELECT FILE_DATA FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1”, “013505.jpg”, &anyFileData);

/*Clean up the temp row we inserted*/
SQLExec(“DELETE FROM PSFILE_ATTDET WHERE ATTACHSYSFILENAME = :1 AND VERSION = 1”, “013505.jpg”);

/*Setup an employee photo record*/
&recTest = CreateRecord(Record.EMPL_PHOTO);
&recTest.EMPLID.Value = “013505”;
&recTest.PSIMAGEVER.Value = (Days365(Date3(1999, 12, 31), %Date) * 86400) + (%Time Time3(0, 0, 0));
&recTest.EMPLOYEE_PHOTO.Value = &anyFileData;

/*Insert/Update the employee photo record*/
&recTest.Insert();
&recTest.Update();

 

Credit:http://stackoverflow.com/questions/18921658/retrieve-image-from-ashx-url-using-java-in-peoplesoft-peoplecode

How to Delete Multiple Files Using PeopleCode

How to Delete Multiple Files Using PeopleCode

How to Delete Multiple Files Using PeopleCode : Deleting files sitting on a server using PeopleCode is one thing I’m sure you will be doing sometime during your PeopleSoft career. The code below should help you out and get you started!

/*The path to the files you need to delete*/
&oldFilesPath = “/my_directory/my_folder”;

/*Notice the “*” at the end of the file name. This means any file that starts with “file_name” will be deleted*/
&oldFiles = “file_name” | “*”;
&PathAndName = &oldFilesPath | &oldFiles;
/*Display file path and name to be deleted */
MessageBox(0, “”, 0, 0, “Delete file: “ | &PathAndName);
&oldFileNames = FindFiles(&PathAndName, %FilePath_Absolute);
/*Loop through files found and delete one by one */
While &oldFileNames.Len > 0/* Delete files one at a time */
&deleteFile = “../../../..” | &oldFileNames.Shift();
/*Display file path and name deleted */
&retcode = DeleteAttachment(URL, &deleteFile);
MessageBox(0, “”, 0, 0, “Deleted file: “ | &deleteFile);
/*Check delete status*/
If (&retcode = %Attachment_Success) Then

MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment succeeded”);
End-If;

If (&retcode = %Attachment_Failed) Then

MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed”);

End-If;

If (&retcode = %Attachment_Cancelled) Then

MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment cancelled”);

End-If;

If (&retcode = %Attachment_FileTransferFailed) Then

MessageBox(0, “File Attachment Status”, 0, 0, “DeleteAttachment failed: File Transfer did not succeed”);

End-If;
End-While;

Credit: http://www.compshack.com/peoplesoft/delete-multiple-files-using-peoplecode

FTP PeopleCode

FTP PeopleCode

I was recently working on an interface that needed to pull files from the vendor via FTP peoplecode. More specifically, I needed to retrieve an unknown number of ASCII files from a vendor’s server, with no specific naming convention.

I have done this before using a ‘call system’ command to kick off a bat script that would handle staging the files. This worked pretty good, and I eventually got the bat script to perform fairly decent error handling. But this interface was being written in App Engine. well more accurately, a PeopleCode program kicked off by an App Engine shell (I still hate writing App Engine programs the “PeopleSoft recommended” way).

PeopleCode does provide the GetAttachment function, but this seemed quite limiting in that it required me knowing the4name of the file I wanted to retrieve. I needed something more flexible. Searching the internet, I found a Slerp article by David Jen that explains how to use PeopleCode’s external library declaration to utilize the FTP functionality in the wininet.dll library. This was great, but it still required me to know the name of the file I wanted to ‘get’. But, at least, I now had another road to pursue. After understanding more of what was available to me in the wininet.dll and playing around with different configurations, I came up with the following:

/************************* DECLARE EXTERNAL FUNCTIONS *************************/
Declare Function GetLastError Library “kernel32”
() Returns long As number;

Declare Function FormatMessageA Library “kernel32”
(long Value As number, long Value As number, long Value As number, long Value As number, string Ref As string, long Value As number, long Value As number) Returns long As number;

Declare Function InternetOpenA Library “wininet.dll”
(string Value As string, long Value As number, string Value As string, string Value As string, long Value As number) Returns long As number;

Declare Function InternetConnectA Library “wininet.dll”
(long Value As number, string Value As string, integer Value As number, string Value As string, string Value As string, long Value As number, long Value As number, long Value As number) Returns long As number;

Declare Function FtpSetCurrentDirectoryA Library “wininet.dll”
(long Value As number, string Value As string) Returns long As number;

Declare Function FtpGetFileA Library “wininet.dll”
(long Value As number, string Value As string, string Value As string, long Value As number, long Value As number, long Value As number, long Value As number) Returns boolean;

Declare Function FtpDeleteFileA Library “wininet.dll”
(long Value As number, string Value As string) Returns boolean;

Declare Function FtpCommandA Library “wininet.dll”
(long Value As number, long Value As number, long Value As number, string Value As string, long Value As number, long Ref As number) Returns boolean;

Declare Function InternetReadFile Library “wininet.dll”
(long Value As number, string Ref As string, integer Value As number, integer Ref As number) Returns boolean;

Declare Function InternetCloseHandle Library “wininet.dll”
(long Value As number) Returns integer As number;

/*********************** END DECLARE EXTERNAL FUNCTIONS ***********************/

/* Program Variable Declarations */
Local array of string &gFileList;
Local number &gHostOpen, &gHostConnect;
Local string &gHostFileName;
Local number &gReturnCode;
Local boolean &gReturnStatus;

Function GetNTMessage(&inReturnCode As number) Returns string;
Local number &l_MsgLength;
Local string &l_ReturnMsg;

&l_MsgLength = FormatMessageA(4096, 0, &inReturnCode, 0, &l_ReturnMsg, 256, 0);
If &l_MsgLength > 0 Then
Return &l_ReturnMsg;
Else
Return “”;
End-If;
End-Function;

Function FTPOpenHostConnection(&inLogFile As File) Returns number;
Local number &l_OPEN_PRECONFIG = 0;
Local number &l_Handle;

/* Open connection to host */
&l_Handle = InternetOpenA(“Peoplecode FTP”, &l_OPEN_PRECONFIG, “”, “”, 0);
If &l_Handle = 0 Then
&inLogFile.WriteLine(“FTP ERROR: Unable to open Internet connection.”);
End-If;
Return &l_Handle;
End-Function;

Function FTPConnectToHost(&inLogFile As File, &inHandleOpen As number, &inHostSystem As string, &inHostDirectory As string, &inHostFTPAccount As string, &inHostPassword As string) Returns number;
Local number &l_FTP_PORT = 21;
Local number &l_INET_FTP = 1;
Local number &l_INET_PASSIVE = 134217728;

Local number &l_HostDirSet, &l_Handle;
Local number &l_ReturnCode;

/* Login to Host */
&l_Handle = InternetConnectA(&inHandleOpen, &inHostSystem, &l_FTP_PORT, &inHostFTPAccount, &inHostPassword, &l_INET_FTP, &l_INET_PASSIVE, 0);

If &l_Handle = 0 Then
&inLogFile.WriteLine(“FTP ERROR: Unable to open connection to ” | &inHostSystem | ” !!!”);
Return 0;
End-If;

/* Change remote directory */
If All(&inHostDirectory) Then /* If host directory passed, set it. */
&l_HostDirSet = FtpSetCurrentDirectoryA(&l_Handle, &inHostDirectory);
Else
&l_HostDirSet = 1;
End-If;

If &l_HostDirSet = 0 Then
&inLogFile.WriteLine(“FTP ERROR: Unable to set directory to ” | &inHostDirectory | ” !!!”);
&l_ReturnCode = InternetCloseHandle(&l_Handle);
Return 0;
End-If;

Return &l_Handle;
End-Function;

Function FTPGetFileList(&inLogFile As File, &inHandleConnect As number) Returns array of string;
Local string &l_FTP_CMD = “NLST”;
Local number &l_ASCII = 1;

Local array of string &l_FileList = CreateArrayRept(“”, 0);

Local number &l_FTPHandle;
Local string &l_Out, &l_Text_Buffer;
Local number &l_Bytes = 100;
Local number &l_Bytes_Read;
Local boolean &l_ReturnStatus;
Local number &l_ReturnCode;

&l_ReturnStatus = FtpCommandA(&inHandleConnect, 1, &l_ASCII, &l_FTP_CMD, 0, &l_FTPHandle);
If &l_FTPHandle = 0 Then
&inLogFile.WriteLine(“FTP ERROR: Unable to get directory !!!”);
Return &l_FileList;
Else
&inLogFile.WriteLine(“Getting List of files from host.”);
&l_ReturnStatus = InternetReadFile(&l_FTPHandle, &l_Text_Buffer, &l_Bytes, &l_Bytes_Read);
While &l_Bytes_Read > 0
&l_Out = &l_Out | &l_Text_Buffer;
&l_ReturnStatus = InternetReadFile(&l_FTPHandle, &l_Text_Buffer, &l_Bytes, &l_Bytes_Read);
End-While;
&l_ReturnCode = InternetCloseHandle(&l_FTPHandle);
End-If;
&l_FileList = Split(&l_Out, Char(13) | Char(10));
&inLogFile.WriteLine(String(&l_FileList.Len) | ” file(s) found.”);
Return &l_FileList;
End-Function;

Function FTPGetFile(&inLogFile As File, &inHandleConnect As number, &inHostFileName As string, &inLocalDirectory) Returns boolean;
Local number &l_FTP_ASCII = 1;
Local string &l_LocalFileName;
Local number &l_ReturnCode;
Local string &l_ReturnMsg;
Local boolean &l_GetFile;

/* Get (Session, local file, remote file, failexist, flags&attibutes, flags, context */
&inLogFile.WriteLine(“Getting ” | &inHostFileName | “…”);
&l_LocalFileName = &inLocalDirectory | &inHostFileName;
&l_GetFile = FtpGetFileA(&inHandleConnect, &inHostFileName, &l_LocalFileName, 0, 0, &l_FTP_ASCII, 0);

If Not &l_GetFile Then
&l_ReturnCode = GetLastError();
&l_ReturnMsg = GetNTMessage(&l_ReturnCode);
&inLogFile.WriteLine(“FTP ERROR: ” | String(&l_ReturnCode) | ” : ” | &l_ReturnMsg);
&inLogFile.WriteLine(“FTP ERROR: Unable to retrieve file !!!”);
Return False;
End-If;

/* Sucessful Get */
&inLogFile.WriteLine(” Get Sucessful.”);
Return True;
End-Function;

Function FTPDeleteFile(&inLogFile As File, &inHandleConnect As number, &inHostFileName As string) Returns boolean;
Local boolean &l_DeleteFile;
Local number &l_ReturnCode;
Local string &l_ReturnMsg;

&l_DeleteFile = FtpDeleteFileA(&inHandleConnect, &inHostFileName);

If Not &l_DeleteFile Then
&l_ReturnCode = GetLastError();
&l_ReturnMsg = GetNTMessage(&l_ReturnCode);
&inLogFile.WriteLine(” FTP ERROR: ” | String(&l_ReturnCode) | ” : ” | &l_ReturnMsg);
&inLogFile.WriteLine(” FTP ERROR: Unable to delete file.”);
Return False;
End-If;

/* SUCCESS */
&inLogFile.WriteLine(” File Deleted from HRSmart server.”);
Return True;
End-Function;

/*****************************************************************************/
/* MAIN PROGRAM
/*****************************************************************************/

/* Log File */
Local File &gLogFile;

/* Host information */
Local string &HOSTSERVER = “www.example.com”;
Local string &HOSTACCOUNT = “usename”;
Local string &HOSTPASSWORD = “password”;
Local string &HOSTDIRECTORY = “”;
Local string &FILE_MASK = “%”;

/* A File Object &gLogFile needs to have already been open prior to calling this routine. */
/* Log information is written to this file */

&gHostOpen = FTPOpenHostConnection(&gLogFile);
If &gHostOpen > 0 Then
&gHostConnect = FTPConnectToHost(&gLogFile, &gHostOpen, &HOSTSERVER, &HOSTDIRECTORY, &HOSTACCOUNT, &HOSTPASSWORD);
If &gHostConnect > 0 Then
&gFileList = FTPGetFileList(&gLogFile, &gHostConnect);
While &gFileList.Len > 0
&gHostFileName = &gFileList.Shift();
If DBPatternMatch(&gHostFileName, &FILE_MASK, False) Then
If FTPGetFile(&gLogFile, &gHostConnect, &gHostFileName, &LOCALDIRECTORY) Then
&gReturnStatus = FTPDeleteFile(&gLogFile, &gHostConnect, &gHostFileName);
End-If;
End-If;
End-While;
&gReturnCode = InternetCloseHandle(&gHostConnect);
&gReturnCode = InternetCloseHandle(&gHostOpen);
Else
&gReturnCode = InternetCloseHandle(&gHostOpen);
End-If;
End-If;

One thing to note… it seems that PeopleCode can only use DLL functions when they return datatypes that are understood by PeopleCode (strings, numbers, boolean). In trying to find a way to search the FTP directory, I came across a couple functions named FindFirstFile and FindNextFile. Unfortunately, these returned a pointer to a pointer to a WIN32_FIND_DATA structure. I could not figure out a way to use these. As a result, I had to take a slightly longer approach using the FTPCommand function.

Credit :http://ideatec.blogspot.com/2005/03/ftp-in-peoplecode.html

PeopleCode To Browse for File and Save attachments To FTP or Database Server

PeopleCode To Browse for File and Save attachments To FTP or Database Server

/* Using add_attachment if required- only using AddAttachment
Declare Function add_attachment PeopleCode FILE_ATTACH_WRK.ATTACHADD FieldChange;
add_attachment(FUNCLIB_UTIL.FTPSITE, &FILEEXTENSION, &SUBDIRECTORY, &FILESIZE, False, &recname, FUNCLIB_UTIL.ATTACHSYSFILENAME, FUNCLIB_UTIL.ATTACHUSERFILE, &MESSAGE_LVL, &RETCODE);
*/

/* All the following assignments to &URL_ID work – I have commented off all except one in each case, because only one assignment is required */
/*&URL_ID = “RECORD://HRS_ATTACHMENTS”;*/
/*&URL_ID = “ftp://user:password@ftpserver.peoplesoft.com:6000/”;*/
/*&URL_ID = “ftp://user:password@ftpserver.peoplesoft.com:6000/PATH”;*/
/*&URL_ID = “URL.HRS_INT_ATCH”;*/
/* The following goes to the default folder (default folder assigned to the login user id) on the FTP server – example: /sw/app/psoft/psofthr*/
&URL_ID = “ftp://pmilind:password@mycompany.com”;
/* If the default folder on FTP server is /sw/app/psoft/psofthr then the following puts it to /sw/app/psoft/psofthr/log */
/*&URL_ID = “ftp://pmilind:password@mycompany.com/log”;*/
/* The following puts the file on the /tmp folder on the system root */
/*&URL_ID = “ftp://pmilind:password@mycompany.com/../../../../tmp”;*/

If Exact(Left(&URL_ID, 4), “URL.”) Then
   &RETCODE = AddAttachment(@(&URL_ID), &ATTACHSYSFILENAME, &FILEEXTENSION, &ATTACHUSERFILE, &FILESIZE);
Else
   &RETCODE = AddAttachment(&URL_ID, &ATTACHSYSFILENAME, &FILEEXTENSION, &ATTACHUSERFILE, &FILESIZE);
End-If;

References:
http://www.pscustomizer.com/peoplesoft-examples/attachments/
http://peoplesoft.ittoolbox.com/groups/technical-functional/peopletools-l/write-file-into-database-using-sqr-2528747
https://forums.oracle.com/forums/thread.jspa?messageID=10320192
http://docs.oracle.com/cd/E15645_01/pt850pbr0/eng/psbooks/tpcl/book.htm?File=tpcl/htm/tpcl02.htm#H4541 
http://docs.oracle.com/cd/E15645_01/pt850pbr0/eng/psbooks/tpcd/chapter.htm?File=tpcd/htm/tpcd11.htm
http://peoplesoftstuff.blogspot.com/2012/07/upload-file-from-local-to-server.html 
http://peoplesoft.ittoolbox.com/groups/technical-functional/peopletools-l/browse-functionality-on-run-control-page-819632