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
 

 

Clarification on the redefine clause

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

New User


Joined: 04 Jul 2007
Posts: 92
Location: Hyderabad

PostPosted: Tue Sep 16, 2008 9:48 pm    Post subject: Clarification on the redefine clause
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

Site Director


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

PostPosted: Wed Sep 17, 2008 12:14 am    Post subject:
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: 92
Location: Hyderabad

PostPosted: Wed Sep 17, 2008 12:31 am    Post subject:
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

Site Director


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

PostPosted: Wed Sep 17, 2008 12:51 am    Post subject:
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: 92
Location: Hyderabad

PostPosted: Wed Sep 17, 2008 12:55 am    Post subject:
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    Post subject: Reply to: Clarification on the redefine clause
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

Site Director


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

PostPosted: Wed Oct 01, 2008 11:13 pm    Post subject:
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    Post subject: Reply to: Clarification on the redefine clause
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

http://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

Site Director


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

PostPosted: Thu Oct 02, 2008 12:35 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Oct 02, 2008 1:23 am    Post subject: Reply to: Clarification on the redefine clause
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    Post subject:
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    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
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts Need clarification of VSAM FCT and DF... pkmurali CICS 15 Sun Apr 10, 2016 1:06 am
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm
No new posts when=group clause: question about the... tuxama DFSORT/ICETOOL 2 Thu Mar 26, 2015 12:51 pm


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