Page 1 of 1

recursive Routine

Posted: Thu Nov 03, 2005 10:14 am
by dsnovice
Hello All,

For most of my querries I found the search button very useful but once in a while I meet with some problems that seem to be dead end with out a helping hand.

I need to write a recursive function that looks up a hash table for a given key

The routine has been defined as below
RoutineName = 'GetWorkDayFromHash'

Common /HashLookup/ FileHandles(100), FilesOpened

Deffun DSRMessage(A1, A2, A3) Calling "*DataStage*DSR_MESSAGE"
Deffun GetWorkDayFromHash(Argument1,Argument2) CALLING 'DSU.GetWorkDayFromHash'

HashTable = Arg1
HashKey = Arg2
FOUND = @FALSE

CALL DSLogInfo(Arg1,Arg2,'GetWorkDayFromHash')


IF OCONV(HashKey,"DW") = 6 or OCONV(HashKey,"DW") = 7 Then
HashKey=HashKey+1
GetWorkDayFromHash(HashTable,HashKey)
--------------------------------------------------------------------------------
but I get the following Error message
Compiling: Source = 'DSU_BP/DSU.GetWorkDayFromHash', Object = 'DSU_BP.O/DSU.GetWorkDayFromHash'
***???
0037 GetWorkDayFromHash(HashTable,HashKey)

^
"DEFNAM" unexpected, Was expecting: Array Name, Variable name,


--------------------------------------------------------------------------------

I Found the link to this answer

"You need to define the function within itself,

Code:
MyFunction(Arg1)
DEFFUN MyFunction(argument1) CALLING 'DSU.MyFunction'

CALL DSLogInfo(Arg1,'MyFunction')
IF Arg1 > 0 THEN MyFunction(Arg1-1)


_________________
- Arnd "
but this doesnt work for me,

Any help would be appreciated
thank you,

dsnovice

Posted: Thu Nov 03, 2005 10:35 am
by ArndW
Your DEFFUN is fine, but a function returns a value, so needs to be part of an assignment statement. You need to specify a line like:

Code: Select all

Ans = GetWorkDayFromHash(HashTable,HashKey)

Posted: Thu Nov 03, 2005 10:38 am
by ailuro
Try assigning the value returned by your Routine to a variable, i.e.

Code: Select all

YourVar = GetWorkDayFromHash(HashTable,HashKey)

Posted: Thu Nov 03, 2005 10:38 am
by dsnovice
ArndW wrote:Your DEFFUN is fine, but a function returns a value, so needs to be part of an assignment statement. You need to specify a line like:

Code: Select all

Ans = GetWorkDayFromHash(HashTable,HashKey)
Thank you ArndW, I am able compile it with out errors

Thank you,

dsnovice