Redefine

What is redefine in COBOL?

Questions by rajcandoit

Showing Answers 1 - 33 of 33 Answers

Umeshsj

  • Sep 27th, 2010
 


REDEFINE clause redefines the previous variable and it utilizes the memory
space of the same.


Eg:
01 WS-EMPLOYEE-NAME PIC X(40).
01 WS-NAME-SPLIT REDEFINES WS-EMPLOYEE-NAME.
05 WS-EMPLOYEE-FIRST-NAME PIC X(20).
05 WS-EMPLOYEE-LAST-NAME PIC X(20).


In the above example WS-EMPLOYEE-NAME & WS-NAME-SPLIT variables uses the same
memory location.


It is also possible to extend the memory of a variable used with REDEFINE
clause.


Eg:
01 WS-VAR1 PIC X(2).
01 WS-VAR2 REDEFINES WS-VAR1 PIC X(6).


PROCEDURE DIVISION.
MOVE ‘MYWORLD’ TO WS-VAR2.
This point of time WS-VAR1 contains MY and WS-VAR2 contains MYWORLD


Re define is used to reuse the memory space from the first bit onwards.

here is an example
01 name pic x(6) value 'murali'.
01 cname redefines name pic x(6).
suppose when ever we want to store same value in two variable iit is better to make the second variable as redefining item.
in the above example we have saved 6byte of memory.

  Was this answer useful?  Yes

atawwaab

  • Jan 6th, 2011
 

REDEFINES::
01 FIELD01   PIC X (10).
01 FIELD02 REDEFINES FIELD01 PIC X (05).

PROCEDURE DIVISION.
MOVE "TESTING 10" TO FIELD01.
.....
(These fields will occupy different values i.e.
FIELD01 WILL HAVE "TESTING 10".
FIELD02 WILL HAVE "TESTI".

  Was this answer useful?  Yes

devesh_rai

  • Jan 22nd, 2011
 

REDEFINES::
01 FIELD01 PIC X (10).
01 FIELD02 REDEFINES FIELD01 PIC X (05).

What will happen if

PROCEDURE DIVISION.
MOVE "TESTING 10" TO FIELD02.
.....
??

  Was this answer useful?  Yes

sujithdan

  • Mar 6th, 2011
 

REDEFINES::
01 FIELD01 PIC X (10).
01 FIELD02 REDEFINES FIELD01 PIC X (05).

What will happen if

PROCEDURE DIVISION.
MOVE "TESTING 10" TO FIELD02.
.....
??



Here FIELD02 is redefined as PIC X (05). So it will have "TESTI". It may give an error as not enough space is there in FIELD02, but that depends on the compiler.

  Was this answer useful?  Yes

Its Just like a type conversion

If we are having a field in database as alphanumeric and we want to superate the $ symbol and superate the numeric value for calculation as follows

Code
  1. 01 db-val             pic x(06) value $75000.

  2. 01 ws-var   redefines db-val.

  3.      05 ws-symb    pic x(01).

  4.      05 ws-amnt    pic 9(05).

  Was this answer useful?  Yes

Karthik

  • Sep 24th, 2012
 

Truncation happens from left to right.

  Was this answer useful?  Yes

Siva

  • Nov 12th, 2017
 

The example specified here gives an error. The redefines variable should have length less than or equal to redefined item.

  Was this answer useful?  Yes

gauravaram

  • Dec 5th, 2018
 

Redefines class is something you can use the existing memory location for your new variable using the redefines caluse
01 emp-data pic x(100)
05 emp-name pic x (40)
05 emp-no pic x(20)
05 filler pix x(40)
01 dep-data redefine emp-data pic x(100)
05 d-name pic x(30)
05 d-num pic x(20).
05 filler pic x(50)

Code
  1. 01 emp-data pic x(100)

  2.   05 emp-name pic x (40)

  3.   05 emp-no pic x(20)

  4.   05 filler pix x(40)

  5.  

  6. 01 dep-data redefine emp-data pic x(100)

  7.    05 d-name pic x(30)

  8.    05 d-num pic x(20).

  9.    05  filler pic x(50)

  Was this answer useful?  Yes

Dhans

  • Sep 2nd, 2019
 

The REDEFINES clause is used to store more than one data items in the same storage area.
Syntax: level-number Data-name1 REDEFINES Data-name-2

data-name-1 is the redefining item or the REDEFINES subject.
data-name-2 is the redefined item or the REDEFINES object.
Example:
Name field can be redefined as First name, Middle name, and Last name
WORKING-STORAGE SECTION.
01 ACCT-EXT.
10 ACCT-EXT-NAME PIC X(30).
10 ACCT-NAM REDEFINES ACCT-EXT-NAME.
15 F-NAME PIC X(10).
15 M-NAME PIC X(10).
15 L-NAME PIC X(10).
10 ACCT-NO PIC 9(8).
10 ADDRESS PIC X(50).

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions