Column to rows

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
turash
Premium Member
Premium Member
Posts: 51
Joined: Fri Apr 06, 2007 10:09 am
Location: Edison, NJ

Column to rows

Post by turash »

I am getting data in sequential file as follows
Input
  • IssuingCompanyCd,013550
    PolOfficeCd,000130
    PolicyNo,WR101
    CertificateNo,101010
    RenlCertNo,000000
    EndorsementEffDt,01012008
    EndorsementSqn,1
Want Convert Output Sequential File like the Following
Output
IssuingCompanyCd,PolOfficeCd,PolicyNo,CertificateNo,RenlCertNo,EndorsementEffDt,EndorsementSqn
013550,000130,WR101,101010,000000,01012008,1

First row is as header in this case

I have tried use pivot, Row Merge without much of luck

Thanks In advance,
Tushar
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You would need to use stage variables to (ultimately) build a concatenated record (including field delimiters) and then only write it out when you have a 'complete record' as one long varchar.

That could be when you read the "EndorsementSqn" record or after you've read 7 records, depending on if you always get all the pieces or not.
-craig

"You can never have too many knives" -- Logan Nine Fingers
turash
Premium Member
Premium Member
Posts: 51
Joined: Fri Apr 06, 2007 10:09 am
Location: Edison, NJ

Post by turash »

I am trying to make 2 records out of the 7 records

1st Record contains first columns of these 7 rows
2nd Record contains second columns of these 7 rows.

Could you please give me more details?
chulett wrote:You would need to use stage variables to (ultimately) build a concatenated record (including field delimiters) and then only write it out when you have a 'complete record' as one long varchar.

That could be when you read the "EndorsementSqn" record or after you've read 7 records, depending on if you always get all the pieces or not.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

You are trying to make 2 records out of each set of 7 records? Or do you only need to produce the 'heading' row once? :?
-craig

"You can never have too many knives" -- Logan Nine Fingers
turash
Premium Member
Premium Member
Posts: 51
Joined: Fri Apr 06, 2007 10:09 am
Location: Edison, NJ

Post by turash »

chulett wrote:You are trying to make 2 records out of each set of 7 records? Or do you only need to produce the 'heading' row once? :?
Lets talk about multi value flat file
Input
IssuingCompanyCd,013550
PolOfficeCd,000130
PolicyNo,WR101
CertificateNo,101010
RenlCertNo,000000
EndorsementEffDt,01012008
EndorsementSqn,1

IssuingCompanyCd,013551
PolOfficeCd,000131
PolicyNo,WR102
CertificateNo,101012
RenlCertNo,000002
EndorsementEffDt,01012009
EndorsementSqn,2

Output
IssuingCompanyCd,PolOfficeCd,PolicyNo,CertificateNo,RenlCertNo,EndorsementEffDt,EndorsementSqn
013550,000130,WR101,101010,000000,01012008,1
013551,000131,WR102,101012,000002,01012009,2

I have to create the header only once and create two more rows with its values.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

If @OUTROWNUM = 1 Then InLink.Field001 Else InLink.Field002
Preserve these values in stage variabales. Constrain your output such that

Code: Select all

InLink.Field001 = 'EndorsementSqn'
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If these header names are known in advance, just name your output columns appropriately and ignore them in the data.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

Hello,

In hurry i tried working for your doubt.

job design like
Input file ----->Transformer------>(2 output)


you will require two stage variables.

one colvalue and other valuecolumns.(stage variables).

your two input columns will be colname and colvalue.

define for colvalue -->colvalue :',': DSLink11.colname.

define for valuecolumns-->If mod(@INROWNUM,7)=0 Then ' ' Else trim(valuecolumns):',': DSLink11.colvalueinp.

in first output put the value for target column as trim(colvalue,',') and in constraint put (@INROWNUM=7),because you have 7 columns.


in second output put value for target column as trim(valuecolumns,',','l') and in constraint put (mod(@INROWNUM,7)=6).

file file in output should be used in second output in append mode.

hope that works for you.
thanks.
sachin1
Participant
Posts: 325
Joined: Wed May 30, 2007 7:42 am
Location: india

Post by sachin1 »

your two input columns will be colname and colvalueinp.
Post Reply