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

redifines example


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

New User


Joined: 16 Feb 2004
Posts: 6

PostPosted: Mon Feb 16, 2004 11:05 am
Reply with quote

can anybody explain the REDIFINES, with a praticle example.


kris
Back to top
View user's profile Send private message
mdtendulkar

Active User


Joined: 29 Jul 2003
Posts: 237
Location: USA

PostPosted: Mon Feb 16, 2004 11:18 am
Reply with quote

Hello Kris,

Following is the excerpt from the IBM COBOL Ref Guide.



The REDEFINES clause allows you to use different data description entries to describe the same computer storage area.

Quote:

level-number data-name-1 (or filler) REDEFINES data-name-2


When specified, the REDEFINES clause must be the first entry following
data-name-1 or FILLER. If data-name-1 or FILLER is not specified, the
REDEFINES clause must be the first entry following the level-number.

The level-numbers of data-name-1 and data-name-2 must be identical, and must not be level 66 or level 88. data-name-1, FILLER Identifies an alternate description for the same area, and is the redefining item or the REDEFINES subject. data-name-2 is the redefined item or the REDEFINES object.

When more than one level-01 entry is written subordinate to an FD entry, a condition known as implicit redefinition occurs. That is, the second level-01 entry implicitly redefines the storage allotted for the first entry. In such level-01 entries, the REDEFINES clause must not be specified.

Redefinition begins at data-name-1 and ends when a level-number less than or equal to that of data-name-1 is encountered. No entry having a level-number numerically lower than those of data-name-1 and data-name-2 can occur between these entries. For example:

Code:

05 A PICTURE X(6).
05 B REDEFINES A.
    10 B-1 PICTURE X(2).
    10 B-2 PICTURE 9(4).
05 C PICTURE 99V99.


In this example, A is the redefined item, and B is the redefining item. Redefinition begins with B and includes the two subordinate items B-1 and B-2. Redefinition ends when the level-05 item C is encountered.

The data description entry for data-name-2, the redefined item, can contain a REDEFINES clause. The data description entry for the redefined item cannot contain an OCCURS clause. However, the redefined item can be subordinate to an item whose data description entry contains an OCCURS clause. In this case, the reference to the redefined item in the REDEFINES clause must not be subscripted. Neither the redefined item nor the redefining item, or any items subordinate to them, can
contain an OCCURS DEPENDING ON clause.

If the GLOBAL clause is used in the data description entry which contains the REDEFINES clause, it is only the subject of that REDEFINES clause that possesses the global attribute.

The EXTERNAL clause must not be specified on the same data description entry as a REDEFINES clause.

If the data item referenced by data-name-2 is either declared to be an external data record or is specified with a level-number other than 01, the number of character positions it contains must be greater than or equal to the number of character positions in the data item referenced by the subject of this entry. If the data-name referenced by data-name-2 is specified with a level-number of 01 and is not declared to be an external data record, there is no such constraint.

When the data item implicitly redefines multiple 01-level records in a file
description (FD) entry, items subordinate to the redefining or redefined item can contain an OCCURS DEPENDING ON clause.

One or more redefinitions of the same storage area are permitted. The entries giving the new descriptions of the storage area must immediately follow the description of the redefined area without intervening entries that define new character positions. Multiple redefinitions must all use the data-name of the original entry that defined this storage area. For example:

Code:

05 A PICTURE 9999.
05 B REDEFINES A PICTURE 9V999.
05 C REDEFINES A PICTURE 99V99.


The redefining entry (identified by data-name-1), and any subordinate entries, must not contain any VALUE clauses.

Hope this helps,

Regards

Mayuresh Tendulkar
Back to top
View user's profile Send private message
kris

New User


Joined: 16 Feb 2004
Posts: 6

PostPosted: Mon Feb 16, 2004 10:45 pm
Reply with quote

thanks for your response.

is it possible for you to eloborate REDIFINES , with any praticle example, which you encountered(coded in he program) in your work / experience, that makes me understand better.



thanks.
Kris
Back to top
View user's profile Send private message
Bharani

New User


Joined: 02 Jul 2004
Posts: 4

PostPosted: Wed Jul 21, 2004 10:30 am
Reply with quote

Hai Krish

Suppose i am having employee code and the data type is alphanumeric.
for example the first employee code is (EM0001)

now i want to add the second employee the code should be generate automatically.

for that we have to do some arithmetic operations. if its alphanumeric means we can't to any arithmetic operations. using redefine we can achieve it.

for example

77 EMP-CODE X(6) VALUE 'EM0001')
01 EMP-CODE1 REDEFINES EMP-CODE.
02 EM PIC X(2).
02 EC PIC 9(4).
.......
......
PROCEDURE DIVISION.
ADD 1 TO EC.
DISPLAY EMP-CODE.


THE VALUE FOR EM IS 'EM'
AND THE VALUE FOR EC WILL BE '0001'

NOW THE EMPLOYEE CODE WILL BE EM0002.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Jul 21, 2004 6:33 pm
Reply with quote

Hai Krish,

The manuals are excellent at telling you how, along with all the caveats and alternatives and exceptions.

A book, on the otherhand, will give you both the how and the why. Go to (or should I say perform? :-) ) Use [URL] BBCode for External Links for reasonably priced books (many under $10 US) on all IT subjects.

Regards, Jack
Back to top
View user's profile Send private message
sudha

New User


Joined: 16 Aug 2004
Posts: 7

PostPosted: Mon Aug 16, 2004 9:38 pm
Reply with quote

hi,

redefines uses the same memory location.

eg: 01 id1 redefines id2

id1 and id2 should be in the same level number
Back to top
View user's profile Send private message
vikas4u

New User


Joined: 12 Aug 2004
Posts: 14
Location: bangalore

PostPosted: Tue Sep 07, 2004 12:29 pm
Reply with quote

hi
u said redifine should have same level no.

the prog. u have written
i.e.
77 emp-code pic x(6).
01 emp-code1 redefine emp-code.

please tell me how it is possible.
the level no. is different.
Back to top
View user's profile Send private message
harinadh

New User


Joined: 01 Sep 2004
Posts: 18

PostPosted: Fri Sep 10, 2004 9:26 am
Reply with quote

I can give you one example.

01 MONDATA PIC X(36)
VALUE "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC".

01 MONTHS REDEFINES MONDATA OCCURS 12 TIMES.
05 MONTH PIC X(3).

NOW MONTH(I) I IS FROM 1 TO 12 WILL CONTAIN MON NAME.
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 REDIFINES with different PIC clause a... COBOL Programming 3
Search our Forums:

Back to Top