Generating a Key between a Header and Detail Record

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
THEDSKID
Premium Member
Premium Member
Posts: 11
Joined: Thu Apr 29, 2004 10:51 am
Location: DALLAS TX
Contact:

Generating a Key between a Header and Detail Record

Post by THEDSKID »

I have a flat file that contains a Header and many Detail records. My problem is that there is no primary or foreign key to join the records. All that I know is that all of the detail records that follow a particular header record, belong to that header.

What I would like to do is to create a sequential value that will generate a value that will link each detail record to its' corresponding header. Please see below:

Any help would be appreciated..


****this is what I have****

HXXX XXX XXX XXXXX

DX X XXX X X XXXX

DX X XXX X X XXXX

HXXX XXX XXX XXXXX

DX X XXX X X XXXX

HXXX XXX XXX XXXXX

DX X XXX X X XXXX

DX X XXX X X XXXX

DX X XXX X X XXXX





****this is what I would like to see****

01 HXXX XXX XXX XXXXX

01 DX X XXX X X XXXX

01 DX X XXX X X XXXX

02 HXXX XXX XXX XXXXX

02 DX X XXX X X XXXX

03 HXXX XXX XXX XXXXX

03 DX X XXX X X XXXX

03 DX X XXX X X XXXX

03 DX X XXX X X XXXX
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

When you say 'this is what I have' does that mean you are currently generating that output? If so, it should be fairly simple to add a couple of stage variables to check for a Header record and increment a counter each time one is encountered.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_s
Charter Member
Charter Member
Posts: 5245
Joined: Thu Jun 16, 2005 11:00 pm

Post by kumar_s »

If you already have the detail record following the header record, what else you exactly looking for?
Impossible doesn't mean 'it is not possible' actually means... 'NOBODY HAS DONE IT SO FAR'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

So... you didn't notice any difference between the two examples?
-craig

"You can never have too many knives" -- Logan Nine Fingers
srinagesh
Participant
Posts: 125
Joined: Mon Jul 25, 2005 7:03 am

Post by srinagesh »

Use a stage variable as a counter.. Initialize the value as 1

increment this value based on the First character of the source string ( If Instr(txt,H) = 1 then... StgVar = StgVar + 1)
Post Reply