$ListSav and $ListSave: Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 6: | Line 6: | ||
These $functions are used to save a $list to be later retrieved with the [[$ListRst] function or the [[$List_Global and $List_Session]] functions. $ListSav and $ListSave are used with $ListRst or $List_Global to pass a $list between separate requests. | These $functions are used to save a $list to be later retrieved with the [[$ListRst] function or the [[$List_Global and $List_Session]] functions. $ListSav and $ListSave are used with $ListRst or $List_Global to pass a $list between separate requests. | ||
The $ListSav and $ListSave functions accept one required argument and one optional argument and return a numeric result. Both are callable $functions . | The $ListSav and $ListSave functions accept one required argument and one optional argument and return a numeric result. Both are callable $functions (see [[Calling Sirius Mods $functions]]). | ||
The first argument is the identifier of the $list to be saved. This is a required argument. | The first argument is the identifier of the $list to be saved. This is a required argument. | ||
The second argument is a string which is the name under which to save the $list. If this argument is omitted, the name is the null string. The $ListRst function can be given the name under which the $list was saved. | The second argument is a string which is the name under which to save the $list. If this argument is omitted, the name is the null string. The $ListRst function can be given the name under which the $list was saved. | ||
==Syntax== | ==Syntax== | ||
<p class="syntax"><section begin="syntax" /> [%RESULT =] $ListSav(list_identifier, name) | <p class="syntax"><section begin="syntax" /> [%RESULT =] $ListSav(list_identifier, name) | ||
Line 19: | Line 20: | ||
</p> | </p> | ||
<p class="caption">%RESULT is set either to 0 or, if an error has occurred, to a negative number.</p> | <p class="caption">%RESULT is set either to 0 or, if an error has occurred, to a negative number.</p> | ||
A $list "saved" via $ListSav or $ListSave will be cleaned up at user logoff. After a $list has been "saved" via $ListSav or $ListSave it is no longer accessible in the current request, but will not be cleaned up at request termination or RELEASE ALL RECORDS processing. The $list is effectively "hidden" until restored via $ListRst or $List_Global. | A $list "saved" via $ListSav or $ListSave will be cleaned up at user logoff. After a $list has been "saved" via $ListSav or $ListSave it is no longer accessible in the current request, but will not be cleaned up at request termination or RELEASE ALL RECORDS processing. The $list is effectively "hidden" until restored via $ListRst or $List_Global. | ||
Only one $list can be saved at a time under a given name. For example: | |||
<p class="code"> B | <p class="code"> B | ||
FOR %I FROM 1 TO 4 | FOR %I FROM 1 TO 4 | ||
Line 35: | Line 35: | ||
</p> | </p> | ||
The request above produces three $lists, as follows: | The request above produces three $lists, as follows: | ||
<ol> | <ol> | ||
<li><tt>HE ATE</tt>, successfully saved via $ListSave under name <tt>A</tt> | <li><tt>HE ATE</tt>, successfully saved via $ListSave under name <tt>A</tt> | ||
<li><tt>SHE ATE</tt>, successfully saved via $ListSave under name '' | <li><tt>SHE ATE</tt>, successfully saved via $ListSave under name '' | ||
<li><tt>IT ATE</tt>, not saved, but accessible under $list identifier %RESULT for the duration of the request | <li><tt>IT ATE</tt>, not saved, but accessible under $list identifier %RESULT for the duration of the request | ||
</ol> | </ol> | ||
The string <tt>WE ATE</tt> is not saved (a list was already saved with the name ''), and since each invocation of $ListNew deletes the list associated with it, the list containing <tt>WE ATE</tt> was deleted in the last iteration of the FOR loop. | |||
The string <tt>WE ATE</tt> is not saved (a list was already saved with the name ''), and since each invocation of [[$ListNew]] deletes the list associated with it, the list containing <tt>WE ATE</tt> was deleted in the last iteration of the FOR loop. | |||
If $ListSav or $ListSave is invoked only with a null name argument, CCATEMP is not used and processing is very efficient. Because many Sirius Software products use $LISTSAV/$LISTRST with the null global $list name, care should be taken of the interaction between global $list names used by your applications and the null $list name. | If $ListSav or $ListSave is invoked only with a null name argument, CCATEMP is not used and processing is very efficient. Because many Sirius Software products use $LISTSAV/$LISTRST with the null global $list name, care should be taken of the interaction between global $list names used by your applications and the null $list name. | ||
To ensure that a $ListSav or $ListSave is not blocked by a previously "saved" list under a given name, you can simply issue a $ListRst to restore any previously saved list under that name, as in | To ensure that a $ListSav or $ListSave is not blocked by a previously "saved" list under a given name, you can simply issue a $ListRst to restore any previously saved list under that name, as in | ||
<p class="code"> %RESULT = $ListDel($ListRst) | <p class="code"> %RESULT = $ListDel($ListRst) | ||
%RESULT = $ListSave(%LIST) | %RESULT = $ListSave(%LIST) | ||
</p> | </p> | ||
Another way to address the problem of a global $list name already in use is to use the $List_Global function. | Another way to address the problem of a global $list name already in use is to use the $List_Global function. | ||
$Lists saved with $ListSave can also be accessed with $List_Global. For example, | $Lists saved with $ListSave can also be accessed with $List_Global. For example, | ||
<p class="code"> %RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST') | <p class="code"> %RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST') | ||
%LIST = $List_Global('MY.GLOBAL.LIST') | %LIST = $List_Global('MY.GLOBAL.LIST') | ||
</p> | </p> | ||
is a valid program. While a name is accessed as a global, however, it is not possible to save another list to the same name. In | is a valid program. While a name is accessed as a global, however, it is not possible to save another list to the same name. In | ||
<p class="code"> %LIST = $List_Global('MY.GLOBAL.LIST') | <p class="code"> %LIST = $List_Global('MY.GLOBAL.LIST') | ||
%RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST') | %RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST') | ||
</p> | </p> | ||
the $ListSave would fail with a return code of -13. It is possible to $ListSave a global $list to a separate name. In | the $ListSave would fail with a return code of -13. It is possible to $ListSave a global $list to a separate name. In | ||
<p class="code"> %LIST = $List_Global('MY.GLOBAL.LIST') | <p class="code"> %LIST = $List_Global('MY.GLOBAL.LIST') | ||
%RESULT = $ListSave(%LIST, 'OTHER.GLOBAL.LIST') | %RESULT = $ListSave(%LIST, 'OTHER.GLOBAL.LIST') | ||
</p> | </p> | ||
the contents of global list MY.GLOBAL.LIST would be saved under the name OTHER.GLOBAL.LIST. MY.GLOBAL.LIST would still be a valid global $list but would be empty. | the contents of global list MY.GLOBAL.LIST would be saved under the name OTHER.GLOBAL.LIST. MY.GLOBAL.LIST would still be a valid global $list but would be empty. | ||
The only difference between $ListSav and $ListSave is that $ListSav will not allow the saving of an empty $list while $ListSave will and that $ListSave will replace an existing saved $list by the same name as long as the existing list is not active as a $List_Global list in the current procedure. For example, in | The only difference between $ListSav and $ListSave is that $ListSav will not allow the saving of an empty $list while $ListSave will and that $ListSave will replace an existing saved $list by the same name as long as the existing list is not active as a $List_Global list in the current procedure. For example, in | ||
<p class="code"> %RESULT = $ListSav(%ALIST, 'A.LITTLE.LIST') | <p class="code"> %RESULT = $ListSav(%ALIST, 'A.LITTLE.LIST') | ||
%RESULT = $ListSav(%BLIST, 'A.LITTLE.LIST') | %RESULT = $ListSav(%BLIST, 'A.LITTLE.LIST') | ||
</p> | </p> | ||
the second $ListSav would fail because a $list is already saved under the name <tt>A.LITTLE.LIST</tt>. While in | the second $ListSav would fail because a $list is already saved under the name <tt>A.LITTLE.LIST</tt>. While in | ||
<p class="code"> %RESULT = $ListSave(%ALIST, 'A.LITTLE.LIST') | <p class="code"> %RESULT = $ListSave(%ALIST, 'A.LITTLE.LIST') | ||
%RESULT = $ListSave(%BLIST, 'A.LITTLE.LIST') | %RESULT = $ListSave(%BLIST, 'A.LITTLE.LIST') | ||
</p> | </p> | ||
the second $ListSave would succeed.<p> | the second $ListSave would succeed.<p> | ||
0 - $list successfully saved | |||
-3 - No room to add list name | |||
(if LISTFC $SirParm parameter not set) | |||
-5 - Required argument not specified | |||
-6 - $List identifier invalid | |||
-13 - Another $list has already been saved with the | -13 - Another $list has already been saved with the | ||
specified name | |||
-14 - $list is null, is not saved ($ListSav only) | -14 - $list is null, is not saved ($ListSav only) | ||
</p> | </p> | ||
Line 98: | Line 109: | ||
<li>[[Japanese functions]]</li> | <li>[[Japanese functions]]</li> | ||
<li>[[Sir2000 Field Migration Facility]]</li> | <li>[[Sir2000 Field Migration Facility]]</li> | ||
</ul> | </ul> | ||
Line 104: | Line 114: | ||
<p class="caption">Products authorizing $ListSav and $ListSave | <p class="caption">Products authorizing $ListSav and $ListSave | ||
</p> | </p> | ||
[[Category:$Functions|$ListSav and $ListSave]] | [[Category:$Functions|$ListSav and $ListSave]] |
Revision as of 17:10, 10 February 2011
<section begin="desc" />and $ListSave: Save global $list<section end="desc" />
Most Sirius $functions have been deprecated in favor of Object Oriented methods. There is no direct OO equivalent for the $ListSav and $ListSave functions because Stringlists can, more naturally, be declared as "Global".
These $functions are used to save a $list to be later retrieved with the [[$ListRst] function or the $List_Global and $List_Session functions. $ListSav and $ListSave are used with $ListRst or $List_Global to pass a $list between separate requests.
The $ListSav and $ListSave functions accept one required argument and one optional argument and return a numeric result. Both are callable $functions (see Calling Sirius Mods $functions).
The first argument is the identifier of the $list to be saved. This is a required argument.
The second argument is a string which is the name under which to save the $list. If this argument is omitted, the name is the null string. The $ListRst function can be given the name under which the $list was saved.
Syntax
<section begin="syntax" /> [%RESULT =] $ListSav(list_identifier, name) [%RESULT =] $ListSave(list_identifier, name) <section end="syntax" />
A $list "saved" via $ListSav or $ListSave will be cleaned up at user logoff. After a $list has been "saved" via $ListSav or $ListSave it is no longer accessible in the current request, but will not be cleaned up at request termination or RELEASE ALL RECORDS processing. The $list is effectively "hidden" until restored via $ListRst or $List_Global.
Only one $list can be saved at a time under a given name. For example:
B FOR %I FROM 1 TO 4 %LIST1 = $ListNew %RESULT = $ListAdd(%LIST1 , - $WORD('HE SHE WE IT', , %I) WITH ' ATE') %RESULT = $ListSave(%LIST1, $WORD('A', , %I)) END FOR END
The request above produces three $lists, as follows:
- HE ATE, successfully saved via $ListSave under name A
- SHE ATE, successfully saved via $ListSave under name
- IT ATE, not saved, but accessible under $list identifier %RESULT for the duration of the request
The string WE ATE is not saved (a list was already saved with the name ), and since each invocation of $ListNew deletes the list associated with it, the list containing WE ATE was deleted in the last iteration of the FOR loop.
If $ListSav or $ListSave is invoked only with a null name argument, CCATEMP is not used and processing is very efficient. Because many Sirius Software products use $LISTSAV/$LISTRST with the null global $list name, care should be taken of the interaction between global $list names used by your applications and the null $list name.
To ensure that a $ListSav or $ListSave is not blocked by a previously "saved" list under a given name, you can simply issue a $ListRst to restore any previously saved list under that name, as in
%RESULT = $ListDel($ListRst) %RESULT = $ListSave(%LIST)
Another way to address the problem of a global $list name already in use is to use the $List_Global function.
$Lists saved with $ListSave can also be accessed with $List_Global. For example,
%RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST') %LIST = $List_Global('MY.GLOBAL.LIST')
is a valid program. While a name is accessed as a global, however, it is not possible to save another list to the same name. In
%LIST = $List_Global('MY.GLOBAL.LIST') %RESULT = $ListSave(%ALIST, 'MY.GLOBAL.LIST')
the $ListSave would fail with a return code of -13. It is possible to $ListSave a global $list to a separate name. In
%LIST = $List_Global('MY.GLOBAL.LIST') %RESULT = $ListSave(%LIST, 'OTHER.GLOBAL.LIST')
the contents of global list MY.GLOBAL.LIST would be saved under the name OTHER.GLOBAL.LIST. MY.GLOBAL.LIST would still be a valid global $list but would be empty.
The only difference between $ListSav and $ListSave is that $ListSav will not allow the saving of an empty $list while $ListSave will and that $ListSave will replace an existing saved $list by the same name as long as the existing list is not active as a $List_Global list in the current procedure. For example, in
%RESULT = $ListSav(%ALIST, 'A.LITTLE.LIST') %RESULT = $ListSav(%BLIST, 'A.LITTLE.LIST')
the second $ListSav would fail because a $list is already saved under the name A.LITTLE.LIST. While in
%RESULT = $ListSave(%ALIST, 'A.LITTLE.LIST') %RESULT = $ListSave(%BLIST, 'A.LITTLE.LIST')
the second $ListSave would succeed.
0 - $list successfully saved -3 - No room to add list name (if LISTFC $SirParm parameter not set) -5 - Required argument not specified -6 - $List identifier invalid -13 - Another $list has already been saved with the specified name -14 - $list is null, is not saved ($ListSav only)