Can we use redefine clause in occurs clause?

Questions by vinayk

Showing Answers 1 - 60 of 60 Answers

suraj

  • Feb 22nd, 2006
 

no, with redefine clause we cant use occurs clause

  Was this answer useful?  Yes

prabhu

  • Mar 17th, 2006
 

yes we can use redefines clause in occurs clauseeg:01 number1 pic x(10) value spaces.01 number2 redefines number1 pic x occurs 10 times.

Parikshit

  • Mar 26th, 2006
 

well, both the above answers are contradictory. I am confused.

  Was this answer useful?  Yes

Pankaj Jindal

  • Mar 31st, 2006
 

don't be confused, we

  Was this answer useful?  Yes

Varun kakkar

  • Apr 7th, 2006
 

No, we cannot use redefines in occurs clause. Compiler wont allow that.

  Was this answer useful?  Yes

as

  • Apr 24th, 2006
 

We can use Occurs & redefine together

01  MY-NAME.                                                    
    05  WS-MY-NAME  PIC X(22) VALUE 'XXXXXXXXXXXX          '.   
    05  WS-MY-NAMR REDEFINES WS-MY-NAME OCCURS 22 TIMES PIC X(1).

Compiler will not allow occurs on 01 level.

murali

  • Apr 25th, 2006
 

Hi,

Prabhu we can not use redefines caluse and occurs caluse in the same statement.For your information occurs clause is not applicable for 01 level

krishna rao

  • Apr 29th, 2006
 

  Some body sent their comments about that question. But one gentle man geave the answer is possible in 01 - Level .but  occurs clause is possible in 01-level or not. first find this thing after that please send answer.

finally my suggestion 01-level occurs is not possible and redefine with occurs is also not possible.

PRABHU

  • Apr 30th, 2006
 

Hi Murali, I Don't No About other cobol.but we can use redefines and occurs clause in same line and in 01 level in Micro Focus Cobol .If You don't beleive i ready to show you my Coding.

  Was this answer useful?  Yes

Thomas Vetticad

  • May 4th, 2006
 

You can use redefine and Occurs in one line in Cobol. If you want examples let me know.  Thx

  Was this answer useful?  Yes

vijay_niit_2000@yahoo.com

  • May 9th, 2006
 

Yes thomas plz give examples, it will be very much clear to all.

  Was this answer useful?  Yes

pr

  • May 16th, 2006
 

we cant use occurs clause in redefines line.

But we can use occurs in that redefines group item

Means example

01 rec pic X(10)

  02 rec1 redefines rec

      05 sno pic xxx occurs 3 times

we can use this type but we can't use redefine & occurs at same time

Lavanya

  • May 19th, 2006
 

 Hi,

    Yes, we can use the redefines clause with occurs clause at the same level, no matter if it is 01 level or 05 level. Here is an example...

Suppose, we have an array where we want to set each element to a different value. b'cos COBOL 85 permits VALUE clauses in conjunction with an OCCURS entry, the follwing code is valid,

   01  month-names  value 'janfebmaraprmayjunjulaugsepoctnovdec'

       05 month occurs 12 times   pic xxx.

But with COBOL 74, we cannot use VALUE clause with OCCURS clause, so we can redefine that storage area into 12 seperate array elements using OCCURS clause.

 01 month-names

    05  string-1        pic x(36) value 'janfebmaraprmayjunjulaugsepoctnovdec'

    05  month redefines string-1 occurs 12 times pic xxx.

 

 

kaushiki

  • May 25th, 2006
 

Hi,

     Redefine clause can be used with OCCUR clause only if, the REDEFINE clause is the subordinate of the OCCUR clause e.g

01 ws-table.

  05 ws-table-el    occurs 5 times.

      10 ws-table-rec           pic x(2).

      10 ws-table-addr         redefines  ws-table-rec pic x(2).

You cannot use REDEFINE and OCCUR in the same level,together.

