IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

convertion from char field to dec


IBM Mainframe Forums -> PL/I & Assembler
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
puzzled_elton

New User


Joined: 09 May 2005
Posts: 7

PostPosted: Sat Jul 07, 2007 6:25 pm
Reply with quote

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
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Tue Jul 10, 2007 8:54 pm
Reply with quote

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
View user's profile Send private message
ilanjai

New User


Joined: 11 Jul 2007
Posts: 2
Location: Hyderabad

PostPosted: Wed Jul 11, 2007 4:42 pm
Reply with quote

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
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1193
Location: Dublin, Ireland

PostPosted: Thu Mar 26, 2009 2:22 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> PL/I & Assembler

 


Similar Topics
Topic Forum Replies
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top