1. Writing CSV File in PeopleCode:-
/* Create CSV File in PeopleSoft - OpenCSV Example */
/* Create java.io.Writer with CSV File Details */
Local JavaObject &ioWriter = CreateJavaObject("java.io.FileWriter", "PeopleSoft_CSV_File.CSV");
/* Create a CSV Writer Object Now */
Local JavaObject &CSVWriter = CreateJavaObject("au.com.bytecode.opencsv.CSVWriter", &ioWriter);
/* Write SQL Query for CSV Output */
Local SQL &dumpSQL = CreateSQL("SELECT OPRID||','||VERSION FROM SYSADM.PSOPRDEFN");
/* Fetch Data */
Local string &csvLine;
/* We create a Java Array that we can pass to CSV Writer */
Local JavaObject &Jarray = CreateJavaArray("java.lang.String[]", 1);
While &dumpSQL.Fetch(&csvLine)
/* Push the input to Peoplecode Array */
Local array of any &classListArray = CreateArrayAny();
&classListArray.Push(&csvLine);
/* Copy input to Java Array */
CopyToJavaArray(&classListArray, &Jarray);
/* Write Java Array to CSV File */
&CSVWriter.writeNext(&Jarray);
End-While;
/* Close SQL Cursor */
&dumpSQL.Close();
/* Close CSV Writer */
&CSVWriter.close();
2.Reading CSV File in PeopleCode:-
/* Read / Parse CSV File PeopleCode Example */
/* Read Input File through FileReader Object */
Local JavaObject &ioReader = CreateJavaObject("java.io.FileReader", "PeopleSoft_CSV_File.CSV");
/* Create a CSV Reader Object Now */
Local JavaObject &CSVReader = CreateJavaObject("au.com.bytecode.opencsv.CSVReader", &ioReader);
/* Create Java String Array that can read CSV Data */
Local JavaObject &Jarray;
/* Read File line by line now */
While True
&Jarray = &CSVReader.readNext();
/* You have the line in a Java Array now */
/* You can now use CopyFromJavaArray and take it to PeopleCode Array */
End-While;
&CSVReader.close();
No comments:
Post a Comment