Offcourse,neither os/vs Cobol or Cobol II supports, OCCURS in level 01.

Thanks

Ranjan K Lall

  • May 29th, 2006
 

Yes we can redifine with occurs clause another way

01 ws-month

    05 ws-mon    pic  x(36) values 'Janfebmarapr.......'.

    05 ws-mon-end  redefines ws-mon.

          10 ws-each-month  Pic x(3) ocuure 12 times.

  Was this answer useful?  Yes

kapilvharande

  • May 30th, 2006
 

Yes, definatly we can use. 

  Was this answer useful?  Yes

arun

  • Jun 16th, 2006
 

Hi

we cannot use redefines in occurs clause. instead what we can do is

01 exm

   05 exm1 occurs 10 times picx(4).

01 redefines exm picx(40).

using this method we can obtain the result.

  Was this answer useful?  Yes

mythili

  • Jul 10th, 2006
 

hi,

       REDEFINES and OCCURS clause cannot appear for the same data item. However REDEFINES clause can appear for a group item whose sub item contains occurs clause

  Was this answer useful?  Yes

Kavitha

  • Sep 25th, 2006
 

Occurs clause can be used inside an redefined clause, where redefined clause should be specified at group level variable(ex, 01) and occurs clause at the low level variable(02).

  Was this answer useful?  Yes

intiaz ali

  • Oct 14th, 2006
 

No, we can't use redefine clause in occurs claus. no version of compiler will execute this.

  Was this answer useful?  Yes

kumar n

  • Aug 7th, 2007
 

If you write code like below, You will get compilation error, here problem with occurs not with Redefine, because occurs doesn't allow level-01.

01 WS-VAR1 PIC X(10) VALUE '1234567890'.              
01 WS-VAR2 REDEFINES WS-VAR1 OCCURS 10 TIMES PIC X(1).



If you write code like below, you will get compilation error.
Because here object of redefines (WS-VAR1) have occurs clause, it is not correct.
Redefines doesn't allow occurs, if it's object have occurs caluse.

01 WS-VAR11.                             
   05 WS-VAR1 OCCURS 10 TIMES PIC X(01). 
   05 WS-VAR2 REDEFINES WS-VAR1 PIC X(10).

If you write code like below, you will not get any error. It will work fine.
Because here occurs clause is with ws-var2 not with ws-var1.

01 WS-VAR12.                                            
   05 WS-VAR1 PIC X(10) VALUE '1234567890'.             
   05 WS-VAR2 REDEFINES WS-VAR1 OCCURS 10 TIMES PIC X(1).



So many people have doubts can we use Redefines with level-01 or not.

In the case of "FD" only, we can't use redefine in 01 level.
in remaining cases we can use redefines with 01 level.


  Was this answer useful?  Yes

sulthan150

  • May 8th, 2008
 

Hi prabhu Ur answer is exactly correct. We can use redefines clause in occurs clause at 01 level.example:working-storage section.01 hd-60 PIC X(60).01 REDEFINES hd-60. 02 hd-60-char PIC X OCCURS 60 TIMES.01 pr-rec1 pic x(60).01 redefines pr-rec1. 02 pr1 pic x occurs 60 times.procedure division. perform varying i from 1 by 1 until i > 60 add 1 to ii move hd-60-char(i) to pr1(ii) end-perform.

  Was this answer useful?  Yes

azzdanger

  • Jul 8th, 2008
 

What would you say about this piece of code?


01  WS-VARIABLE PIC X(5).                             
01  WS-RED REDEFINES WS-VARIABLE.                     
    05  WS-VAR1            PIC 9(05).                 
    05  WS-VAR2 REDEFINES WS-VAR1 PIC X OCCURS 5 TIMES
                    INDEXED BY WS-INDEX.              


Well, my COBOL compiler does not allow OCCURS at level 01, forget REDEFINES.

  Was this answer useful?  Yes

