phantom in routine

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

ppalka
Participant
Posts: 118
Joined: Thu Feb 10, 2005 7:25 am
Contact:

phantom in routine

Post by ppalka »

Hello,

I have an annoying phantom in my routine, I try to find it but I can't :(
Please help...

Nvl code:
If IsNull(arg) Then
Ans = default
End Else
Ans = arg
End

This is my routine code:

DEFFUN Nvl(arg,default) CALLING "DSU.Nvl"

Ans = ""

If IsNull(account_type) Then
Ans = 'Account Type is NULL for ID = ':Nvl(id,"")
return (Ans)
End

If IsNull(book_code) Then
Ans = 'Deal Book is NULL for CUSTOMER=':Nvl(customer,"")
return (Ans)
End

If IsNull(counterparty_code) Then
Ans = 'Counterparty Code is NULL for ORIGIN=':Nvl(origin,""):' and CUSTOMER=':Nvl(customer,"")
return (Ans)
End

If IsNull(currency) Then
Ans = 'Currency is NULL'
return (Ans)
End

If IsNull(balance_c) and IsNull(balance_d) Then
Ans = 'Balance is NULL for ID=':Nvl(id,"")
return (Ans)
End

cp = Nvl(compound_periodicity,'')
If Not(IsNull(compound_periodicity)) AND cp<>'A' and cp<>'S' and cp<>'Q' and cp<>'M' and cp<>'N' Then
Ans = 'Compound Periodicity not in (A, S, Q, M, N)'
return (Ans)
End

If Not(Nvl(interest_reinvest,'F')<>'T' or Nvl(compound_periodicity,'N')='N') Then
Ans = 'Check Interest Reinvest and Compound Periodicity'
return (Ans)
End

p = Nvl(periodicity, '')
If Not(IsNull(periodicity)) AND p<>'A' and p<>'S' and p<>'Q' and p<>'M' and p<>'N' Then
Ans = 'Periodicity not in (A, S, Q, M, N)'
return (Ans)
End

ab = Nvl(accrual_basis, '')
If Not(IsNull(accrual_basis)) AND ab<>'1' and ab<>'2' and ab<>'3' and ab<>'4' and ab<>'5' and ab<>'B' Then
Ans = 'Accrual Basis not in (1, 2, 3, 4, 5, B)'
return (Ans)
End

If (Nvl(interest_reinvest,'F')='T') and (Nvl(compound_periodicity,'N')<>'N') Then
Ans = 'Incorrect interest reinvest and/or compound periodicity'
return (Ans)
End

return (Ans)

Thanks in advance.
Best regards,
Piotrek
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If you look at that phantom message, and post it here, we could tell you what it is saying.

Chances are that your If statements are referencing variables that don't exist within the function.

account_type,book_code, counterparty_code, etc are not declared, are you passing them as arguments?
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ascen
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 12, 2006 6:47 am
Contact:

Post by ascen »

kcbland wrote:If you look at that phantom message, and post it here, we could tell you what it is saying.

Chances are that your If statements are referencing variables that don't exist within the function.

account_type,book_code, counterparty_code, etc are not declared, are you passing them as arguments?
upsss, I forgot to post my phantom message ...
I will do it on monday.
These variables are all parameters passed to routine.
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Are you able to compile it and test it without any error.
I think the phantom error is only during the call of the routine from within a job.
If thats the case, the phantom error during runtime occurs due to un-initialized variables.
I see you have not initialized the variables cp, p and ab.
That must be causing the phantom error.
Also, please surround the code with the code tags and use proper indentation so that we can understand it better.

Try initializing them, just put three lines in the begining where you have initialized Ans

Code: Select all

cp = ''
p = ''
ab = ''
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ppalka
Participant
Posts: 118
Joined: Thu Feb 10, 2005 7:25 am
Contact:

Post by ppalka »

I get the following error:
<error>
DataStage Job 673 Phantom 24706
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 44, Variable previously undefined. Zero length string used.
DataStage Phantom Finished
</error>

I can compile the routine without any error/warning and when I test it it works fine.

The code of the routine with indentations:

Code: Select all

      DEFFUN Nvl(arg,default) CALLING "DSU.Nvl"

      Ans = ""
      p = ''
      ab = ''
      cp = ''

      If IsNull(account_type) Then
         Ans = 'Account Type is NULL for ID = ':Nvl(id,"")
         return (Ans)
      End

     If IsNull(book_code) Then
         Ans = 'Deal Book is NULL for CUSTOMER=':Nvl(customer,"")
         return (Ans)
      End

     If IsNull(counterparty_code) Then
         Ans = 'Counterparty Code is NULL for ORIGIN=':Nvl(origin,""):' and CUSTOMER=':Nvl(customer,"")
         return (Ans)
      End

      If IsNull(currency) Then
         Ans = 'Currency is NULL'
         return (Ans)
      End

      If IsNull(balance_c) and IsNull(balance_d) Then
         Ans = 'Balance is NULL for ID=':Nvl(id,"")
         return (Ans)
      End

      cp = Nvl(compound_periodicity,'')
      If Not(IsNull(compound_periodicity)) AND cp<>'A' and cp<>'S' and cp<>'Q' and cp<>'M' and cp<>'N' Then
         Ans = 'Compound Periodicity not in (A, S, Q, M, N)'
         return (Ans)
      End

      If Not(Nvl(interest_reinvest,'F')<>'T' or  Nvl(compound_periodicity,'N')='N') Then
         Ans = 'Check Interest Reinvest and Compound Periodicity'
         return (Ans)
      End

      p = Nvl(periodicity, '')
      If Not(IsNull(periodicity)) AND p<>'A' and p<>'S' and p<>'Q' and p<>'M' and p<>'N' Then
         Ans = 'Periodicity not in (A, S, Q, M, N)'
        return (Ans)
      End

      ab = Nvl(accrual_basis, '')
      If Not(IsNull(accrual_basis)) AND ab<>'1' and ab<>'2' and ab<>'3' and ab<>'4' and ab<>'5' and ab<>'B' Then
         Ans = 'Accrual Basis not in (1, 2, 3, 4, 5, B)'
         return (Ans)
      End

      If (Nvl(interest_reinvest,'F')='T') and (Nvl(compound_periodicity,'N')<>'N') Then
         Ans = 'Incorrect interest reinvest and/or compound periodicity'
         return (Ans)
      End

      return (Ans)

