Skip to main content
KathleenHambrick
Participating Frequently
May 26, 2022 12:25 PM UTC

Using Indexes within basic

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
------------------------------

    15 replies

    Participating Frequently
    Jun 9, 2022 1:28 PM UTC
    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
    ------------------------------
    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
    ------------------------------
    Tyrel Marak
    Participating Frequently
    Jun 9, 2022 2:04 PM UTC
    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
    ------------------------------
    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
    ------------------------------
    Participating Frequently
    Jun 9, 2022 2:27 PM UTC
    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
    ------------------------------
    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
    ------------------------------
    KathleenHambrick
    Participating Frequently
    Jun 9, 2022 2:29 PM UTC
    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
    ------------------------------
    Tyrel, the doc say reset is ignored if using the ID (record) as Osvaldo is.... have you found differently?

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    Tyrel Marak
    Participating Frequently
    Jun 9, 2022 2:53 PM UTC
    Tyrel, the doc say reset is ignored if using the ID (record) as Osvaldo is.... have you found differently?

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    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
    ------------------------------