Return function in datastage 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

Post Reply
parvathi
Participant
Posts: 103
Joined: Wed Jul 05, 2006 4:48 am
Contact:

Return function in datastage routine

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post 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:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post 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:
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 »

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
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Cool, learnt something new today 8)
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply