Page 1 of 1

Return function in datastage routine

Posted: Tue Feb 06, 2007 8:27 am
by parvathi
Hi all,
I saw a routine with the code like this
If InputArg = '' Then
Call DSLogWarn('InputArg is required.' , c_routineName ); Return
End

v_OPID = '100'
v_logFolder = 'dir'

Ans=v_OPID

IN THIS IF MY INPUT ARGUMENT IS NULL WHAT WILL HAPPEN.
WHAT DOES THE RETURN STATEMENT DO?
WILL IT RETURN BACK TO LINE V_OPID
CAN'T I USE VARIABLES WITH OUT DECLARING.

Posted: Tue Feb 06, 2007 8:40 am
by chulett
Put any code you are curious about into a 'test' routine in the Administrator and then use the Test functionality there. You may have trouble checking for empty parameters there, so for testing sake change it to check for a recognizable string:

If InputArg = 'empty' Then Call DSLogWarn...

As to the "Can't I use variables without declaring" question - yes. Their first use instantiates them.

ps. posting in ALL CAPS is considered SHOUTING, please use your inside voice here. :wink:

Posted: Tue Feb 06, 2007 8:40 am
by ArndW
If the input argument is NULL then it is not equal to "".
But if it is "" then it will execute taht code and exit the routine. The RETURN statement should read RETURN({value}) to be correct, though

Posted: Tue Feb 06, 2007 8:44 am
by DSguru2B
Or if this is not the complete routine and the code that you have shown is part of a subroutine then Return will pass the execution back to the calling block. I still dont get the semicolon, is that correct systax guys? :roll:

Posted: Tue Feb 06, 2007 8:52 am
by ArndW
Yes, the semicolon is used to put multiple commands on one physical line of source code. I use it all the time for commenting inline:

Code: Select all

 a = 1 ;** set the value of "a" to 1

Posted: Tue Feb 06, 2007 8:53 am
by DSguru2B
Cool, learnt something new today 8)

Posted: Tue Feb 06, 2007 3:38 pm
by ray.wurlod
Whenever creating routines that some other induhvidual may call, you need to check for three forms of invalid argument - unassigned, null and otherwise invalid.

Code: Select all

If UnAssigned(Arg1) Or IsNull(Arg1)
Then
   RETURN(@NULL)  ; * return immediately
End
If Arg1 = ""   ; * for example
Then
   Ans = @NULL
End
Else
   * Here Arg1 is OK to keep processing
End