How to read hashed file in basic

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
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

A hashed file must be opened:
  • with an OPEN statement if there exists a VOC entry for the hashed file
    with an OPENPATH statement if there is no VOC entry for the hashed file
Every record in a hashed file has a key. The READ statement requires that a key value be given. Variants of the READ statement allow the record to be locked for updating (READU) or locked against others updating it (READL).
Key values can be obtained from active Select Lists.

Similarly, the WRITE statement and the DELETE statement require that the key value be given.

A hashed file that has been opened with either OPEN or OPENPATH should be closed with a CLOSE statement when you are finished with it.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
asorrell
Posts: 1707
Joined: Fri Apr 04, 2003 2:00 pm
Location: Colleyville, Texas

Post by asorrell »

Just in case you need a manual for BASIC:

IBM InfoSphere DataStage BASIC Reference Guide
Version 11 Release 3

http://publibfp.boulder.ibm.com/epubs/pdf/c1942790.pdf
Andy Sorrell
Certified DataStage Consultant
IBM Analytics Champion 2009 - 2020
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Or, on the off chance it doesn't really need to be done in BASIC - create a little Server job to do that. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

The OP states a requirement to do this within "a job control".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Another approach would be to query the hashed file using DataStage SQL (or RetrieVe) and direct the output into the required text file via either the DIVERT.OUT, the COMO, or the LPTR mechanism.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

ray.wurlod wrote:The OP states a requirement to do this within "a job control".
Of course but we all know how ephemeral these "needs" can be at times, hence my phrasing. And "job control" is perfectly capable of running a job. :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 »

Here's a simple example:

Code: Select all

OPEN '','VOC' TO VOCFilePtr ELSE STOP 'Unable to open VOC'
SELECT VOCFilePtr TO 1

READNEXT Key FROM 1 ELSE Key = ''

LOOP UNTIL Key=''
   READ Record FROM VOCFilePtr, Key ELSE STOP 'Unable to read record "':Key:'" FROM VOC'
   READNEXT Key FROM 1 ELSE Key = ''
REPEAT
CLOSE VOCFilePtr
igorbmartins
Participant
Posts: 161
Joined: Mon Mar 17, 2008 10:33 am

Post by igorbmartins »

Thank you everybody. I will check all alternatives and I will post here the results.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Keep in mind the facts that Ray noted, Arnd's code needs a VOC entry to work. Meaning the hashed file needs to either live in a project or you've created one for it manually. If you've pathed the hashed file elsewhere, change the OPEN to OPENPATH appropriately.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

So your overall strategy has to include opening the hashed file, opening the sequential file, establishing a Select List on the hashed file, using a loop to process the records from the hashed file, for each of which you extract your required columns (fields), build the output line and write it to the text file. At the end you close both files.
In the following sample code, some error handling has been omitted for clarity.

Code: Select all

Equate Tab To Char(9)
OpenPath '/pathname/of/HashedFile' To fptrIn
Then
   OpenSeq '/pathname/of/TextFile' to fptrOut
   Then
      LineCount = 0        ; * number of lines written to output file
      Select fptrIn To 1   ; * Select List #1 contains all keys from hashed file
      Loop While ReadNext ID From 1
         Read Record From fptrIn, ID
         Then
            * Output line consists of fields 2, 3 and 5 from the hashed file.
            Field2 = Field(Record, @FM, 2)
            Field3 = Field(Record, @FM, 3)
            Field5 = Field(Record, @FM, 5)
            Line = Field2 : Tab : Field3 : Tab : Field5
            WriteSeq Line To fptrOut Then LineCount += 1
         End
      Repeat
      Call DSLogInfo(LineCount : " lines written to file. ", 'ReadHashedFile')
   End
    CloseSeq fptrOut
    Close fptrIn
End
Else
   Call DSLogFatal('Unable to open hashed file.', 'ReadHashedFile')
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