ReadRowset method: File class
Syntax
ReadRowset()
Description
The ReadRowset method is a file layout method. It instantiates a PeopleCode rowset object based on the file layout definition, then populates the rowset with one transaction from the file. A transaction is considered to be one instance of level zero data contained in a file record, plus all of its subordinate data. If you put more than one segment at level zero, each segment is read in sequence.
Note:
You must specify a file layout using the SetFileLayout method before using ReadRowset, otherwise it will return NULL.
When ReadRowset is executed, it moves the starting point for the next read operation to the beginning of the next rowset, so each transaction in the file can be read in turn by subsequent ReadRowset operations. When no more data remains to be read from the file, ReadRowset returns NULL.
If you’re using the SetFileId method with ReadRowset to process an input file based on multiple file layouts, ReadRowset returns NULL when it reads a FileId file record (line) between the rowsets.
When ReadRowset returns NULL, you can use the IsFileId property to determine if you’ve reached the end of the file or a FileId record.
Note:
When using ReadRowset, if a value in the file exceeds the defined length in the file layout, it is ignored. The given record field is flagged with an edit error which can be programmatically checked.
If the ReadRowset encounters a line in the file containing the FileId, and the lines following this are not a new rowset, the process considers it to be an invalid FileId. You can specify whether to ignore the invalid record or terminate the PeopleCode with the IgnoreInvalidId property.
Note:
If you’re using the SetFileId method with ReadRowset to process an input file based on multiple layouts, FileId file records between the rowsets are considered to be valid file records, and won’t generate any errors, regardless of the state of the IgnoreInvalidId property.
Parameters
None.
Returns
A populated rowset.
Example
The following example reads and processes an entire file. The data in the file is based on a single File layout definition:
&MYFILE.GetFile(&SOMENAME, "R", "UTF8");
If &MYFILE.SetFileLayout(FILELAYOUT.SOMELAYOUT) then
&SOMEROWSET = &MYFILE.ReadRowset();
While &SOMEROWSET <> NULL
/* Process the contents of each &SOMEROWSET */
&SOMEROWSET = &MYFILE.ReadRowset();
End-While;
End-If;
&MYFILE.Close();
Considerations for Using Dates With ReadRowset
Single digits in dates in the form MMDDYY or MMDDYYYY must be padded with zeros. That is, if the date in your data is February 3, 2000, the form must be:
02/03/2000
or
02/03/00
The following is not valid.
2/3/00
Considerations for Using XML With ReadRowset
If all of the fields in the file layout are not present in the XML, no data is written to the database. If there are additional tags in the XML, they are ignored.
Considerations for Using Nested Data with ReadRowset
If you are processing input files with a large amount of nested data, your application server may run out of memory before the system finishes processing all of the data.
This may happen because of the differences between processing a single-level rowset and a multi-level rowset. If you are reading the rows of a single-level (level 0) rowset from a file, the file is processed one row at a time, that is, only one row resides in memory at a time.
However, if you are reading the rows of a multi-level (parent-child) rowset from a file, then for each level 0 row, all of the associated child rows (and all of their associated child rows) simultaneously reside in memory. As a result, during the processing a large input data file that is associated with a multi-level rowset (through a multi-level file layout definition), your application server may run out of memory.
To work around this, consider doing one of the following:
-
Retain your original file layout definition and split the original input file into smaller (but structurally unchanged) pieces
-
Flatten out your original file layout definition (that is, split it up into several single-level definitions) as well as split the original input file into several single-level pieces.
Considerations for Using Default Values with ReadRowset
The system variables related to date and time (for example, %Date, %Time, and %DateTime) cannot be used to specify the value of the Default Value property of a file layout field. This topic is covered in detail in the Application Designer PeopleBook.
See Application Designer Developer’s Guide: Specifying File Field Properties
Related Topics