Hi Folks, I am trying to Read inbound file using arrays by using the following code. I can able to read the file using arrays. I am in a situation where I don’t have field lengths and Data Types for the values that I am getting in inbound CSV file. So when I am reading data from CSV file I need to check for each field length and I have to truncate data which exceeds length in my record for that field. Before loading data to PS table how can I check the length of each field in the following code? Any help would be appreciated. Thanks in Advance. Peter Local File &MYFILE; Local Record &REC1; Local array of string &ARRAY; &MYFILE = GetFile(““C:Documents and SettingsAdministratorDesktopWBT Report.csv””, ““r””, ““a””, %FilePath_Absolute); &LOGFILE = GetFile(““C:Documents and SettingsAdministratorDesktopWBT Report.csv.err””, ““W””, %FilePath_Absolute); &REC1 = CreateRecord(Record.XX_DD_CRSE_TMP); &ARRAY = CreateArrayRept(“”“”, 0); If &MYFILE.IsOpen Then If &MYFILE.SetFileLayout(FileLayout.XX_TR_FL) Then While &MYFILE.ReadLine(&STRING); &ARRAY = Split(&STRING, “”,“”); For &I = 1 To &REC1.FieldCount &REC1.GetField(&I).Value = &ARRAY [&I]; End-For; /* do additional processing here for converting values / &REC1.Insert(); End-While; Else / do error processing - filelayout not correct / End-If; Else / do error processing - file not open */ End-If; &MYFILE.Close(); &LOGFILE.Close();

Instead of
&REC1.GetField(&I).Value = &ARRAY [&I]; (in your original post)
You could use
&REC1.GetField(&I).Value = Left(&ARRAY [&I],&REC1.GetField(&I).FieldLength);

I agree with Howler_Fish though. An array is a cumbersome construct. I’d avoid it if at all possible. You have defined a file layout and a record definition already, so you must have some idea of file structure and where it’s supposed to go.

Thanks for your reply Howler and Bay.
I tried looping in PSDBFIELD to get the length of each field and doing substring of each field with the value that I am getting from inbound file.
It works perfectly.
It is taking more time to load data but in my case without knowing lengths of fields I don’t have another option.

Thanks guys for your quick response.

I am sure there is a better way but you may try checking LENGTH field in PSDBFIELD table.

If you really don’t know the layout at all in advance, then you can write something hideous as below:

For &I = 1 To &REC1.FieldCount
If Len(&Array[&I]) > &REC1.GetField(&I).FieldLength then
Error – too long
end-if;
Evaluate &REC1.GetField(&I).Type
When = “DATE”
/* Do date formatting tests /
When = “DATETIME”
/
Do datetime formatting tests /
When = /
Look the others up in PeopleCode API Reference Field Class Type Property */
End-Evalute

If &FieldIsNotInError then
&REC1.GetField(&I).Value = &ARRAY [&I];
End-If

However you seem to have an idea of what the record should look like (since you have hardcoded &REC).

It might be worthwhile attempting to read the data directly into the record using a try / exception construct. That way if a line fails any edits (XXX in a num field) you can catch it then without too much trouble.