View previous topic :: View next topic |
Author |
Message |
chikdu Beginner
Joined: 06 Jul 2005 Posts: 29 Topics: 20
|
Posted: Fri Apr 29, 2011 9:32 am Post subject: Selecting a field from cobol copybook layout |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Fri Apr 29, 2011 10:07 am Post subject: |
|
|
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 |
|
|
chikdu Beginner
Joined: 06 Jul 2005 Posts: 29 Topics: 20
|
Posted: Fri Apr 29, 2011 10:54 am Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Fri Apr 29, 2011 11:09 am Post subject: |
|
|
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 |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Apr 29, 2011 3:13 pm Post subject: |
|
|
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 |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Mon May 02, 2011 7:33 am Post subject: |
|
|
You could code a REDEFINES following the copybook. |
|
Back to top |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Wed Jun 29, 2011 10:02 am Post subject: |
|
|
....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 |
|
|
|
|