unidata

Is there a way to check if a savedlist is empty in Unidata?


is there a way to check if a savedlist is empty in Unidata (and if so generate a new savedlist)?

The pseudo code would essentially be:
IF savedlist1 IS EMPTY
SELECT PERSON SAMPLE 1
SAVE.LIST savedlist1

(if not empty, leave the original savedlist1 as is)

An alternative approach is if a SELECT statement does not return any results, is there a way to prevent a savedlist from being created, like this:

create a savedlist in case nothing is selected for what I actually want
SELECT PERSON SAMPLE 1
SAVE.LIST savedlist1

create the savedlist of what I actually want, if it fails use the one above
SELECT PERSON WITH NAME EQ 'Bruce' REQUIRE.SELECT
SAVE.LIST savedlist1 (IF selection returned results)

I have tried adding REQUIRE.SELECT and SELECT.ONLY, but by the time it gets to the SAVE.LIST command the selection is terminated, and I just get "No active select list, creating empty saved list." Trying to add either to the SAVELIST line results in a syntax error.

The final way I thought to manage this is by appending the select statement to an existing savedlist, but I have not had luck with MERGE.LIST or TO with that:
SELECT PERSON WITH NAME EQ 'Bruce' TO savedlist1
TO can't be used with SELECT/COUNT/SUM/TAPE


Solution

  • Are you building a paragraph, if yes, you can check for @SYSTEM.RETURN.CODE (please check the manual for exact syntax). It will be -1 if nothing is selected.