|
The following examples show how the assembler processes substrings
depending on the value of the elements n, e1,
and e2. - In the usual case, the assembler generates a correct substring
of the specified length:
Value of Variable Character Value
Notation Symbol of Substring
'ABCDE'(1,5) ABCDE
'ABCDE'(2,3) BCD
'ABCDE'(2,*) BCDE
'ABCDE'(4,*) DE
'&C'(3,3) ABCDE CDE
'&PARAM'(3,3) ((A+3)*10) A+3
- When e1 has a zero or negative value,
the assembler generates a null string and issues error message ASMA093E.
Character Value
Notation of Substring
'ABCDE'(0,5) null character string
'ABCDE'(0,*) null character string
- When the value of e1 exceeds n,
the assembler generates a null string and issues error message ASMA092E.
Value of Variable Character Value
Notation Symbol of Substring
'ABCDE'(7,3) null character string
'ABCDE'(6,*) null character string
- When e2 has a value less than one, the
assembler generates the null character string. If e2 is
negative, the assembler also issues error message ASMA095W.
Value of Variable Character Value
Notation Symbol of Substring
'ABCDE'(4,0) null character string
'ABCDE'(3,-2) null character string
- When e2 indexes past the end of the
character expression (that is, e1+e2 is
greater than n+1), the assembler issues
warning message ASMA094I, and generates a substring
that includes only the characters up to the end of the character expression
specified.
Value of Variable Character Value
Notation Symbol of Substring
'ABCDE'(3,5) CDE
Figure 1 shows the results
of an assembly of SETC instructions with different substring notations.
Figure 1. Sample
assembly using substring notation Loc Object Code Addr1 Addr2 Stmt Source Statement HLASM R6.0 2008/07/11 17.48
8 &STRING SETC 'STRING' 00008000
9 &SUBSTR1 SETC '&STRING'(0,4) 00009000
** ASMA093E Substring expression 1 less than 1; default=null - OPENC
10 &SUBSTR2 SETC '&STRING'(7,4) 00010000
** ASMA092E Substring expression 1 points past string end; default=null - OPENC
11 &SUBSTR3 SETC '&STRING'(3,0) 00011000
12 &SUBSTR4 SETC '&STRING'(3,-2) 00012000
** ASMA095W Substring expression 2 less than 0; default=null - OPENC
13 &SUBSTR5 SETC '&STRING'(3,4) 00013000
14 &SUBSTR6 SETC '&STRING'(3,5) 00014000
** ASMA094I Substring goes past string end; default=remainder
15 END 00015000
You can suppress the ASMA094I message by specifying the FLAG(NOSUBSTR)
option or by setting the ACONTROL FLAG(NOSUBSTR) value. When this
is done, the listing changes ( Figure 2).
Figure 2. Sample
assembly using substring notation with messages suppressed Loc Object Code Addr1 Addr2 Stmt Source Statement HLASM R6.0 2008/07/11 17.48
7 ACONTROL FLAG(NOSUBSTR)
8 &STRING SETC 'STRING' 00008000
9 &SUBSTR1 SETC '&STRING'(0,4) 00009000
** ASMA093E Substring expression 1 less than 1; default=null - OPENC
10 &SUBSTR2 SETC '&STRING'(7,4) 00010000
** ASMA092E Substring expression 1 points past string end; default=null - OPENC
11 &SUBSTR3 SETC '&STRING'(3,0) 00011000
12 &SUBSTR4 SETC '&STRING'(3,-2) 00012000
** ASMA095W Substring expression 2 less than 0; default=null - OPENC
13 &SUBSTR5 SETC '&STRING'(3,4) 00013000
14 &SUBSTR6 SETC '&STRING'(3,5) 00014000
15 END 00015000
Character (SETC) expressions can be used only in conditional assembly
instructions. Table 1 shows examples
of using character expressions.
Table 1. Use of character
expressionsUsed in |
Used as |
Example |
---|
SETC instruction |
Operand |
&C SETC 'STRING0' |
AIF or SETB instruction |
Character string in character relation |
AIF ('&C' EQ 'STRING1').B |
Substring notation |
First part of notation |
'SELECT'(2,5) returns 'ELECT' |
Built-in functions |
Operand |
&VAR SETC (LOWER '&twenty.&six')
&AB SETA A2B('10')
|
|