View previous topic :: View next topic
|
Author |
Message |
nirmal.poikaikumaran
New User
Joined: 29 Nov 2005 Posts: 66 Location: Bangalore
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
Is this a trick question? EMP-PERCENT is not a redefine. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
I don't see any connection between the two fields so what is the problem? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
nirmal.poikaikumaran
New User
Joined: 29 Nov 2005 Posts: 66 Location: Bangalore
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
|
|
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 |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
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 |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
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 |
|
|
don.leahy
Active Member
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
|
|
Back to top |
|
|
|