What follows is a simple piece of PeopleCode to upload a flat file into a table in PeopleSoft.
One thing to make sure you do is to set the Qualifier to optional in the File Layout Definition properties. If you fail to do so and don't encapsulate your variables with your definition qualifier, e.g. double quotes, then the process will fail with a garbage error message along the lines of "cannot insert NULL into". You have been warned.
Local File &FILE; Local Record &REC; Local Rowset &FRS; &FILE = GetFile(TY_TL_GRPLD_AET.FILENAME, "R", %FilePath_Absolute); &REC = CreateRecord(Record.TY_TL_GRPLD); &SQL = CreateSQL("%Insert(:1)"); If Not &FILE.IsOpen Then Error (TY_TL_GRPLD_AET.FILENAME | " failed file open"); Else If Not &FILE.SetFileLayout(FileLayout.TY_TL_GRPLD) Then Error ("TY_TL_GRPLD: failed SetFilelayout"); Else &FRS = &FILE.ReadRowset(); If &FILE.IsError Then Error ("Error reading rowset"); End-If; While &FRS <> Null &FRS.GetRow(1).TY_TL_GRPLD.CopyFieldsTo(&REC); &SQL.execute(&REC); &FRS = &FILE.ReadRowset(); If &FILE.IsError Then Error ("Error reading rowset"); End-If; End-While; End-If; &FILE.Close(); End-If;
One thing to make sure you do is to set the Qualifier to optional in the File Layout Definition properties. If you fail to do so and don't encapsulate your variables with your definition qualifier, e.g. double quotes, then the process will fail with a garbage error message along the lines of "cannot insert NULL into". You have been warned.