The SETA instruction assigns an arithmetic value to a SETA symbol. You can specify a single value or an arithmetic expression from which the assembler computes the value to assign.
You can change the values assigned to an arithmetic or SETA symbol. This lets you use SETA symbols as counters, indexes, or for other repeated computations that require varying values.
|
A global variable symbol in the name field must have been previously declared as a SETA symbol in a GBLA instruction. Local SETA symbols need not be declared in a LCLA instruction. The assembler considers any undeclared variable symbol found in the name field of a SETA instruction as a local SET symbol. The variable symbol is assigned a type attribute value of N.
Figure 40 defines an arithmetic expression.
*-----------*
| |
|Arithmetic |
|Expression |
| |
*-----*-----*
|
V Can be any of
*------------*-----------*--------------------*----------*
V V V V V
*-----*-----* *----*----* *----*--------------* *---*----* ---*----*
|Arithmetic | | (Arith. | | Arithmetic-Valued | |+Arith. | |-Arith. |
|Term | | Exp.) | | Built-in Function | |^ Exp. | |^ Exp. |
*-----*-----* *---------* *-------------------* *+-------* *+-------*
| *----*-----*
V Can be any of |
*-------------*-------------*-------------* unary operators
V V V V
*-----*-----* *-----*-----* *-----*-----* *-----*-----*
| | |Predefined | | Self- | | |
| Variable | |Absolute | | Defining | | Attribute |
| Symbol | |Ordinary | | Term | | Reference |
| | |Symbol | | | | | Operators Allowed
*-----------* *-----------* *-----------* *-----*-----*
| Unary: + Positive
| - Negative
| Can
V only be Binary: + Addition
*-----*-----* - Subtraction
| Length | * Multiplication
| Scale | / Division
| Integer |
| Count |
Arith. Exp. = Arithmetic Expression | Number |
| Defined |
*-----------*Table 58 shows the variable symbols that are allowed as terms in an arithmetic expression.
| Variable symbol | Restrictions | Example | Valid value |
|---|---|---|---|
| SETA | None | --- | --- |
| SETB | None | --- | --- |
| SETC | Value must evaluate to an unsigned binary, hexadecimal or decimal self-defining term | 123 | 123 |
| Symbolic parameters | Value must be a self-defining term |
&PARAM &SUBLIST(3) |
X'A1' C'Z' |
|
&SYSLIST(n) &SYSLIST(n,m) |
Corresponding operand or sublist entry must be a self-defining term |
&SYSLIST(3) &SYSLIST(3,2) |
24 B'101' |
|
&SYSDATC &SYSM_HSEV &SYSM_SEV &SYSNDX &SYSNEST &SYSOPT_DBCS &SYSOPT_RENT &SYSOPT_XOBJECT &SYSSTMT |
None | --- | --- |
The following example shows a SETA statement with a valid self-defining term in its operand field:
&ASYM1 SETA C'D' &ASYM1 has value 196 (C'D')
The second statement in the following example is valid because in the two positions in the SETA operand where a term is required (either side of the + sign), the assembler finds a valid self-defining term:
&CSYM2 SETC 'C''A''' &CSYM2 has value C'A' &ASYM3 SETA &CSYM2+&CSYM2 &ASYM3 has value 386 (C'A' + C'A')
A SET statement is not rescanned by the assembler to see whether substitutions might affect the originally-determined syntax. The original syntax of the self-defining term must be correct. Therefore the assembler does not construct a self-defining term in a SETA statement. The third statement of the next example shows this:
&CSYM3 SETC '3' &CSYM has value 3 (C'3') &ASYM3 SETA &CSYM3 &ASYM has value 3 &ASYM4 SETA C'&ASYM3' Invalid self-defining term
In this example C'&ASYM3' is not a valid term.
The SETA symbol in the name field can be subscripted. If the same SETA symbol has not been previously declared in a GBLA or LCLA instruction with an allowable dimension, then the symbol is implicitly declared as a local SETA array variable.
The assembler assigns the value of the expression in the operand field to the position in the declared array given by the value of the subscript. The subscript expression must not be 0 or have a negative value.
Table 59 shows how arithmetic expressions can be used.
| Used in | Used as | Example |
|---|---|---|
| SETA instruction | Operand | &A1 SETA &A1+2 |
| AIF or SETB instruction | Term in arithmetic relation | AIF (&A*10 GT 30).A |
| Subscripted SET symbols | Subscript | &ASYM(&A+10-&C) |
| Substring notation | Subscript | 'STRING'(&A*2,&A-1) |
| Sublist notation | Subscript |
Given sublist (A,B,C,D) named &PARAM, if &A=1 then &PARAM(&A+1)=B |
| &SYSLIST | Subscript |
&SYSLIST(&M+1,&N-2) &SYSLIST(N'&SYSLIST) |
| SETC instruction | Character string in operand |
Given &C SETC '5-10*&A' 1 if &A=10 then &C=5-10*10 2 Given &D SETC '5-10*&A' 1 if &A=-10 then &D=5-10*10 3 |
| Built-in functions | Operand | &VAR SETA (NOT &OP1) &VAR SETA BYTE(64) |
When an arithmetic expression is used in the operand field of a SETC instruction (see 1 in Table 59), the assembler assigns the character value representing the arithmetic expression to the SETC symbol, after substituting values (see 2 in Table 59) into any variable symbols. It does not evaluate the arithmetic expression. The mathematical sign (+ or -) is not included in the substituted value of a variable symbol (see 3 in Table 59), and any insignificant leading zeros are removed.
Here are the built-in functions for arithmetic (SETA) expressions:
Example
After the following statements &VAR contains the arithmetic value +2.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 AND &OP2)
The result of the B2A function is the same as
&value SETA B'bitstring'
except that null strings are allowed by B2A but not by SETA.
Examples
B2A('') has value 0
B2A('0000000101') has value 5
B2A('11111111111111111111111111111110') has value -2
The result of C2A is the same as would be obtained from
&value SETA C'charstring'
except that C2A gives a zero result for null strings, and does not pair apostrophes or ampersands before conversion.
Example
C2A('') has value 0
C2A('+') has value 78
C2A('1') has value 241
C2A('0000') has value -252645136
Null argument strings return zero.
The result of the D2A function is the same as
&value SETA decstring
except that SETA does not allow leading plus or minus signs.
Examples
D2A('') indicates an error condition
D2A('000') has value 0
D2A('10') has value 10
D2A('+100') has value 100
D2A('-5') has value -5
Examples
DCLEN('') has value 0 (null string)
DCLEN('''') has value 1 (argument is a single apostrophe)
DCLEN('''''') has value 2 (argument is two apostrophes)
DCLEN('&&') has value 1 (argument is two ampersands)
DCLEN('a''''b') has value 3 (DCVAL string would be "a'b")
DCLEN('a''''b&&c') has value 5 (DCVAL string would be "a'b&c")
DCLEN('&&&''''''') has value 4 (DCVAL string would be "&&''")
Note: DCLEN is similar to DCVAL, except that DCLEN returns only the length of the result, not the paired string.
Examples
After the following statements &VAR contains the arithmetic value 3.
Name Operation Operand
&OP1 SETC 'abcdef'
&OP2 SETC 'cde'
&VAR SETA ('&OP1' FIND '&OP2')
In the above example the character c in &OP2 is the first character found in &OP1. Consider the following example where the character c, in &OP1, has been replaced with the character g.
Name Operation Operand
&OP1 SETC 'abcdef'
&OP2 SETC 'gde'
&VAR SETA ('&OP1' FIND '&OP2')
&VAR contains the arithmetic value 4. The character d in &OP2 is the first character found in &OP1.
In the following example, the ordering of the characters in the second operand is changed to egd.
Name Operation Operand
&OP1 SETC 'abcdef'
&OP2 SETC 'egd'
&VAR SETA FIND('&OP1','&OP2')
&VAR still contains the arithmetic value 4. Because FIND is looking for a single character from the character string, the order of the characters in the second operand string is irrelevant.
Examples
INDEX('ABC','B') has value 2
INDEX('ABC','D') has value 0
Example
ISBIN('10101') returns 1
ISBIN('101010101010101010101010101010101') returns 0 (excess digits)
ISBIN('12121') returns 0 (non-binary digits)
ISBIN('') indicates an error condition
Example
ISDEC('12345678') returns 1
ISDEC('+25') returns 0 (non-decimal character)
ISDEC('2147483648') returns 0 (value too large)
ISDEC('00000000005') returns 0 (too many characters)
ISDEC('') indicates an error condition
Example
ISHEX('ab34CD9F') returns 1
ISHEX('abcdEFGH') returns 0 (non-hexadecimal digits)
ISHEX('123456789') returns 0 (too many characters)
ISHEX('') indicates an error condition
Examples
ISSYM('Abcd_1234') returns 1
ISSYM('_Abcd1234') returns 1
ISSYM('##@$_') returns 1
ISSYM('1234_Abcd') returns 0 (invalid initial character)
ISSYM('') indicates an error condition
Example
After the following statements &VAR contains the arithmetic value -11.
Name Operation Operand &OP1 SETA 10 &VAR SETA (NOT &OP1)
Example
After the following statements &VAR contains the arithmetic value +10.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 OR &OP2)
Example
After the following statements &VAR contains the arithmetic value +8.
Name Operation Operand &OP1 SETA 2 &OP2 SETA 2 &VAR SETA (&OP1 SLA &OP2)
Example
After the following statements &VAR contains the arithmetic value +40.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 SLL &OP2)
Examples
After the following statements &VAR contains the arithmetic value +2.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 SRA &OP2)
After the following statements &VAR contains the arithmetic value -1.
Name Operation Operand &OP1 SETA -344 &OP2 SETA 40 &VAR SETA (&OP1 SRA &OP2)
Compare this result with the result in the second example under SRL below.
Examples
After the following statements &VAR contains the arithmetic value +2.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 SRL &OP2)
After the following statements &VAR contains the arithmetic value 0.
Name Operation Operand &OP1 SETA -344 &OP2 SETA 40 &VAR SETA (&OP1 SRL &OP2)
The result of the X2A function is the same as
&value SETA X'hexstring'
except that null strings are allowed by X2A but not by SETA.
Examples
X2A('00000101') has value 257
X2A('C1') has value 193
X2A('') has value 0
X2A('FFFFFFF0') has value -16
Example After the following statements &VAR contains the arithmetic value +8.
Name Operation Operand &OP1 SETA 10 &OP2 SETA 2 &VAR SETA (&OP1 XOR &OP2)
The following is a summary of coding rules for arithmetic expressions:
An arithmetic expression must not contain two terms in succession; however, any term may be preceded by up to 24 unary operators. +&A*-&B is a valid operand for a SETA instruction. The expression &FIELD+- is invalid because it has no final term.
The assembler evaluates arithmetic expressions during conditional assembly processing as follows:
The assembler permits a SETC variable to be used as a term in an arithmetic expression if the character string value of the variable is a self-defining term. The value represented by the string is assigned to the arithmetic term. A null string is treated as zero.
Examples:
LCLC &C(5) &C(1) SETC 'B''101''' &C(2) SETC 'C''A''' &C(3) SETC '23' &A SETA &C(1)+&C(2)-&C(3)
In evaluating the arithmetic expression in the fifth statement, the first term, &C(1), is assigned the binary value 101 (decimal 5). To that is added the value represented by the EBCDIC character A (hexadecimal C1, which corresponds to decimal 193). Then the value represented by the third term &C(3) is subtracted, and the value of &A becomes 5+193-23=175.
This feature lets you associate numeric values with EBCDIC or hexadecimal characters to be used in such applications as indexing, code conversion, translation, and sorting.
Assume that &X is a character string with the value ABC.
&I SETC 'C'''.'&X'(1,1).'''' &VAL SETA &TRANS(&I)
The first statement sets &I to C'A'. The second statement extracts the 193rd element of &TRANS (C'A' = X'C1' = 193).
The following code converts a hexadecimal value in &H into a decimal value in &VAL:
&X SETC 'X''&H''' &VAL SETA &X
The following code converts the double-byte character Da into a decimal value in &VAL. &VAL can then be used to find an alternative code in a subscripted SETC variable:
&DA SETC 'G''<Da>''' &VAL SETA &DA
Although you can use a predefined absolute symbol as an operand in a SETA expression, you cannot substitute a SETC variable whose value is the same as the symbol. For example:
ABS EQU 5 &ABS SETA ABS &ABS has value 5 &CABS SETC 'ABS' &CABS has value 'ABS' &ABS SETA &CABS invalid usage
The G-type self-defining term is valid only if the DBCS assembler option is specified.
The arithmetic value assigned to a SETA symbol is substituted for the SETA symbol when it is used in an arithmetic expression. If the SETA symbol is not used in an arithmetic expression, the arithmetic value is converted to a character string containing its absolute value, with leading zeros removed. If the value is 0, it is converted to a single 0.
Example:
MACRO
&NAME MOVE &TO,&FROM
LCLA &A,&B,&C,&D
&A SETA 10 Statement 1
&B SETA 12 Statement 2
&C SETA &A-&B Statement 3
&D SETA &A+&C Statement 4
&NAME ST 2,SAVEAREA
L 2,&FROM&C Statement 5
ST 2,&TO&D Statement 6
L 2,SAVEAREA
MEND
-------------------------------------------------------------------
HERE MOVE FIELDA,FIELDB
-------------------------------------------------------------------
+HERE ST 2,SAVEAREA
+ L 2,FIELDB2
+ ST 2,FIELDA8
+ L 2,SAVEAREA
Statements 1 and 2 assign the arithmetic values +10 and +12, respectively, to the SETA symbols &A and &B. Therefore, statement 3 assigns the SETA symbol &C the arithmetic value -2. When &C is used in statement 5, the arithmetic value -2 is converted to the character 2. When &C is used in statement 4, however, the arithmetic value -2 is used. Therefore, &D is assigned the arithmetic value +8. When &D is used in statement 6, the arithmetic value +8 is converted to the character 8.
The following example shows how the value assigned to a SETA symbol may be changed in a macro definition.
MACRO
&NAME MOVE &TO,&FROM
LCLA &A
&A SETA 5 Statement 1
&NAME ST 2,SAVEAREA
L 2,&FROM&A Statement 2
&A SETA 8 Statement 3
ST 2,&TO&A Statement 4
L 2,SAVEAREA
MEND
-------------------------------------------------------------------
HERE MOVE FIELDA,FIELDB
-------------------------------------------------------------------
+HERE ST 2,SAVEAREA
+ L 2,FIELDB5
+ ST 2,FIELDA8
+ L 2,SAVEAREA
Statement 1 assigns the arithmetic value +5 to SETA symbol &A. In statement 2, &A is converted to the character 5. Statement 3 assigns the arithmetic value +8 to &A. In statement 4, therefore, &A is converted to the character 8, instead of 5.
A SETA symbol may be used with a symbolic parameter to refer to an operand in an operand sublist. If a SETA symbol is used for this purpose, it must have been assigned a positive value.
Any expression that may be used in the operand field of a SETA instruction may be used to refer to an operand in an operand sublist. Sublists are described in Sublists in operands.
The following macro definition adds the last operand in an operand sublist to the first operand in an operand sublist and stores the result at the first operand. A sample macro instruction and generated statements follow the macro definition.
MACRO
ADDX &NUMBER,® Statement 1
LCLA &LAST
&LAST SETA N'&NUMBER Statement 2
L ®,&NUMBER(1)
A ®,&NUMBER(&LAST) Statement 3
ST ®,&NUMBER(1)
MEND
-------------------------------------------------------------------
ADDX (A,B,C,D,E),3 Statement 4
-------------------------------------------------------------------
+ L 3,A
+ A 3,E
+ ST 3,A
&NUMBER is the first symbolic parameter in the operand field of the prototype statement (statement 1). The corresponding characters (A,B,C,D,E) of the macro instruction (statement 4) are a sublist. Statement 2 assigns to &LAST the arithmetic value +5, which is equal to the number of operands in the sublist. Therefore, in statement 3, &NUMBER(&LAST) is replaced by the fifth operand of the sublist.
[ Top of Page | Previous Page | Next Page | Contents | Index ]