Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Regrading Redefine Clause: what will be the output

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Regrading Redefine Clause: what will be the output
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: 1439
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 1:04 pm    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 1:24 pm    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Wed Mar 28, 2007 3:45 pm    Post subject:
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    Post subject:
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    Post subject:
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

Active Member


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

PostPosted: Wed Mar 28, 2007 5:18 pm    Post subject:
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    Post subject:
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: 149
Location: Ottawa Canada

PostPosted: Wed Mar 28, 2007 8:17 pm    Post subject:
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

Site Director


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

PostPosted: Wed Mar 28, 2007 8:39 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts it is possible output a SET value fro... Martylin JCL & VSAM 5 Fri Sep 22, 2017 7:08 am
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
No new posts BUILD OUTFIL based on condition other... balaji81_k DFSORT/ICETOOL 13 Fri Sep 08, 2017 11:06 pm
No new posts Hardcoded negative sign value in output scdinesh SYNCSORT 8 Fri Sep 08, 2017 5:28 am
No new posts SORT Trailer Count - LRECL Output co... amorante DFSORT/ICETOOL 5 Tue Aug 29, 2017 8:57 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us