View previous topic :: View next topic
|
Author |
Message |
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
Hi all,
Please let me know
what will happen if we code
05 Var1 PIC A(9) VALUE ' ABCDEFGHI'.
05 var2 REDEFINES VAR1 PIC 9(9).
Thanks |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
You will not get any error. |
|
Back to top |
|
|
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
Can you please explain this, why this one didnot hit any Error as first Var1 is for storing Alphabets and var2 for digits...
Thanks ! |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Ashish,
Use QW option in Mainframes, it is explained clearly there. |
|
Back to top |
|
|
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
Murali ,Thanks a lot for your response as i don't have access to
Mainframe so i am not able to see this option..
can you please give me the provide me the details.
so that i can clear my doubt... |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Asish,
Example given in quick reference
Code: |
05 FIELDA PIC X(09) VALUE 'ABCDEFGHI'.
05 FIELDB REDEFINES FIELDA.
10 FIELDX PIC S9(5) COMP-3.
10 FIELDY PIC X(6).
05 FIELDC REDEFINES FIELDA PIC X(5).
88 FIELDC-IS-SPACES VALUE SPACES.
05 FIELDD PIC S9(3) COMP-3 VALUE 0. |
Explanation given -
Quote: |
All descriptions for a redefined area are always in effect. And although the different descriptions share a common storage area, they are treated by the compiler (and at execution time) according to their data format and type and as if they were occupying separate storage areas. |
Hope this clears your doubt. If not, we are here to help you. |
|
Back to top |
|
|
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
Hi Murali,
what I understand from the above quote is that the compiler will treat each of the description in redefine clause as separate description and treat them as each of them will occupy separate stoeage areas...
so
05 var2 REDEFINE var1 PIC 9(9)
is treated by the compiler as if var2 with pic 9(9) contains 'ABCDEFGHI'
but how this is possible a variable with numeric type contains a string of
alphabets .
please let me know if the below code works fine or not and what is its
output.
WORKING-STORAGE SECTION.
.
.
.
05 A PIC 9(9) VALUE 'ABCDEFGHI'
.
.
PROCEDURE DIVISION.
.
.
DISPLAY A.
.
.
.
Please let me know if I am on the right track or not...
Thanks !! |
|
Back to top |
|
|
earsha
New User
Joined: 16 Mar 2007 Posts: 17 Location: Pune
|
|
|
|
Ashish,
if you code in the following way
05 Var1 PIC A(9) VALUE ' ABCDEFGHI'.
05 var2 REDEFINES VAR1 PIC 9(9).
The above code will not give you any error because The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.
but you code like
05 A PIC 9(9) VALUE 'ABCDEFGHI'
.
.
PROCEDURE DIVISION.
.
.
DISPLAY A.
it will deninately gives you an error.because here you are assiging the non-numeric data to numeric variables.
i hope you are clear with the redefines clause concept. |
|
Back to top |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
In short - you must try to do something with the variable before you get an error - e.g., add it or add to it. The compiler is not running your program.
It would be possible to code the program to overwrite the field with numerics before using the numeric variable - in that case there would be no error - a poorly written program, but no error. |
|
Back to top |
|
|
a69356
New User
Joined: 01 Dec 2006 Posts: 21 Location: Gurgaon
|
|
|
|
I got the Point that In Redefine we can use the different data description entries to describe the same computer storage area. but the thing which still bothering me is that how a variable with numeric datatype will refers to variable with Alphabetic datatype...
when the same is not possible in
05 A PIC 9(9) VALUE 'ABCDEFGHI'
.
.
PROCEDURE DIVISION.
.
.
DISPLAY A.
|
|
Back to top |
|
|
TG Murphy
Active User
Joined: 23 Mar 2007 Posts: 148 Location: Ottawa Canada
|
|
|
|
Although the initial value of your field is ABCEDFGHI, the compiler has no way of knowing that your program may have a requirement - at some point in the logic - to move the value 123456789 into your field.
The compiler does not want to prevent you from doing this so it doesn't generate a compile error. In other words, the compiler trusts that the programmer will handle the situation correctly but is willing to let you shoot yourself in the foot from time to time for the sake of being flexible. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
The redefines provides a way to assign multiple names (and PICtures) to the same physical address within the program. There is no consideration of content, only length. The compiler will tell you if you try to redefine a 10-byte field with a 15-byte-field.
It is completely up to the programmer to ensure that the contents of a redefined field are valid for the operation to be performed. One of the few good reasons (IMHO) to redefine a "pic x" with a "pic 9" is to check if the picx is numeric and if so, use the pic9 in a number operation - if picx not numeric (and it should be), raise a "not numeric" error. |
|
Back to top |
|
|
|