String Comparision fail

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
srividya
Participant
Posts: 62
Joined: Thu Aug 25, 2005 2:31 am
Location: Ashburn,VA

String Comparision fail

Post by srividya »

Hi alll

I have an issue while reading data from a comma delimited file. There is a simple if then else statement in a stage variable which does basic string comparison

if Field(trim(Lnk_Src_Socn.Field002),",",1) ='COS' Then 'Type1' else if Field(trim(Lnk_Src_Socn.Field002),",",1) ='MOS'
Then 'Type2' else if Field(trim(Lnk_Src_Socn.Field002),",",1) ='FOS' Then 'Type3' else StgNotificationType

This string comparison is failing frequently. I have checked the below points

1. Made sure there are no special characters in the file.
2. Loaded the string into a DB table, and wrote a select on the same string values. Got positive results
3. did a unix Grep on the file, to get positive result set again
4. trimmed the field to 3 characters, hoping that it will strip any invisible special characters
5. i went back and checked to the source and made sure nothing has changed when they generate this string.

Is there anything i can do to understand what the issue.

this simple if then else is the heart of the whole process, and with this failing i am missing most of data loads frequently
Thanks for help
Sri
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Can you provide an example dataset of how inputs will occur.

Also display the Field(trim(Lnk_Src_Socn.Field002),",",1) to check the values.
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

Try this

Code: Select all

if Field(trim(Lnk_Src_Socn.Field002),",",1)[1,3] ='COS' Then 'Type1' else if Field(trim(Lnk_Src_Socn.Field002),",",1)[1,3] ='MOS' 
Then 'Type2' else if Field(trim(Lnk_Src_Socn.Field002),",",1)[1,3] ='FOS' Then 'Type3' else StgNotificationType
You are the creator of your destiny - Swami Vivekananda
srividya
Participant
Posts: 62
Joined: Thu Aug 25, 2005 2:31 am
Location: Ashburn,VA

Post by srividya »

Sai

Sample of the input data set i get

01,COS
02,chasidh,dasdasd,asdasdasd,wdfddwasd,
03,dsfds,dsasd,asdasd,asdasdas,
04,dfoprewo,qwqe,reteererqwe

01,MOS
02,chasidh,dasdasd,asdasdasd,wdfddwasd,
03,dsfds,dsasd,asdasd,asdasdas,
04,dfoprewo,qwqe,reteererqwe

01,FOS
02,chasidh,dasdasd,asdasdasd,wdfddwasd,
03,dsfds,dsasd,asdasd,asdasdas,
04,dfoprewo,qwqe,reteererqwe

Depending on the 01 Record the data is split into different tables.

Field002 is of length 1000, Anything after the first "comma" on any row is read into Field002

Thanks
srividya
Participant
Posts: 62
Joined: Thu Aug 25, 2005 2:31 am
Location: Ashburn,VA

Post by srividya »

Anbu, the if then else is a "bit" long :lol:
it also has strings with four characters which have values like COSH,COSL :?

but yes i did try to restrict the code to read the first 3 characters only, the COS that read correctly was from COSH and COSL, the one with COS only failed :shock: :cry:
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

What is the output you are getting now ?

Assuming that StgNotificationType is the name of the stage variable, you need to include a condition Field001 = '01'. Otherwise each record will be used in derivation.

PS : Please provide meaningful names rather than field001 and field002 - which appears as defaults.
srividya
Participant
Posts: 62
Joined: Thu Aug 25, 2005 2:31 am
Location: Ashburn,VA

Post by srividya »

the output i get is 0 now, which is the initial value for the stage variable. I have taken care to flow only 01 records to this stage variable
Post Reply