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

Regrading Redefine Clause: what will be the output


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

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Mar 28, 2007 12:45 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 1:04 pm
Reply with quote

You will not get any error.
Back to top
View user's profile Send private message
a69356

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Mar 28, 2007 1:15 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 1:24 pm
Reply with quote

Ashish,

Use QW option in Mainframes, it is explained clearly there.
Back to top
View user's profile Send private message
a69356

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Mar 28, 2007 3:39 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 3:45 pm
Reply with quote

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. icon_smile.gif
Back to top
View user's profile Send private message
a69356

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Mar 28, 2007 4:51 pm
Reply with quote

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
View user's profile Send private message
earsha

New User


Joined: 16 Mar 2007
Posts: 17
Location: Pune

PostPosted: Wed Mar 28, 2007 5:14 pm
Reply with quote

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
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Mar 28, 2007 5:18 pm
Reply with quote

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
View user's profile Send private message
a69356

New User


Joined: 01 Dec 2006
Posts: 21
Location: Gurgaon

PostPosted: Wed Mar 28, 2007 7:18 pm
Reply with quote

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.

icon_sad.gif
Back to top
View user's profile Send private message
TG Murphy

Active User


Joined: 23 Mar 2007
Posts: 148
Location: Ottawa Canada

PostPosted: Wed Mar 28, 2007 8:17 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Mar 28, 2007 8:39 pm
Reply with quote

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
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 Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
No new posts XL C Trace Preprocessor Output All Other Mainframe Topics 3
Search our Forums:

Back to Top