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

Storage occupation formula for COMP-3


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

New User


Joined: 13 Jun 2005
Posts: 24

PostPosted: Tue Jan 31, 2006 1:51 pm
Reply with quote

hi guyz,

01 filed1 pic s9(3) comp-3.
for this internally how many bytes will it take.do v have to use the formula n/2 + 1 or else n+1/2.if i'm using n/2 + 1 then it'll take 3 bytes. if i use the other formula it'll take 2 bytes.
so which one shuld be used.
Back to top
View user's profile Send private message
madhavihmk

New User


Joined: 31 Jan 2006
Posts: 8
Location: Chennai

PostPosted: Tue Jan 31, 2006 2:08 pm
Reply with quote

Hi ,

U need to use n/2 + 1
Back to top
View user's profile Send private message
nuthan

Active User


Joined: 26 Sep 2005
Posts: 146
Location: Bangalore

PostPosted: Tue Jan 31, 2006 3:25 pm
Reply with quote

Hi,

If its even u have to use n/2 + 1

If its odd u have to use n+1/2
Back to top
View user's profile Send private message
Hames

New User


Joined: 03 Oct 2005
Posts: 49

PostPosted: Tue Jan 31, 2006 4:51 pm
Reply with quote

Hi nuthan,

You have to use the formula n/2 + 1.

If n is odd, you have to round the answer to the nearest integer.

that is if n/2 + 1 = 2.5 then you round it to 3.
Back to top
View user's profile Send private message
DavidatK

Active Member


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

PostPosted: Wed Feb 01, 2006 3:47 am
Reply with quote

shammiullah,


Let?s start out with some truths.
1 - The compiler always allocates comp-3 fields in full bytes (unless you?re using a Burroughs computer that allocates in 1/2 bytes, I?ll bet most of you don?t even know what a Burroughs computer is! icon_wink.gif )
2 - Each digit in the PIC occupies 1 half byte, or .5 full bytes
3 - The sign will occupy 1 half byte or .5 full bytes. (Even if it is unsigned, there is always a sign allocation)

Example: PIC S9(3) COMP-3.
PIC S9(3) COMP-3 will occupy 3 half bytes or 1.5 full bytes.
The sign occupies 1 half byte or .5 full bytes.
Therefore PIC S9(3) COMP-3 will occupy 2 full bytes.

Another example: PIC 9(4) COMP-3
A PIC 9(4) COMP-3 will occupy 4 half bytes, or 2 full bytes.
The sign (even when unsigned) will occupy 1 half byte, or .5 full bytes.
The sum of these two is 5 half bytes, or 2.5 full bytes.
Remember, the compiler always allocates in full bytes, therefore, the compiler will add 1 half byte, so PIC 9(4) will occupy 6 half bytes or 3 full bytes.

You use the formula n/2 + ? rounded up to a full byte.

n/2 = number of full bytes the digits from the PIC will use
? = the number of full bytes the sign will use
rounded to full byte = number of full bytes the compiler adds to allocate in full bytes only. This will be 0, or .5 only

Hope this helps,

Dave
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 CLIST - Virtual storage allocation error CLIST & REXX 5
No new posts CICS vs LE: STORAGE option CICS 0
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Insufficient Storage ABENDS & Debugging 7
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
Search our Forums:

Back to Top