|
Definition status: Declared and Defined |
Top Previous Next |
|
A named item or item referenced by a passed parameter may be declared but may never have had any data put into it or may be both declared and have data. A conditional can be structured to test whether an argument or named item was ever defined or declared. The syntax then would be one of the following
$If declared itemname gamsstatement
which tests whether the item has been declared in a set, parameter, table, model, equation, file, acronym, or variable statement
$If defined itemname gamsstatement
that tests whether the item has been defined with data somewhere. Example set aaa; scalar bbb /1/; $If not declared aaa display 'aaa is not declared'; $If not declared bbb display 'bbb is not declared'; $If not declared ccc display 'ccc is not declared'; $If not defined aaa display 'aaa is not defined'; $If not defined bbb display 'bbb is not defined'; $If not defined ccc display 'ccc is not defined';
yields
59 set aaa; 60 scalar bbb /1/; 63 display 'ccc is not declared'; 64 display 'aaa is not defined'; 66 display 'ccc is not defined';
where aaa has no data (in this case no assigned set elements) and the $If causes generation of an action (in this case a display) since it is not being defined and the ccc tests generate both messages since it is not mentioned anywhere. |