View previous topic :: View next topic
|
Author |
Message |
dp33770
New User
Joined: 04 Jul 2007 Posts: 91 Location: Hyderabad
|
|
|
|
I need few clarification on the redefine clause.
1.Can we redefine pic x(10) with s9(15).
2. If we have a group variable as below
01 main-rec
05 id pic s9(4)
05 name pic x(10)
05 value pic s9(4) comp
01 ex-rec redefines main-rec pic x(100)
is this possible ? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
A simple rule is that a larger field should never redefine a smaller field. It doesn't matter how they are defined. Larger should not redefine smaller. |
|
Back to top |
|
|
dp33770
New User
Joined: 04 Jul 2007 Posts: 91 Location: Hyderabad
|
|
|
|
Oh thanks Dick....
So it it possible to redefine the same structure with same or smaller size ? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome
Quote: |
So it it possible to redefine the same structure with same or smaller size ? |
Yes, redefines should be the same or smaller. My preference is to make them the same even if i need to put some filler at the end of the smaller. |
|
Back to top |
|
|
dp33770
New User
Joined: 04 Jul 2007 Posts: 91 Location: Hyderabad
|
|
|
|
Thanks ... |
|
Back to top |
|
|
mkarthikeyan
New User
Joined: 07 Aug 2008 Posts: 34 Location: Bangalore
|
|
|
|
Dick,
Even i got a shock when i compiled and run the following program in Enterprise Cobol 3.4.1 on z/OS. So I would like to conclude that we can redefine the smaller element with a longer element
------------------------------------------------------------------------------------
Working-Storage Section.
01 Ws-Small Pic X(10) Value 'abcdefchig'.
01 Ws-Long Redefines WS-Small.
05 Ws-Long1 Pic X(10).
05 Ws-Long2 Pic X(10).
Procedure Division.
0000-Start.
Move '1234567890' To Ws-Long2
Display 'Length of Small : ' Length of Ws-Small
Display 'Length of Long1 : ' Length of Ws-Long1
Display 'Length of Long2 : ' Length of Ws-Long2
Display 'Length of Long : ' Length of Ws-Long
Display 'Content of Small : ' WS-Small
Display 'Content of Long1 : ' WS-Long1
Display 'Content of Long2 : ' WS-Long2
Display 'Content of Long : ' WS-Long
-------------------------------------------------------------------------------------
Output
Length of Small : 000000010
Length of Long1 : 000000010
Length of Long2 : 000000010
Length of Long : 000000020
Content of Small : abcdefchig
Content of Long1 : abcdefchig
Content of Long2 : 1234567890
Content of Long : abcdefchig1234567890
------------------------------------------------------------------------------------- |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Yes, there are things that "Can be done" that maybe should not be done. This is one of them.
While the compiler usually no longer issues a warning (let alone a fatal), i believe it is a bad practice.
If you ensure the redefined items are the same size, you will encounter fewer surprises later when the code needs to be maintained. I can think of no business reason to incorporate such code. |
|
Back to top |
|
|
mkarthikeyan
New User
Joined: 07 Aug 2008 Posts: 34 Location: Bangalore
|
|
|
|
Dick,
I would like to defer on your statement.
The compiler issue a warning when i redefine it as below but not in previous case.
01 Ws-Small.
05 Ws-Smaller Pic X(10) Value 'abcdefchig'.
05 Ws-Long Redefines WS-Smaller Pic X(20).
IGYDS1154-W "WS-LONG" redefined a smaller item. The program was accepted as written.
Please read the below document on what is enhanced in E-Cobol
www-1.ibm.com/support/docview.wss?uid=swg27006657&aid=1
Please don't advice when u r not sure. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Please don't advice when u r not sure. |
Someday, it may be proper for you council thus. It is not this day. Obviously, you did not bother to check many/any of my others replies to questions throughout the forum - if i was not sure, i would either not post or qualify with "i believe. . .".
Before posting previously, i compiled the following and you should notice that there was no warning raised.
Code: |
01 SOME-STUFF.
05 SOME-VALUE PIC X(15) VALUE SPACES.
05 SOME-VALUE-R REDEFINES SOME-VALUE PIC S9(15).
05 EDITED-VALUE PIC 99999-.
*
01 SOME-BIGGER-STUFF REDEFINES SOME-STUFF PIC X(100).
ERPRISE COBOL FOR Z/OS 3.4.1 TESTCBX2 DATE 10/01/200
.
.
END OF COMPILATION 1, PROGRAM TESTCBX2, NO STATEMENTS FLAGGED.
|
I believe you entirely missed the point that even though the compiler will permit this, it should not be used. It is a bad coding practice. The compiler issuing or not issuing a warning really doesn't matter.
Quote: |
I would like to defer on your statement. |
I suspect you meant refer rather than defer as you surely did not defer. . |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Karthikeyan m,
If you had bothered to read the document, for which you provided a link,
you would not have made an ass out of yourself with your comments.
page 35 mentions the ability to redefine a 01 level with a larger item.
page 38 stipulates what dick provided in the above code window,
referring to 'non 01 level items'
- quote taken from page 37 -
where you probably stopped reading.
That is the difference between a rookie and a professional:- a professional reads the complete documentation to understand the subject
- a rookie reads until he has found something that fits his preconceived argument
as far as defer, refer, you probably meant to say 'differ'.
and no, dick does not need help protecting himself. I just felt that he was
much to diplomatic with you, being the gentleman that he is and I am not.
Most of the problems people pose in this forum
would not be problems if - they would read the documentation
- they would not misquote the documentation.
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hi Dick,
Quote: |
as far as defer, refer, you probably meant to say 'differ'. |
Good catch
Later,
d |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
Play nice, boys. |
|
Back to top |
|
|
|