File Class Properties

In this section, we discuss each File Class property.

Description

This property is a file layout property. This property returns the current record as a string. The CurrentRecord property is used in combination with the SetFileId and ReadRowset methods and IsNewFileId property when reading files that contain data based on multiple file layouts.

If the ReadRowset method returns NULL, either the current record is a FileId record or the end of file has been reached. The IsNewFileId enables you to determine which. If it is a FileId, you can parse the string returned by CurrentRecord to determine the file layout definition to be used.

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

This property is read-only.

Example

&RECSTRING = &MYFILE.CurrentRecord;

Description

This property is a file layout property that’s used in combination with the ReadRowset method. It returns a Boolean value that specifies whether file records with invalid FileIds are ignored. Each time ReadRowset is executed, it may encounter a file record that doesn't qualify as part of the rowset because its File ID isn’t part of the current file layout, or because it occurs in an invalid position in the rowset. If IgnoreInvalidId is False, the PeopleCode program terminates; if IgnoreInvalidId is True, ReadRowset ignores the invalid file record. The default value is True.

This property is read-write.

Example

&MYFILE.IgnoreInvalidId = False;

Description

This property is a file layout property. It returns a Boolean value indicating whether a field error condition was generated by the last file layout method executed. If an error condition was generated, IsError returns True; if not, IsError returns False. The default value is False.

This property is read-only.

Example

The following example shows where IsError would be used:

&MYFILE.Open(&SOMENAME, "R");
&MYFILE.SetFileLayout(FILELAYOUT.SOMELAYOUT);
&MYROWSET = &MYFILE.ReadRowset();
If &MYFILE.IsError Then
   /* Examine the EditError property of each field in the rowset 
      to find the one with the error, and respond accordingly */
End-If;
&MYFILE.Close();

Description

This property is a file layout property. It returns a Boolean value indicating whether a FileId file record has been encountered. When the ReadRowset method reads a transaction from an input file, it examines the current file record following the transaction. If that file record is a FileId file record, IsNewFileId returns True; if not, IsNewFileId returns False.

IsNewFileId is used in combination with the SetFileId method and CurrentRecord property when reading files that require multiple file layouts.

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.

This property is read-only.

Example

&MYFILE.SetFileLayout(FILELAYOUT.SOMELAYOUT) then  /* Set the first layout */
&MYFILE.SetFileId("999", 1);  /* Set the FileId */
&SOMEROWSET = &MYFILE.ReadRowset();  /* Read the first rowset */
While &SOMEROWSET <> NULL
   If &MYFILE.IsNewFileId Then
      /* Examine &MYFILE.CurrentRecord for the next layout */
      /* Set the next layout */
      &MYFILE.SetFileId("999", 1);  /* Set the FileId */
   End-If;
   /* Process the current &SOMEROWSET */
   &SOMEROWSET = &MYFILE.ReadRowset();  /* Read the next rowset */
End-While;

Description

This property returns a Boolean value indicating whether the file is open. If the file object is open, IsOpen returns True; if not, IsOpen returns False.

This property is read-only.

Example

The following example opens a file, writes a line to it, and closes it:

&MYFILE.Open("item.txt", "W");
If &MYFILE.IsOpen Then
   &MYFILE.WriteLine("Some text.");
   &MYFILE.Close();
End-If;

Description

This property returns as a string the name of the external file. If no file is currently associated with the file object, Name returns a NULL string.

This property is read-only.

Example

&TMP = &MYFILE.Name;

Description

Use the TerminateLines property to indicate whether all output data lines are to be terminated at the end of the defined data length. This property is a file layout property associated with fixed file layouts only.

This property takes a Boolean value: True to force output data lines to be terminated at the end of the defined data length; False to keep all lines all at the maximum of their own length or that of their children. The default value is false.

This property is read-write.

Example

If &FILE_CREATED = "N" Then
   &FILE_CREATED = "Y";
   &FILENAME = &MSGNAME | "_" | &PROCESS_INSTANCE | "_*.out";
   &FILE = GetFile(&FILENAME, "N", "U");
   &FILE.SetFileLayout(@("FILELAYOUT." | &MSGNAME));
   &FILE.TerminateLines = True;
   &RS_LVL0 = &FILE.CreateRowset();
   &REC_MSG_LVL0 = &RS_LVL0(&ROWCNT0).GetRecord(1);
   
   If EO_BATLIB_AET.CREATE_FILE_FLG = "C" Then
      &STRING = "998       " | &MSGNAME;
      &FILE.WriteLine(&STRING);
   End-If;
End-If;

Description

Use the UseSpaceForNull property to specify whether the WriteRowset method writes <qualifier> <qualifier> (<qualifier>-space-<qualifier>) for all the Null or empty character fields of a CSV-type file layout, or if the method writes <qualifier><qualifier> (<qualifier>-<qualifier>).

This property takes a Boolean value: false if WriteRowset writes <qualifier>-<qualifier>, true if WriteRowset writes <qualifier>-space-<qualifier>. The default is False.

Note: The state of this property has no effect on the behavior of the ReadRowset method. It also has no effect when the associated file layout is of type fixed or XML.

This property is read-write.

Example

Local File &LOGFILE;
Local File &FILE1;
Local File &FILE2;
Local Record &REC1;
Local SQL &SQL1;
Local Rowset &RS1;
Local Row &ROW1;

