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

Redefines usage


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nirmal.poikaikumaran

New User


Joined: 29 Nov 2005
Posts: 66
Location: Bangalore

PostPosted: Wed Mar 09, 2011 6:33 pm
Reply with quote

Hi Team,

I have a record structure like this

Code:
01 EMP-MASTER.
     02  EMP-DET.
           05  EMP-MARK1     PIC 9(3).         
           05  EMP-MARK2     PIC 9(3).
           05  EMP-MARK3     PIC 9(3).
     02  EMP-PERCENT.
           05  PERCENT        PIC 9(3)v9(2).
           05  GRADE-NUM    PIC 9(4).


Suppose i increase the field size of EMP-MARK1 from 9(3) to 9(6), how does the redefine EMP-PERCENT be modified?

Kindly advise

Thanks
Nirmal
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Wed Mar 09, 2011 6:39 pm
Reply with quote

Is this a trick question? EMP-PERCENT is not a redefine.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Mar 09, 2011 6:42 pm
Reply with quote

I don't see any connection between the two fields so what is the problem?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Mar 09, 2011 6:50 pm
Reply with quote

Nirmal - we see only what you show and in the code you postd there is no REDEFINE used. So your question and the example you show don't go with each other. I'd make a guees that you have field definitions as below:
Code:
01 EMP-MASTER.
     02  EMP-DET.
           05  EMP-MARK1     PIC 9(3).         
           05  EMP-MARK2     PIC 9(3).
           05  EMP-MARK3     PIC 9(3).
     02  EMP-PERCENT REDEFINES EMP-DET.
           05  PERCENT        PIC 9(3)v9(2).
           05  GRADE-NUM    PIC 9(4).
- is this correct?
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 Mar 09, 2011 8:46 pm
Reply with quote

Hello,

Quote:
how does the redefine EMP-PERCENT be modified
Accepting that the redefinition Anuj posted is what you meant to post, there is no way we can tell you how to change the redefinition. . . We know nothing about your original data or what/why the change. . .

Depending on what these fields have to do with each other (if anything) you may need to change some field length or add a FILLER somewhere. If they actually have nothing to do with each other, suggest you re-read Craig's reply.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Mar 10, 2011 2:45 am
Reply with quote

Generally, if you increase the lenght of the redefined area, you can get away with not changing anything in the redefinition area. The compiler may issue a warning for your redefines being shorter than the origin area, but if the 2 definition structures has no interaction, you can expect no difference in execution. It is however good practice to add or increase a filler in the redefinition to make lengths match.

But if the 2 definitions interact, like processing the same data in 2 different ways, you usually must modify both structures in order to maintain the same behavior in your program.

On the other hand, never let your redefined area be shorter than any of it's redefines, that will definitly cause trouble or inpredictable behavior of your program.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 10, 2011 3:59 am
Reply with quote

Quote:
On the other hand, never let your redefined area be shorter than any of it's redefines, that will definitly cause trouble or inpredictable behavior of your program.
Kjeld: the rules have changed a bit on this. From the manual on REDEFINES:
Quote:
If the redefined data item (data-name-2) is declared to be an external data record, the size of the redefining data item (data-name-1) must not be greater than the size of the redefined data item. If the redefined data item is not declared to be an external data record, there is no such constraint.

The following example shows that the redefining item, B, can occupy more storage than the redefined item, A. The size of storage for the REDEFINED clause is determined in number of bytes. Item A occupies 6 bytes of storage and item B, a data item of category national, occupies 8 bytes of storage.




05 A PICTURE X(6).
05 B REDEFINES A GLOBAL PICTURE N(4).

Back to top
View user's profile Send private message
nirmal.poikaikumaran

New User


Joined: 29 Nov 2005
Posts: 66
Location: Bangalore

PostPosted: Thu Mar 10, 2011 7:52 am
Reply with quote

dick scherrer wrote:
Hello,

Quote:
how does the redefine EMP-PERCENT be modified
Accepting that the redefinition Anuj posted is what you meant to post, there is no way we can tell you how to change the redefinition. . . We know nothing about your original data or what/why the change. . .

Depending on what these fields have to do with each other (if anything) you may need to change some field length or add a FILLER somewhere. If they actually have nothing to do with each other, suggest you re-read Craig's reply.


Hi Dick/Anuj,

Yeah that was a typo, i missed out the connection part. Anuj's data structure is what I have.

Thanks
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 10, 2011 7:59 am
Reply with quote

Since you have 3 3-byte variables and you're redefining them into a 5-byte and a 4-byte variable: increasing the first 3-byte variable from 3 to 6 bytes means the 5-byte and 4-byte variables now overlay the first two variables instead of all 3 variables. Is this wrong? Only analysis of the application will tell -- and since we don't work at your site, nor do we work on your application, we really cannot tell you anything about the impact. You may have to increase PERCENT from 5 to 8 bytes, you may have to add a filler, you may have to redesign the code entirely -- there's no way of knowing without looking into the code.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Mar 10, 2011 5:25 pm
Reply with quote

