capture the reject record based on column length

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

moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

capture the reject record based on column length

Post by moulipx »

Hi,
I need some help regarding rejection of records based on column length for each record.

please find sample below file format. And my contains nearly 300 columns .

col1,col2,col3,col4
aaa,bbbb,cccc,dddd
111,22,333,datadata

And the metadata of file is

ColName length

col1 3
col2 4
col3 3
col4 4


My requirement is to reject the record if the column value length is greater than actual length.

In the above scneario i need to capture the second record since col4 of second record length is greater than 4

111,22,333,datadata.

please help me in solving this issue.

Can i achieve this in transformer without using in stagevariables. Since my file contains 300 records

Thanks in advance
Chandra Mouli
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: capture the reject record based on column length

Post by SURA »

What is your source ?

SEQ file ? If so, you can choose the data type as char(length) and use the
reject mode to output and write it in a file.

DS User
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Re: capture the reject record based on column length

Post by moulipx »

My Source is Sequentail file . And i can't use CHAR datatype while reading the file Since in some times my columns values length may be less than metadata length specified.
Chandra Mouli
SURA
Premium Member
Premium Member
Posts: 1229
Joined: Sat Jul 14, 2007 5:16 am
Location: Sydney

Re: capture the reject record based on column length

Post by SURA »

You can use the Length function in the TFM and reject.

DS User
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Re: capture the reject record based on column length

Post by moulipx »

as i said my source file is having 300 columns. it's very tedious to use so many stage variables . Is there anyway to do in transformer.
Chandra Mouli
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Re: capture the reject record based on column length

Post by zulfi123786 »

Or you could use a single stage variable and dump a huge derivation for all 300 columns in the same :wink:
- Zulfi
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

I did sequential file stage. But for VARCHAR fields if the data length is greater than original column length the row is getting rejected.

plesae guide me on this..
Chandra Mouli
zulfi123786
Premium Member
Premium Member
Posts: 730
Joined: Tue Nov 04, 2008 10:14 am
Location: Bangalore

Post by zulfi123786 »

moulipx wrote:But for VARCHAR fields if the data length is greater than original column length the row is getting rejected.
From what i recollect Varchar should not drop/reject a recrod if the length exceeds what is defined, it just strips off the extra characters.

you can verify this by turning all your columns to varchar and i am sure your records wont get dropped/rejected
- Zulfi
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

Actally the records are not getting rejected if for varchar fields.
Chandra Mouli
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

moulipx wrote:Actally the records are not getting rejected if for varchar fields.
Could someone help me on this..
Chandra Mouli
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Are you certain you can't use CHAR for this? Have you actually tried it? It's a delimited file so it seems to me that it should read it based on the delimiters rather than the field size and if one is 'short' it will use the PAD character defined to expand it to full size, so make sure that is set to 0x20.
-craig

"You can never have too many knives" -- Logan Nine Fingers
mobashshar
Participant
Posts: 91
Joined: Wed Apr 20, 2005 7:59 pm
Location: U.S.

Post by mobashshar »

Hi,
One option I can think of is as follows:

Make sure the input field are defined as Varchar. In Transformer create a extra column as flagcol for each input column. So it will be like flagcol1, flagcol2,.... etc.

In transformer use this logic to set the flag flagcol1 = IF (Len(trimleadingtrailing(lnk_input.col1)) = 3) THEN "Y" ELSE "N". Do this for all your input columns and change the length value to 3 or 4 based on column requirement.

Finally use the Filter stage to filter/reject the rows. You can use this logic flagcol1 = "Y" AND flagcol2 = "Y" AND flagcol3 = "Y" AND flagcol4 = "Y" and make sure to set the Output Rejects = True.

This way you will get all the rows with valid length in Col1, Col2, Col3 and Col4 in the output and rows with Invalid length will be rejected.

Hope this helps

Mobashshar
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

I used CHAR datatypes for all fields. But in PADCHAR property it is not allowing me to set 0x20.Then i choosed SPACE property. But all the colums fields the short of length specified are failed are getting dropped.
Chandra Mouli
moulipx
Participant
Posts: 22
Joined: Tue Mar 09, 2010 8:13 am

Post by moulipx »

please somebody help me on this
Chandra Mouli
paultechm
Participant
Posts: 27
Joined: Wed Jul 25, 2007 2:09 am

Re: capture the reject record based on column length

Post by paultechm »

Read it as a single varchar column with out any lenght.In transformer put a constraint like length(column)>(take the total metadata length sum) then reject it


-Paul
Post Reply