View previous topic :: View next topic
|
Author |
Message |
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
|
|
hi,
what happens when we move comp-1 value to comp-3? |
|
Back to top |
|
|
khamarutheen
Active Member
Joined: 23 Aug 2005 Posts: 677 Location: NJ
|
|
Back to top |
|
|
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
|
|
THANKS FOR YOUR REPLY.
BUT I ASKED WHAT HAPPENS WHEN WE MOVE COMP-1 VALUE TO COMP-3? |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi karthik1680,
Here is the answer for your query.
example
Quote: |
01 A PIC 9(4) COMP value 1000.
01 B PIC 9(4) COMP-3 value 3000. |
Now, inside the procedure division say move A to B.
The result of B(comp-3) variable will be 1000+
NOTE
I tested using MS COBOL 85.
Let me know in case of any concerns. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi There,
As a follow up to my previous post I would to like add some more points about comp and comp3.
Like comp-3 will add '+' in the LSB and store the rest of the bits.
Say for eg:
01 A pic 9(5) value 10001 comp.
01 B pic 9(4) value 3000 comp3.
Now if we use Move A to B.
The result of B will be 0001+. As you can see '+' is placed in place of '1' in the LSB of B after moving value of A to B.
Hope now you understand the actual usage of comp and comp3.
NOTE
Make use of our forums for various forms of COMP and COMP-3. |
|
Back to top |
|
|
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
|
|
hi iknow,
thanks for your reply.but what happens in vs-cobol . this is a interview question |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi karthik1680,
You raised an excellent quetion. I need to check on this one.
I will let you know the exact solution. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Iknow,
The ques is about COMP-1 not COMP. |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi mmwife,
Sorry for the inconvenience. Let me give the exact solution on this.
Thanks for correcting me. |
|
Back to top |
|
|
karthik1680 Warnings : 2 New User
Joined: 14 May 2005 Posts: 64 Location: chennai
|
|
|
|
hi iknow
waiting for your reply |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
COMP-1 is a floating point field, that requires no picture.
In the following examples, please pay careful attention to how positive and negative numbers are handled. Particularly, pay attention to how fractional numbers are stored and rounded when moved to the COMP-3 field in examples 6 and 7. Then look at example 8 and how it moves to a COMP-3 field with sufficient precision to show the inaccuracies of floating point numbers.
The floating point number is displayed as ?-.21474000E 05?
The letters at the end of the other numbers represent the number + sign. If you look at these in hex, you will understand.
If this doesn?t answer your questions. Come back again.
WORKING-STORAGE SECTION.
01 WS.
05 WS-COMP-1 COMP-1.
05 WS-COMP-3 PIC S9(7) COMP-3.
05 WS-COMP-3A PIC S9(9) COMP-3.
05 WS-COMP-3B PIC S9(9)V9(6) COMP-3.
Example 1:
MOVE -12345 TO WS-COMP-3.
DISPLAY WS-COMP-3.
Results: 001234N
Example 2:
MOVE -21474 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
MOVE WS-COMP-3 TO WS-COMP-3A.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' ' WS-COMP-3A.
Results: -.21474000E 05 002147M 00002147M
Example 3:
MOVE -1 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' '.
Results: -.10000000E 01 000000J
Example 4:
MOVE 21474 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' '.
Results: .21474000E 05 0021474
Example 5:
MOVE 1 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' '.
Results: .10000000E 01 0000001
Example 6:
MOVE 27.563 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' '.
Results: .27563004E 02 0000028
Example 7:
MOVE 27.499 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3.
DISPLAY WS-COMP-1 ' ' WS-COMP-3 ' '.
Results: .27498993E 02 0000027
Example 8:
MOVE 27.499 TO WS-COMP-1.
MOVE WS-COMP-1 TO WS-COMP-3B.
DISPLAY WS-COMP-1 ' ' WS-COMP-3B ' '.
Results: .27498993E 02 000000027498993 |
|
Back to top |
|
|
iknow
Active User
Joined: 22 Aug 2005 Posts: 411 Location: Colarado, US
|
|
|
|
Hi Davidatk,
Thanks for your reply.
I tried using MS-COBOL85 but the problem is COMP-1 is not recognized by MS-COBOL85. |
|
Back to top |
|
|
|