View previous topic :: View next topic
|
Author |
Message |
tejdeep0274
New User
Joined: 28 Jan 2015 Posts: 10 Location: India
|
|
|
|
In general , COMP is similar to Binary format of storage and 8 bits or one byte can store signed values of -128 to +127 but when it comes to defining the picture class 1 to 4 of comp occupies 2 bytes then s9(1) comp should be able to store -32768 to +32767. But when i tried in online compilers and pass +127 value to s9(1) comp it stores only +7.
with the output as example i told the interviewers that s9(1) comp can store value upto -9 to 9 (tested in online compiler) and to store +123 we need to define s9(3) comp. But interviewers are surprised and i am confused. Please point me in right direction. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
Is your question about COBOL, or about the interviewers?
|
|
Back to top |
|
|
tejdeep0274
New User
Joined: 28 Jan 2015 Posts: 10 Location: India
|
|
|
|
About cobol and specifically COMP storage understanding. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
1. Learn how to use Code button when posting your samples of code/data to the forum. Never use attachments, and especially - screenshots!
2. The specification PIC S9(1) COMP (that is COMP-1 by default) is different from PIC S9(1). It often depends on both the platform where the program is running, and/or on the COBOL compiler version.
In case of System/Z any variable from PIC S9(1) COMP to PIC S9(4) COMP is compiled into the same IBM halfword binary field (that is DS H), which can actually store the values -32768 to +32767.
There are options in COBOL (do not recall them from my mind, and lazy to RTFM) to control: how to handle the values beyond the initially defined range (e.g. out of the range -9...+9).
It looks like the physically stored value +127, when DISPLAYED, is truncated to its initial definition S9(1). |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3076 Location: NYC,USA
|
|
|
|
Moved to right section |
|
Back to top |
|
|
tejdeep0274
New User
Joined: 28 Jan 2015 Posts: 10 Location: India
|
|
|
|
Now we are discussing comp storage and for defining NULL POINTER we use S9(4) COMP but in general . but a null pointer holds -1 when null is being fetched. The same -1 can be stored in any PIC b/w S9(1) COMP to S9(4) COMP. When we use only S9(4) COMP. Are we only to use any PIC as between 1 to 4? |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2127 Location: USA
|
|
|
|
tejdeep0274 wrote: |
Now we are discussing comp storage and for defining NULL POINTER we use S9(4) COMP but in general . but a null pointer holds -1 when null is being fetched. The same -1 can be stored in any PIC b/w S9(1) COMP to S9(4) COMP. When we use only S9(4) COMP. Are we only to use any PIC as between 1 to 4? |
1. This is not NULL POINTER, but rather NULL INDICATOR used in DB2 for unloaded database table fields. They are two different entities!
2. How the mix between POINTER-INDICATOR is related to your original question???
3.
Quote: |
Are we only to use any PIC as between 1 to 4? |
- please, explain the meaning of this sentence?
You can use various PIC S9(n), and various PIC S9(m) COMP.
If 1<=m<=4 then binary halfword (2 bytes) is allocated for this field.
If m>4, then binary fullword (4 bytes) is allocated for this field.
For PIC S9(n) - exactly n bytes are allocated for this field, as unpacked decimal format.
It is explained in details in any COBOL manual, if you had ever read at least one of them. |
|
Back to top |
|
|
|