View previous topic :: View next topic
|
Author |
Message |
amajhi
New User
Joined: 21 Jul 2006 Posts: 18 Location: Pune
|
|
|
|
Hi All,
In my program I have declared two variables as :
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. ARVIND.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 A PIC X(9) VALUE '12345'.
77 B REDEFINES A PIC 9(5).
PROCEDURE DIVISION.
DISPLAY 'A :' A.
MOVE A TO B.
DISPLAY 'B :' B.
STOP RUN. |
Output which I am getting is
[/code]
Here I have two doubts :-
1. Can we move Alphanumeric to Numeric.
2. If we can then for positions 2,3,4 in B why it is displaying spaces.
Thanks,
Arvind |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
aravind,
Why are you moving the value of A when it is redefined? Remove the MOVE statement and check. It will have 12345 in B.
Quote: |
Can we move Alphanumeric to Numeric. |
Yes, you can move alphanumeric to numeric. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
aravind,
Code: |
77 A PIC X(9) VALUE '12345'.
77 B REDEFINES A PIC 9(5).
|
Code: |
A has '12345 ' or '12345bbbb' where b = space
|
you moved something 'almost' to itself.
since B is numeric, the starting point of the sending field is the length of the receiving field (5) and since it is numeric, it is left justified instead of right (as in an alpha move). So you moved '5bbbb' to B and the right most byte was set to zero.
as aaru said, before the move, b contained 12345. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
This is what manual says about such move.
Unpredictable!!!! |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
Back to top |
|
|
rahul.banik
New User
Joined: 23 Jan 2007 Posts: 16 Location: Mysore
|
|
|
|
Hi All,
This is almost same like Aravind's program.But I've declared 'B' separately(not redefines A).
Code: |
WORKING-STORAGE SECTION.
77 A PIC X(9) VALUE '12345'.
77 B PIC 9(5) VALUE ZEROES.
PROCEDURE DIVISION.
DISPLAY 'A :' A.
DISPLAY 'B :' B.
MOVE A TO B.
IF B IS NUMERIC
DISPLAY ' B IS STILL NUMERIC '
END-IF.
DISPLAY 'B :' B.
GOBACK. |
Output which I am getting is like that:
Code: |
A :12345
B :00000
B :5
|
Can anyone explain it.
Thanks,
Rahul |
|
Back to top |
|
|
Aaru
Senior Member
Joined: 03 Jul 2007 Posts: 1287 Location: Chennai, India
|
|
|
|
rahul,
Welcome to the forums.
Quote: |
Output which I am getting is like that:
Code:
A :12345
B :00000
B :5
Can anyone explain it.
|
It is well explained in Dick's last post on thi stopic.
Dick Wrote:
Quote: |
since B is numeric, the starting point of the sending field is the length of the receiving field (5) and since it is numeric, it is left justified instead of right (as in an alpha move). So you moved '5bbbb' to B and the right most byte was set to zero |
Post your queries if you are not convinced. |
|
Back to top |
|
|
liwony
New User
Joined: 13 Apr 2007 Posts: 4 Location: china
|
|
|
|
Aaru wrote: |
rahul,
Welcome to the forums.
Quote: |
Output which I am getting is like that:
Code:
A :12345
B :00000
B :5
Can anyone explain it.
|
It is well explained in Dick's last post on thi stopic.
Dick Wrote:
Quote: |
since B is numeric, the starting point of the sending field is the length of the receiving field (5) and since it is numeric, it is left justified instead of right (as in an alpha move). So you moved '5bbbb' to B and the right most byte was set to zero |
Post your queries if you are not convinced. |
but Output I got which is like this:
A:12345 B:00000 B:5 0
can anyone explain it
thanks
liwony |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
The explanation for the MOVE result observed by Arvind is contained in the link below:
publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/igy3lr10/6.2.24.1?SHELF=&DT=20020920180651&CASE=
I've Quoted the pertinent parts here:
Quote: |
The following rules outline the execution of valid elementary moves. When the receiving field is:
Numeric or Numeric-edited:
Except where zeros are replaced because of editing requirements, alignment by decimal point and any necessary zero filling take place, as described under "Alignment rules" in topic 5.1.6.6.
MMW- this produces the intermediate result "5bbbb"- MMW
If the receiving item is unsigned, the absolute value of the sending item is moved, and no operational sign is generated for the receiving item.
When the sending item is alphanumeric, the data is moved as if the sending item were described as an unsigned integer.
MMW- to produce an unsigned integer the MOVE rtn ORs the hi-order nybble of the low-order byte (X'40') to produce an X'F0' - this produces the final result "5bbb0"- MMW
|
|
|
Back to top |
|
|
liwony
New User
Joined: 13 Apr 2007 Posts: 4 Location: china
|
|
|
|
Hi, ammwife
thanks for ur link |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
HIH. |
|
Back to top |
|
|
|