Example of a CSV being created via a file layout (the file layout must be defined as type ‘CSV’)
/* Declare varaibles */
Global File &CSVFile, &fileLog;
Local Rowset &fileRS;
/* Define CSV file and write column headings */
&CSVFile = GetFile("file_name.csv", "w", "a", %FilePath_Relative);
&CSVFile.WriteLine("Column 1,Column 2,Column 3,Column 4");
/* Set the file layout for the CSV file */
&CSVFile.SetFileLayout(FileLayout.FILE_LAYOUT_NAME);
/* Populate the rowset for the file layout */
&fileRS = &CSVFile.CreateRowset();
&fileRS.Fill("where EMPLID = :1", ¤tEmplid);
/* Write the rowset to file and close the file */
&CSVFile.WriteRowset(&fileRS, True);
&CSVFile.Close();
*********************************************************************
Direct Write for a CSV
Example of a CSV being created directly, without the use of a file layout:
Local integer &i;
Local string &CSVLine;
Local Record &acadCareerRec;
Local Rowset &acadCareerRS;
Local File &CSVFile;
/* Define CSV file and write column headings */
&CSVFile = GetFile("file_name.csv", "w", "a", %FilePath_Relative);
&CSVFile.WriteLine("Column 1,Column 2,Column 3,Column 4");
/* Define rowset and fill with values */
&acadCareerRS = CreateRowset(Record.ACAD_CAR_TBL);
&acadCareerRS.Fill();
/* Loop through each row of the rowset */
for &i = 1 to &acadCareerRS.ActiveRowCount
&acadCareerRec = &acadCareerRS.GetRow(&i).ACAD_CAR_TBL;
/* Write the current details to file */
&CSVLine = &acadCareerRec.INSTITUTION.Value | "," |
&acadCareerRec.ACAD_CAREER.Value | "," |
&acadCareerRec.DESCR.Value;
&CSVFile.Writeline(&CSVLine);
end-for;
/* Close the CSV File */
&CSVFile.Close();
*****************************************************
No comments:
Post a Comment