Hash file created in UniVerse

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
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Hash file created in UniVerse

Post by mleroux »

I create a hash file in UV:

Code: Select all

create.file Time_D_Keys 30
That works fine. Then I add a field in the dictionary:

Code: Select all

INSERT INTO DICT Time_D_Keys(@ID, F1, LOC, FORMAT) VALUES ('TimeKey', 'D', 1, '8L');
Also works fine. When I import the UV file definition into DS, I get two fields, AT.ID (@ID) and TimeKey.

What I'd like to do is have a hash file with @ID hidden, and TimeKey only, but the TimeKey field must be the key, not @ID. How do I do that? With the REVISE command? If so, how?
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Post by mleroux »

I ended up doing the above using a job. So I have a hash file now (Time_D_Keys) with only one column, which is a key (according to the imported DS UniVerse def.) BUT...

I populate this hash file with a routine:

Code: Select all

FileNameOnDisk = "Time_D_Keys"

open FileNameOnDisk to TimeDimHash else
  print 'ERROR: Unable to open ' : FileNameOnDisk : '!'
  stop
end

clearfile TimeDimHash
* StartDate is an arg with YYYY-MM-DD HH:MM:SS format.
DateInt = Iconv(MatchField(StartDate,"0X' '2N':'2N':'2N",1),"D-YMD[4,2,2]")
* NumCycles gets a + 1 at the end because the date range is inclusive
NumCycles = Iconv(MatchField(EndDate,"0X' '2N':'2N':'2N",1),"D-YMD[4,2,2]") - DateInt + 1

for i = 1 to NumCycles
  rec = ''
  rec = convert(" ", "", oconv(DateInt,'DYMD[4,2,2]'))
  write rec on TimeDimHash, i else
    print 'ERROR: Unable to write to ' : FileNameOnDisk : '!'
    stop
  end
  DateInt += 1
next i

close TimeDimHash
Ans = 0
return(Ans)
When this routine has run, the column in the hash file contains the record number. When I add another column into the UV dictionary like this...

Code: Select all

INSERT INTO DICT Time_D_Keys(@ID, F1, LOC, FORMAT) VALUES ('TestColumn', 'D', 2, '8L');
...then I see the date values in the second column (TestColumn), but that's not what I want. I need the column with the date values to be a key. :?
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
datastage
Participant
Posts: 229
Joined: Wed Oct 23, 2002 10:10 am
Location: Omaha

Post by datastage »

My UniVerse skills are moderate, and there are some UniVerse gurus on this forum so I'll let them answer you in detail.

But if you didn't know, or the others didn't know, IBM provides on its website a 2-user free license for UniVerse 10 Personal Edition so you can have lots of fun on Saturday nights enhancing your UniVerse skills.

http://www-306.ibm.com/software/data/u2/universe/

Saturday night has never been this fun! And if you don't have anything to do Friday night there is the same for UniData 6.
Byron Paul
WARNING: DO NOT OPERATE DATASTAGE WITHOUT ADULT SUPERVISION.

"Strange things are afoot in the reject links" - from Bill & Ted's DataStage Adventure
mleroux
Participant
Posts: 81
Joined: Wed Jul 14, 2004 3:18 am
Location: Johannesburg, South Africa
Contact:

Post by mleroux »

I love being married to a beautiful woman. 8) Now I never have to stare at a PC on a Saturday night anymore. Oh hang on, I never did, except in the hard-core gamer days...

Anyway, I downloaded all the UniVerse manuals from http://www-306.ibm.com/software/data/u2 ... ry/96univ/. That seems enough fun for now!

I tried modifying the routine so that the key (and recno) is the date key, but now I just sit with an empty hash file:

Code: Select all

FileNameOnDisk = "Time_D_Keys"

open FileNameOnDisk to TimeDimHash else
  print 'ERROR: Unable to open ' : FileNameOnDisk : '!'
  stop
end

clearfile TimeDimHash
* StartDate is an arg with YYYY-MM-DD HH:MM:SS format.
DateInt = Iconv(MatchField(StartDate,"0X' '2N':'2N':'2N",1),"D-YMD[4,2,2]")
* NumCycles gets a + 1 at the end because the date range is inclusive
EndDateInt = Iconv(MatchField(EndDate,"0X' '2N':'2N':'2N",1),"D-YMD[4,2,2]") - DateInt + 1

for DateInt = DateInt to EndDateInt
  rec = ''
  rec = convert(" ", "", oconv(DateInt,'DYMD[4,2,2]'))
  write rec on TimeDimHash, DateInt else
    print 'ERROR: Unable to write to ' : FileNameOnDisk : '!'
    stop
  end
next i

close TimeDimHash
Ans = 0
return(Ans)
Suggestions still welcome!
Morney le Roux

There are only 10 kinds of people: Those who understand binary and those who don't.
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

This should be close enough.

Code: Select all

FileNameOnDisk = "Time_D_Keys" 

