In a transform function, I have the code as following:
(the two pass into parameters are: HashFileName, Key1)
*--------------------------------------------------------------------------------------------------------------------------------------------
RoutineName = 'ReadMaxCenYear'
Common/HashLookup/ FileHandles(100), FilesOpened
Locate HashFileName IN FilesOpened Setting POS Then
Read Rec From FileHandles(POS), Key1 Then Ans = Rec(1)
Else Ans = @Null End
*--------------------------------------------------------------------------------------------------------------------------------------------
The code has been compiled with no errors, however, when test run, I got the result as the following:
*--------------------------------------------------------------------------------------------------------------------------------------------
TEST #1
*******
Arg1 = pctwrkMaxCenYear
Arg2 = max_cen_yr
Test completed.
Result = Program "TSTReadMaxCenYear.B": Line 5, Variable "ANS" previously undefined. Empty string used.
*--------------------------------------------------------------------------------------------------------------------------------------------
Any body can help?
Basic code test error
Moderators: chulett, rschirm, roy
Basic code test error
Kwang
First of all do you know what this does? Do you know why they are doing this? Please do Atl-C to add code blocks.
HashLookup is called a named common. It is used here because opening a hash file over and over is slow. They store how many files opened and then add one to it to open a new one. The file pointers of opened files are stored in a dimensioned array named FileHandles. You can up to 100 files opened at one time before this logic fails.
Key1 is the hash file key or what is also called record id. You need to use
Instead of:
Because you never dimensioned Rec. This called a dynamic array because you do not have to predefine how many elements are in this array with a DIM statement.
A LOCATE statement will look for an exact value in a dimesioned or dynamic array and return where it found it. Like the third element of the array matches this HashFileName. If this HashFileName is not in the array then it has not been opened so you need to open it.
I hope this helps. There are lots of code examples in the routines supplied with DataStage. This BASIC code can also be used in job control of a job.
Code: Select all
* ReadMaxCenYear(HashFileName, Key1)
RoutineName = 'ReadMaxCenYear'
Ans = @NULL
Common /HashLookup/ FileHandles(100), FilesOpened
Locate HashFileName IN FilesOpened Setting POS Else
FilesOpened = FilesOpened + 1
Open HashFileName to FileHandles(FilesOpened) Else
goto TheEnd
End
End
Read Rec From FileHandles(POS), Key1 Then
Ans = Rec<1>
End Else
Ans = @Null
End
TheEnd:
Key1 is the hash file key or what is also called record id. You need to use
Code: Select all
Rec<1>
Code: Select all
Rec(1)
A LOCATE statement will look for an exact value in a dimesioned or dynamic array and return where it found it. Like the third element of the array matches this HashFileName. If this HashFileName is not in the array then it has not been opened so you need to open it.
I hope this helps. There are lots of code examples in the routines supplied with DataStage. This BASIC code can also be used in job control of a job.
Mamu Kim