View previous topic :: View next topic
|
Author |
Message |
Lavanya_Dhushetty Warnings : 2 New User
Joined: 30 Aug 2007 Posts: 24 Location: Chennai
|
|
|
|
See the following table definition:
01 WS-TABLE.
05 WS-VAR-A PIC X(2) OCCURS 1 to 90 TIMES DEPENDING ON WS-D.
If WS-D is 50 how much memory will be used by this table?
Answers:
a.180 Bytes
b.90 Bytes
c.COBOL will allocate depending on the availability of the memory
d.100 Bytes
e.182 Bytes |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Answer a. |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
COBOL will allocate maximum memory that can an OCCURS DEPENDING ON table can occupy. I hope you are clear with the answer now..
This can be confusing but it is the fact. Dynamic memory allocation is not very easy in COBOL. |
|
Back to top |
|
|
Lavanya_Dhushetty Warnings : 2 New User
Joined: 30 Aug 2007 Posts: 24 Location: Chennai
|
|
|
|
How it could be A???????Can U please explain it??? |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
|
|
Lavanya, I have already given the explanation. This much explantion should be enough for an interview question. I told you this can be confusing, as your experience will grow then things will be clearer to you.
One more thing, I was actually expecting question like 'What is advantage of occurs depending on if it allocates max memory?'
Here is the key-
You don't save memory in program, but when you write record to file, you will save those bytes. Let me know if you have any further question.
Murali,
Question was about memory allocation I guess. Not about calculating length of field. COBOL does not dynamically allocate memory for occurs depending on. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Lavanya_Dhushetty wrote: |
How it could be A???????Can U please explain it??? |
What should be the answer accroding to you ? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
How it could be A???????Can U please explain it??? |
Quote: |
PIC X(2) OCCURS 1 to 90 TIMES |
How could the length be anything other than 180 (2x90)? |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
dick scherrer wrote: |
Hello,
Quote: |
How it could be A???????Can U please explain it??? |
Quote: |
PIC X(2) OCCURS 1 to 90 TIMES |
How could the length be anything other than 180 (2x90)? |
The amount of memory allocated for the table would be 180 but the amount used would be 100 (2 x 90 and 2 x 50). The extra 80 bytes would be wasted since it can not be reallocated. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
I believe that (unlike dasd) when space is allocated by a load module it is also used. Those bytes are filled (just not referenced when the code runs).
I suppose the "right" answer to the original question depends on how the question was intended |
|
Back to top |
|
|
|