View previous topic :: View next topic
|
Author |
Message |
Debasis Misra Warnings : 1 New User
Joined: 16 Sep 2008 Posts: 72 Location: Bangalore
|
|
|
|
A PIC 9(05).
B PIC 9(3).
Case1
-----------
Move A to B
Then, if A = 12345
B = 345
So, my first 2 MSB is truncating.
Case 2
-------------
A temporary variable : C PIC X(3).
Move A to C
Move C to B
Then, if A = 12345
B = 123
Its correct.
But if A = 00009
then B =000
Which is incorrect.
-----------------------
A and C declaration we cant change.
Please help me out. |
|
Back to top |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
Debasis Misra,
Why dont you declare
B PIC 9(3) as
B PIC 9(5).
if you have a input which can be a 5 Digit number. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Which is incorrect. |
No, it is correct (per cobol rules) - it is just not what you want.
Simply said it is extremely poor design to try to put 5 digits into 3.
You will change something or run the risk of something important being processed incorrectly.
If a value is 12345 why would 123 be an acceptable result for a numeric move? |
|
Back to top |
|
|
Debasis Misra Warnings : 1 New User
Joined: 16 Sep 2008 Posts: 72 Location: Bangalore
|
|
|
|
Sorry ANAND, its my mistake.
'A and C declaration we cant change' -- wrong
'A and B declaration we cant change' -- correct one. |
|
Back to top |
|
|
anandinmainframe
Active User
Joined: 31 May 2007 Posts: 171 Location: India
|
|
|
|
Debasis Misra,
Quote: |
'A and B declaration we cant change' -- correct one.
|
if your declaration is like this then i guess you can never resolve this problem. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Without regard to the specific lines of code and variable definitions, it would be a good idea to show all possible patterns of input that may arrive for processing and what the output should be for each different type of input.
Once the rules are understood by those of us involved with this topic, more useful suggestions will result. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
If you desire 123 in B, try MOVE A(1:) to B(1:).
But, as Dick has hinted, you may be surprised by the results with some A values, e.g. A=12; result of MOVE: B=000. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
You could use EVALUATE to determine which bytes of A to move to B, but as was said earlier this is a bad design -- moving 5 bytes to 3 bytes means something is going to get lost. |
|
Back to top |
|
|
|