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: |
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 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: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
|