Write in the record from the external file using File layout

We can get the solution for able problem using the file layout in the peoplesoft . To read in the CSV file we use the following PeopleCode using the following steps:

(1) It reads the file into a temporary record.

(2) Each line of the file is read into a string.

(3) The string is split into an array, with the value of each field in the array becoming an element in the array.

(4)The value of each field in the record is assigned a value from the array.

After additional processing (for example, converting strings into dates or numbers, verifying data, and so on) the record can be inserted into the database.
To insert the final data into the database, this code must be associated with a PeopleCode event that allows database updates, that is, SavePreChange, WorkFlow, SavePostChange, and so on. This code could also be used as part of an Application Engine program.

Local File &MYFILE;
Local Record &REC;
Local array of string &ARRAY;

&MYFILE = GetFile("c:\temp\chinnuraavi.txt", "R", %FilePath_Absolute);
&REC = CreateRecord(RECORD.ABS_HIST_TEST);
&ARRAY = CreateArrayRept("", 0);

If &MYFILE.IsOpen Then
   If &MYFILE.SetFileLayout(FILELAYOUT.ABS_HIST) Then
      While &MYFILE.ReadLine(&STRING);
         &ARRAY = Split(&STRING, ",");
         For &I = 1 To &REC.FieldCount
            &REC.GetField(&I).Value = &ARRAY[&I];
         End-For;
      /* do additional processing here for converting values */
         &REC.Insert();
      End-While;
   Else
      /* do error processing - filelayout not correct */
   End-If;
Else
   /* do error processing - file not open */
End-If;

&MYFILE.Close();

SHARE

peoplesoft

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Phaniraavi@gmail.com