Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Alphanumeric to numeric moves

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Alphanumeric to numeric moves
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: 6968
Location: porcelain throne

PostPosted: Thu Mar 26, 2009 10:33 pm    Post subject:
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: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Thu Mar 26, 2009 10:46 pm    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Thu Mar 26, 2009 10:56 pm    Post subject:
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: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Fri Mar 27, 2009 12:10 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Validate if a Value from the file is ... balacsv2 COBOL Programming 8 Mon Jun 19, 2017 11:52 pm
No new posts Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
This topic is locked: you cannot edit posts or make replies. How to move a long alphanumeric data ... lind sh COBOL Programming 8 Mon Dec 05, 2016 7:51 pm
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us