open FileNameOnDisk to TimeDimHash else 
  Cmd = "create.file Time_D_Keys 30"
  execute Cmd
   open FileNameOnDisk to TimeDimHash then
      open 'DICT', FileNameOnDisk to DictTimeDimHash then
         FieldName = "TimeKey"
         DictRec = ''
         DictRec<1> = 'D'
         DictRec<2> = 0
         DictRec<3> = ''
         DictRec<4> = FieldName
         DictRec<5> = "6R"
         DictRec<6> = "S"
         write DictRec on DictTimeDimHash, FieldName else stop
         DictRec = "PH"
         DictRec<1> = FieldName
         write DictRec on DictTimeDimHash, "@KEY" else stop
         FieldName = "DateYYYYMMDD"
         DictRec = ''
         DictRec<1> = 'D'
         DictRec<2> = 1
         DictRec<3> = ''
         DictRec<4> = FieldName
         DictRec<5> = "10R"
         DictRec<6> = "S"
         write DictRec on DictTimeDimHash, FieldName else stop
         DictRec = "PH"
         DictRec<1> = FieldName
         write DictRec on DictTimeDimHash, "@" else stop
      end else 
         print 'ERROR: Unable to open DICT ' : FileNameOnDisk : '!' 
         stop 
      end
   end else 
      print 'ERROR: Unable to open ' : FileNameOnDisk : '!' 
      stop 
   end 
end 
clearfile TimeDimHash 
* StartDate is an arg with YYYY-MM-DD HH:MM:SS format. 
DateInt = Iconv(StartDate, "D-YMD[4,2,2]")
EndDateInt = Iconv(EndDate, "D-YMD[4,2,2]")

for DateInt = DateInt to EndDateInt 
  rec = '' 
  rec = convert("-", "", oconv(DateInt,'D4-YMD[4,2,2]')) 
  write rec on TimeDimHash, DateInt else 
    print 'ERROR: Unable to write to ' : FileNameOnDisk : '!' 
    stop 
  end 
next DateInt

close TimeDimHash 
Ans = 0 
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I would have created the hashed file with CREATE TABLE, which builds the dictionary for you. (SO does creating the hashed file from a Hashed File stage!)

Code: Select all

CREATE TABLE Time_D_Keys
(
   TimeKey CHAR(8) NOT NULL PRIMARY KEY
);
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
yserrano
Premium Member
Premium Member
Posts: 52
Joined: Thu Jan 31, 2008 1:23 pm
Location: Santo Domingo

Post by yserrano »

Please excuse me for bringing up this old thread.

I am hoping that someone could explain some doubts I have about ray.wurlod post:
I would have created the hashed file with CREATE TABLE, which builds the dictionary for you.
Is it possible? When you create a table a hashed file is created?
It looks much more simple than kduke code, but are both methods equivalent?
Could I call the Create Table function from an After/Before routine or from the job's Job Control?
Is the hashed file created outiside the universe (in a file directory)?

I am using version 8 server.

Thank you,

yserrano
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

First, an alternative to the original question. What gets displayed by a query is governed by an entry called @SELECT or @ in the file dictionary.

Code: Select all

INSERT INTO DICT Time_D_Keys(@ID, F1, F2) VALUES ('@', 'PH', 'TimeKey ID.SUP');
Now to your more recent questions.
yserrano wrote:When you create a table a hashed file is created?
Yes
yserrano wrote:It looks much more simple than kduke code, but are both methods equivalent?
Yes, with one exception - a hashed file created with CREATE TABLE must be deleted with DROP TABLE.
yserrano wrote:Could I call the Create Table function from an After/Before routine or from the job's Job Control?
Yes, through ExecUV in the former case and DSExecute in the latter.
yserrano wrote:Is the hashed file created outiside the universe (in a file directory)?
By default no but this can be managed with DATA and DICT clauses in the CREATE TABLE statement itself.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
yserrano
Premium Member
Premium Member
Posts: 52
Joined: Thu Jan 31, 2008 1:23 pm
Location: Santo Domingo

Post by yserrano »

Yes, through ExecUV in the former case and DSExecute in the latter.
Is it possible to run this routine to create the hashed file from outside a Job?, i mean, through an API or something like that?

Regards


Edit: I am currently reading the Universe System Description manual, so I will probably have an answer for tomorrow and will be sharing it here. But please feel free to help if you'd like to.

Edit: Many thanks to ray.wurlod and the other posters for their help.
yserrano
Premium Member
Premium Member
Posts: 52
Joined: Thu Jan 31, 2008 1:23 pm
Location: Santo Domingo

Post by yserrano »

Hello,
After several tests and reading I achieved what I needed.
Developing ray.wurlod's suggestion I am using the CREATE TABLE statement to generate the hashed files.
It was not easy because of my poor knowledge of the UniVerse interface. Here are some basic tips for those who may need them.

- From a command prompt I moved to my project directory.
- Used the UniVerse shell (uvsh) to run the CREATE TABLE command.
- In order to create the hashed files outside of the universe, I used the DATA and DICT options.
- Tested in Designer the hashed files using the View Data option.

It is worth mention that there are several ways to achieve this (see above suggestions).

Thank you all,

yserrano
Post Reply