Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using occurs and redefines together?

Status
Not open for further replies.

confusedlady

Programmer
Apr 26, 2001
163
US
Does anyone know the "rules" of using the occurs clause in conjunction with redefines for the same area of memory? Like, would this be possible?:

01 complete-string pic x(120)
01 little-strings redefines complete string.
05 each-one occurs 30 times.
10 single-code pic x(3).
10 a-space pic x(1).

In the procedure division, I just move spaces to the a-space field because I don't think I can assign it a value in WS. I hope this question is understandable even! confusedlady
 
I think I understand your questions.

1. Your REDEFINE and your OCCURS, as coded, look valid.
2. Yes, you cannot assign a value to a subscripted item in Working Storage.

However, moving spaces to complete-string will also blank out every occurrence of single-code and a-space; since complete-string and little-strings share the same physical space.

So, it all depends on what your application requirements are.

Dimandja
 
No, I only move the space to a-space (10 level). Essentially what I want is to be able to loop thru building a string (up to 30 time). I increment the loop by one on each pass(w/perform varying). Each iteration moves a byte-code to single-code, and a space to a-space. When I drop out of loop, referencing complete-string is all 30 codes w/a space between.

So if it looks valid the way I have it, I hope I'm on the right track. Thanks! confusedlady
 
oops, that should be "moves a 3-digit code", not a byte-code confusedlady
 
Why not drop the redefines altogether:
Code:
01  complete-string.
    05 each-one occurs 30 times.
        10 single-code               pic x(3).
        10 a-space                   pic x(1).

One might also drop the dataname each-one if it's not used (e.g. 05 occurs 30 times.)

Glenn
 
Thanks to both of you for the help. Now you have me thinking,Glenn, I can still reference complete-string without that redefines, and that each-one does seem unnecessary.......I'll save that for Monday's changes :) confusedlady
 
Hi CL,

Some of the later implementations of COBOL permit a value clause in a table element. Using Glenn's example:


01 complete-string.
05 each-one occurs 30 times.
10 single-code pic x(3).
10 a-space pic x(1) value space.

Regards, Jack.


 
Hi CL,

Some of the later implementations of COBOL permit a value clause in a table element. Using Glenn's example:


01 complete-string.
05 each-one occurs 30 times.
10 single-code pic x(3).
10 a-space pic x(1) value space.

Regards, Jack.


 
Glenn/Jack-Thanks again. I took out the redefining 01 level (and little-strings), and also used the value clause to get a space. My compiler is OK with that.

This place is great for bringing on the forehead slap and "Now why didn't I see that?" :)

confusedlady
 
Thanks Jack for your tip. I didn't know that my COBOL compiler also supports a value on an OCCURS clause.

I tried:
WORKING-STORAGE SECTION.
01 complete-string.
05 each-one occurs 30 times.
10 single-code pic x(3) value "ABC".
10 a-space pic x(1) value "/".

PROCEDURE DIVISION.
1000-start.
DISPLAY complete-string
STOP RUN.

And the result surprised me:
ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/ABC/
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top