Sometime two or more different variables defined in a program are not in use simultaneously. Their memory can be then saved by sharing the same location for all such variables which will not be used simultaneously. For this we can use redefine verb in cobol. The redefine verb.
Using redefine the same memory location can be used for different variables, but the care of usage of the memory hence, variables should be taken as the content of any on of the redefined variable are reflected in the all of its redefined variables.
Example- mailing list where the addressee may be either a person or a company, but never both. To include both an individual name field and a company name field would waste space, since only one of them would ever be filled, so the name field can be reused (redefined) as company name. Furthermore, while a company name requires just one field, the individual name is usually composed of two fields, last name and first name. For example, bytes 1-12 might be last name, and bytes 13-20 the first name. But when redefined, bytes 1-20 would be the company name. Now you have two fields redefined by one field. COBOL can handle this just fine, but most PC applications don't use redefined fields and do not deal with this well
01 SUBSCRIBERS.
05 TYPE-OF-NAME PIC X.
05 INDIVIDUAL-NAME.
10 LAST-NAME PIC X(12).
10 FIRST-NAME PIC X(8).
05 COMPANY-NAME REDEFINES INDIVIDUAL-NAME PIC X(20).
05 ADDRESS PIC X(20)
05 CITY PIC X(15)
05 STATE PIC X(2)
05 ZIP PIC X(5)
Here, TYPE-OF-NAME indicates the type of name saved in the 20 bytes of name field, whether it is person name or company name. It takes 1 byte to be stored but saves another 20 bytes, also in many cases it will not be needed.
its very easy to understand...thank u very much..
ReplyDeletegreat example. thanks.
ReplyDeleteit's ok.but if it is a full program, then it would be good. because I don't know how to display this.
ReplyDeleteis redefine allowed for 01 level in file section??
ReplyDelete