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

Is this a valid move


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
amajhi

New User


Joined: 21 Jul 2006
Posts: 18
Location: Pune

PostPosted: Thu Nov 29, 2007 4:54 pm
Reply with quote

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:
A :12345
B :5   0
[/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
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Nov 29, 2007 5:41 pm
Reply with quote

aravind,

Quote:
MOVE A TO B.


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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Nov 29, 2007 5:58 pm
Reply with quote

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

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Thu Nov 29, 2007 6:56 pm
Reply with quote

This is what manual says about such move.
Unpredictable!!!!
Back to top
View user's profile Send private message
Aaru

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Thu Nov 29, 2007 7:02 pm
Reply with quote

Abhijit,

Thanks for the link. It makes sense as there is no necessity to move when redefined.

Aravind,

Quote:
Can we move Alphanumeric to Numeric.


check this topic

http://ibmmainframes.com/viewtopic.php?t=6130
Back to top
View user's profile Send private message
rahul.banik

New User


Joined: 23 Jan 2007
Posts: 16
Location: Mysore

PostPosted: Fri Nov 30, 2007 12:55 pm
Reply with quote

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

Senior Member


Joined: 03 Jul 2007
Posts: 1287
Location: Chennai, India

PostPosted: Fri Nov 30, 2007 1:41 pm
Reply with quote

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

New User


Joined: 13 Apr 2007
Posts: 4
Location: china

PostPosted: Fri Nov 30, 2007 8:42 pm
Reply with quote

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

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Dec 01, 2007 7:48 am
Reply with quote

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

New User


Joined: 13 Apr 2007
Posts: 4
Location: china

PostPosted: Sat Dec 01, 2007 10:32 am
Reply with quote

Hi, ammwife

thanks for ur link
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Dec 01, 2007 7:06 pm
Reply with quote

HIH.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts How to move DB2 Installation HLQ DB2 4
No new posts How to move values from single dimens... COBOL Programming 1
No new posts Reading the CSV data in COBOL and mov... COBOL Programming 4
Search our Forums:

Back to Top