Skip to main content
Alan Warren
New Participant
Jan 5, 2022 9:38 AM UTC
Question

Criteria Apply Differently in LIST vs SELECT

Hi Folks,

First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

I've got a computed column ADDR.G82.SANITY.CHECK defined as
SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
SAVE.LIST CNADDR
GET.LIST CNADDR
LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
<<lists 922 correct records>>

Trying it with SELECT
GET.LIST CNADDR
SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
<<returns two records, not 922>>

The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    18 replies

    Manu Fernandes
    Inspiring
    Jan 5, 2022 2:43 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Hi

    In uniquery/retrieve you can't nest SELECT in subr of I-type. 
    Your subselect return error, Check the capturing. 

    When I need it, I build a index key and use BASIC SELECTINDEX inside the subr of the itype, it works very good. 

    Do you need a sample ? 
    Alan Warren
    New Participant
    Jan 5, 2022 2:56 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Thanks for the response @Manu Fernandes!  I seem to have picked the wrong format for this question, as I can't reply to you and have to post my reply as an "answer".

    Constantly learning :)

    I'm not sure what you mean by "check the capturing"​...like executing the select with a "-C"?  Unfortunately I've got a vendor layer between my code and the generated I-type subroutine. 

    The SELECTINDEX idea sounds brilliant, but our VAR's tooling prohibits me from using SELECTINDEX or their own S.GET.INDEX.

    I can't for the life of me find a document saying "thou shalt not select from a computed column", such a document would be great to send to my VAR as their tooling actually facilitates it.

    I guess I'll have to consider re-working my design to allow key based access to my validation file, or writing this bit of functionality outside of my vendor's supported tooling
    Manu Fernandes
    Inspiring
    Jan 5, 2022 5:09 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Re

    Has I understand, into CC.G82.ADDRESS.SANITY.CHECK there is EXECUTE 'SELECT....'

    You can put a CAPTURING to retrieve the error. 

    More over, into UVHOME directory there is a 'errrlog' file which log all execution error. You can read yours into. 

    If the uv/errlog file did not existe create it. (touch)  with everybody write right. Then rerrun your sample. 
    All errors appears into errlog file. 

    Regards
    Alan Warren
    New Participant
    Jan 5, 2022 7:49 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Thanks again Manu,

    We're on UniData but I was able to ​enable error logging by creating 
    /usr/ud82/include/msglevelconfig

    I wasn't seeing any error output in there, so I added a syntax error to the criteria, re-compiled and sure enough getting lots of great info in $UDTBIN/udt.errlog.

    So, applying the select in the I-SUBR isn't generating an error.  Perhaps UniData is more permissive on this than Universe?

    I tried adding a capturing, but I can't seem to make anything appear on the output on the console or the udt.errlog.
    Jonathan Smith
    Rocketeer
    Jan 6, 2022 7:36 AM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Alan,

    Firstly does the ADDRESS file have an index on the ADDR.G82.SANITY.CHECK field. If you do a LIST.INDEX ADDRESS at ECL it will tell you which fields are indexed.
    A SELECT command will use an Index if present, if the index is 'stale' then this would account for the behaviour you are seeing, as a SELECT will use the value in the index not the value (or calculated value) from the file. A LIST command will display the value (or calculated value) on the file at the time the LIST command is issued.

    We do issue warnings about indexing on caculated or derived values,  a simple example is having a file with a customer number in it and having a dictionary using a TRANSLATE function to the 'CUSTOMERS' file to get the customer name. You can create an index on your file indexing against the name from the CUSTOMERS file. However if the CUSTOMERS file is upated with a new name then the index on your file is now incorrect and has become stale. The reason being the CUSTOMERS file knows nothing about the index on your file. Another example would be to create an index on someone's age from their date of birth, this will become stale very quickly.

    This could be the same situation that you are seeing if the ADDR.G82.SANITY.CHECK field is indexed and relies on calculated or derived information.

    There is a tool called guide_ndx which can be used to check not just the physical condition of an index in UniData but also the logical condition of the file and report mismatches between what is in the file and what is indexed.

    So if ADDR.G82.SANITY.CHECK is indexed then the command 'guide_ndx -x3,ADDR.G82.SANITY.CHECK ADDRESS' will check the index file for both logical and physical errors. The output files from the command will be called GUIDE_XERROR.LIS and GUIDE_XSTATS.LIS

    If GUIDE_XERROR.LIS contains any errors then the index will be need to rebuilt, the quickest way is to delete the index, recreate it and build again. This in itself comes with some extra warnings if you need to do this.

    As a first step, check to see if the field is indexed, and if it is indexed run guide_ndx at level 3 to report any errors and we can then discuss next steps.
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    David Green
    Inspiring
    Jan 6, 2022 7:40 AM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Alan,

    In your subroutine try to save off @ID, @RECORD, and @DICT.  Then restore them before exiting.​​
    Ian McGowan
    Participating Frequently
    Jan 6, 2022 1:37 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    If the subroutine CC.G82.ADDRESS.SANITY.CHECK is doing a SELECT statement internally, it's probably overwriting the default select list 0.  The two records you get are from whatever the last ADDRESS record selects.  If you can change the sub, doing something like EXECUTE "SELECT BLAH FROM ADDRESS..." RTNLIST SANITY.CHECK and then where you use that (perhaps with another execute, add PASSLIST SANITY.CHECK, or if it's a readnext do READNEXT ID FROM SANITY.CHECK), that might help.

    I think Manu is saying the same thing, but I'm not into that whole brevity thing or whatever man :-)
    Shawn Waldie
    Jan 6, 2022 1:45 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Alan, I'm a colleague developer.
    There are a few ways you can protect your incoming savedlist, and if you send a snippet of your code, I can offer a suggestion or two.
    Jonathan Smith
    Rocketeer
    Jan 6, 2022 3:57 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    Looking at Alan's description more carefully it's unlikely to be an index problem and will be a problem with using mutilple select lists (the advice I gave on index checking and virtual attributes etc is still good troubleshooting advice).

    If we could see the code involved we would know how to avoid the problem you are seeing as it appears the SELECT statement using the WITH clause is destroying select list 0 in the subroutine where the LIST statement using the same WITH condition is not destroying select list 0.

    If you could provide the code for "CC.G82.ADDRESS.SANITY.CHECK" we should be able to work out what is going on and where the protection needs to go in the code.
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS
    Jonathan Smith
    Rocketeer
    Jan 6, 2022 4:35 PM UTC
    Hi Folks,

    First time posting here, but I've been working with UniData for about 5 years now after mostly working with MySQL and Oracle databases.    We get UniData through a VAR, but I'm pretty sure they think I'm crazy so hoping to get some wisdom from the community here.

    I've got a computed column ADDR.G82.SANITY.CHECK defined as
    SUBR("CC.G82.ADDRESS.SANITY.CHECK",COUNTRY,STATE,ZIP)

    The subroutine opens another entity and selects against it to try to match postal code first letter to province and state to ZIP to see if addresses look "sane".

    If I use the computed column in SELECT criteria with an active list, it fails with wildly wrong results.  However, if I execute a
    SELECT ADDRESS WITH COUNTRY = 'CN' SAMPLE 1000
    SAVE.LIST CNADDR
    GET.LIST CNADDR
    LIST ADDRESS COUNTRY STATE ZIP WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<lists 922 correct records>>

    Trying it with SELECT
    GET.LIST CNADDR
    SELECT ADDRESS WITH ADDR.G82.SANITY.CHECK = 'Y'
    <<returns two records, not 922>>

    The generated code does do some list protection, but I'm wondering if SELECT possibly does some parallel processing that make list protection logic prone to failure when executed in computed columns?

    So, I guess I'm hoping someone can shed some light on the internals of select vs list criteria application.  Or if there are best practices for applying select criteria in a CC subroutine?

    I beleive the problem that Alan is seeing can be demostrated using the UniData demo account

    I wrote a simple program called ADD.CHECK

    SUBROUTINE ADD.CHECK(RET.VALUE,STATE,ZIP)
    EXECUTE 'SELECT STATES WITH @ID = ' : DQUOTE(STATE) CAPTURING SCREEN
    IF SYSTEM(11) = 0 THEN RET.VALUE = 0 ELSE RET.VALUE = 1
    END

    I compiled and cataloged the program
    I then added a dictionary into the CUSTOMER file called ADD.SAN.CHECK

    001: I
    002: SUBR("ADD.CHECK",STATE,ZIP)
    003:
    004: Add Check
    005: 1R
    006: S

    I then did a CD CUSTOMER before using the new dictionary

    At ECL if you do LIST CUSTOMER WITH ADD.SAN.CHECK = 1 STATE ZIP you will see the results you expect (15 in my case)

    LIST CUSTOMER WITH ADD.SAN.CHECK = 1 STATE ZIP 21:40:03 06 Jan 2022 1
    Cust...... ST Zip Code

    12 WI 98733
    3 NY 10017
    201 CO 80209
    204 CO 80209-44
    44
    207 CO 80209
    210 WI 53140
    190 CO 80301
    202 CO 80403
    4 WI 53140
    25 WI 53142
    208 KS 50505
    206 CO 80209
    11 TX 60606
    8 WI 50208
    2 CO 80443
    15 records listed

    If you however do SELECT CUSTOMER WITH ADD.SAN.CHECK = 1 you get the following

    1 records selected to list 0.

    >

    So there is a difference in the way UniData itself is dealing the two commands.

    The problem is also further complicated if you do the following

    SELECT CUSTOMER WITH STATE
    SAVE.LIST JDS
    GET.LIST JDS
    LIST CUSTOMER STATE ZIP ADD.SAN.CHECK
    LIST CUSTOMER STATE ZIP ADD.SAN.CHECK 21:51:53 06 Jan 2022 1
    Cust...... ST Zip Code Add Check

    12 WI 98733 0
    1 record listed

    So in summary the problem is complicated by the data and program itself, without seeing the whole program and the files being used it will be very difficult to advise on a process that will allow this to work everytime. We can look at looking other select lists other than 0 or even using a SELECTINDEX but we need to see everything that is going on.
    Rocket Software - Senior Principal Technical Support Engineer - UniData ATS