Skip to main content
Matthew Wright
Participating Frequently
Jan 10, 2023 7:42 PM UTC

Remove an item from a SELECT list?

Please excuse a basic question. but is it possible to delete an item from a select list like you can with an array?

SelStr = ' WITH ORD.CODE = "A"  AND ORD.SHIP.DATE < "1/01/2023"'
XCmd = 'SSELECT ORDERS' : SelStr : ' TO 1'
CRT XCmd ; EXECUTE XCmd
  LOOP
    READNEXT ORD.ID FROM 1 ELSE EXIT
          IF ORD.ID = 12192209 THEN
      DELETE ORD.ID FROM 1?????
         END
   REPEAT
END

------------------------------
Matthew Wright
Analyst
Tomago Aluminium Co PTY Ltd.
Tomago NSW AU
------------------------------

    10 replies

    David Green
    Inspiring
    Jan 10, 2023 7:55 PM UTC
    Please excuse a basic question. but is it possible to delete an item from a select list like you can with an array?

    SelStr = ' WITH ORD.CODE = "A"  AND ORD.SHIP.DATE < "1/01/2023"'
    XCmd = 'SSELECT ORDERS' : SelStr : ' TO 1'
    CRT XCmd ; EXECUTE XCmd
      LOOP
        READNEXT ORD.ID FROM 1 ELSE EXIT
              IF ORD.ID = 12192209 THEN
          DELETE ORD.ID FROM 1?????
             END
       REPEAT
    END

    ------------------------------
    Matthew Wright
    Analyst
    Tomago Aluminium Co PTY Ltd.
    Tomago NSW AU
    ------------------------------
    Matthew,

    A READNEXT consumes a select list.  So by doing the READNEXT it is already deleted from the list.

    So you could just do something like:

    ...
    IF ORD.ID = 12192209 THEN
       NULL
    END ELSE
      ...
    END
    (This is my preferred method, then if something changes it is easily added to.)

    You could also use CONTINUE
    IF ORD.ID = 12192209 THEN CONTINUE
    (I don't like this method, i think all loops should have one entrance and one exit.)

    You could convert the Active Select List into an Array, then delete what you want out of the array.  See FORMLIST and READLIST.
    From UniQuery you can use MERGE.LIST to manipulate your select list.

    ------------------------------
    David Green
    Computer Programmer
    Rocket Forum Shared Account
    ------------------------------
    Matthew Wright
    Participating Frequently
    Jan 10, 2023 8:10 PM UTC
    Matthew,

    A READNEXT consumes a select list.  So by doing the READNEXT it is already deleted from the list.

    So you could just do something like:

    ...
    IF ORD.ID = 12192209 THEN
       NULL
    END ELSE
      ...
    END
    (This is my preferred method, then if something changes it is easily added to.)

    You could also use CONTINUE
    IF ORD.ID = 12192209 THEN CONTINUE
    (I don't like this method, i think all loops should have one entrance and one exit.)

    You could convert the Active Select List into an Array, then delete what you want out of the array.  See FORMLIST and READLIST.
    From UniQuery you can use MERGE.LIST to manipulate your select list.

    ------------------------------
    David Green
    Computer Programmer
    Rocket Forum Shared Account
    ------------------------------
    Thanks for the quick reply David thats cleared a few things up for me.

    I probably should have mentioned what my ultimate aim is,

    For the given select list - I want to loop through each item in the list, and check if a record exists on another file with the same ID
    If there is no matching record, I wanted to remove the item from the select list, and then continue to use that select list further down in the program with the bad values removed.

    But it sounds like the best way would be to convert the select list to an array, process it, and then convert that array back to a select list?


    ------------------------------
    Matthew Wright
    Analyst
    Tomago Aluminium Co PTY Ltd.
    Tomago NSW AU
    ------------------------------
    Manu Fernandes
    Inspiring
    Jan 11, 2023 2:15 AM UTC
    Thanks for the quick reply David thats cleared a few things up for me.

    I probably should have mentioned what my ultimate aim is,

    For the given select list - I want to loop through each item in the list, and check if a record exists on another file with the same ID
    If there is no matching record, I wanted to remove the item from the select list, and then continue to use that select list further down in the program with the bad values removed.

    But it sounds like the best way would be to convert the select list to an array, process it, and then convert that array back to a select list?


    ------------------------------
    Matthew Wright
    Analyst
    Tomago Aluminium Co PTY Ltd.
    Tomago NSW AU
    ------------------------------
    hi Matthew,

    I suggest you use :

    SELECT fileA 
    SELECT fileB 

    the result is a list of existing from B limited by A 

    manu

    ------------------------------
    manu fernandes
    ------------------------------
    Participating Frequently
    Jan 11, 2023 7:14 AM UTC
    hi Matthew,

    I suggest you use :

    SELECT fileA 
    SELECT fileB 

    the result is a list of existing from B limited by A 

    manu

    ------------------------------
    manu fernandes
    ------------------------------

    Hi Matthew,

    picking up on Manus suggestion.

    i would Externally select FileA, outside of the program but use an "I descriptor" to do the checking on the second File, if the record exists, as this means if FileB has a different Key you can still  check, then save your list, then in your program rather than Execute Select you Execute Get list

    Thanks

    Andy



    ------------------------------
    Andrew Milne
    Business Systems Manager
    Potter and Moore Innovations
    Peterborough, Cambs GB
    ------------------------------
    Tyrel Marak
    Participating Frequently
    Jan 11, 2023 8:01 AM UTC

    Hi Matthew,

    picking up on Manus suggestion.

    i would Externally select FileA, outside of the program but use an "I descriptor" to do the checking on the second File, if the record exists, as this means if FileB has a different Key you can still  check, then save your list, then in your program rather than Execute Select you Execute Get list

    Thanks

    Andy



    ------------------------------
    Andrew Milne
    Business Systems Manager
    Potter and Moore Innovations
    Peterborough, Cambs GB
    ------------------------------
    Matthew,

    Following up with the last two posts:

    1. In your BASIC program, if you want to do what Manu suggests, you can do it with something like this:
      STMTS = 'SELECT FILEA'
      STMTS<-1> = 'SELECT FILEB TO 1'
      EXECUTE STMTS
      Alternatively you could
      STMTS = 'SELECT FILEA'
      STMTS<-1> = 'SELECT FILEB'
      EXECUTE STMTS RTNLIST MYLIST
      LOOP WHILE READNEXT ID FROM MYLIST DO...
    2. If you don't want the multiple statements and want to use Andrew's suggestion, the I-Type would be something like:
      TRANS(FILEB,@ID,0,'X') = @ID
      That gives you 0 for not also in FILEB, or 1 for also in FILEB, so if the I-Type in FILEA is called ALSOB, then you could
      SELECT FILEA WITH ALSOB = 0

    Obviously this is rough, but I think you get the idea. 

    For more complicated selections, you can combine SELECT ... TO n statements with MERGE.LIST n1 ... n2 TO n3 statements.  You can accomplish some very complicated intersections, unions, etc using this approach.  If you follow #1 above, you can have a string of STMTS executed in one go ending in exactly the keys you're looking for.  Doing this, you can also more easily leverage indices on your files.

    At any rate, I hope you find some of this helpful.

    Thanks,

    ------------------------------
    Tyrel Marak
    Technical Support Manager
    Aptron Corporation
    Florham Park NJ US
    ------------------------------
    Mike Rajkowski
    Rocketeer
    Jan 11, 2023 3:51 PM UTC
    Please excuse a basic question. but is it possible to delete an item from a select list like you can with an array?

    SelStr = ' WITH ORD.CODE = "A"  AND ORD.SHIP.DATE < "1/01/2023"'
    XCmd = 'SSELECT ORDERS' : SelStr : ' TO 1'
    CRT XCmd ; EXECUTE XCmd
      LOOP
        READNEXT ORD.ID FROM 1 ELSE EXIT
              IF ORD.ID = 12192209 THEN
          DELETE ORD.ID FROM 1?????
             END
       REPEAT
    END

    ------------------------------
    Matthew Wright
    Analyst
    Tomago Aluminium Co PTY Ltd.
    Tomago NSW AU
    ------------------------------
    In addition to the other suggestions provide, you can also use the MERGE.LIST command.

    i.e.

    Assume you have two files.

    LIST ONE 12:43:04 Jan 11 2023 1
    ONE.......

    1
    2
    3
    3 records listed

    LIST TWO 12:43:49 Jan 11 2023 1
    TWO.......

    1
    3
    2 records listed


    :SELECT ONE TO 1

    3 records selected to list 1.

    :SELECT TWO TO 2

    2 records selected to list 2.

    :MERGE.LIST 1 INTERSECT 2
    2 record(s) selected.

    ------------------------------
    Mike Rajkowski
    MultiValue Product Evangelist
    Rocket Internal - All Brands
    DENVER CO US
    ------------------------------
    Peter Cheney
    Participating Frequently
    Jan 11, 2023 5:57 PM UTC
    Please excuse a basic question. but is it possible to delete an item from a select list like you can with an array?

    SelStr = ' WITH ORD.CODE = "A"  AND ORD.SHIP.DATE < "1/01/2023"'
    XCmd = 'SSELECT ORDERS' : SelStr : ' TO 1'
    CRT XCmd ; EXECUTE XCmd
      LOOP
        READNEXT ORD.ID FROM 1 ELSE EXIT
              IF ORD.ID = 12192209 THEN
          DELETE ORD.ID FROM 1?????
             END
       REPEAT
    END

    ------------------------------
    Matthew Wright
    Analyst
    Tomago Aluminium Co PTY Ltd.
    Tomago NSW AU
    ------------------------------
    Hi Matthew,

    If I had to avoid a particular record id then I'd probably do something like the below and specify the select list too. My preference is to avoid exit and continue commands. The 'loop while readnext' will be true as long as there's something to read from idList.

    If the record id you want to avoid changes or there are multiple record id's to avoid then reading them in from a control would be one option. If they were value mark separated you could use matches 'matches' instead.

    execute XCmd rtnlist idList capturing output
    loop while readnext ORD.ID from idList do
    * Option 1. Just one constant id to avoid
     if ORD.ID # 12192209 then
    * process your records as desired
    end
    * Option 2. Avoiding a changing list of id's
    if ORD.ID matches 12192209:@vm:12192210:@vm:12192211 else
    * process your records as desired
    end
    repeat
    ​Hope this helps.
    Cheers,
    Peter

    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Doug Averch
    Inspiring
    Jan 12, 2023 11:25 AM UTC
    Hi Matthew,

    If I had to avoid a particular record id then I'd probably do something like the below and specify the select list too. My preference is to avoid exit and continue commands. The 'loop while readnext' will be true as long as there's something to read from idList.

    If the record id you want to avoid changes or there are multiple record id's to avoid then reading them in from a control would be one option. If they were value mark separated you could use matches 'matches' instead.

    execute XCmd rtnlist idList capturing output
    loop while readnext ORD.ID from idList do
    * Option 1. Just one constant id to avoid
     if ORD.ID # 12192209 then
    * process your records as desired
    end
    * Option 2. Avoiding a changing list of id's
    if ORD.ID matches 12192209:@vm:12192210:@vm:12192211 else
    * process your records as desired
    end
    repeat
    ​Hope this helps.
    Cheers,
    Peter

    ------------------------------
    Peter Cheney
    Developer and Systems Superstar
    Firstmac
    Brisbane Qld Australia
    ------------------------------
    Here is a simple code proposal that will run on Universe, Unidata, and others:
         EXECUTE Xcmd
         READLIST ORG.LIST FROM 1 ELSE STOP
         NEW.LIST = ORG.LIST
         MAX.FM = DCOUNT(VAR,@FM)
         FOR X = MAX.FM TO 1 STEP -1
            ORD.ID = ORG.LIST<X>
            IF ORD.ID = 121921209 THEN
               DEL NEW.LIST<X>
            END
         NEXT X
    ​

    Posted: 01-12-2023 11:23



    ------------------------------
    Doug Averch
    Owner
    U2 Logic
    ------------------------------
    Doug Averch Owner https://www.u2logic.com/
    Participating Frequently
    Jan 12, 2023 3:54 PM UTC
    hi Matthew,

    I suggest you use :

    SELECT fileA 
    SELECT fileB 

    the result is a list of existing from B limited by A 

    manu

    ------------------------------
    manu fernandes
    ------------------------------
    I'd like to suggest a slight amendment to Manu's SELECT then SELECT suggestion.

    SELECT fileA
    SELECT fileB REQUIRE.SELECT

    The 'REQUIRE.SELECT' keyword will cause no items to be returned IF the first SELECT command returned no items.

    An example of where this would be useful would be:

    SELECT TRANSACTIONS WITH TRAN.DATE = "01.01.2023" AND WITH CUSTOMER = "12345"
    SELECT TRANSACTIONS.PENDING

    In the above if the first SELECT returned no records, the second select would return the entire contents of the TRANSACTIONS.PENDING file. Which would be incorrect.
    By adding the REQUIRE.SELECT to the second SELECT command, no records would be returned. Which would be a correct result.

    Regards,


    ------------------------------
    Bruce Philp
    Senior Services Consultant
    Meier Business Systems PTY LTD
    Carnegie VIC AU
    ------------------------------
    Peter Cheney
    Participating Frequently
    Jan 12, 2023 5:43 PM UTC
    I'd like to suggest a slight amendment to Manu's SELECT then SELECT suggestion.

    SELECT fileA
    SELECT fileB REQUIRE.SELECT

    The 'REQUIRE.SELECT' keyword will cause no items to be returned IF the first SELECT command returned no items.

    An example of where this would be useful would be:

    SELECT TRANSACTIONS WITH TRAN.DATE = "01.01.2023" AND WITH CUSTOMER = "12345"
    SELECT TRANSACTIONS.PENDING

    In the above if the first SELECT returned no records, the second select would return the entire contents of the TRANSACTIONS.PENDING file. Which would be incorrect.
    By adding the REQUIRE.SELECT to the second SELECT command, no records would be returned. Which would be a correct result.

    Regards,


    ------------------------------
    Bruce Philp
    Senior Services Consultant
    Meier Business Systems PTY LTD
    Carnegie VIC AU
    ------------------------------
    If you wanted to execute a external selects then you could also use a 'passlist' to pass records from the first select to the second.
    ------------------------------------------------------------------------------- Note: This email (inc all attachments) is for the use of the intended recipient(s) only. Privileged or confidential information may be contained in this communication. If you have received this email in error, please notify the sender immediately and then delete all copies of this message from your computer network. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this email without the author's prior permission. If you are the intended recipient and you do not wish to receive similar electronic messages from us in future, then please respond to the sender to this effect. We have taken precautions to minimise the risk of transmitting software viruses, but advise you to carry out your own virus checks on this email and its attachments. We do not accept liability for any loss or damage caused by software viruses and do not represent that this transmission is free from viruses or other defects. Firstmac Limited (ABN 59 094 145 963) (AFSL 290600)