Date Validation

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
sumitgulati
Participant
Posts: 197
Joined: Mon Feb 17, 2003 11:20 pm
Location: India

Date Validation

Post by sumitgulati »

Hi All,

I am getting a 6 digit integer as my input. I have to check if the input integer is a valid date in format MMDDYY. Here is what I do:

I format the integer to get a character in the format MM/DD/YY and then use IConv on this to convert it to internal date.

Code: Select all

Arg = Substrings(Arg1,1,2):'/':Substrings(Arg1,3,2):'/':Substrings(Arg1,5,2)

Ans = Iconv(Arg, "D/MDY[2,2,2]")
Arg1 being the input integer. I expect Iconv to give error message for invalid date but it does not do that. I tried with following Arg1 values:
043102 - Since in April there are only 30 days it should report an error
023001 - Since in February only 28 days are present it should report an error

Its not working. Is there any better way of validating the date.

Regards,
Sumit
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Iconv is giving you an error on dates like that, you just aren't seeing it. Check out the online help for the Status function. It (among other things) allows you to check the success or failure of a date conversion, and the online help shows you how to do that.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sumitgulati
Participant
Posts: 197
Joined: Mon Feb 17, 2003 11:20 pm
Location: India

Post by sumitgulati »

Thanks Craig. I just went through the Status() stuff and tried that. It works perfectly fine.

Regards,
Sumit
sumitgulati
Participant
Posts: 197
Joined: Mon Feb 17, 2003 11:20 pm
Location: India

Post by sumitgulati »

Hi,

I wrote the following code in my transformer to validate Arg1, which is coming from the source:

Code: Select all

If 
Field(Iconv(Substrings(Arg1,5,6), "DMDY[2,2,2]"):"-":Status(),"-",2)=0 Then 'N' else 'Y'
Sample data for Arg1:
AAAA022802
AAAA022902
AAAA022904

The code works fine when put in a routine. However when the code is put into a transformer to set an ERROR_FLAG it does not accept it. It says:
Variable 'Status' not defined

Any idea why is this so? Is there any other way to perform Iconv and access the Status in Transformer Derivation?

Regards,
Sumit
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No, you had it right at first - it must be done in a Routine. That is the only way to use multiple lines of 'code'. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
sumitgulati
Participant
Posts: 197
Joined: Mon Feb 17, 2003 11:20 pm
Location: India

Post by sumitgulati »

Consider the below code for a routine:

Code: Select all

Ans = Field(Iconv(Arg1, "DMDY[2,2,2]"):"-":Status(),"-",2)

It is just a single line code that accepts Arg1 as input.

When I put Field(Iconv(Arg1, "DMDY[2,2,2]"):"-":Status(),"-",2) in transformer I get the following error:
Variable 'Status' not defined

Regards,
Sumit
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And? :lol: Like I said, gotta do it in a routine.

Perhaps I should have said "It's the only way to use multiple lines of code or certain functions'. I'm sure Ray will be along later tonight to give us all the gory details of the Whys and the Wherefors. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
sumitgulati
Participant
Posts: 197
Joined: Mon Feb 17, 2003 11:20 pm
Location: India

Post by sumitgulati »

Thanks Craig. I have now converted it to a routine. Lets wait and see what Ray has to say on this.

Regards,
Sumit
dhiraj
Participant
Posts: 68
Joined: Sat Dec 06, 2003 7:03 am

Post by dhiraj »

this should be even faster :wink:

Code: Select all

Iconv(Arg1, "DMDY[2,2,2]")
Ans=status()
Dhiraj
Post Reply