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

    Manu Fernandes
    Inspiring
    May 26, 2022 12:29 PM UTC
    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
    ------------------------------
    Hi 

    Check BSCAN it's the response of your needs.

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 26, 2022 3:30 PM UTC
    Hi 

    Check BSCAN it's the response of your needs.

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    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
    ------------------------------
    Manu Fernandes
    Inspiring
    May 26, 2022 3:42 PM UTC
    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
    ------------------------------
    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
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 26, 2022 6:02 PM UTC
    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
    ------------------------------
    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
    ------------------------------
    Tyrel Marak
    Participating Frequently
    May 27, 2022 7:39 AM UTC
    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
    ------------------------------
    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
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 27, 2022 8:58 AM UTC
    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
    ------------------------------
    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
    ------------------------------
    KathleenHambrick
    Participating Frequently
    May 27, 2022 9:37 AM UTC
    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
    ------------------------------
    Got this to work - THANKS MANU & TYREL!

    ------------------------------
    Kathleen Hambrick
    Programmer at Colwell
    ------------------------------
    Chuck Stevenson
    Participating Frequently
    May 27, 2022 10:03 AM UTC
    Hi 

    Check BSCAN it's the response of your needs.

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    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
    ------------------------------
    New Participant
    May 27, 2022 10:26 AM UTC
    Hi 

    Check BSCAN it's the response of your needs.

    Regards

    ------------------------------
    Manu Fernandes
    ------------------------------
    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
    ------------------------------
    Chuck Stevenson
    Participating Frequently
    May 27, 2022 10:30 AM UTC
    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
    ------------------------------
    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
    ------------------------------