IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Clarification on the redefine clause


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
dp33770

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Tue Sep 16, 2008 9:48 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Wed Sep 17, 2008 12:14 am
Reply with quote

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

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Wed Sep 17, 2008 12:31 am
Reply with quote

Oh thanks Dick....
So it it possible to redefine the same structure with same or smaller size ?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Sep 17, 2008 12:51 am
Reply with quote

You're welcome icon_smile.gif

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

New User


Joined: 04 Jul 2007
Posts: 91
Location: Hyderabad

PostPosted: Wed Sep 17, 2008 12:55 am
Reply with quote

Thanks ... icon_smile.gif
Back to top
View user's profile Send private message
mkarthikeyan

New User


Joined: 07 Aug 2008
Posts: 34
Location: Bangalore

PostPosted: Wed Oct 01, 2008 10:55 pm
Reply with quote

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

Moderator Emeritus


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

PostPosted: Wed Oct 01, 2008 11:13 pm
Reply with quote

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

New User


Joined: 07 Aug 2008
Posts: 34
Location: Bangalore

PostPosted: Thu Oct 02, 2008 12:00 am
Reply with quote

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

Moderator Emeritus


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

PostPosted: Thu Oct 02, 2008 12:35 am
Reply with quote

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. . icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Oct 02, 2008 1:14 am
Reply with quote

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
  1. they would read the documentation
  2. they would not misquote the documentation.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Oct 02, 2008 1:23 am
Reply with quote

Hi Dick,

Quote:
as far as defer, refer, you probably meant to say 'differ'.
Good catch icon_wink.gif

Later,

d
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Oct 02, 2008 2:39 am
Reply with quote

Play nice, boys. icon_lol.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts To search DB2 table based on Conditio... DB2 1
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
No new posts SUSBSCRIPT WITH SIGN IN PIC CLAUSE COBOL Programming 3
No new posts usage of CASE in WHERE clause DB2 10
No new posts Cobol redefines for Signed pictured c... COBOL Programming 4
Search our Forums:

Back to Top