View previous topic :: View next topic
|
Author |
Message |
puzzled_elton
New User
Joined: 09 May 2005 Posts: 7
|
|
|
|
Please let me know the convertion from char field to DEC. bcoz iam facing probelm while moving a CHAR filed which is containing a value of 9,2 to a DEC(5,2) filed.
iam getting the below error in sysout.
ONCODE=612 The CONVERSION condition was raised because a conversion error occurred when converting a character string to an arithmetic value.
please let me know the answer asap. |
|
Back to top |
|
|
krisprems
Active Member
Joined: 27 Nov 2006 Posts: 649 Location: India
|
|
|
|
puzzled_elton
This is a information from a PL/I pdf, this may help you!
Quote: |
CHARACTER
The source string must represent a valid arithmetic constant or complex
expression; otherwise, the CONVERSION condition is raised. The constant can
be preceded by a sign and can be surrounded by blanks. The constant cannot
contain blanks between the sign and the constant, or between the end of the
real part and the sign preceding the imaginary part of a complex expression.
The constant has base, scale, mode, and precision attributes. It converts to the
attributes of the target when they are independent of the source attributes, as in
the case of assignment. See the specific target types of coded arithmetic data
using the attributes of the constant as the source.
If an intermediate result is necessary, as in evaluation of an operational
expression, the attributes of the intermediate result are the same as if a decimal
fixed-point value of precision had appeared in place of the string. (This allows
the compiler to generate code to handle all cases, regardless of the attributes of
the contained constant.) Consequently, any fractional portion of the constant
might be lost. See the specific target types of coded arithmetic data using
FIXED DECIMAL as the source.
It is possible that during the initial conversion of the character data item to an
intermediate fixed decimal number, the value might exceed the default size of
the intermediate result. If this occurs, the SIZE condition is raised if it is
enabled.
If a character string representing a complex number is assigned to a real target,
the complex part of the string is not checked for valid arithmetic characters and
CONVERSION cannot be raised, since only the real part of the string is
assigned to the target.
A null string and a string of blanks both give the value zero. |
|
|
Back to top |
|
|
ilanjai
New User
Joined: 11 Jul 2007 Posts: 2 Location: Hyderabad
|
|
|
|
A simple solution for such conversions is to use a PIC variable.
Example (ignoring programming syntax)
DCL CHAR_FIELD CHAR(9,2);
DCL DEC_FIELD FIXED DEC(5,2);
DCL PIC_FIELD PIC'9(9)V99';
PIC_FIELD = CHAR_FIELD;
DEC_FIELD = PIC_FIELD;
Now the DEC field can be used as it is. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
Code: |
DCL CHAR_FIELD CHAR(9);
DCL PIC_FIELD PIC'(9)9' BASED(ADDR(CHAR_FIELD));
DCL DEC_FIELD DEC FIXED(9,2);
DEC_FIELD = PIC_FIELD; |
Works.
Garry. |
|
Back to top |
|
|
|