Reading seq files from BASIC job

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Reading seq files from BASIC job

Post 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
tonystark622
Premium Member
Premium Member
Posts: 483
Joined: Thu Jun 12, 2003 4:47 pm
Location: St. Louis, Missouri USA

Post 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
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post by gpbarsky »

Tony:

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

Thank you very much.

Guillermo P. Barsky
Buenos Aires - Argentina
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
gpbarsky
Participant
Posts: 160
Joined: Tue May 06, 2003 8:20 pm
Location: Argentina

Post 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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Guillermo

It is the variable used in a readseq statement.

Kim.

Kim Duke
DwNav - ETL Navigator
www.Duke-Consulting.com
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
Post Reply