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

COMP, COMP1, COMP2 & COMP3 in COBOL


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
raghu_4412
Warnings : 1

New User


Joined: 01 Mar 2004
Posts: 4
Location: Bangalore

PostPosted: Sat Mar 06, 2004 8:17 am
Reply with quote

hello sir,

please explain me about COMP, COMP1, COMP2 & COMP3 with an example? how is memory allocated in each of the above?

what is meant by halfword & fullword binary in COMP & how the memory allocates?


please clear me doubt about the above mentiones questions.
Back to top
View user's profile Send private message
sanga_1978

New User


Joined: 07 Mar 2004
Posts: 1

PostPosted: Sun Mar 07, 2004 8:35 pm
Reply with quote

hai,


the following is the details of COMP items.


BINARY
Specified for binary data items. Such items have a decimal equivalent
consisting of the decimal digits 0 through 9, plus a sign. Negative
numbers are represented as the two's complement of the positive number
with the same absolute value.

The amount of storage occupied by a binary item depends on the number
of decimal digits defined in its PICTURE clause:

Digits in PICTURE Clause Storage Occupied
1 through 4 2 bytes (halfword)
5 through 9 4 bytes (fullword)
10 through 18 8 bytes (doubleword) │
The leftmost bit of the storage area is the operational sign.

PACKED-DECIMAL
Specified for internal decimal items. Such an item appears in storage
in packed decimal format. There are 2 digits for each character
position, except for the trailing character position, which is
occupied by the low-order digit and the sign. Such an item can
contain any of the digits 0 through 9, plus a sign, representing a
value not exceeding 18 decimal digits.

The sign representation uses the same bit configuration as the 4-bit
sign representation in zoned decimal fields (see Table 12 in
topic 2.7.12.2 and Table 13 in topic 2.7.12.2).

COMPUTATIONAL or COMP
Representation of the COMPUTATIONAL phrase is system-dependent and is
normally assigned to representations that yield the greatest
efficiency when arithmetic operations are performed on that system.
For the VS COBOL II compiler, the COMPUTATIONAL phrase is synonymous
with BINARY.

COMPUTATIONAL-1 or COMP-1
Specified for internal floating-point items (single precision).
COMP-1 items are 4 bytes long. The sign is contained in the first bit
of the leftmost byte and the exponent is contained in the remaining 7
bits. The last 3 bytes contain the mantissa.

COMPUTATIONAL-2 or COMP-2
Specified for internal floating-point items (double precision).
COMP-2 items are 8 bytes long. The sign is contained in the first bit
of the leftmost byte and the remaining 7 bits contain the exponent.
The remaining 7 bytes contain the mantissa.

COMPUTATIONAL-3 or COMP-3 (internal decimal)
For VS COBOL II, this is the equivalent of PACKED-DECIMAL.

COMPUTATIONAL-4 or COMP-4 (binary)
For VS COBOL II this is the equivalent of BINARY.

by
g.s.sanker
Back to top
View user's profile Send private message
thalapradheep

New User


Joined: 05 Dec 2007
Posts: 4
Location: India

PostPosted: Mon Jan 28, 2008 5:01 pm
Reply with quote

How much bytes will S9(18) Comp will occupy?
Back to top
View user's profile Send private message
sri_mf

Active User


Joined: 31 Aug 2006
Posts: 218
Location: India

PostPosted: Mon Jan 28, 2008 5:08 pm
Reply with quote

How much bytes will S9(18) Comp will occupy?


8 bytes
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 632
Location: Wisconsin

PostPosted: Mon Jan 28, 2008 6:24 pm
Reply with quote

Really? 8 bytes? It uses less than 1/2 of its size? That doesn't seem quite logical to me... Does it seem correct to you? Which platform is that on? From what I read the size of COMP is compiler vendor specific.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jan 28, 2008 10:14 pm
Reply with quote

Hello,

With Enterprise COBOL, these:

Code:
 77  SMLBINARY           PIC S9(2)  COMP  VALUE 10.   
 77  MEDBINARY           PIC S9(9)  COMP  VALUE 100.   
 77  BIGBINARY           PIC S9(18) COMP  VALUE 100.   
result in these lengths:
Code:
 BLW=00000+018         2C
 BLW=00000+020         4C
 BLW=00000+028         8C
Back to top
View user's profile Send private message
Shanmugavel

New User


Joined: 15 Dec 2006
Posts: 7
Location: CHENNAI

PostPosted: Sat Jun 14, 2008 11:14 pm
Reply with quote

dick scherrer,

I didn't understand the above piece of code and BLW is.
Can you explain it some more?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sun Jun 15, 2008 2:46 am
Reply with quote

Hello,

The 77-level variables "code" is to show 3 binary numbers of different length.

The "result" is what the compiler assigned for these variables and is generated in the listing from the compile.

There are no executable instructions. These were only to demonstrate the length of these data items.
Back to top
View user's profile Send private message
sid_aec

New User


Joined: 01 Jul 2008
Posts: 60
Location: Kolkata

PostPosted: Tue Jul 15, 2008 3:34 pm
Reply with quote

Hi ,

I think what senario Dick actually wanted to explain is as below:

PIC S9(01) COMP -> PIC S9(04) COMP :Takes 2 bytes.
PIC S9(05) COMP -> PIC S9(09) COMP :Takes 4 bytes.
PIC S9(10) COMP or above :Takes 8 bytes.
Back to top
View user's profile Send private message
manishmittal

New User


Joined: 25 Apr 2008
Posts: 49
Location: Gurgaon

PostPosted: Fri Jun 12, 2009 3:21 pm
Reply with quote

Hi all,

My apologies for replying to an year old post.But i just want to confirm if the above answer is correct.

Thanks.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 12, 2009 3:27 pm
Reply with quote

manishmittal wrote:
My apologies for replying to an year old post.But i just want to confirm if the above answer is correct.


well you could either mimic Dick's experiment, or you could check the COBOL Prg Guide and insure that sanga_1978 paraphrased everything properly.
Back to top
View user's profile Send private message
manishmittal

New User


Joined: 25 Apr 2008
Posts: 49
Location: Gurgaon

PostPosted: Fri Jun 12, 2009 3:30 pm
Reply with quote

I tried it by defining some binary variables with different lenghts in a copubook and then opening this copybook against a dummy input file usinf Fileaid.But the results i got are conflicting with this post.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 12, 2009 5:10 pm
Reply with quote

manishmittal wrote:
I tried it by defining some binary variables with different lenghts in a copubook and then opening this copybook against a dummy input file usinf Fileaid.But the results i got are conflicting with this post.


what different lenghts did you use? elementary items defined as USAGE Binary are 2,4,8 bytes long, depending upon the pic clause.

what are the conflicting results?
Back to top
View user's profile Send private message
manishmittal

New User


Joined: 25 Apr 2008
Posts: 49
Location: Gurgaon

PostPosted: Fri Jun 12, 2009 5:15 pm
Reply with quote

Please accept my apologies.After going thru the Program Reference guide and changing the copybook according to that i found the same results as mentioned in the post..

Thanks for the clarification.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jun 12, 2009 5:25 pm
Reply with quote

Manish,

apologies are not needed.
That you have learned something is of paramount importance;
that was the reason for my remarks.
good luck!
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
Search our Forums:

Back to Top