Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

can we move values to 0 th position of an array

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: can we move values to 0 th position of an array
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 07, 2010 9:00 pm    Post subject: Reply to: can we move values to 0 th position of an array
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: 7908
Location: Bellevue, IA

PostPosted: Thu Jan 07, 2010 9:23 pm    Post subject:
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

Site Director


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

PostPosted: Thu Jan 07, 2010 11:10 pm    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Thu Jan 07, 2010 11:35 pm    Post subject: Reply to: can we move values to 0 th position of an array
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Jan 08, 2010 12:06 am    Post subject: Reply to: can we move values to 0 th position of an array
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    Post subject:
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

Site Director


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

PostPosted: Fri Jan 08, 2010 12:51 am    Post subject:
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: 15
Location: Oklahoma City, OK USA

PostPosted: Fri Jan 08, 2010 2:33 am    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to move a long alphanumeric data ... lind sh COBOL Programming 6 Mon Dec 05, 2016 7:51 pm
No new posts Overlaying one set of charater values... Kevin Lindsley SYNCSORT 7 Sat Nov 05, 2016 3:21 am
No new posts Low values Results from VARCHAR FORMAT balaji81_k DB2 10 Thu Oct 20, 2016 1:18 am
No new posts Protection Exception while move 0 to ... Kevin Vaz CICS 10 Tue Oct 18, 2016 4:19 pm
No new posts How can we create a flat file in JAVA... rakesh.v18 Java & MQSeries 7 Fri Sep 23, 2016 10:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us