View previous topic :: View next topic
|
Author |
Message |
praveensn
New User
Joined: 30 Jul 2008 Posts: 32 Location: Pune
|
|
|
|
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 |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Please check with OCCURS DEPENDING ON |
|
Back to top |
|
|
praveensn
New User
Joined: 30 Jul 2008 Posts: 32 Location: Pune
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
hikaps14
Active User
Joined: 02 Sep 2005 Posts: 189 Location: Noida
|
|
|
|
"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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
Back to top |
|
|
praveensn
New User
Joined: 30 Jul 2008 Posts: 32 Location: Pune
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
praveensn
New User
Joined: 30 Jul 2008 Posts: 32 Location: Pune
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
praveensn
New User
Joined: 30 Jul 2008 Posts: 32 Location: Pune
|
|
|
|
Thanks all for helping me out.
Regards,
Praveen.N |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|