Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Table Declaration in COBOL - query

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
simmimahajan

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 7:28 pm    Post subject: Table Declaration in COBOL - query
Reply with quote

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

Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed May 16, 2007 7:47 pm    Post subject:
Reply with quote

What's not possible? What line follows your last line?

[BTW - you need periods (.) after each line.]
Back to top
View user's profile Send private message
simmimahajan

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 7:52 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 7:55 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Wed May 16, 2007 9:07 pm    Post subject:
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 9:28 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed May 16, 2007 10:43 pm    Post subject:
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 10:50 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Wed May 16, 2007 11:34 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Wed May 16, 2007 11:39 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu May 17, 2007 3:43 am    Post subject:
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Thu May 17, 2007 8:41 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Thu May 17, 2007 9:09 pm    Post subject:
Reply with quote

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

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Thu May 17, 2007 9:24 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Thu May 17, 2007 9:26 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Thu May 17, 2007 9:30 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

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

Global Moderator


Joined: 18 Nov 2006
Posts: 3158
Location: Tucson AZ

PostPosted: Fri May 18, 2007 9:09 pm    Post subject:
Reply with quote

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

New User


Joined: 27 Mar 2007
Posts: 30
Location: USA

PostPosted: Fri May 18, 2007 9:12 pm    Post subject: Re: Table Declaration in COBOL - query
Reply with quote

I Accept.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us