View previous topic :: View next topic
|
Author |
Message |
mlp
New User
Joined: 23 Sep 2005 Posts: 91
|
|
|
|
There is a scenario which I am facing currently as mentioned below.
01 XYZ PIC X(2000).
01 PQR PIC X(2001).
The PQR has some data and in the last byte of PQR there is character 'V' stored and then we issue move statement as below.
MOVE XYZ TO PQR
After this the 2001th byte of PQR which has character 'V' becomes space.
I checked many times in the code but could not figure out the reason.
As per my knowledge the last character should have been retained.
Can anybody justify this behaviour? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
but as per cobol knowledge ( and the <majority> of other languages )
char moving
from smaller to larger clears/fills the <excess> trailing <space> with blanks
from larger to smaller ( if allowed ) truncates the excess ( trailing side )
numeric moving
from smaller to larger clears/fills the <excess> leading <space> with zeroes
from larger to smaller ( if allowed ) truncates the excess (leading side )
that' s what is GENERALLY safe to assume
to retain <some> values in the destination use a <substringing> approach,
==>for cobol the reference modification |
|
Back to top |
|
|
mlp
New User
Joined: 23 Sep 2005 Posts: 91
|
|
|
|
I tried with a sample program and found out that whatever you are saying is correct.
My wrong presumption led me to post this topic. So learning is, dont presume without verification !!
It is always better to be enlightened..... |
|
Back to top |
|
|
jerryte
Active User
Joined: 29 Oct 2010 Posts: 202 Location: Toronto, ON, Canada
|
|
|
|
The below is from the COBOL Reference guide. This is under the heading "Alignment Rules" in the Data Division Overview chapter. It is refering to any kind of a data move.
Alphanumeric, alphanumeric-edited, alphabetic, DBCS
For these receiving items, the following rules apply:
1. The data is aligned at the leftmost character position, and (if necessary) truncated or padded with spaces at the right.
2. If the JUSTIFIED clause is specified for this receiving item, the above rule is modified as described in “JUSTIFIED clause”
COBOL will truncate or pad a field as needed. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
In your example, because of the data-lengths, COBOL probably generates an Assembler MVCL or (worst case), calls a COBOL run-time routine.
Bill |
|
Back to top |
|
|
|