IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Using Occurs Clause to move data


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
praveensn

New User


Joined: 30 Jul 2008
Posts: 32
Location: Pune

PostPosted: Wed Jan 07, 2009 7:03 pm
Reply with quote

Hi,

I am having a small query on OCCURS clause.

Currently i am using the occurs clause as

05 WS05-COUNT OCCURS 10 TIMES.
10 WS10-VAR2 PIC 9(02).

So my requirement is, to change the number 10(occurs 10 times) to one variable like R which is declared at working storage.

Like,

Move 10 to R
Then,
05 WS05-COUNT OCCURS R TIMES.
10 WS10-VAR2 PIC 9(02).

But this is not working.

So can you please help me out in this so that i can replace the number from a variable.

Thanks in advance,
Praveen.N
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Wed Jan 07, 2009 7:08 pm
Reply with quote

Please check with OCCURS DEPENDING ON
Back to top
View user's profile Send private message
praveensn

New User


Joined: 30 Jul 2008
Posts: 32
Location: Pune

PostPosted: Wed Jan 07, 2009 7:18 pm
Reply with quote

Hi,

I have checked with OCCURS DEPENDING ON R TIMES, but i am getting the same error.

My main requirement is to send the send the R vale through JCL and recieve it in Cobol and pass it to R.

How can i proceed with this..

Thanks,
Praveen.N
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Jan 07, 2009 7:40 pm
Reply with quote

Praveen: what you want to do cannot be done in COBOL. COBOL requires all WORKING-STORAGE items to be declared (size and type) at compile time. You want to change a value at run time. This is not permitted under the definition of WORKING-STORAGE in COBOL..
Back to top
View user's profile Send private message
hikaps14

Active User


Joined: 02 Sep 2005
Posts: 189
Location: Noida

PostPosted: Wed Jan 07, 2009 7:43 pm
Reply with quote

"OCCURS DEPENDING ON"
You should have found this in the manuals or in some the previous topics discussed here.

05 WS10-VAR2 PIC 9(02).
05 WS05-COUNT OCCURS 0 TO 10 TIMES DEPENDING on WS10-VAR2.

Now you may move any nemeric between 0 and 10 to WS10-VAR2.

Note : You need to mention the MAX size of table in case of DEPENDING ON clause as well.

Thanks,
-Kapil.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 08, 2009 12:37 am
Reply with quote

Hello,

Instead of this:
Code:
05 WS10-VAR2 PIC 9(02).
05 WS05-COUNT OCCURS 0 TO 10 TIMES DEPENDING on WS10-VAR2.
i'd suggest
Code:

05 R           PIC 9(02).
05 WS05-COUNT OCCURS 1 TO 10 TIMES DEPENDING ON R.
    10 WS10-VAR2 PIC 9(02).
.
MOVE 10 TO R.
etc.
which is more similar to the original request. Also, i don't use zero for an ODO. . . If i have none, it is either invalid or i don't need to use the array icon_wink.gif
Back to top
View user's profile Send private message
praveensn

New User


Joined: 30 Jul 2008
Posts: 32
Location: Pune

PostPosted: Thu Jan 08, 2009 11:09 am
Reply with quote

Hi,

Thanks:)

I have tried this, but here since it is occuring for only 10 times the value of R should not exceed 10 right.

But my requirement is to send the value of R through JCL in parm and use it in the program.It may be 10 or 20 etc..

For example.

We are sending value '30' from JCL in parm and recieve it in a variable say ws-count1 which is PIC 9(2), now I have to replace this value in occurs clause,


WS05-COUNT OCCURS ws-count1 times, but this is not working.

So i need some other options for this.

Thanks,
Praveen.N
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 08, 2009 11:26 am
Reply with quote

Hello,

Quote:
now I have to replace this value in occurs clause,
No, you don't want to replace the value in the source based on the jcl. You need to make a one-time change to the source to accomodate the smallest and largest number of entries the array may ever contain.

When the job is submitted, the value from the jcl needs to be checked to ensure it is both numeric and within the allowable range.

Once the value from the jcl has been validated, it becomes the limit for that execution. There is no changing the definition of the odo at run-time.
Back to top
View user's profile Send private message
praveensn

New User


Joined: 30 Jul 2008
Posts: 32
Location: Pune

PostPosted: Thu Jan 08, 2009 12:26 pm
Reply with quote

Hi Disk,


I have done as per your suggestion.

05 WS05-COUNT OCCURS 0 TO 50 TIMES DEPENDING ON S
10 WS10-VAR2 PIC 9(02).

and the value of S is 10 which is passed through JCL as parm.

So the loop should execute only for 10 times if i am not wrong.
10 is the limit, but it is accepting 11th one also.


Thanks,
Praveen.N
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jan 08, 2009 5:51 pm
Reply with quote

Do you have SSRANGE compile option turned on?

Also, even if you set S to 10 there is nothing in COBOL preventing you from using the 11th, 12th, ... occurrences of the table (other than SSRANGE). It is syntactically correct to define a table of 50 items and refer to the 9,725th element of the table by setting your subscript variable to 9725. Do this long enough and you will get storage related abends, but COBOL doesn't enforce any kind of range checking unless you're using the right compile option.
Back to top
View user's profile Send private message
praveensn

New User


Joined: 30 Jul 2008
Posts: 32
Location: Pune

PostPosted: Thu Jan 08, 2009 5:56 pm
Reply with quote

Thanks all for helping me out.

Regards,
Praveen.N
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Jan 08, 2009 9:47 pm
Reply with quote

One of the most common mistakes in dealing with tables is trying to reference an occurrence outside of the valid range. Always always check for referencing an invalid index/subscript when incrementing it to make sure it does not exceed the valid range.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Thu Jan 08, 2009 10:16 pm
Reply with quote

Hello,

Quote:
So the loop should execute only for 10 times if i am not wrong.
10 is the limit, but it is accepting 11th one also.
The procedure code must be in control (not the array). The code needs to ensure that the process does not attempt to increment beyond the last valid occurrence for "this" execution.

You want the code to catch this error, not the system. If you do not implement the proper code, you may have to deal with an abend. Or worse, a process that generates invalid output with no abend. . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
Search our Forums:

Back to Top