SetFileId method: File class

Syntax

SetFileId(fileid, position)

Description

The SetFileId method is a file layout method. If your input file contains data based on more than one File Layout definition, you must use this method in combination with the CurrentRecord and IsNewFileId properties and the ReadRowset method to process the file correctly.

Note:

SetFileId, CurrentRecord and IsNewFileId don’t apply to CSV and XML format input files. You can use only fixed format files to implement multiple file layouts.

See CurrentRecord property: File class, IsNewFileId property: File class, ReadRowset method: File class.

At each point in the input file where the structure of the rowset changes, there must be an extra line in the file containing the file record (line), the FileId file record (line), that signifies that the change. Each FileId file record must have the following components:

  • A value that designates it as a Fileid. Only one FileId value is necessary throughout the file, such as "999".

  • A name field that identifies the file layout needed for the rowset that follows. This field could contain the name of the file layout as it’s defined in Application Designer.

These lines containing the FileId are not part of any rowset. They can contain other information, which will be disregarded by the system. The FileId identifier and the file layout names aren’t automatically stored anywhere; they exist only in the input file’s FileId file records and in the PeopleCode.

To process an input file that requires multiple file layouts:

  1. Use SetFileLayout to specify the file layout definition to use.

    If you’re specifying the initial file layout for this file, it doesn’t have to be the correct one. You can determine the correct file layout to use for the first rowset during a subsequent step.

  2. Use SetFileId to specify the value of the FileId field, fileid, that’s used throughout the file to designate FileId file records.

    Note:

    After each execution of SetFileLayout, the SetFileId setting is disabled. Be sure to re-specify the FileId value if you expect the file layout to change, so the system continues looking for the next FileId file record.

  3. Use ReadRowset to read the next rowset from the file.

    The current file record is also stored in the CurrentRecord property as a string. The PeopleCode process determines whether it’s the beginning of a new rowset, or a FileId file record according to the fileid you specified. If it’s a FileId file record, the process sets the IsNewFileId property to True; if not, it sets the IsNewFileId property to False.

    Note:

    If this is the first execution of ReadRowset on the file, it returns NULL upon encountering the initial FileId file record, but still stores that file record in CurrentRecord and sets IsNewFileId accordingly.

  4. If the rowset returned isn’t NULL, process that rowset as necessary.

  5. If IsNewFileId is False, go back to step 3 to continue reading rowsets from the file. If IsNewFileId is True, examine CurrentRecord to determine which new file layout to use, and go back to step 1.

You can repeat this procedure one rowset at a time, proceeding through the remainder of the input file. When ReadRowset returns NULL, no more rowset data is available.

Parameters

Parameter Description

fileid

Specify the value of the FileId field used in the current file.

position

Specify the column in the FileId file record where the FileId field starts. The default is 1.

Returns

None.

Example

&rsFile = &MYFILE.ReadRowset();
&CurrentRecord = &MYFILE.CurrentRecord;
&IsNewFileID = &MYFILE.IsNewFileId;
If &MYFILE.IsNewFileId Then
   &FILELAYOUT = FindFileID(&CurrentRecord);
   &MYFILE.SetFileLayout(@("FileLayout." | &FILELAYOUT));
   &MYFILE.SetFileId("999", 1);
End-If;