Check specific pos in flat file

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
thirupri
Premium Member
Premium Member
Posts: 40
Joined: Wed Sep 17, 2003 3:41 am
Location: Saudi Arabia
Contact:

Check specific pos in flat file

Post by thirupri »

Hi,

I am getting back a status file. I have to open the file and check the exact position of the record in the file and based on this I have to other action like (sending mail if it is not success or change the status of the processed record if it is success)

The file name is StatusSpot.txt

And records as follows:

001FTP S0092COMPLETED 2003101111:53:17
002KSPB100 S0092COMPLETED 2003101111:54:30
003MURBGER S0000COMPLETED 2003101111:54:35


N.B: I have to check the 12th character for each record in the file.
Best Regards,
Thiruma Valavan
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Well, not sure how much help you need but perhaps we can get this party started.

Assuming you want to build a Server Job to do this. If you are familiar with building Job Control, this would seem to me to be much easier to accomplish writing it in BASIC as a "Batch". :shock: But, be that as it may...

* You could define your fixed-width input file in pieces - 11, 1, rest - then test the second field.
* You could define it as one long "field" and substring out the 12th character - field_name[12,1]
* Keep in mind there isn't anything like an 'update' action for sequential files in the GUI so if you need to change the status character, you'll need do so and then write the results out to a new file. You can build after-job actions to manipulate the files, if desired.

The email action could get interesting. If, using your example, all three records indicated failure do you need to send three emails or just one? Depending on how your job is structured, you may be able to leverage something like DSGetLinkInfo. Check for a non-zero row count going down a "failure" link and act appropriately.

-craig
thirupri
Premium Member
Premium Member
Posts: 40
Joined: Wed Sep 17, 2003 3:41 am
Location: Saudi Arabia
Contact:

Post by thirupri »

Craig,
I want to write a server Job using Script only. I am having the problem is how to specify a fixed width file in a script. Please help me on this issue.

Regards,

Thiruma Valavan.
Best Regards,
Thiruma Valavan
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Thiruma

When you say script then I assume you mean BASIC. If you did this in BASIC then you need to:

openseq "StatusSpot.txt" to SeqFilePtr else stop
eof = @false
loop
readseq Rec from SeqFilePtr else eof = @true
while not(eof) do
MyStat = Rec[12,10]
... do whatever ...
repeat
close SeqFilePtr

...........................
Rec[12,10] is a substring function.
readseq reeds one line at a time.


Kim.
Mamu Kim
vmcburney
Participant
Posts: 3593
Joined: Thu Jan 23, 2003 5:25 pm
Location: Australia, Melbourne
Contact:

Post by vmcburney »

This does not look like a fixed width document, it looks like a space delimited document. The first field has several fields concatenated together, the 2nd string has two fields together.

001FTP S0092COMPLETED 2003101111:53:17
002KSPB100 S0092COMPLETED 2003101111:54:30
003MURBGER S0000COMPLETED 2003101111:54:35

What you can do is read it in as a sequential file with three fields delimited by a space. You can now use field 2 to find the status. If you are expecting valid records to have the word COMPLETED and invalid records to have the word REJECTED you can set up an output link to an invalid record file and put a constraint on this link, INDEX(INPUT.COL2, "REJECTED") > 1. Another output leads to a file of valid records. INDEX(INPUT.COL, "COMPLETED") > 1. Another output leads to a reject file that captures all records that do not have either status.

You then output the three strings to these files using the same format and column definitions as the input document.
thirupri
Premium Member
Premium Member
Posts: 40
Joined: Wed Sep 17, 2003 3:41 am
Location: Saudi Arabia
Contact:

Post by thirupri »

Thanks to all. Special Thanks to Guru (Kim). It's working. Once again thanks to all.

Thiruma Valavan.
Best Regards,
Thiruma Valavan
Post Reply