Basic code test error

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
Kwang
Participant
Posts: 20
Joined: Tue Nov 04, 2003 4:27 pm
Location: Canada

Basic code test error

Post by Kwang »

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?
Kwang
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

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.

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:

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

Code: Select all

Rec<1>
Instead of:

Code: Select all

Rec(1)
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.
Mamu Kim
Kwang
Participant
Posts: 20
Joined: Tue Nov 04, 2003 4:27 pm
Location: Canada

Post by Kwang »

Actually I figured it out yesterday. And the code is similar to yours. Thank you for your kind response, Kim.

Kathy
Kwang
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

Kathy

You are very welcome but I think many people need to understand this code at this level or detail.
Mamu Kim
Post Reply