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

can we move values to 0 th position of an array


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

New User


Joined: 01 Jul 2008
Posts: 60
Location: Kolkata

PostPosted: Thu Jan 07, 2010 8:50 pm
Reply with quote

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
View user's profile Send private message
valyk

Active User


Joined: 16 Apr 2008
Posts: 104
Location: South Carolina

PostPosted: Thu Jan 07, 2010 8:54 pm
Reply with quote

If the array is in a linkage area, I believe it will cause a storage violation.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 07, 2010 9:00 pm
Reply with quote

Enquiring minds want to know --- Why do you need to do this?

Perplexing to say the least.... icon_rolleyes.gif

Bill
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 07, 2010 9:23 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Jan 07, 2010 11:10 pm
Reply with quote

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
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Thu Jan 07, 2010 11:11 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 07, 2010 11:35 pm
Reply with quote

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
View user's profile Send private message
sid_aec

New User


Joined: 01 Jul 2008
Posts: 60
Location: Kolkata

PostPosted: Thu Jan 07, 2010 11:49 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 08, 2010 12:06 am
Reply with quote

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
View user's profile Send private message
ridgewalker58

New User


Joined: 26 Sep 2008
Posts: 51
Location: New York

PostPosted: Fri Jan 08, 2010 12:09 am
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Fri Jan 08, 2010 12:51 am
Reply with quote

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
View user's profile Send private message
CaptBill

New User


Joined: 28 May 2009
Posts: 20
Location: Oklahoma City, OK USA

PostPosted: Fri Jan 08, 2010 2:33 am
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Jan 08, 2010 2:42 am
Reply with quote

without ssrange option in effect, you can have negative and zero subscripts and indexes.
Back to top
View user's profile Send private message
Chirantan Banerjee

New User


Joined: 08 Oct 2009
Posts: 12
Location: Kolkata, India

PostPosted: Fri Feb 12, 2010 5:23 pm
Reply with quote

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
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
Search our Forums:

Back to Top