View previous topic :: View next topic
|
Author |
Message |
sid_aec
New User
Joined: 01 Jul 2008 Posts: 60 Location: Kolkata
|
|
|
|
In a program I found that values are moved into a table field and the subscript field displaying as zero.Can we move values to a table field using a subscript which contain value as zero.
As per my understanding it should through system abend like S0c4. |
|
Back to top |
|
|
valyk
Active User
Joined: 16 Apr 2008 Posts: 104 Location: South Carolina
|
|
|
|
If the array is in a linkage area, I believe it will cause a storage violation. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Enquiring minds want to know --- Why do you need to do this?
Perplexing to say the least....
Bill |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
There is a manual link at the top of the page. Click on it, find the COBOL Language Reference manual, read section 1.8.1.9 where it says (among other things):
Quote: |
The lowest permissible occurrence number represented by a subscript is 1. The highest permissible occurrence number in any particular case is the maximum number of occurrences of the item as specified in the OCCURS clause. |
If you use a value outside these limits, you are accessing memory that is not part of the array and may not even be part of your program. You may get normal results, unexpected results, or possibly an abend (but that is not going to happen in all cases), depending upon where in memory the invalid subscript points.
I echo Bill's comment -- why on earth do you even think you need to do this? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
In a program I found that values are moved into a table field and the subscript field displaying as zero |
Not a new "want to do" but rather a discovery. . .
Personally, i'd find a way to get rid of this. . . |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
If you are READing a variable length -flat- (not VSAM) file - and you are not using the VARYING and DEPENDING ON clause -- in the FD -- THEN you can get to the FIRST 4 BYTES of the record -- to find the length of the VARIABLE RECORD --
01 rec1.
05 LL-BB-AREA occurs 2.
10 ll-length pic 9(04) comp.
10 filler pic x(02).
01 ws-record-length pic 9(04) comp.
MOVE LL-LENGTH (0) TO WS-RECORD-LENGTH.
MICKEY MOUSE - YES -- CUMBERSOM -- YES but it works |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
After the introduction of COBOL2, version 3, you could specify -
RECORD IS VARYING IN SIZE FROM Minimum-Length TO Maximum-Length CHARACTERS DEPENDING ON WS-REC-LGTH.
03 WS-REC-LGTH PIC 9(08) BINARY.
Where WS-REC-LGTH in an unsigned WS variable. Personally, I always specify this as an unsigned binary-fullword, but it's not a mandate.
On a READ of a variable-length record, WS-REC-LGTH will contain the actual length.
On a WRITE (and before it is issued), the programmer would populate WS-REC-LGTH with the desired record-length.
YMMV....
Bill |
|
Back to top |
|
|
sid_aec
New User
Joined: 01 Jul 2008 Posts: 60 Location: Kolkata
|
|
|
|
Thanks Guys.But my question was when a value is being moved to a table field with subscript as 0 then why this is not abending as the program is not supposed to access that memory or as mentioned by Robert may be it is just accessing the memory before the first occurence but
If that memory is being used by other program then it may override any value of that memory.
I mean I am not sure whether it is supposed to abend, if no then can it cause any error to any other program as it is accessing a memory before its first occurence which a program not supposed to do. Please reply if you have more ideas about such scenario. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Is this ARRAY in Working-Storage? Is it the first WS definition or are there other definitions before it? EG -
Code: |
03 WS-WORKAREA PIC X(256).
03 WS-ARRAY OCCURS 100 TIMES PIC X(256).
03 WS-SUB PIC 9(08) COMP VALUE ZERO.
MOVE HIGH-VALUES TO WS-ARRAY (WS-SUB).
|
In this example, if you use a subscript to address element ZERO of the ARRAY and you initialize it to (for example) HIGH-VALUES, field WS-WORKAREA would then be set to HIGH-VALUES.
Remember, 01 levels are aligned on a doubleword (8-byte) boundary, so this is also a separate consideration.
Bill |
|
Back to top |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
If your table field is in working storage -- you won't get an ADDRESS violation -- you are working in the address space that you have access to.
you will simply get the area that PRECEEDS the table entry filled with whatever you are moving |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
If that memory is being used by other program then it may override any value of that memory. |
Which may or may not cause an abend or some other problem due to what values were "walked on".
This may run for years more and some innocent modification to some other part of the code may abend or behave strangely.
IBM used to use a phrase that fits:
"The results may be unpredictable".
As i mentioned earlier, i'd personally get this fixed. |
|
Back to top |
|
|
CaptBill
New User
Joined: 28 May 2009 Posts: 20 Location: Oklahoma City, OK USA
|
|
|
|
Are you sure the field is a subscript and not an index?
Please show the code and datat definitions related to this quiestion. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
without ssrange option in effect, you can have negative and zero subscripts and indexes. |
|
Back to top |
|
|
Chirantan Banerjee
New User
Joined: 08 Oct 2009 Posts: 12 Location: Kolkata, India
|
|
|
|
dbzTHEdinosauer wrote: |
without ssrange option in effect, you can have negative and zero subscripts and indexes. |
And if you are not explicitly using ssrange then nossrange is the default option and that is why you are not getting an abend.
Please get the code fixed because if this code is running in production then you can never be sure if it is actually messing up something in every run .... very silently. |
|
Back to top |
|
|
|