MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Selecting a field from cobol copybook layout

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
chikdu
Beginner


Joined: 06 Jul 2005
Posts: 29
Topics: 20

PostPosted: Fri Apr 29, 2011 9:32 am    Post subject: Selecting a field from cobol copybook layout Reply with quote

Hi,
I have a copybook layout like this
Code:

05  FIELD1.
   10 FIELD2.
      15 FIELD2 PIC X(10).
   10 FIELD2.

And I want to select the first FIELD2 in my cobol program.If I give FIELD2 of FIELD1 then it gives me an error because of the multiple occurances.

Is there a way to get around this without changing the field names?

Thanks,
Chikdu.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Fri Apr 29, 2011 10:07 am    Post subject: Reply with quote

chikdu,

why can't you refer it is as FIELD2 OF FIELD2 ? Btw please try to stay away from such poor coding practices.

Kolusu.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
chikdu
Beginner


Joined: 06 Jul 2005
Posts: 29
Topics: 20

PostPosted: Fri Apr 29, 2011 10:54 am    Post subject: Reply with quote

Kolusu,
I need to access the first FIELD2
10 FIELD2.

Sorry I cant help it...It wasn't soemthing that I coded for.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12369
Topics: 75
Location: San Jose

PostPosted: Fri Apr 29, 2011 11:09 am    Post subject: Reply with quote

chikdu,

What makes you think that it isn't referring to the first field2? Is that the entire definition of the copybook ? If so does it even compile when there is no PIC definition on the last Field2?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Fri Apr 29, 2011 3:13 pm    Post subject: Reply with quote

Quote:
select the first

select is a db2 term.

in COBOL you want an unambiguous reference to an address.

with your copybook and the repeated use of FIELD2 as a reference name,
it is impossible to reference any of the FIELD2s without ambiguity,
which is the error that you are receiving from the compiler.

if you don't reference an ambiguous reference name,
the compiler will allow almost anything.

you are lucky, it is all x type,
which means you can use reference modification based on the lvl-05 reference name FIELD1,
unless of course there are repeated FIELD1 reference names within the structure,
which means you will have to use the lvl-01 reference name with ref-mod.

if you have multiple lvl-01 reference names that are the same,
you have storage that is wasted and can not be addressed.
don't even know if it will compile.
as long as no reference to the structures (lvl-01's) are made.
since normally some field with a defined structure (if not the lvl-01 reference name)
is reference in the code someplace, your compile will fail due to the ambiguity.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Mon May 02, 2011 7:33 am    Post subject: Reply with quote

You could code a REDEFINES following the copybook.
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 625
Topics: 175
Location: Stockholm, Sweden

PostPosted: Wed Jun 29, 2011 10:02 am    Post subject: Reply with quote

....or of course, you could ignore the whole copybook and define your own definition instead. Basically, IF that copybook is for real, the person who created it should be shot. I mean to say, what the hell is FIELD1 (apart from being the first field). What is FIELD2 (apart ..........)
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group