View previous topic :: View next topic
|
Author |
Message |
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Can we declare in working storage the following:-
05 ws-emp occurs 50 times depending on emp-count
10 ws-name pic x(10)
10 ws-address pic x(50)
10 ws-prev-comp occurs 10 times depending on ws-prev-comp-count
I know this is not possible. But my compiler passes it through and doesn't give any error message. But I need to know the logical reason as to why this cannot happen and why does compiler pass it through.
Thanks,
Simmi |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
What's not possible? What line follows your last line?
[BTW - you need periods (.) after each line.] |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Pls do not be concerned about the SYNTAX. I know such declaration in working storage won't give correct results when you run it. But I want to know the logical reason for the same as to why this declaration is logically incorrect?. Hope I'm clear. |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Actually this question was asked in an interview and all I know is such table declaration doesn't give correct results and I want to know logical reason for the same. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
Not clear at all, because you haven't said what results you are looking for, and with no PROCEDURE code, nothing happens anyway. Just declaring fields cannot produce results. |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Ok I think I should re-frame my question.
It is as follows:-
1) Is the above declaration for the table correct and possible?
2) Is the above declaration logical?
3) Will it yield correct results?
It's an interview question and all I know about it is that this declaration is logically incorrect and now I'm curious to understand the reason for the same.
Can you help me with that?
Thanks,
Simmi |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
simmimahajan wrote: |
1) Is the above declaration for the table correct and possible?
2) Is the above declaration logical?
3) Will it yield correct results? |
I may be old and blind, but I don't see anything wrong with it. Perfectly logical and should not have any problem using it correctly.
Why do you thing it isn't? |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Hi William,
I'm sorry to say but all I know is this declaration is logically incorrect and believe me I'm striving hard to find answer for the same but am unable to do that. I thought somebody out here can answer me as to why this is logically incorrect. The interviewer did not reply as to why this is incorrect and since then am trying to figure out the reason for the same and finally posted it as a query.
Thanks,
Simmi |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
simmimahajan wrote: |
I'm sorry to say but all I know is this declaration is logically incorrect |
Wrong!
From the Enterprise COBOL for z/OS Programming Guide Version 3 Release 3:
Quote: |
The following example illustrates the possible types of occurrence of complex ODO: |
Code: |
01 FIELD-A.
02 COUNTER-1 PIC S99.
02 COUNTER-2 PIC S99.
02 TABLE-1.
03 RECORD-1 OCCURS 1 TO 5 TIMES
DEPENDING ON COUNTER-1 PIC X(3).
02 EMPLOYEE-NUMBER PIC X(5).
02 TABLE-2 OCCURS 5 TIMES
INDEXED BY INDX.
03 TABLE-ITEM PIC 99.
03 RECORD-2 OCCURS 1 TO 3 TIMES
DEPENDING ON COUNTER-2.
04 DATA-NUM PIC S99. |
|
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Hey thanks william.... I think now I can stop working on this question coz even I did not get any error while declaring it..thanks a lot :-) |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
When you say
Quote: |
But my compiler passes it through and doesn't give any error message |
you added more lines of code?
The bit you posted will not compile as it is.
There are a few reasons it won't compile, but what waves to me is this:
Code: |
10 ws-prev-comp occurs 10 times depending on ws-prev-comp-count
|
There is no picture associated with ws-prev-comp and the lowest level items must have a picture. |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Yes you are right! I shall get back to you..I still have some doubt will first try and code a small program and get back to you..to see it everything is working fine or not.
Thanks for all your help. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1050 Location: Richmond, Virginia
|
|
|
|
I asked earlier what line followed the last line shown, but you did not asnwer.
Your last line has no PIC and no following lines defining fields at any level, so it makes no sense to me. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
When simmimahajan wrote "But my compiler passes it through and doesn't give any error message" I just made the assumption that the data fields for the ODO objects and any data fields subordinate to the second occurs were defined.
I figured he was having trouble with an ODO within an ODO...... |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Hi "Phrzby Phil"
Pls understand it's just an interview question and I was trying to figure out what was wrong in it. As already said I am working on a small program and shall get back to everybody out here with concerns if any.
Thanks for all you help.
Regards,
Simmi |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
Hi William,
You are absolutely right, declaration was and still is not a problem for me. The sample in the post was just for illustration purpose, i was trying to understand is something logically wrong in it or not? but since you gave me the screenshot of the enterprise cobol pgm, I was confident it is absolutely fine and has no problem in it. But as said I still have some concerns but would like to get back to you only when am sure of the exact problem I faced with such declaration.
Thanks again,
Regards,
Simmi |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
simmimahajan wrote: |
we can prove this is not logical. When you just compile your program with this declaration it will not give any error but when you code and run it it gives error. |
You keep saying "not logical", yet it is perfectly logical....
Quote: |
the reason why this is not logical ... is the element declared under level 15 should be two dimensional. It cannot be one dimenional. If its one dimensional it doesn't understand corresponding to which WS-NAME you have entered WS-PREV-COMP. |
It is one dimensional, but it is within another array and therefore you must specify which entry of that array - yes, you need to specify two subscripts or indexes to address it.
Quote: |
Actually when I was asked this question I just did not understand that even the declaration
15 WS-PREV-COMP OCCURS 3 TIMES DEPENDING ON WS-CNT10
PIC X(25).
should have two sub scripts so that it can understand the name it is storing against. |
So to close this thread off, I guess that part of the interview question referred to WS-PREV-COMP with only one subscript?
It wasn't the table, but the reference to the entry in the table that was not right. |
|
Back to top |
|
|
simmimahajan
New User
Joined: 27 Mar 2007 Posts: 30 Location: USA
|
|
|
|
I Accept. |
|
Back to top |
|
|
|