Page 1 of 1

Posted: Mon Sep 26, 2016 4:46 pm
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.

Posted: Mon Sep 26, 2016 7:32 pm
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

Posted: Mon Sep 26, 2016 9:25 pm
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:

Posted: Mon Sep 26, 2016 10:25 pm
by ray.wurlod
The OP states a requirement to do this within "a job control".

Posted: Mon Sep 26, 2016 10:27 pm
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.

Posted: Mon Sep 26, 2016 10:32 pm
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:

Posted: Tue Sep 27, 2016 2:41 am
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

Posted: Tue Sep 27, 2016 5:20 am
by igorbmartins
Thank you everybody. I will check all alternatives and I will post here the results.

Posted: Tue Sep 27, 2016 6:54 am
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.

Posted: Tue Sep 27, 2016 5:42 pm
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