Hi there.
Within a BASIC job, I am reading a sequential file, which was generated by a server job. The file is a comma separated file.
I am reading fine each record of the file, but when I want to assign the content of the fields, I cannot.
I am using the following formula:
AuxField = RecordField;
where number es the number of the field in the record, beginning with 0. But nothing happens.
The question: does anybody know how to get the record fields ?
Thanks in advance.
Guillermo P. Barsky
Buenos Aires - Argentina
Reading seq files from BASIC job
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 483
- Joined: Thu Jun 12, 2003 4:47 pm
- Location: St. Louis, Missouri USA
Guillermo,
Typically you can get each field from a delimited string by using the Field function.
An example of getting the first field might be:
Field1 = Field(InputString, ",", 1)
To return the fifth field in the string do:
Field5 = Field(InputString, ",", 5)
I'm not sure I correctly understood your questions, so if this does not address your problem, please try and restate your question.
Best regards,
Tony
Typically you can get each field from a delimited string by using the Field function.
An example of getting the first field might be:
Field1 = Field(InputString, ",", 1)
To return the fifth field in the string do:
Field5 = Field(InputString, ",", 5)
I'm not sure I correctly understood your questions, so if this does not address your problem, please try and restate your question.
Best regards,
Tony
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
The array of fields is one-based, not zero-based; that is, the first field number is 1, not zero.
DataStage BASIC has a shorthand notation called "delimited substring extraction" that you may prefer; though it generates exactly the same compiled code as the FIELD function. For example:
Field001 = RecordString[",", 1, 1]
Field002 = RecordString[",", 2, 1]
The comma inside the square brackets asserts that RecordString is delimited by comma characters. The two numeric arguments are the start field number and count (how many comma-delimited fields to return).
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
DataStage BASIC has a shorthand notation called "delimited substring extraction" that you may prefer; though it generates exactly the same compiled code as the FIELD function. For example:
Field001 = RecordString[",", 1, 1]
Field002 = RecordString[",", 2, 1]
The comma inside the square brackets asserts that RecordString is delimited by comma characters. The two numeric arguments are the start field number and count (how many comma-delimited fields to return).
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
Guillermo
It is the variable used in a readseq statement.
Kim.
Kim Duke
DwNav - ETL Navigator
www.Duke-Consulting.com
It is the variable used in a readseq statement.
Kim.
Kim Duke
DwNav - ETL Navigator
www.Duke-Consulting.com
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
It's a sequential file, so I trust that you are processing it with READSEQ rather than READ. Either is possible, but READSEQ is more efficient.
OpenSeq pathname To filevariable
Then
Loop
While ReadSeq RecordString From filevariable
* code to process this line
* in RecordString variable
Repeat
CloseSeq filevariable
End
In this example the file is read a line at a time. This requires limited memory overhead.
OpenPath directorypath To filevariable
Then
Read EntireFile From filevariable, filename
Then
Loop
Remove RecordString From EntireFile Setting MoreLines
* code to process current line
* in RecordString variable
While MoreLines
Repeat
End ; * end of Read statement
Close filevariable
End ; * end of Open statement
In this example, the entire sequential file is read into a variable, necessitating use of rather more memory than the ReadSeq example. The directory containing the file is opened, the filename used as the "key value" for a key-based Read statement.
In both of these examples error checking has been omitted for clarity. You do not omit error checking for a production system!
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518
OpenSeq pathname To filevariable
Then
Loop
While ReadSeq RecordString From filevariable
* code to process this line
* in RecordString variable
Repeat
CloseSeq filevariable
End
In this example the file is read a line at a time. This requires limited memory overhead.
OpenPath directorypath To filevariable
Then
Read EntireFile From filevariable, filename
Then
Loop
Remove RecordString From EntireFile Setting MoreLines
* code to process current line
* in RecordString variable
While MoreLines
Repeat
End ; * end of Read statement
Close filevariable
End ; * end of Open statement
In this example, the entire sequential file is read into a variable, necessitating use of rather more memory than the ReadSeq example. The directory containing the file is opened, the filename used as the "key value" for a key-based Read statement.
In both of these examples error checking has been omitted for clarity. You do not omit error checking for a production system!
Ray Wurlod
Education and Consulting Services
ABN 57 092 448 518