Robert Sample wrote:
Quote:
On the other hand, never let your redefined area be shorter than any of it's redefines, that will definitly cause trouble or inpredictable behavior of your program.
Kjeld: the rules have changed a bit on this. From the manual on REDEFINES:
Quote:
If the redefined data item (data-name-2) is declared to be an external data record, the size of the redefining data item (data-name-1) must not be greater than the size of the redefined data item. If the redefined data item is not declared to be an external data record, there is no such constraint.

The following example shows that the redefining item, B, can occupy more storage than the redefined item, A. The size of storage for the REDEFINED clause is determined in number of bytes. Item A occupies 6 bytes of storage and item B, a data item of category national, occupies 8 bytes of storage.




05 A PICTURE X(6).
05 B REDEFINES A GLOBAL PICTURE N(4).


Just because it is allowed, it might not be considered good practice.

In the example above, if you update B, what storage beyond A is actually updated? Does the compiler actually reserve 8 bytes of storage fra the start of A (an implicit filler)?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Mar 10, 2011 5:47 pm
Reply with quote

Yes, the compiler does reserve the extra two bytes.
Code:
       01  WS-VARS.
           03  A                           PIC X(06).
           03  B                           REDEFINES A
                                           PIC N(4).
           03  C                           PIC X(03) VALUE 'END'.
storage map:
Code:
WS-VARS . . . . . . . . . . . . . . . . . . . BLW=00000  000               DS 0C
  A . . . . . . . . . . . . . . . . . . . . . BLW=00000  000   0 000 000   DS 6C
  B . . . . . . . . . . . . . . . . . . . . . BLW=00000  000   0 000 000   DS 8C
  C . . . . . . . . . . . . . . . . . . . . . BLW=00000  008   0 000 008   DS 3C
It certainly is not good practice, but if someone is relying upon the compiler to generate an error for this, it doesn't -- just a warning:
Code:
 ==000016==> IGYDS1154-W "B" redefined a smaller item.  The program was accepted as written.
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Mar 10, 2011 6:15 pm
Reply with quote

I've seen them using compile option FLAG(E) sometimes - result? -- even this warning message won't show up. And then they complian, Application Programmer is not competent enough! Sigh!
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Thu Mar 10, 2011 6:51 pm
Reply with quote

Kjeld wrote:
Just because it is allowed, it might not be considered good practice.

In the example above, if you update B, what storage beyond A is actually updated? Does the compiler actually reserve 8 bytes of storage fra the start of A (an implicit filler)?
I totally agree that it's a poor practice. We used to rely on getting a compiler error to tell us that we've used up all the space in a redefined area. Now, if you don't notice the Warning message, then the impact can be serious; especially if the redefined area is used for IO operations.
Back to top
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Thu Mar 10, 2011 6:55 pm
Reply with quote

Before this change you would get the same warning, but, referencing the example above, modifying the 8 bytes of B would imply modifying the 6 bytes of A and 2 first bytes of C. And the structure length of WS-VARS has increased with 2 bytes.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Thu Mar 10, 2011 6:57 pm
Reply with quote

Robert Sample wrote:
Yes, the compiler does reserve the extra two bytes.
Code:
       01  WS-VARS.
           03  A                           PIC X(06).
           03  B                           REDEFINES A
                                           PIC N(4).
           03  C                           PIC X(03) VALUE 'END'.
storage map:
Code:
WS-VARS . . . . . . . . . . . . . . . . . . . BLW=00000  000               DS 0C
  A . . . . . . . . . . . . . . . . . . . . . BLW=00000  000   0 000 000   DS 6C
  B . . . . . . . . . . . . . . . . . . . . . BLW=00000  000   0 000 000   DS 8C
  C . . . . . . . . . . . . . . . . . . . . . BLW=00000  008   0 000 008   DS 3C
It certainly is not good practice, but if someone is relying upon the compiler to generate an error for this, it doesn't -- just a warning:
Code:
 ==000016==> IGYDS1154-W "B" redefined a smaller item.  The program was accepted as written.

Alas, I'm afraid that the compiler only reserves the "extra two bytes" for WORKING STORAGE items, not for LINKAGE SECTION items.
Programs containing mismatched REDEFINES in a LINKAGE SECTION may still end up in deep doodoo.
Back to top
View user's profile Send private message
don.leahy

Active Member


Joined: 06 Jul 2010
Posts: 765
Location: Whitby, ON, Canada

PostPosted: Thu Mar 10, 2011 7:07 pm
Reply with quote

FYI, IGYDS1154 was demoted from a severe error to a warning by the Enterprise Cobol 3.4 compiler.

Here is a link to a SHARE presentation from 2007:

www-01.ibm.com/support/docview.wss?uid=swg27006657&aid=1
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts STEM usage in REXX CLIST & REXX 14
No new posts z/OS Modules Usage report using SMF 42 DFSORT/ICETOOL 2
No new posts Concatenate 2 fields (usage national)... COBOL Programming 2
No new posts JCL and TAPE drives: how to maximize ... JCL & VSAM 9
No new posts Usage of BINSEARCH PL/I PL/I & Assembler 1
Search our Forums:

Back to Top