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

What is Data Type of Index of the Array.


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

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Tue Feb 02, 2010 11:57 am
Reply with quote

Hi Experts,

I have defined an array as follows
10 ACTIVITY-TABLE-AREA.
15 ACTIVITY-TABLE OCCURS 1 TO 5000 TIMES
DEPENDING ON TBL-CTR
INDEXED BY INDEX.

And a variable SAVE-INDEX as S9(3) COMP-3.I want to save the index of array in a variable. When I am trying

MOVE INDEX TO SAVE-INDEX it is giving an error "INDEX was defined as a type that was invalid in this context."

Is this possible to save index of array in a variable?

Thanks,
Rahul Gupta
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Tue Feb 02, 2010 1:24 pm
Reply with quote

I guess that INDEX internally is a fullword binary.
So you have to use a cobol equivalent.

01 SAVE-INDEX PIC S9(9) BINARY.
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Tue Feb 02, 2010 1:55 pm
Reply with quote

Try this.

Set SAVE-INDEX to INDEX
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Tue Feb 02, 2010 2:12 pm
Reply with quote

THank You for your response.
@ PeterHolland
It is still giving the same when I used the datatype as S9(9) BINARY.

@ Mathiv Anan
I don't know the correct datatype of Index ,so we cannot use that statement.

Thanks
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Feb 02, 2010 2:35 pm
Reply with quote

rgupta wrote:
@ Mathiv Anan
I don't know the correct datatype of Index ,so we cannot use that statement.

Have you tried it?
It works. Define SAVE-INDEX as normal display numeric.
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Tue Feb 02, 2010 2:47 pm
Reply with quote

Thanks Sambhaji for your response.
I defined 01 SAVE-INDEX as PIC S9(9) BINARY and then I did Set SAVE-INDEX to INDEX. It worked.
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Tue Feb 02, 2010 6:45 pm
Reply with quote

rgupta71,
At 2:42 AM it DID NOT work and at 3:17 AM, it DID work? Am I missing something?
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Tue Feb 02, 2010 6:57 pm
Reply with quote

@ Terry Heinze
Initially I was using MOVE statement to save the Index variable in a working storage variable instead of using SET.Also at 2:42 I was not knowing the datatype of SAVE-INDEX.Sambhaji and PeterHolland mentioned the datatype which helped me solve this issue.
Mathiv Anan gave me the correct statement to use SET instead of MOVE.

Thanks everyone.
Back to top
View user's profile Send private message
ridgewalker58

New User


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

PostPosted: Fri Feb 05, 2010 12:32 am
Reply with quote

10 ACTIVITY-TABLE-AREA.
15 ACTIVITY-TABLE OCCURS 1 TO 5000 TIMES
DEPENDING ON TBL-CTR
INDEXED BY INDEX.

The word INDEX is a COBOL Reserved word -- CHANGE IT to something else like INDEX-A.

If you create an INDEX WORKING-STORAGE field that is not associated with a TABLE -- you usually code it like this
01 ws-index-fld usage INDEX.

SO DO NOT USE INDEX AS A DATA NAME
Back to top
View user's profile Send private message
rgupta71

Active User


Joined: 21 Jun 2009
Posts: 160
Location: Indore

PostPosted: Sat Feb 06, 2010 10:48 am
Reply with quote

Thank You ridgewalker58.

I will keep that in my mind.
Back to top
View user's profile Send private message
mdtanweer

New User


Joined: 26 Mar 2009
Posts: 6
Location: Bangalore

PostPosted: Thu Feb 11, 2010 5:14 pm
Reply with quote

Hi Experts,

I have an array indexed by WT-INDEX. Please tell me the picutre claus i need to give for this WT-INDEX variable.
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Thu Feb 11, 2010 5:32 pm
Reply with quote

You can get plenty of information by searching this forum.

Also, refer to the sections 1.8.1.7, 1.8.1.8 and 1.8.1.9 in below manual link.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/handheld/Connected/BOOKS/IGY3LR50/CCONTENTS?
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Thu Feb 11, 2010 5:35 pm
Reply with quote

There is a link to manuals at the top of the page. Find the COBOL Language Reference and Programming Guide manuals and read the information in them about OCCURS/INDEXes.
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 Feb 11, 2010 5:39 pm
Reply with quote

Indexes (properly plural as Indices) don't have a PICTURE clause. Internally, they are represented as aligned binary-fullwords and are built buy the compiler and stored in the TGT.

If you define an INDEX in WORKING-STORAGE, it's as easy as -

03 WS-INDEX INDEX.

You don't specify a VALUE clause.

Indices in WS can only be SET to other Indices associated with a given array and are used primarily as a work-area. Although not "quite" as efficient, binary-fullwords in WS can also be specified as an index work-area and are more popular with programmers than WS indices.

I've rarely used WS Indices and use WS binary-fullwords instead.

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

New User


Joined: 26 Mar 2009
Posts: 6
Location: Bangalore

PostPosted: Mon Feb 15, 2010 4:02 pm
Reply with quote

Hi Experts,
I declared 05 save-index pic s9(9) binary and used set save-index to index. Then i tried: display save-index but its not displaying the value rather its displaying only blanks. Could you please help
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Mon Feb 15, 2010 4:25 pm
Reply with quote

Hi Mohammad,

Posting your code would be helpful to get a solution.
Back to top
View user's profile Send private message
mdtanweer

New User


Joined: 26 Mar 2009
Posts: 6
Location: Bangalore

PostPosted: Mon Feb 15, 2010 4:37 pm
Reply with quote

@ Mathi

My code is like this:
declaration:-
05 SAVE-INDEX PIC S9(9) BINARY

SET SAVE-INDEX TO INDEX (here INDEX is the index of an array)
DISPLAY SAVE-INDEX
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Feb 20, 2010 8:40 pm
Reply with quote

Hi Mohammad,

To display the occurence # of the table field pointed to by an iINDEX you have to define a numeric filed (zoned decimal), then:

SET numeric field TO INDEX, then DISPLAY numerc field.

BTW, if I recall correctly, the INDEX contains the offset into the table of the data item referenced by the INDEX, not the occurence#. That's why you have to execute the SET - to do the conversion.
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 Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
No new posts SCOPE PENDING option -check data DB2 2
No new posts Check data with Exception Table DB2 0
No new posts JCL EXEC PARM data in C Java & MQSeries 2
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
Search our Forums:

Back to Top