And once againg, thanks in advance.

Kind regards,
Piotrek
ppalka
Participant
Posts: 118
Joined: Thu Feb 10, 2005 7:25 am
Contact:

Post by ppalka »

DSguru2B wrote:

Code: Select all

cp = ''
p = ''
ab = ''
I add that code on the beginning of my routine and I still get the same error :/
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Yes, thats what happens when there is an undefined variable used. You have to try to pin point which variable has been left undefined.
Go through your code again and make sure that:
- you are passing account_type, book_code etc. and have not left any one of them out
- The ones you are not passing, have been defined
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ppalka
Participant
Posts: 118
Joined: Thu Feb 10, 2005 7:25 am
Contact:

Post by ppalka »

Now I left only that code:

Code: Select all

Ans = ""
cp = ""

If IsNull(account_type) Then
   Ans = 'Account Type is NULL for ID = '
   return (Ans)
End

If IsNull(book_code) Then
   Ans = 'Deal Book is NULL for CUSTOMER='
   return (Ans)
End

if isNull(compound_periodicity) then cp = "#" else cp = compound_periodicity
if isNull(cp) or cp="" or len(cp)=0 then cp="#"
If Not(IsNull(compound_periodicity)) then
   if cp="A" or cp = "S" or cp="Q" or cp="M" or cp="N" Then Ans=""
   else return("Compound Periodicity not in (A, S, Q, M, N)")
End

<error>
And now I am getting such error:
DataStage Job 673 Phantom 8406
Program "DSU.chkAccount": Line 16, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 16, Variable "cp" previously undefined. Empty string used.
Program "DSU.chkAccount": Line 16, Variable previously undefined. Zero length string used.
Program "DSU.chkAccount": Line 16, Variable "cp" previously undefined. Empty string used.
DataStage Phantom Finished
</error>

So how it is possible that cp is undefined?
How can I handle that?
Is there any way to catch the input record which cause the error?

Best regards,
Piotrek
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

In that above code, try to replace double quotes with single quotes. I know its a very long shot but try it. You never know.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Try doing a global replace of "cp" to "xx" in your manager to see if it really is cp and not perhaps op in your code. You could also change your line to "IF INDEX('ASQMN',cp,1) THEN Ans='' ELSE RETURN('yourtext')"
ppalka
Participant
Posts: 118
Joined: Thu Feb 10, 2005 7:25 am
Contact:

Post by ppalka »

It seems that the problem was caused by value returned by another routine, and that value was used as an input parameter to this routine(compound_periodicity).
There was no null handling statement.
But the question is why datastage doesn't return the phantom or something else in that previous routine?
ascen
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 12, 2006 6:47 am
Contact:

Post by ascen »

ArndW wrote:"IF INDEX('ASQMN',cp,1) THEN Ans='' ELSE RETURN('yourtext')"
What is doing that "IF" statement?
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Ascen - say again? The INDEX function will return a 0 if the 1-char len value of the variable "cp" is not found in the string otherwise it will return a value. An condition in DataStage BASIC evaluates to 0 or '' as being the equivalent of false and anything else to be TRUE.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Is "default" in the Nvl function a hard coded value or a variable? If it's a variable, does it have a value assigned on every possible path through the code?

Check out the Assigned() or Unassigned() function - I always build one of these into routines that someone else may call, so as to check for arguments that may be in an unassigned state. It's called "bulletproofing".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ascen
Premium Member
Premium Member
Posts: 67
Joined: Wed Apr 12, 2006 6:47 am
Contact:

Post by ascen »

ray.wurlod wrote:Is "default" in the Nvl function a hard coded value or a variable? If it's a variable, does it have a value assigned on every possible path through the code?
default - an argument of the routine
When I wrote post about that the phantom was caused by value returned by another routine, I wasn't writing about Nvl routine, but the other one.
And in that routine there was no path where the input args are nulls. So it was the problem.
But I am dissapointed about ds, that it didn't return some phantom about error in that previous routine.
Check out the Assigned() or Unassigned() function - I always build one of these into routines that someone else may call, so as to check for arguments that may be in an unassigned state. It's called "bulletproofing".
These are builtin ds routines/transforms??
I will check it.
Thanks
Post Reply