Priyeshnn

  • Sep 18th, 2010
 


Its quite possible with VS VCOBOL II version. Occurs clause is not allowed in the 01 level that is true .But for all the above code mentioned it at the 05 level. This is the sample code that you can try out.

01 WS-TEST-REDIFINE.                                    
   05 NAME-ACT  PIC X(10) VALUE SPACES.                   
   05 NAME-TMP REDEFINES WS-NAME OCCURS 10 TIMES PIC X

PROCEDURE DIVIION

MOVE 'SMALE DATA' TO NAME-ACT
DISPLAY NAME-TMP(1) ==>This will display "S".

  Was this answer useful?  Yes

Yes,  redefines can be use with occurs clause but  redefines should come before occurs and occurs shdnt be at 01 level .

for eg:

01 WS-MONTH.

05 FILLER PIC X(03) VALUE ‘JAN’.

05 FILLER PIC X(03) VALUE ‘FEB’.

05 FILLER PIC X(03) VALUE ‘MAR’.

05 FILLER PIC X(03) VALUE ‘APR’.

05 FILLER PIC X(03) VALUE ‘MAY’.

05 FILLER PIC X(03) VALUE ‘JUN’.

05 FILLER PIC X(03) VALUE ‘JUL’.

05 FILLER PIC X(03) VALUE ‘AUG’.

05 FILLER PIC X(03) VALUE ‘SEP’.

05 FILLER PIC X(03) VALUE ‘OCT’.

05 FILLER PIC X(03) VALUE ‘NOV’.

05 FILLER PIC X(03) VALUE ‘DEC’.

 

01 WS-MONTH-RED REDEFINES WS-MONTH.

05 WS-M-NAME PIC X(03) OCCURS 12 TIMES INDEXED BY M.

 

  Was this answer useful?  Yes

01 small-group-item.

03 small-data-item pic x(100) value "this is a test".

01 large-group-item redefines small-group-item.

03 free-form-text pic x(100) occurs 10 times.


Also Prev-data-name may contain the OCCURS clause, although thisis not compatible with ANSI COBOL. If such a situation exists, the compiler will return a "caution" warning indicating a non-ANSI construct. Cautions are shown only when you compile with the "-a" option.
When you REDEFINE a data item with an OCCURS clause, the redefining item starts at the same memory location as the first occurrence of the redefined item.


Hope this helps to everyone who ever was is in confusion as i was in before.



Thanks
Sri

  Was this answer useful?  Yes

Neelesh Baghel

  • Aug 25th, 2011
 

We can use redefine with occurs clause 100% sure
02 W-FUND-NO PIC X(2) OCCURS 12.
02 W-FUND-NO-RED REDEFINES W-FUND-NO OCCURS 12.

Code
  1. 02 W-FUND-NO              PIC X(2)    OCCURS 12.

  2. 02 W-FUND-NO-RED  REDEFINES W-FUND-NO OCCURS 12.

  3.  

  Was this answer useful?  Yes

neelesh singh

  • Oct 12th, 2011
 

Yes we can use
ex 02 W-PHIAC-GRP-RED REDEFINES W-PHIAC-GRP OCCURS 20

please don't answer if u r not sure its make confusion for others.

  Was this answer useful?  Yes

balasukumar

  • Mar 15th, 2012
 

no

  Was this answer useful?  Yes

nandan

  • Apr 28th, 2012
 

yes we can create and the answer is same as neelesh has given

  Was this answer useful?  Yes

balasukumar

  • May 10th, 2012
 

no. why because occurs cant be used for redefines clause.

  Was this answer useful?  Yes

ARPANA K CHANDRA

  • May 10th, 2012
 

NO.occurs cant be redefined.

  Was this answer useful?  Yes

Harsha

  • Jul 25th, 2014
 

Redefine with occur is possible
Redefine within occur is possible
Occur within redefine is possible
Redefining occur clause is not possible

Let me know if anything is not clear

  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