Redefines clause in occurs clause



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Redefines clause in occurs clause

Postby vinod_rana » Fri May 06, 2011 7:20 pm

Please answer
Can we use redefine clause in occurs clause?
vinod_rana
 
Posts: 8
Joined: Thu Apr 21, 2011 12:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines clause in occurs clause

Postby Robert Sample » Fri May 06, 2011 8:23 pm

As stated, the answer is NO. An OCCURS clause can contain only OCCURS (or OCCURS DEPENDING ON and variable name(s) associated with the ODO), ASCENDING / DESCENDING KEY, INDEXED BY.

Now if you had asked if a variable defined using an OCCURS clause could be redefined -- that is a very different question and chapter 5.3.13 of the COBOL Language Reference manual addresses it.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Redefines clause in occurs clause

Postby Deepak kumar25 » Sat Apr 21, 2012 4:23 pm

AS STATED ROBERT:
IN MY POINT OF VIEW:
WE CAN REDEFINE A DATA ITEM HAVE AN OCCURs CLAUSE.
but we cannot redefine a data item having occurs clause.
as an example:
01 g1.
03 WS-Y1 OCCURS 4 TIMES PIC X(5).
03 WS-Y2 REDEFINES WS-Y1 PIC 9(5).
it gives error.
A definition of an object of a "REDEFINES" clause contained an "OCCurs" clause.
01 g2.
03 ws-y1 pic 9(5) value 12345.
03 ws-y2 redefines ws-y1 occurs 5 times pic x(5).
the second does not gives error.



thanks:
Deepak kumar
mainframe trainer(applied labs)
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines clause in occurs clause

Postby BillyBoyo » Sat Apr 21, 2012 4:32 pm

Well, for someone who has gone from asking for a book on Cobol not much more than a year ago to a "mainframe trainer", I'm not sure you have got the hang of it.

Robert's first point is not connected to your comments in any way, and your comments don't seem to be connected to the poorly-worded question.

Your first can be done, you just have to know how to define the data.

Your second, you say, "does not give an error". Look closely at your compile listing. If it might not technically be an "error", but there is a diagnostic message, and your code is confusing, misleading and asking for trouble (as in program not working, or not understood by the next person who has to look at it).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Redefines clause in occurs clause

Postby Deepak kumar25 » Sat Apr 21, 2012 5:18 pm

billy,
yes you are right it gives warning message
"WS-Y2" redefined a smaller item. The program was accept was accepted as written.
BUT it what the problem it may created. explain me in brief
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines clause in occurs clause

Postby BillyBoyo » Sat Apr 21, 2012 6:09 pm

The problems are multiple, I'm not sure how "brief" I can be about it.

01  file-record-in-fd.
    05  fixed-part-of-record pic x(50).
    05  ws-y1 pic x(5).
    05  some-more-of-record pic x(100).

01  file-record-in-fd.
    05  fixed-part-of-record pic x(50).
    05  ws-y1 pic x(5).
    05  ws-y2 redefines ws-y1 occurs 5 times pic x(5).
    05  some-more-of-record pic x(100).


In the first, the record is 155 bytes long. some-more-of-record starts at dsplacement 55.

In the second, the record is175 bytes long. some-more-of-record starts at dsplacement 75.

The data for some-more-of-record is on the file, so hasn't moved. The incorrect redefines has screwed it up.

When we look at the length of a record on the edit screen, we "ignore" a REDEFINES when calculating the length. Yours wastes time.

What are you trying to do with the REDEFINES that way? That will puzzle the next person looking at the program, and waste time, cause frustration etc.

Even if it "works" for some particular odd idea, it is quite likely that the next person along will consider it as an error and look to "fix" it, not look at some dumb method that does something desired.

I could go on, but won't.

It doesn't address the actual question, either, or Robert's response. So it would seem you did not understand either of those.

Maybe you are a "trainee" trainer? If not, I'm not sure what advantage you see in posting such code as you did, and being unable to do the other one correctly as well.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Redefines clause in occurs clause

Postby Deepak kumar25 » Sat Apr 21, 2012 6:26 pm

k i will tell, it due to new compiler v3r4 which allows the warning level diagnostic.
Deepak kumar25
 
Posts: 34
Joined: Mon Jan 10, 2011 10:51 am
Has thanked: 0 time
Been thanked: 0 time

Re: Redefines clause in occurs clause

Postby Robert Sample » Sat Apr 21, 2012 6:28 pm

IN MY POINT OF VIEW:
WE CAN REDEFINE A DATA ITEM HAVE AN OCCURs CLAUSE.
Honestly, who cares what your point of view is? My references are the COBOL manuals, which give me (almost) everything I need to know about COBOL. Opinions (or points of view) are not required. And in the few cases where the manuals don't clearly indicate, it is usually pretty easy to put together a test to find out how the compiler handles that specific case. If you are telling your students to follow your point of view, instead of the manuals, you are doing them a grave disservice -- not to mention being grossly unprofessional.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Redefines clause in occurs clause

Postby BillyBoyo » Sat Apr 21, 2012 6:34 pm

       01  A-NICELY-NAMED-GROUP.
           05  A-NICELY-NAMED-PIECE-OF-DATA OCCURS 5 TIMES.
               10  DATA-WHICH-DEFINES-LENGTH    PIC X(5).
               10  A-REDEFINES REDEFINES
                   DATA-WHICH-DEFINES-LENGTH.
                     15   FILLER OCCURS 5.
                          20  EVEN-EACH-BYTE    PIC X.


This is what I believe you were trying to do, and said you can't. You'd have got to something like this following Robert's second comment.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Redefines clause in occurs clause

Postby BillyBoyo » Sat Apr 21, 2012 6:36 pm

Deepak kumar25 wrote:k i will tell, it due to new compiler v3r4 which allows the warning level diagnostic.


The compiler does allow different levels of diagnostic to cause the compile to fail (not generate an object). The compiler does not, however, make those settings itself. So no, it is not the compiler...
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post