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

Interviewers are surprised with my answer to COMP storage?


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

New User


Joined: 28 Jan 2015
Posts: 10
Location: India

PostPosted: Mon May 23, 2022 11:14 am
Reply with quote

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

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Mon May 23, 2022 8:33 pm
Reply with quote

Is your question about COBOL, or about the interviewers?
36_2_51.gif
Back to top
View user's profile Send private message
tejdeep0274

New User


Joined: 28 Jan 2015
Posts: 10
Location: India

PostPosted: Mon May 23, 2022 10:08 pm
Reply with quote

About cobol and specifically COMP storage understanding. 36_2_18.gif
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Mon May 23, 2022 10:43 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Tue May 24, 2022 5:55 am
Reply with quote

Moved to right section
Back to top
View user's profile Send private message
tejdeep0274

New User


Joined: 28 Jan 2015
Posts: 10
Location: India

PostPosted: Tue May 24, 2022 7:47 pm
Reply with quote

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

Senior Member


Joined: 29 Apr 2008
Posts: 2018
Location: USA

PostPosted: Tue May 24, 2022 8:28 pm
Reply with quote

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
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 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