Monday 5 August 2013

FileLayout Code for Loading and Writing data

Write the Data to a CSV file

Local File &X_PAY;
Local Record &Rec3;
Local SQL &SQL3;

&Rec3 = CreateRecord(Record.Record Name);
&SQL3 = CreateSQL("%SelectAll (:1)", &Rec3);
&FileName2 = "C:\Output_File_Name.csv";
&X_PAY = GetFile(&FileName2, "W", "A", %FilePath_Absolute);

If &X_PAY.IsOpen Then;
   If &X_PAY.SetFileLayout(FileLayout.FielLayout Name) Then;
      While &SQL3.Fetch(&Rec3)
         &X_PAY.WriteRecord(&Rec3);
      End-While;
   End-If;
End-If;



Load the Data from a CSV file

Local File &FILE1;
Local Rowset &RS1;
Local Record &Rec1;
Local SQL &SQL1;


&Rec1 = CreateRecord(Record.Record Name);
&SQL1 = CreateSQL("%Insert(:1)");
&Filename = "C:\Load_Data_File.csv";

If FileExists(&Filename, %FilePath_Absolute) Then
   &FILE1 = GetFile(&Filename, "R", "A", %FilePath_Absolute);
End-If;

&FILE1.SetFileLayout(FileLayout.FielLayout Name);
&RS1 = CreateRowset(Record.X_PAY);
&RS1 = &FILE1.ReadRowset();

While &RS1 <> Null
   &RS1.GetRow(1).X_PAY.CopyFieldsTo(&Rec1);
   &SQL1.Execute(&Rec1);
   &RS1 = &FILE1.ReadRowset();
End-While;

&FILE1.Close();

No comments:

Post a Comment