Thursday, 6 September 2012

REDEFINE & RENAME clause

What is REDEFINE clause ?

 REDEFINE means again define.


 Working-Storage Variable of your COBOL is again defined by this clause.


 Here same storage is used by other variables results in memory utilisation is good.


What is level number used for REDEFINE clause?


Level number 66 (Rename clause), 88 (condition clause), 01(Root clause) not used in defining REDEFINE clause.


REDEFINE data item should not have OCCURS clause.


Program:



W-S section:





 Program:





Output:





Can we have more than one redefine clause pointed same memory location?

For this i am writing one more REDEFINE clause which redefines STUDENT-NAME.


Here i am going to add 02 DEPT-DETAILS REDEFINES STUDENT-NAME.


Let’s see what will happen.


PROGRAM:


W-S section:



   
                                                                                                                                                                

PROCEDURE DIVISION:





  OUTPUT:





We can REDEFINE same W-S variable many times.

 What is RENAME Clause?


It used to REGROUP the W-S data items.

Uses level no. 66.

Here you can take already defined variable from your W-S section and club together in new variable.


SYNTAX:


66  Data-item Name RENAMES Data-item 1 thru data-item n.


PROGRAM:




W-S section:






 PROCEDURE DIVISION:



      
 OUTPUT:




Can we add multiple Rename clauses in one program?

YES. You can see below program for more detail.


PROGRAM:


 W-S section:






PROCEDURE DIVISION:





OUTPUT:






16 comments:

  1. Thanks you for the info. You seem to have put a lot of effort into this!

    ReplyDelete
  2. very well compiled answer ....great work keep it on !!!!!

    ReplyDelete
  3. Great job. excellent explaination

    ReplyDelete
  4. I have a small query can we pick the dataitems sequentially or i pick randomly like
    66 OUTPUT-REC RENAMES F-NAME,DEPT-HOD
    F-NAME from student-rec and DEPT-HOD from detp-record. please reply to my query. is the syntax i wrote is correct ?

    ReplyDelete
  5. Hi Lalita,

    your code will not work as incorrect syntax for rename..

    ReplyDelete
    Replies
    1. I want only 2 records in a new group one is f-name and other one is dept-hod

      Delete
  6. Then u must have fname as last record and dept hod as first record if u wanna do it by rename clause..

    ReplyDelete
  7. Pls try this and tell me answer..
    66 outputrec renames fname thru. Fname
    66 outputtec renames depthod thru depthod

    pls share ur answer after compiling

    ReplyDelete
  8. Thnaks Avinash. so that means i have to access the records sequentially. I don't have mainframe id right now

    ReplyDelete
  9. Right..In any query drop me an email at akamble9488@gmail.com

    ReplyDelete
  10. Thank you so much. Great day bbye

    ReplyDelete
  11. DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 WS-EMP-DETAILS.
    05 WS-FIRST-NAME PIC X(5).
    05 WS-MIDDLE-NAME PIC X(5).
    05 WS-LAST-NAME PIC X(5).
    05 WS-HOUSE-NO PIC X(5).
    05 WS-STREET PIC X(10).
    05 WS-CITY PIC X(10).
    05 WS-PIN PIC 9(6).
    66 WS-EMP-NAME RENAMES WS-FIRST-NAME THRU WS-LAST-NAME.
    66 WS-EMP-ADDRESS RENAMES WS-HOUSE-NO THRU WS-PIN.
    PROCEDURE DIVISION.
    MOVE 'JOHN HAMISH WATSON' TO WS-EMP-NAME
    MOVE '221B,BAKER STREET,LONDON 653302'
    TO WS-EMP-ADDRESS
    DISPLAY WS-FIRST-NAME WS-LAST-NAME
    DISPLAY WS-HOUSE-NO WS-STREET
    STOP RUN.



    what would be the answer for this.

    ReplyDelete