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

What will happen if we move values to zero subscript variab?


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

New User


Joined: 29 Jan 2007
Posts: 33
Location: chennai

PostPosted: Fri Apr 25, 2008 1:58 pm
Reply with quote

In Cobol array concept,ie., OCCURS CLAUSE

What will happen if we try to execute the below statement..

say ,

MOVE '2' TO EXAMPLE(0)

ie., moving the value to Zero subscript variable. Will that be possible to move to Zero subscript variables ?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Apr 25, 2008 2:15 pm
Reply with quote

Hi,

The lowest possible subscript value is 1 which points to first item in the table.

for your query y dont you try it out and see what happens ?
Back to top
View user's profile Send private message
mymains
Currently Banned

New User


Joined: 24 Apr 2008
Posts: 5
Location: Banglore

PostPosted: Fri Apr 25, 2008 2:45 pm
Reply with quote

i think it is possible to move the value to the subscript .
thnkz
mymains
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Apr 25, 2008 3:02 pm
Reply with quote

Quote:

i think it is possible to move the value to the subscript


since a subscript is just a numeric field, the obvious answer is yes.

The subject had you bothered to read the OP post is what will happen
Quote:

MOVE '2' TO EXAMPLE(0)


The execution of an instruction (without the SSRANGE options on) with a zero subscript is an excpetion - error.

But even if the SSrange Options are off, and your instruction with a 0 value in the subscript executes without error, you will not populate the table being subscripted - you will populate an area before the defined cobol internal table.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri Apr 25, 2008 3:04 pm
Reply with quote

I don't think that an instruction with a literal value of 0 as the index value will compile.

with a subscript, you can even use negative values, if the SSRANGE option is off.
Back to top
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Apr 25, 2008 7:38 pm
Reply with quote

I agree with Dick, the code won't compile if you code (0) in the subcript.
However you can do this
Code:
  move 0 to sub
  move '2' to EXAMPLE(sub)

this should compile and it will populate area before the array.
I have seen typical use of such 'tricky' code to get the RDW of variable length record. If you are trying to do the same, use the RECORD IS VARYING clause of COBOL instead.
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 Apr 25, 2008 8:21 pm
Reply with quote

Agkshirsagar,

You're very correct with that statement as it applies to COBOL2 and greater.

I remember trying this, by setting the subscript to ZERO, in a COBOL2 environment about 20 years ago and it did NOT work.

FWIW, this trick was outlined in both of Harvey Bookman's COBOL2 and COBOL/370 books (from the J. Ranade series / McGraw Hill), late 80's / early 90's.

Harvey has since retired.

Regards,

Bill
Back to top
View user's profile Send private message
bamohan

New User


Joined: 29 Jan 2007
Posts: 33
Location: chennai

PostPosted: Sat Apr 26, 2008 9:00 am
Reply with quote

Thanks for all your responses.. I will give a try and let u know..
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