View previous topic :: :: View next topic

Author 
Message 
vaibhavjadhav
New User
Joined: 27 Jul 2007 Posts: 33 Location: mumbai




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: 
WORKINGSTORAGE SECTION.
01 WSA1 PIC X(17)
VALUE '12345678901.1234'.
01 WSB1 PIC 9(17).
01 WSB2 PIC S9(11)V9(4).
01 WSB3 PIC S9(12)V9(4).
01 WSB4 PIC 9(12)V9(4).
PROCEDURE DIVISION.
MOVE WSA1 TO WSB1
MOVE WSA1 TO WSB2
MOVE WSA1 TO WSB3
MOVE WSA1 TO WSB4
Output:
WSA1 : 12345678901.1234
WSB1 : 12345678901.1234
WSB2 : 678901.1234000{
WSB3 : 5678901.1234000{
WSB4 : 5678901.12340000 
Please do reply. 

Back to top 




dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6962 Location: porcelain throne




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 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 7869 Location: Bellevue, IA




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 


dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6962 Location: porcelain throne




unfortunately, his destination variables are display, which means the decimal has not been removed.
Code: 
01 WSB1 PIC 9(17).
01 WSB2 PIC S9(11)V9(4).
01 WSB3 PIC S9(12)V9(4).
01 WSB4 PIC 9(12)V9(4).
PROCEDURE DIVISION.
...
MOVE WSA1 TO WSB1
MOVE WSA1 TO WSB2
MOVE WSA1 TO WSB3
MOVE WSA1 TO WSB4
Output:
WSB1 : 12345678901.1234
WSB2 : 678901.1234000{
WSB3 : 5678901.1234000{
WSB4 : 5678901.12340000



Back to top 


Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 7869 Location: Bellevue, IA




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 WSB1 is 17 bytes to 17 bytes; decimal positions align to the right of the last digit so WSB1 is a copy of WSA1.
2. The move to WSB2 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 WSB2 are zero. The last 11 bytes of WSA1 are moved to the 11 bytes of WSB2 before the decimal point. Since WSB2 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 WSB3 works exactly the same as for the move to WSB2, except one more character is moved before the decimal point.
4. The move to WSB4 works exactly the same as the move to WSB3, 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 


