Hi Everyone,
I was trying out varchar_format() and ran across this:
values ( varchar_format(12345,'99990'), '|' )
....+....1....+....2....+....3....+....4....+....5..
VALUES
12345
Data width . . . . . . : 262
Shift to column . . . . . .
+...23....+...24....+...25....+...26..
VALUES
|
So I read the documentation for v7r3 about varchar_format
(
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/db2/rbafzscavarcharformat.htm)
and it says:
"The result is a string representation of/rounded-input-value/. The data
type of the result is varying-length character or varying-length graphic
based on the data type of theformat-string. If a single argument is
specified the length attribute is 42. Otherwise the length attribute is
254. The actual length of the result is determined by/format-string/, if
specified. Otherwise, the actual length of the result is the smallest
number of characters that can represent the value
of/rounded-input-value/. If the resulting string exceeds the length
attribute of the result, the result will be truncated."
So I tried it without the format string:
values (12345, varchar_format(12345), '|' )
....+....1....+....2....+....3....+
VALUES VALUES VALUES
12,345 12345 |
The first test looks right according to the docs "Otherwise the length
attribute is 254." When written to a file:
Field File Type Length
SEL0001 TESTVCF VARCHAR 254
SEL0002 TESTVCF VARCHAR 1
But the second does not: "If a single argument is specified the length
attribute is 42." When written to a file:
Field File Type Length
SEL0001 TESTVCF VARCHAR 11
SEL0002 TESTVCF VARCHAR 1
The docs also say:
"The actual length of the result is determined by/format-string/, if
specified. Otherwise, the actual length of the result is the smallest
number of characters that can represent the value of/rounded-input-value/."
Besides the obvious that the docs are not matching the actual results,
why is the length attribute not set to the actual length? Expecting a
5-character result and getting 254 requires another function to make it
a reasonable length for a report.
--
*Peter Dow* /
Dow Software Services, Inc.
909 793-9050
petercdow@xxxxxxxxx <mailto:petercdow@xxxxxxxxx>
pdow@xxxxxxxxxxxxxx <mailto:pdow@xxxxxxxxxxxxxx> /
As an Amazon Associate we earn from qualifying purchases.