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

What happens when we move comp-1 value to comp-3


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

New User


Joined: 14 May 2005
Posts: 64
Location: chennai

PostPosted: Wed Dec 07, 2005 7:57 am
Reply with quote

hi,

what happens when we move comp-1 value to comp-3?
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Wed Dec 07, 2005 10:58 am
Reply with quote

hi frnd,
Refer this link for more thing about COMP Fields

www.discinterchange.com/reading_COBOL_layouts_.html
Back to top
View user's profile Send private message
karthik1680
Warnings : 2

New User


Joined: 14 May 2005
Posts: 64
Location: chennai

PostPosted: Wed Dec 07, 2005 11:44 am
Reply with quote

THANKS FOR YOUR REPLY.
BUT I ASKED WHAT HAPPENS WHEN WE MOVE COMP-1 VALUE TO COMP-3?
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Thu Dec 08, 2005 9:36 am
Reply with quote

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
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Thu Dec 08, 2005 9:49 am
Reply with quote

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
View user's profile Send private message
karthik1680
Warnings : 2

New User


Joined: 14 May 2005
Posts: 64
Location: chennai

PostPosted: Fri Dec 09, 2005 7:00 am
Reply with quote

hi iknow,
thanks for your reply.but what happens in vs-cobol . this is a interview question
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Fri Dec 09, 2005 7:13 am
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Dec 10, 2005 6:01 am
Reply with quote

Hi Iknow,

The ques is about COMP-1 not COMP.
Back to top
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Sat Dec 10, 2005 11:45 am
Reply with quote

Hi mmwife,

Sorry for the inconvenience. Let me give the exact solution on this.


Thanks for correcting me.
Back to top
View user's profile Send private message
karthik1680
Warnings : 2

New User


Joined: 14 May 2005
Posts: 64
Location: chennai

PostPosted: Tue Dec 13, 2005 6:48 pm
Reply with quote

hi iknow
waiting for your reply
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Tue Dec 13, 2005 11:58 pm
Reply with quote

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
View user's profile Send private message
iknow

Active User


Joined: 22 Aug 2005
Posts: 411
Location: Colarado, US

PostPosted: Wed Dec 14, 2005 6:21 am
Reply with quote

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
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 COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
No new posts Interviewers are surprised with my an... Mainframe Interview Questions 6
No new posts How to move DB2 Installation HLQ DB2 4
Search our Forums:

Back to Top