Previous Topic Next topic Print topic


POSITION

Abbreviation: POS

POSITION is an attribute that is used in conjunction with the DEFINED attribute. It specifies the bit or character within the basis variable at which the defined variable is to begin. Its format is:

POSITION(expression)

where expression is an integer expression that specifies the position relative to the start of the basis variable. The range of the expression is from 1 to n, where n is defined as:

n = basis_length – defined_length+1

where basis_length is the length of the basis variable in bits or characters and defined_length is the length of the defined variable in bits or characters.

Both the defined variable and the basis variable must be fixed-length bit strings, fixed-length character strings, pictured variables, or aggregates containing any of these data types.

In the following example, the two DO-groups accomplish the same purpose. The second makes use of the POSITION attribute:

DECLARE X CHARACTER(200);
DECLARE Y CHARACTER(1) DEF X POS(I);

DO I = 1 to 200;
   IF SUBSTR(x,i,1) = '?' THEN 
      CALL ERROR();

DO I = 1 to 200;
   IF Y = '?' THEN   /* Uses position attributes */ 
      CALL ERROR();
Previous Topic Next topic Print topic