Direct assignment

Top  Previous  Next

Data may also be entered through replacement or assignment statements.  Such statements involve the use of a statement like

 

parametername(setdependency) = expression;

 

where the parameters on the left hand side must have been previously defined in a set, parameter or table statement.

Examples:

(caldata.gms)

scalar  a1;

scalars a2 /11/;

parameter   cc(j) , bc(j) /j2 22/;

a1=10;

a2=5;

cc(j)=bc(j)+10;

cc("j1")=1;

Notes:

When a statement like cc(j)=bc(j)+10; is executed this is done for all elements in j so if j had 100,000 elements this would define values for each and every one.
These assignments can be the sole entry of a data item or may redefine items.
If an item is redefined then it has the new value from then on and does not retain the original data.
The example cc("j1")=1; shows how one addresses a single specific element not the whole set, namely one puts the entry in quotes (single or double).  This is further discussed in the Sets chapter.
Calculations do not have to cover all set element cases of the parameters involved (through partial set references as discussed in the Sets chapter).  Set elements that are not computed over retain their original values if defined or a zero if never defined by entry or previous calculation.
A lot more on calculations appears in the Calculating Items chapter.