Using set attributes

Top  Previous  Next

Set elements have attributes that may be recovered during execution.  In particular there are 6 attributes that may be revered in a statement of a for

 a(setname)=setname.attribute;

where

 setname is the name of the set

 attribute is one of the following

.len length of the current set element

ord  which gives the position of the element in the current set so for the first element is at position one, the second at two etc.
pos  which gives the element position without the requirement that the set be ordered so for the first element is at position one, the second at two etc.
off  which gives the position in the current set less one (i.pos-1) so for the first element is at position zero, the second at one etc
uel  which gives the element position in the unique element list
val  which converts set element names that happen to be numbers into values.
len  which gives the length  of the text for the set element name (a count of the number of characters)

 

Notes:

ord  is the same as the function ord and only works when the set is ordered otherwise it generates a compilation error.
pos  which gives the element position without the requirement that the set be ordered so for the first element is at position one, the second at two etc.
val generates a number of the set element has a numeric counterpart (ie when the element text is "1" or "100" etc but not when any non numeric characters .excepting a decimal point are present in the set element name in which case an execution error occurs

Examples:

 

set id set to find attributes for / aa,'-inf',1,12,24,'13.14',inf /;

parameter report(id,*) gives set values;

         report(id,'value')    = id.val;

         report(id,'length')   = id.len;

         report(id,'offset')   = id.off;

         report(id,'position') = id.pos;

         report(id,'ord') = id.ord;

         report(id,'uel') = id.uel;;

display report;

 

which generates the output

 

**** Exec Error at line 188: Coud not extract number from element: aa

(this error is because element "aa" is non numeric)

 

----    194 PARAMETER report  gives set values

 

            value      length      offset    position         ord         uel

 

aa           UNDF       2.000                   1.000       1.000    4260.000

-inf         -INF       4.000       1.000       2.000       2.000    4261.000

1           1.000       1.000       2.000       3.000       3.000    4262.000

12         12.000       2.000       3.000       4.000       4.000    4263.000

24         24.000       2.000       4.000       5.000       5.000    4264.000

13.14      13.140       5.000       5.000       6.000       6.000    4265.000

inf          +INF       3.000       6.000       7.000       7.000    4266.000

 

Note aa has an undefined value