Lookup(looping in the ref table)
Moderators: chulett, rschirm, roy
Lookup(looping in the ref table)
Hi,
I have a input record like:
col1 col2 col3
66 41 55
Ref table data like:
col1 col2 col3 Status
66 41 55 1 66 41 56
66 41 56 1 66 41 57
66 41 57 0 66 41 58
What i need to do is, I have to look for the record with 66 41 55 in the ref data and If finds the record then check for the status. If the status = 1 then transfers the vaalues 66 41 56.
And again look for the record with this new values in the ref data if finds check the status and tranfers the values if status =1. I need to do this until status=0 finally capture those values of 66 41 58.
How can i achieve this?.(Looping in the ref data).
I would be grateful for any assistance.
Thanks,
Naren
I have a input record like:
col1 col2 col3
66 41 55
Ref table data like:
col1 col2 col3 Status
66 41 55 1 66 41 56
66 41 56 1 66 41 57
66 41 57 0 66 41 58
What i need to do is, I have to look for the record with 66 41 55 in the ref data and If finds the record then check for the status. If the status = 1 then transfers the vaalues 66 41 56.
And again look for the record with this new values in the ref data if finds check the status and tranfers the values if status =1. I need to do this until status=0 finally capture those values of 66 41 58.
How can i achieve this?.(Looping in the ref data).
I would be grateful for any assistance.
Thanks,
Naren
Naren,
this can be done with either a recursive lookup or a loop within a routine. You could chain lookups in a job, but you could only link back one level per lookup - if you know your maximum depth of recursion you could do it in a job directly.
You could solve it with a relatively short DS routine. How that is coded depends upon how you defined your key (single column or several ones)
this can be done with either a recursive lookup or a loop within a routine. You could chain lookups in a job, but you could only link back one level per lookup - if you know your maximum depth of recursion you could do it in a job directly.
You could solve it with a relatively short DS routine. How that is coded depends upon how you defined your key (single column or several ones)
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
could anyone please shed some light on how to write the recursive routine.
Thanks in advance.
Thanks in advance.
ArndW wrote:Naren,
this can be done with either a recursive lookup or a loop within a routine. You could chain lookups in a job, but you could only link back one level per lookup - if you know your maximum depth of recursion you could do it in a job directly.
You could solve it with a relatively short DS routine. How that is coded depends upon how you defined your key (single column or several ones)
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Provide a DEFFUN declaration that refers to the function itself.
Then, within your routine, you can invoke it recursively. Make sure to give yourself an exit strategy.
Example
This really also needs a Matches "1N0N" test to guarantee that the argument is a positive integer.
Code: Select all
DEFFUN MyRoutine(Arg1, Arg2) Calling DSU.MyRoutine
Example
Code: Select all
FUNCTION Factorial(X)
DEFFUN Factorial(Arg1) Calling "DSU.Factorial"
If X > 1 And X < 20
Then
Ans = X * Factorial((X - 1))
End
Else
Ans = 1 ; * argument out of range
End
RETURN(Ans)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Hi all,
Let me put my requirement in this way,
Input Data:
a,b
b,c
c,d
Output Data should be like
a,d
b,d
c,d
Any clues pls.
Thanks
Naren
Let me put my requirement in this way,
Input Data:
a,b
b,c
c,d
Output Data should be like
a,d
b,d
c,d
Any clues pls.
Thanks
Naren
ray.wurlod wrote:Provide a DEFFUN declaration that refers to the function itself.Then, within your routine, you can invoke it recursively. Make sure to give yourself an exit strategy.Code: Select all
DEFFUN MyRoutine(Arg1, Arg2) Calling DSU.MyRoutine
ExampleThis really also needs a Matches "1N0N" test to guarantee that the argument is a positive integer.Code: Select all
FUNCTION Factorial(X) DEFFUN Factorial(Arg1) Calling "DSU.Factorial" If X > 1 And X < 20 Then Ans = X * Factorial((X - 1)) End Else Ans = 1 ; * argument out of range End RETURN(Ans)
Naren,
Here is a shell program that is a "hint" - it doesn't use COMMON to skip re-opening the file and only uses a simple key, one column with your 0 or 1 STATUS and one column with the next key. Don't just copy this and run it - there is no error checking or handling and you should go through each line to understand what is happening so that you can finish the routine to your specifications.
Here is a shell program that is a "hint" - it doesn't use COMMON to skip re-opening the file and only uses a simple key, one column with your 0 or 1 STATUS and one column with the next key. Don't just copy this and run it - there is no error checking or handling and you should go through each line to understand what is happening so that you can finish the routine to your specifications.
Code: Select all
Routine GetFinalStatus(Key)
DEFFUN GetFinalStatus(Key) CALLING 'DSU.GetFinalStatus'
COMMON/GetFinalStatusCommon/FilePointer
IF NOT(FilePointer) THEN OPEN '','HashReferenceFile' TO FilePointer ELSE CALL DSLogFatal('oops','')
READ XrefRecord FROM FilePointer,Key ELSE XrefRecord = ''
IF XrefRecord<1>='0' ;** 1st field of the hashed file
THEN
** We have a valid exit
Ans = XrefRecord<2> ; set return value
END
ELSE
Ans = GetFinalStatus(XrefRecord<2>)
END
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Hi,
Here, iam not able to open my Hash file by giving the full path.It always going to else part only.
could you please explain it.
Here, iam not able to open my Hash file by giving the full path.It always going to else part only.
could you please explain it.
ArndW wrote:Naren,
Here is a shell program that is a "hint" - it doesn't use COMMON to skip re-opening the file and only uses a simple key, one column with your 0 or 1 STATUS and one column with the next key. Don't just copy this and run it - there is no error checking or handling and you should go through each line to understand what is happening so that you can finish the routine to your specifications.
Code: Select all
Routine GetFinalStatus(Key) DEFFUN GetFinalStatus(Key) CALLING 'DSU.GetFinalStatus' COMMON/GetFinalStatusCommon/FilePointer IF NOT(FilePointer) THEN OPEN '','HashReferenceFile' TO FilePointer ELSE CALL DSLogFatal('oops','') READ XrefRecord FROM FilePointer,Key ELSE XrefRecord = '' IF XrefRecord<1>='0' ;** 1st field of the hashed file THEN ** We have a valid exit Ans = XrefRecord<2> ; set return value END ELSE Ans = GetFinalStatus(XrefRecord<2>) END
naren - if you have a full pathed hashed file you need to use OPENPATH, not OPEN.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Re: Lookup(looping in the ref table)
Isn't it just simpler to use the hash lookup utility.
naren6876 wrote:Hi,
I have a input record like:
col1 col2 col3
66 41 55
Ref table data like:
col1 col2 col3 Status
66 41 55 1 66 41 56
66 41 56 1 66 41 57
66 41 57 0 66 41 58
What i need to do is, I have to look for the record with 66 41 55 in the ref data and If finds the record then check for the status. If the status = 1 then transfers the vaalues 66 41 56.
And again look for the record with this new values in the ref data if finds check the status and tranfers the values if status =1. I need to do this until status=0 finally capture those values of 66 41 58.
How can i achieve this?.(Looping in the ref data).
I would be grateful for any assistance.
Thanks,
Naren
-
- Charter Member
- Posts: 130
- Joined: Mon Sep 06, 2004 3:05 am
- Location: Dubai,UAE