&LOGFILE = GetFile("C:\Temp\currency.log", "W", "A", %FilePath_Absolute);
If (&LOGFILE = Null) Then
   Exit;
End-If;
If Not (&LOGFILE.SetFileLayout(FileLayout.CURRENCY_FL)) Then
   &LOGFILE.WriteLine("SetFileLayout() on LOGFILE failed.");
End-If;

&FILE1 = GetFile("C:\Temp\currency_nonspaced.csv", "W", "A", %FilePath_Absolute);
If (&FILE1 = Null) Then
   &LOGFILE.WriteLine("FATAL ERROR:  GetFile() on non-spaced output file failed.");
   &LOGFILE.Close();
   Exit;
End-If;
If Not (&FILE1.SetFileLayout(FileLayout.CURRENCY_FL)) Then
   &LOGFILE.WriteLine("FATAL ERROR:  SetFileLayout() on non-spaced output file failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   Exit;
End-If;

&FILE2 = GetFile("C:\Temp\currency_spaced.csv", "W", "A", %FilePath_Absolute);
If (&FILE2 = Null) Then
   &LOGFILE.WriteLine("FATAL ERROR:  GetFile() on spaced output file failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   Exit;
End-If;
If Not (&FILE2.SetFileLayout(FileLayout.CURRENCY_FL)) Then
   &LOGFILE.WriteLine("FATAL ERROR:  SetFileLayout() on spaced output file failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   &FILE2.Close();
   Exit;
End-If;

&REC1 = CreateRecord(Record.CURRENCY_CD_TBL);
If (&REC1 = Null) Then
   &LOGFILE.WriteLine("FATAL ERROR:  CreateRecord() on record failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   &FILE2.Close();
   Exit;
End-If;

&RS1 = CreateRowset(Record.CURRENCY_CD_TBL);
If (&RS1 = Null) Then
   &LOGFILE.WriteLine("FATAL ERROR:  CreateRowset() on record failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   &FILE2.Close();
   Exit;
End-If;

&SQL1 = CreateSQL("%Selectall(:1)", &REC1);
If (&SQL1 = Null) Then
   &LOGFILE.WriteLine("FATAL ERROR:  CreateSQL() failed.");
   &LOGFILE.Close();
   &FILE1.Close();
   &FILE2.Close();
   Exit;
End-If;

If (&FILE1.UseSpaceForNull) Then
   &LOGFILE.WriteLine("UseSpaceForNull is True on non-spaced output, by default.");
Else
   &LOGFILE.WriteLine("UseSpaceForNull is False on non-spaced output, by default.");
End-If;
If (&FILE2.UseSpaceForNull) Then
   &LOGFILE.WriteLine("UseSpaceForNull is True on spaced output, by default.");
Else
   &LOGFILE.WriteLine("UseSpaceForNull is False on spaced output, by default.");
End-If;

&FILE1.UseSpaceForNull = True;
If (&FILE1.UseSpaceForNull) Then
   &LOGFILE.WriteLine("Setting UseSpaceForNull to True succeeded on non-spaced output.");
Else
   &LOGFILE.WriteLine("Setting UseSpaceForNull to True failed on non-spaced output.");
End-If;
&FILE2.UseSpaceForNull = True;
If (&FILE2.UseSpaceForNull) Then
   &LOGFILE.WriteLine("Setting UseSpaceForNull to True succeeded on spaced output.");
Else
   &LOGFILE.WriteLine("Setting UseSpaceForNull to True failed on spaced output.");
End-If;

&FILE1.UseSpaceForNull = False;
If (&FILE1.UseSpaceForNull) Then
   &LOGFILE.WriteLine("Setting UseSpaceForNull to False failed on non-spaced output.");
Else
   &LOGFILE.WriteLine("Setting UseSpaceForNull to False succeeded on non-spaced output.");
End-If;
&FILE2.UseSpaceForNull = False;
If (&FILE2.UseSpaceForNull) Then
   &LOGFILE.WriteLine("Setting UseSpaceForNull to False failed on spaced output.");
Else
   &LOGFILE.WriteLine("Setting UseSpaceForNull to False succeeded on spaced output.");
End-If;

&FILE1.UseSpaceForNull = False;
&FILE2.UseSpaceForNull = True;
&I = 1;
While &SQL1.Fetch(&REC1)
   &ROW1 = &RS1.GetRow(1);
   &REC1.CopyFieldsTo(&ROW1.CURRENCY_CD_TBL);
   &FILE1.WriteRowset(&RS1, True);
   &FILE2.WriteRowset(&RS1, True);
   REM   &LOGFILE.WriteLine("Got row " | String(&I));
   &I = &I + 1;
End-While;

&FILE1.Close();
&FILE2.Close();
&LOGFILE.Close();


Description

Use this property to specify whether or not the WriteRowset method zero-extends the value it writes for decimal fields for CSV or XML format files.

For example, for a decimal field defined as 6.3, the value 1.12 will be written as follows depending on the value of ZeroExtend:

True: 1.120

False: 1.12

This property takes a Boolean value: true if WriteRowset zero-extends the value it writes; false otherwise. The default value is true.

Note: This property has no effect in the case of a fixed-position format file. In addition, it does not affect the behavior of the ReadRowset method.

This property is read-write.