Sequential file different number of fields every row

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
gomez
Premium Member
Premium Member
Posts: 83
Joined: Tue Jun 22, 2004 6:11 am

Sequential file different number of fields every row

Post by gomez »

Hi All:
I have to extract a sequential file which has the following structure:
Header
Detail1
Detail2
Trailer
This structure repeats itself in the file. The first 6 characters in a line indicates the type - Header/Detail/Trailer.
However Detail line can be 1 or many between a header and trailer.
I want to extract them all, transform the detail row and load them all into a single file obviously in the exact order. Any clue on how this can be done?

I referred to the post

Code: Select all

http://www.dsxchange.com/viewtopic.php?t=103989&postdays=0&p
in the forum which talks about a similar scenario. The difference is in the repeating patterns in the same file
Appreciate any help on this

Thanks
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

If you do not need the Header/Trailer rows then just ignore them (drop them in a transform stage). If you need some data from a Header line, put it into a stage variable in the same transform stage where you drop these rows.
gomez
Premium Member
Premium Member
Posts: 83
Joined: Tue Jun 22, 2004 6:11 am

Post by gomez »

Thanks ArndW. I would need the header/trailer data as well. I would have to bring them out in the same order as
header
detail1
detail2
trailer
header
detail1
detail2
detail3
trailer
And a header/detail/ trailer consists of different number of fields
Do I bring them as a single field into the transformer. Then using staging variables route them to three different links from the transformer into row splitter stages. Now how do I collect them in the same order as I read into the final target
Thanks
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

You can use the method you suggested and use the @INROWNUM variable as a key to rejoin them after processing, or just declare additional columns in the input file that aren't used, just mark them as "incomplete column - retain" and don't use them for the record formats that don't use them.
gomez
Premium Member
Premium Member
Posts: 83
Joined: Tue Jun 22, 2004 6:11 am

Post by gomez »

Thanks ARNDW. Yes I am actually stuck in the next step. I have now generated 3 files - Header, Detail, Trailer using Transformer/Row splitter. However I wouldnt be able to use a Merge Stage to merge the Header file, Detail file and Trailer file since they have different columns. I wouldnt be able to use a Link Collector either since there is no single column configuration that I can define in the stage.
Thanks
gomez
Premium Member
Premium Member
Posts: 83
Joined: Tue Jun 22, 2004 6:11 am

Post by gomez »

My job design is like this

Code: Select all

Source --> Transformer(to split 3 data streams) -->Row Splitter (three of them one  for each stream)---> Transformer(to transform data - three of them for each stream)--->  Row Merge (three of them for each stream)---> Transform(to create a key column-three of them for each stream) ---> Link Collector --->Output
My input files to the Link Collector are
Header file,
Detail file,
Trailer file
I use Sort/Merge Algorithm in Link Collector.
However, the output from Link Collector is like
Trailer1
Detail1
Detail1
Header1
Header2
Detail2
Detail2
Trailer2
Trailer3
Detail3
Detail3
Header3

Any clue on why this happens?

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

Post by vmcburney »

Different parts of your job are processing at different speeds which mixes up the order of your rows. You need to add a sequence number to the start of all header, detail and tail records using an @inrownum and send it down all three paths, in your collector sort by that sequence number.
gomez
Premium Member
Premium Member
Posts: 83
Joined: Tue Jun 22, 2004 6:11 am

Post by gomez »

Thanks vmcburney. I tried this and it works. I like the way you also explained to why this happened. Appreciate that. Thanks
Post Reply