Rocket U2 | UniVerse & UniData

 View Only
Expand all | Collapse all

Using Indexes within basic

  • 1.  Using Indexes within basic

    Posted 05-26-2022 12:25
    I remember being able to open an index file on Universe within basic and reading the records in an xref type fashion. Where I am working now isn't using indexes but rather executing multiple external selects from within a program, not ideal.

    Does anyone have a simple ditty showing how to open this file within the basic program? Anything special about the VOC entry for the index file?

    Thanks,
    Kathleen

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------


  • 2.  RE: Using Indexes within basic

    PARTNER
    Posted 05-26-2022 12:29
    Hi 

    Check BSCAN it's the response of your needs.

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------



  • 3.  RE: Using Indexes within basic

    Posted 05-26-2022 15:30
    Looking into this but no, I used to have a voc pointer to the index file itself - not the data file - and I could open that file within basic and read from it...

    Thank you for this BSCAN option.

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------



  • 4.  RE: Using Indexes within basic

    PARTNER
    Posted 05-26-2022 15:42
    So Yes you can define a voc entre, to adress the index file type 25, 
    001 F
    002 I_File/INDEX00x
    003 D_VOC

    Use basic INDICES() to define the 00x. 

    If you use openpath no need for a voc define. 

    A BSCANgive the same as a read on t25 file without complex work to open it. 

    Regards 


    ------------------------------
    Manu Fernandes
    ------------------------------



  • 5.  RE: Using Indexes within basic

    Posted 05-26-2022 18:02
    Got this to work... but had to use the option on line2...unfortunately that causes other issues... cant get it to work with named list numbers.  Anyone?

    0001: OPEN 'SOH.PL' TO F.FILE ELSE STOP
    0002: $OPTIONS INFORMATION
    0003: SELECTINDEX "BASE","P1180" FROM F.FILE TO 1
    0004: READLIST IDS FROM 1 THEN
    0005: MAX=DCOUNT(IDS,@AM)
    0006: FOR JJ = 1 TO MAX
    0007: PRINT IDS<JJ>
    0008: NEXT JJ
    0009: END ELSE
    0010: PRINT 'NONE'
    0011: END
    0012: END

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------



  • 6.  RE: Using Indexes within basic

    PARTNER
    Posted 05-27-2022 07:39
    Edited by Tyrel Marak 05-27-2022 07:40
    Hi Kathleen,

    We all have our favorite ways of doing things :-).  I know you want to use SELECTINDEX, but BSCAN will get you what you want.

    OPEN 'SOH.PL' TO F.FILE ELSE STOP
    UN = ''; IDS = ''
    BSCAN UN,IDS FROM F.FILE,'PL180' USING 'BASE' RESET ELSE STOP
    IF UN # 'PL180' THEN STOP
    MAX = DCOUNT(IDS,@AM)
    etc...

    I think I have that right, but I've never really used SELECTINDEX, so I may have confused the key and the name of the index.  Also, the "ELSE STOP" and "THEN STOP" could be made more useful, but this is just a roughed out example based on your code above.  At any rate, maybe that will help.

    ------------------------------
    Tyrel Marak
    Technical Support Manager
    Aptron Corporation
    Florham Park NJ US
    ------------------------------



  • 7.  RE: Using Indexes within basic

    Posted 05-27-2022 08:58
    oh, no, I dont want to use selectindex - I wanted to open the file and read directly. No objection to bscan over selectindex and if i dont have to change options it would be a bonus! There was no working example I could find but I will try what you wrote here now.

    If I get a working example of something I can usually apply it - thanks Tyrel

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------



  • 8.  RE: Using Indexes within basic

    Posted 05-27-2022 09:37
    Got this to work - THANKS MANU & TYREL!

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------



  • 9.  RE: Using Indexes within basic

    Posted 05-27-2022 10:30
    I occasionally have cause to make a voc pointer lke that:
    001 F
    002 I_File/INDEX00x
    003 D_VOC    --->    But 003 D_UVIDX  instead.

    D_VOC doesn't make a lot of sense since indexes are not structured like VOCs.

    My dict looks something like this   (I don't know how to format with fixed width font here):

    Dct Id. @ID
    Type... D
    F2..... 0
    FORMAT. 20L
    F6..... S

    Dct Id. @REC
    Type... I
    F2..... LOWER( @RECORD )
    FORMAT. 30L
    F6..... M

    Dct Id. BYTES
    Type... I
    F2..... LEN( @RECORD ) + LEN( @ID ) + 24

    Dct Id. LINES
    Type... I
    F2..... DCOUNT( @RECORD, @AM )

    Dct Id. PRIMARY.TBL
    Type... I
    F2..... MATCHFIELD( SUBR( '*FSTAT', @FILENAME, 'PATH' ), "0X'I_'0X'\'0X", 3 )

    Dct Id. XVFY
    Type... I
    F2..... EQS( XLATE( PRIMARY.TBL, @RECORD, [indexed field], 'X' ), REUSE( @ID ) )
    FORMAT. 10L

    FSTAT is my own sub that returns info to a dict from FILEINFO() &/or STATUS statement.
    XLATE()  is like TRANS(), except the file nbame is resolved at runtime instead of compiled.

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    San Ignacio BZ
    ------------------------------



  • 10.  RE: Using Indexes within basic

    Posted 05-27-2022 10:03
    Edited by Chuck Stevenson 05-27-2022 10:21
    Depending on what you want to accomplish.

    SELECTINDEX is simpler.  I find it suits most of my needs.

    BSCAN is richer, but more complicated because it does more & harder to decipher for a novice maintenance programmer who has to read you program 5 years from now.    But if you need its richness, then it is simpler than all the code you'd have to write around SELECTINDEX to accomplish the same.

    EXECUTE "SELECT file WITH indexed.fld ..."
    If it's a single execution, say during the init of the program Is plenty fast on today's hw & more readable still.

    (I'm all about readability because it keeps a program maintainable.
    If it is correct, but unreadable, it will become incorrect.
    If it is incorrect, but readable, it will become correct.)

    ------------------------------
    Chuck Stevenson
    DBA / SW Developer
    Pomeroy
    San Ignacio BZ
    ------------------------------



  • 11.  RE: Using Indexes within basic

    Posted 05-27-2022 10:56
    Hello Kathleen,

    The VOC does not need any special configuration.  This is UniData SELECTINDEX code but I believe it works for Universe also.

    OPEN '',"UV.FILE.NAME" TO UV.FILE.NAME ELSE STOP "UV.FILE.NAME file issue"
    SELECTINDEX "INDEX.NAME", INFO.TO.SEARCH.FOR FROM UV.FILE.NAME

    Hope this helps!

    Sincerely, Steve Gleason

    ------------------------------
    Steve Gleason
    Senior Programmer Analyst
    Staar Surgical
    Monrovia CA US
    ------------------------------



  • 12.  RE: Using Indexes within basic

    Posted 06-09-2022 13:28
    Hi everyone.
    Regarding the subject of BSCAN:

    Could it be that there is an error in the documentation of the BSCAN command?

    It says that if [rec.variable] is specified after [ID.variable], then [rec.variable] will be assigned
    with the contents of the record whose ID is [ID.variable].

    I am using this command with a secondary index, but instead, this is what I get:
    [ID.variable] has the same value as [record], and [rec.variable] has the ID of the record I'm looking for.

    Example:

    BSCAN XX, YY FROM FILE.A, "432010" USING "INDEXNAME" BY "A" THEN...

    In this case, XX="432010" and YY="04" (@ID of the record I'm searching)
    And the contents of the record is missing.

    Any thoughts?

    ------------------------------
    Osvaldo Djivelekian
    Senior Developer
    Seguros Sura Chile
    Santiago CL
    ------------------------------



  • 13.  RE: Using Indexes within basic

    PARTNER
    Posted 06-09-2022 14:04
    Osvaldo,

    Using BSCAN to sift through an index won't give you records, only keys.  Before using BSCAN, set XX and YY to blank.  Then after using BSCAN, the XX is the current match and YY the keys associated with that match.  BSCAN can be used for more than indices, but in the case of an index, you should just get XX being the same as what you were searching for (which you can test afterward).  Also, I've never had to use the BY clause, since an index isn't really stored in that way.  Finally, you should RESET, or subsequent runs will start where it left off and can cause problems.

    XX = ''; YY = ''
    BSCAN XX,YY FROM FILE.A,'432010' USING 'INDEXNAME' THEN
       IF XX = '432010' THEN
          LOOP
             REMOVE KEY FROM YY SETTING MORE
             READ REC FROM FILE.A,YY THEN
                do stuff
             END
          WHILE MORE REPEAT
       END
    END​

    ------------------------------
    Tyrel Marak
    Technical Support Manager
    Aptron Corporation
    Florham Park NJ US
    ------------------------------



  • 14.  RE: Using Indexes within basic

    Posted 06-09-2022 14:27
    Hi Tyrel.

    Thank you for your response.

    I'm taking into account your suggestions and I'll modify the routine accordingly.

    Regards.
    Osvaldo

    ------------------------------
    Osvaldo Djivelekian
    Senior Developer
    Seguros Sura Chile
    Santiago CL
    ------------------------------



  • 15.  RE: Using Indexes within basic

    Posted 06-09-2022 14:29
    Tyrel, the doc say reset is ignored if using the ID (record) as Osvaldo is.... have you found differently?

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------



  • 16.  RE: Using Indexes within basic

    PARTNER
    Posted 06-09-2022 14:53
    Hi Kathleen,

    That's what sticks in my head, but it's been years since I wrote my first prototype.  There were several possible inputs, so there was an internal subroutine to do the BSCAN over and over.  I recall that anything after the first input did not work, but I fixed it with RESET.  I've never changed my approach since then.  I recall thinking that it shouldn't have been a problem, but just went with it.  If I get time, I'll do some tests.

    ------------------------------
    Tyrel Marak
    Technical Support Manager
    Aptron Corporation
    Florham Park NJ US
    ------------------------------