How to split one record into several records

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

How to split one record into several records

Post by ambasta »

Hi All,
I am writing from dataset to Oracle.From Dataset Col.A[char(20)] and Col.B[char(30)] is coming.I need to populate Col.X using Col.A and col.B,but Col.X is having datatype as Char(2) only.Logic is... if Col.B is having data of more than 2 character then populate 2-2 char one by one.It is difficult to explain so,i am giving the following example to make my requirement clear.
If Source is like this...

ColA ColB

2846789NYXH75005C AXAMG1

VINNAGATEST000001 CS

Target should store it as

ColA Col .X

2846789NYXH75005C AX

2846789NYXH75005C AM

2846789NYXH75005C G1

VINNAGATEST000001 CS

Please help me and let me know if you want any more detail .


Thanks in Advance.
Last edited by ambasta on Thu Nov 02, 2006 10:53 am, edited 2 times in total.
ambasta
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Assuming there is a maximum number of values for the two-character codes, separate them into separate columns (probably in a Modify or Transformer stage using substring techniques), then use a Pivot stage to generate a row for each.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

Post by ambasta »

Thanks Ray,
I cannot create any additional column.what i need to do is...split one record and populate it as several records.I am not aware of pivot stage.can you plz explaim me a bit...

Thanks.
ambasta
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

Step 1. I will use basic transformer.
Step2. Assuming you have only two columns (column-A and column-B). I will pass both the columns to a routine.
Step3. Function of routine:

Code: Select all

 a. loop through column-B , read 2 bytes every time and create a result something like below.
              Alogorithm: Lets have two variable  RtnColA and RtnColB
                   Read 2 byte and loop till end of string and perform below derivation for every loop. You can have a counter or something like that
                 RtnColA=RtnColA  :char(13): column-A
                 RtnColB= RtnColB :char(13): 2-Byte[i]

                b. In the end the routine should return a string something like
                       2846789NYXH75005C :char(13): 2846789NYXH75005C : char(13): 2846789NYXH75005C : char(13): VINNAGATEST000001 : '|' : AX : char(13):  AM : char(13):  G1 : char(13):  CS 
Step4: In transformer output link side.
O/Pcolumn-A = Routine Result, substring first portion before pipe (|)

O/Pcolumn-A = Routine Result, substring second portion after pipe (|).


Note: 1. char(13) is carriage return
2. The algorithm may not be 100% accurate, you may have to add checks like, if column-B is all spaces..something may be required for first
and last record.
3. Even if you have more than 2 column. I will pass a concatenated value of all columns as first parameter to routine and second parameter would be column-B
Shantanu Choudhary
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

talk2shaanc wrote:Note: 1. char(13) is carriage return
char(13):char(10) is the CR for dos.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

Post by ambasta »

Thanks Shantanu for your precious Input.but i cannot use server job and in Parallel job there is no Basic Transformer.
ambasta
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

DSguru2B wrote:
talk2shaanc wrote:Note: 1. char(13) is carriage return
char(13):char(10) is the CR for dos.
Thanks, for correcting me...actually, i didn't notice the OS given...

ambasta, I was talking about PX job only. In PX you should ideally have Basic transformer
Shantanu Choudhary
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

ambasta wrote:I cannot create any additional column.
You CAN create as many additional columns in your job as you require. Columns are link properties. These extra columns may exist only on the link between your Transformer stage and your Pivot stage.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ambasta
Participant
Posts: 93
Joined: Thu Jan 19, 2006 10:29 pm
Location: Bangalore

Post by ambasta »

Thanks Ray,
Can you please elaborate... how to do that in transformer stage??I am having very urgent requirement.can you please help me??

Thanks
ambasta
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Etiquette Note
We don't do urgent here. It is an all volunteer site, we post as and when we can. And then only if we've something to contribute. If you need urgent, then sign up for premium service with your support provider, and learn the true cost of urgent.

Or, as the old saying goes, lack of planning on your part does not constitute an emergency on my part.

Create column definitions - or, to be totally professional - a table definition for the intermediate record schema.

For example, FirstCode, SecondCode, ThirdCode, up to as many as you'll ever need. Make them Char(2) and nullable.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
samsuf2002
Premium Member
Premium Member
Posts: 397
Joined: Wed Apr 12, 2006 2:28 pm
Location: Tennesse

Post by samsuf2002 »

u can use this code in the transformer if it fits ur requirement

Declare stage variables as follows:
StageVar =DSLink3.No
StageVar1 =StageVar<> StageVar1
StageVar2 =StageVar
StageVar3 =DSLink3.Type:',':DSLink3.Name1:',': DSLink3.Name2
StageVar4 =IF StageVar2=1 then DSLink3.No:',': StageVar5 else Trim(StageVar4):',':Trim(StageVar5)

Output has two column with the below derivation:
No =DSLink3.No
Output =StageVar4
Check for the field length of the Output Column to be suficient to hold the concatenated data

Remove Duplicate Stage:
Pass the rows through a Remove Duplicate Stage and give the key as NO and select Last in the property Duplicate to Retain

Tested With:
Code:
1|A|AA|W
1|B|BB|N
1|C|CC|Y
1|D|DD|Z
2|A|AA|W
2|B|BB|N
2|C|CC|Y


Output:
Code:
1,A,AA,W,B,BB,N,C,CC,Y,D,DD,Z
2,A,AA,W,B,BB,N,C,CC,Y











OR







StageVar=DSLink3.No
StageVar2=StageVar<> StageVar1
StageVar1=StageVar
StageVar5=DSLink3.Type:',':DSLink3.Name1:',': DSLink3.Name2
StageVar4=IF StageVar2=1 then DSLink3.No:',': StageVar5 else Trim(StageVar4):',':Trim(StageVar5)
hi sam here
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

That's a nice vertical pivot, samsuf2002, but the question required a horizontal pivot. :oops:
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply