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

How the comp-3 is stored in the system


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

New User


Joined: 31 May 2005
Posts: 11

PostPosted: Tue May 31, 2005 3:51 pm
Reply with quote

hi,

i just want to know how the comp-3 is stored in the system and when it

is displayed how is it displayed.

Ex : 01 z pic s9(4) comp-3 value +1234.

how is it stored .....

and if given

display z.

how is it displayed

siva
Back to top
View user's profile Send private message
kanak

Moderator


Joined: 12 Mar 2005
Posts: 252
Location: India

PostPosted: Tue May 31, 2005 4:31 pm
Reply with quote

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

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.
No idea how it get displayed.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Jun 01, 2005 8:37 am
Reply with quote

Hi siva,

It is converted to external decimal format (unpacked) before it is DISPLAYed.

Everthing looks normal except for the sign: it's diplayed using the low order 4 bits of the packed field as the high order 4 bits of the displayed byte and the low order digit of the packed field as the low order 4 bits of the diplayed byte.

E.g. X'011C' DISPLAYs as 01A (X'F0F1C1').
Back to top
View user's profile Send private message
Ashutosh Shrinet

New User


Joined: 22 Aug 2004
Posts: 10
Location: New Delhi

PostPosted: Wed Jun 01, 2005 8:46 am
Reply with quote

hi siva
comp3 stored as packed decimal format.if u want to display it first u move this variable into another variable which's usage clause is display. then u can see the value of comp3.otherwise it will show in hexadecimal.
Back to top
View user's profile Send private message
senthilkumar selvaraju

New User


Joined: 30 May 2005
Posts: 16

PostPosted: Wed Jun 01, 2005 12:25 pm
Reply with quote

hi siva, Ashutosh Shrinet message is correct. as per your example it takes 3 bytes( n/2 + 1)

n- number of bytes (1234 i.e 4 bytes)

1 - for sign so (4/2 + 1) = 3 bytes (but i am not sure about odd bytes storage ) If any having answer please reply.........
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Fri Jun 03, 2005 4:35 am
Reply with quote

Hi Ashutosh,

You said:
Quote:
comp3 stored as packed decimal format.if u want to display it first u move this variable into another variable which's usage clause is display. then u can see the value of comp3.otherwise it will show in hexadecimal.

Have you ever tried to DISPLAY a COMP-3 field? You're in for a surprise.

The best way to formulate the size of a packed (COMP-3) field is to count the number of digit desired add 1 for the sign and divide by 2. BTW, there's ALWAYS a sign, even if you don't put one in the PIC.

If there's a remainder add 1 to answer. For example:
1234 is 4 digits; add 1 for the sign; divide by 2 = 2 1/2; add 1 to the 2 in the ans = 3 bytes.

12345 is 5 digits; add 1 for the sign; divide by 2 = 3; no remainder, no add 1; the ans = 3 bytes.
Back to top
View user's profile Send private message
mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 237
Location: USA

PostPosted: Sun Jun 05, 2005 2:28 am
Reply with quote

Jack,

We remember it this way

Quote:
For Even Digit Field formula is --> N /2 + 1
For Odd Digit Field formula is --> (N + 1)/2


icon_lol.gif

Regards
Mayuresh
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Jun 05, 2005 3:36 am
Reply with quote

Mayuresh,

But 1st, one must understand. icon_idea.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Jun 13, 2005 8:31 am
Reply with quote

Hi Mayuresh,

I should have added this to my previous post.

In my opinion the best way to calc the # of bytes in a comp-3 field is to total the # of 9s. If the total is even, divide by 2; if odd add 1 THEN divide by 2.

It eliminates playing w/the fraction and makes the division straightforward.
Back to top
View user's profile Send private message
mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 237
Location: USA

PostPosted: Mon Jun 13, 2005 4:15 pm
Reply with quote

Very True Jack,

Its the same formula which I showed.

EVEN 9's --> (N/2 + 1)
ODD 9's --> ((N+1)/2)

N = Number of 9's

icon_biggrin.gif

Regards,
Mayuresh
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jun 14, 2005 7:35 am
Reply with quote

No, Mayuresh. Mine was a sentence; YOUR'S was a formula. icon_wink.gif
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 Sysplex System won't IPL at DR site I... All Other Mainframe Topics 2
No new posts How to delete a user's alias from the... JCL & VSAM 11
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts JCL Dynamic System Symbols JCL & VSAM 3
Search our Forums:

Back to Top