Page 1 of 1

Reading seq files from BASIC job

Posted: Tue Jul 22, 2003 2:03 pm
by gpbarsky
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

Posted: Tue Jul 22, 2003 2:41 pm
by tonystark622
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

Posted: Tue Jul 22, 2003 2:58 pm
by gpbarsky
Tony:

You understood perfectly well. And that is exactly what I needed.

Thank you very much.

Guillermo P. Barsky
Buenos Aires - Argentina

Posted: Tue Jul 22, 2003 5:09 pm
by ray.wurlod
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

Posted: Wed Jul 23, 2003 9:51 am
by gpbarsky
Ray:

RecordString is the name of the record in the READ.... sentence, or is a function ?

And thank you for answering me.

Guillermo P. Barsky
Buenos Aires - Argentina

Posted: Wed Jul 23, 2003 10:58 am
by kduke
Guillermo

It is the variable used in a readseq statement.

Kim.

Kim Duke
DwNav - ETL Navigator
www.Duke-Consulting.com

Posted: Wed Jul 23, 2003 5:13 pm
by ray.wurlod
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