Figure 204. Using Numeric and Character Parameters
*..1....+....2....+....3....+....4....+....5....+....6....+....7...+....
D*Name++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++
D p7 s 7p 3 inz (1234.567)
D s9 s 9s 5 inz (73.73442)
D f8 s 8f inz (123.456789)
D c15a s 15a inz (' 123.456789 -')
D c15b s 15a inz (' + 9 , 8 7 6 ')
D result1 s 15p 5
D result2 s 15p 5
D result3 s 15p 5
/FREE
// using numeric parameters
result1 = %dec (p7) + 0.011; // "result1" is now 1234.57800
result2 = %dec (s9 : 5: 0); // "result2" is now 73.00000
result3 = %dech (f8: 5: 2); // "result3" is now 123.46000
// using character parameters
result1 = %dec (c15a: 5: 2); // "result1" is now -123.45
result2 = %dech(c15b: 5: 2); // "result2" is now 9.88000
/END-FREE
Figure 205. Handling Currency Symbols and Thousands Separators
*-----------------------------------------------------------------
* If the character data is known to contain non-numeric characters
* such as thousands separators (like 1,234,567) or leading
* asterisks and currency symbols (like $***1,234,567.89), some
* preprocessing is necessary to remove these characters from the
* data.
*-----------------------------------------------------------------
D data s 20a inz('$1,234,567.89')
D num s 21p 9
/free
// Use the %XLATE built-in function to replace any currency
// symbol, asterisks or thousands separators with blanks
num = %dech(%xlate('$*,' : ' ' : data)
: 21 : 9);
// If the currency symbol or thousands separator might
// vary at runtime, use variables to hold these values.
num = %dech(%xlate(cursym + '*' + thousandsSep : ' ' : data)
: 21 : 9);