Returns a string that is a section of a nominated variable or constant.
&SUBSTR data i [ j ]
&SUBSTR provides a means of isolating part of a string or variable. &SUBSTR is a built-in function and must be used to the right of an assignment statement.
Operands:
A variable or constant from which the extraction of data is to be performed.
The position within the data at which the extraction is to start. The value of i must be greater than 0. The first character in a variable is counted as 1. If i exceeds the length of the variable, then a null value is extracted.
The length of data to be extracted. If j is omitted or exceeds the length remaining in the variable, the remaining length is used. j must be 0 or greater. If 0 is specified, then a null value is extracted.
Examples: &SUBSTR
&A = ABCDEF &B = &SUBSTR &A 3 2 -* &B is set to CD &C = &SUBSTR &A 4 -* &C is set to DEF
Used in calculating a number as a percentage.
&PC = (&CURR * 10000) / &INIT &A = &LENGTH &PC &A = &A - 1 &B = &SUBSTR &PC &A &A = &LENGTH &PC &A = &A - 2 &PC = &SUBSTR &PC 1 &A &PC = &CONCAT &PC . &B % &WRITE Percentage is &PC
Notes:
The process of variable substitution eliminates null variables from a statement. Therefore care should be taken to ensure any expected variables are supplied on the &SUBSTR statement or invalid results can occur.
If &CONTROL DBCS or DBCSN or DBCSP is in effect, &SUBSTR is sensitive to the presence of DBCS data.
| Copyright © 2009 CA. All rights reserved. |
|