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

Alphanumeric to numeric moves


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

New User


Joined: 27 Jul 2007
Posts: 33
Location: mumbai

PostPosted: Thu Mar 26, 2009 10:29 pm
Reply with quote

Hi,

I am moving some alpha numeric fields to numeric fields but i am not getting the correct output. please have alook at the move statements shown below, also please provide me with the correct output.

Code:
WORKING-STORAGE SECTION.                 
01 WS-A1                        PIC X(17)
     VALUE '-12345678901.1234'.         
01 WS-B1                       PIC 9(17).
01 WS-B2                       PIC S9(11)V9(4).
01 WS-B3                       PIC S9(12)V9(4).
01 WS-B4                       PIC  9(12)V9(4).

PROCEDURE DIVISION.   
    MOVE WS-A1 TO WS-B1
    MOVE WS-A1 TO WS-B2
    MOVE WS-A1 TO WS-B3
    MOVE WS-A1 TO WS-B4

Output:
WS-A1 : -12345678901.1234
WS-B1 : -12345678901.1234
WS-B2 : 678901.1234000{ 
WS-B3 : 5678901.1234000{
WS-B4 : 5678901.12340000


Please do reply.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Mar 26, 2009 10:33 pm
Reply with quote

try numval..........as far as
Quote:
also please provide me with the correct output.


you are going to have to generate the output yourself.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 26, 2009 10:46 pm
Reply with quote

Quote:
I am moving some alpha numeric fields to numeric fields but i am not getting the correct output.
Based on the variables you provided and the move statements given, the output you display is exactly what is expected from COBOL.

What do you consider the "correct output"?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Thu Mar 26, 2009 10:56 pm
Reply with quote

unfortunately, his destination variables are display, which means the decimal has not been removed.
Code:

01 WS-B1 PIC 9(17).
01 WS-B2 PIC S9(11)V9(4).
01 WS-B3 PIC S9(12)V9(4).
01 WS-B4 PIC 9(12)V9(4).

PROCEDURE DIVISION.
...
MOVE WS-A1 TO WS-B1
MOVE WS-A1 TO WS-B2
MOVE WS-A1 TO WS-B3
MOVE WS-A1 TO WS-B4

Output:
WS-B1 : -12345678901.1234
WS-B2 : 678901.1234000{
WS-B3 : 5678901.1234000{
WS-B4 : 5678901.12340000
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Fri Mar 27, 2009 12:10 am
Reply with quote

To expand upon my earlier post: the COBOL Language Reference manual (link at the top of the page) section 6.2.24.2 states that when doing an elementary item move, and the receiving field is numeric, and the sending field is alphanumeric, the sending field is treated as an unsigned integer. Does it matter that the sending field has a period and a dash in it? No, because all the fields are DISPLAY so no conversions will be done. If any receiving field were computational or packed decimal there would be a S0C7 abend.

1. The move to WS-B1 is 17 bytes to 17 bytes; decimal positions align to the right of the last digit so WS-B1 is a copy of WS-A1.

2. The move to WS-B2 aligns the sending field decimal point (to the right of the last digit) to the implied decimal point. Since there are no digits after the decimal point in the sending field, the last 4 digits of WS-B2 are zero. The last 11 bytes of WS-A1 are moved to the 11 bytes of WS-B2 before the decimal point. Since WS-B2 is a signed field, the F0 for the last digit is converted to a plus sign (C0), giving the indicated value.

3. The move to WS-B3 works exactly the same as for the move to WS-B2, except one more character is moved before the decimal point.

4. The move to WS-B4 works exactly the same as the move to WS-B3, except the final character is left as an unsigned integer and therefore F0 instead of C0.

Understanding the way COBOL does MOVE statements requires reading the manual since the results may not be obvious unless you've really studied the rules.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Convert HEX to Numeric DB2 3
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts Handling the numeric data in unstring... COBOL Programming 18
No new posts convert alphanumeric PIC X(02) to hex... COBOL Programming 3
Search our Forums:

Back to Top