Page 1 of 1

Getting Number of Columns of Hashed File

Posted: Mon Jun 22, 2009 5:42 am
by DS_SUPPORT
I am writing a routine , which will get HashedFileName as Input and Check the Values in all columns of it. By default the hashed file will contain 1 row, and i wanted to see all the values of all columns is there in a specified range.

I am writing something like this

Code: Select all

OpenPath FilePath:HashFileName TO HashVal
Then
Read Record From HashVal, CurrID
            Then
               RVal = Record
               Print Record
               ColCount = DCount(RVal,@FM)
              * Print DCount(RVal,@VM) : "@VM Count"
              * Print DCount(RVal,@FM) : "@FM Count"
              * Print DCount(RVal,@TM) : "@TM Count"
              * Print DCount(RVal,@AM) : "@AM Count"
              * Print "ColCount" : ColCount
               Ans = ColCount
            End 

End

And once i get the number of columns i will loop it and read the value and will check whether it is there within our range values.

The Problem i am encountering is, The hashed File which i am giving as input contains 5 columns (3 Keys and 2 Non Keys), DCount (@FM) gives me 2 , where as i need 5 as the Output, what value i have to use for counting the number of columns in the Hashed File, or is there any other way to read the Hashed File and check the number of Column and its values?

Posted: Mon Jun 22, 2009 7:14 am
by DS_SUPPORT
And after getting the column count, I will loop all the columns, i want to read the column value like Record<1>, so whether i will be able to read the Key columns and its value also like this.

Posted: Mon Jun 22, 2009 7:22 am
by ArndW
DataStage hashed files have only 1 key column. Your 3 keys are actually just one dynamic array string in CurrID that contains some separator character; thus the 2 column result returned by your DCOUNT() is correct.

Posted: Mon Jun 22, 2009 5:07 pm
by ray.wurlod
Try this.

Code: Select all

ColCount = DCount(Convert(@TM,@FM,RVal),@FM)
The single physical key is typically made up of values separated by text mark characters (@TM).

Posted: Mon Jun 22, 2009 11:02 pm
by DS_SUPPORT
Thanks for the Replies. Using DCount(Convert(@TM,@FM,RVal),@FM) doent give me the desired results, So I have used two loops one for validating the Keys and one for Validating Non Keys.

Code: Select all

            Read Record From HashVal, CurrID
            Then
               RVal = Record
******* Loop and Validate the Key Fields
               KeyColCount = DCount(CurrID,@TM)
               For I = 1 to KeyColCount
                   CurrKey = Field(CurrID,@TM,I)
                   Print CurrKey : "I Val" : I
******* Do the Required Validations here
               Next
***** Loop and Validate the Non Key Fields
               ColCount = DCount(Record,@FM)
               For I = 1 to ColCount
                  CurrCol  = Field(Record,@FM,I)
                   Print CurrCol  : "Col  Val : " : I
***** Do the Required Validations here
               Next
               Ans = KeyColCount 
            End 
And by doing this, i am able to fetch all the column values. And now this leads me to one more requirement, Is there any way to get the Column Names for the Directory Pathed Hashed Files. I dont want to create the VOC as this will be generic routine, and it can be called for validating any Hashed Files. So it will be more like creating VOC entry for all the Hashed Files.

Posted: Mon Jun 22, 2009 11:42 pm
by ray.wurlod
To open the dictionary with OpenPath, specify "D_hashedfilename" as the entryname portion of the pathname.