View previous topic :: View next topic
|
Author |
Message |
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Hi ,
I am getting data conversion error, here is the details:
When converting Fixed Decimal to Pic to Char, the following works fine:
EVENT_AMT_FD = -12345.67;
EVENT_AMT_P4 = EVENT_AMT_FD;
EVENT_AMTCHR = EVENT_AMT_P4;
Where
DCL EVENT_AMT_FD FIXED DEC(13,2);
DCL EVENT_AMT_P4 PIC'(10)ZV.99S';
DCL EVENT_AMTCHR CHAR(14);
Result is EVENT_AMTCHR=' 12345.67-'
But in the below case, I get conversion error.
EVENT_AMTCHR = ' 12345.67-';
EVENT_AMT_P4 = EVENT_AMTCHR; ==> this statement fails with conversion condition
EVENT_AMT_FD = EVENT_AMT_P4;
Where
DCL EVENT_AMT_FD FIXED DEC(13,2);
DCL EVENT_AMT_P4 PIC'(10)ZV.99S';
DCL EVENT_AMTCHR CHAR(14);
Thanks |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2022 Location: USA
|
|
|
|
I don't have PL/I compiler available. But in theory:
EVENT_AMTCHR is stored as
EVENT_AMT_P4 is assigned the value extended to its full length (14 chars), using string assignment rules:
Code: |
EVENT_AMT_P4 = ' 12345.67- ' |
When trying to apply the declared PIC template, it must fail at the first dot in place of expected digit, isn't it?
Code: |
EVENT_AMTCHR ' 12345.67-'
EVENT_AMT_P4 ' 12345.67- '
PIC 'ZZZZZZZZZZV.99S'
Result ' 12345????????'
|
I guess right alignment of the value in EVENT_AMTCHR is needed, with total length 14 characters.
P.S.
Conversion from DECIMAL to PICTURE is performed using different rules. |
|
Back to top |
|
|
maxsubrat
Active User
Joined: 27 Feb 2008 Posts: 110 Location: india
|
|
|
|
Thanks for the reply sergeyken.
Suppose I declare,
DCL EVENT_AMT_P5 PIC'(10)SV.99';
then during conversion, it dis not fail.
If I declare , EVENT_AMT_P5 PIC'(10)ZV.99S';
then it fails due to :
The CONVERSION condition was raised because a conversion error occurred when converting a character string to an arithmetic with IBM0032S ONCODE=612.
Thanks |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Have you read the PL/I Language Reference manual for your compiler level? I have looked at the manual for version 5.2.4 and there is a complete chapter (chapter 4) on data conversion. It is not up to me to read it to help you. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2022 Location: USA
|
|
|
|
maxsubrat wrote: |
Thanks for the reply sergeyken.
Suppose I declare,
DCL EVENT_AMT_P5 PIC'(10)SV.99';
then during conversion, it dis not fail.
If I declare , EVENT_AMT_P5 PIC'(10)ZV.99S';
then it fails due to :
The CONVERSION condition was raised because a conversion error occurred when converting a character string to an arithmetic with IBM0032S ONCODE=612.
Thanks |
I agree with Nic Clouston: the conversion between character strings, and various numeric formats is usually very tricky. It may depend not only on the used language, but also on the version of the language/compiler. You must read carefully the manual on your specific version of PL/I syntax/compiler. I don't have any PL/I manual on hand, and the last time I used PL/I was about 12-15 years ago.
I mentioned one of possible theoretical conversion problems; this may be true or not.
I suggest you to perform multiple stand-alone tests on CONVERSION-ONLY between various data formats you're interested in, to find out how the actual conversion rules do work? The description from a manual is often very messy; I prefer to try the required options in my own minor tests.
This is your own major task, before asking such questions in the forum, without your own investigation
I do not see if you really tried to think about the origins of your problem, did you? |
|
Back to top |
|
|
|