View previous topic :: View next topic
|
Author |
Message |
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
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 |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
Try this.
Set SAVE-INDEX to INDEX |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
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 |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1248 Location: Richfield, MN, USA
|
|
|
|
rgupta71,
At 2:42 AM it DID NOT work and at 3:17 AM, it DID work? Am I missing something? |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
@ 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 |
|
|
ridgewalker58
New User
Joined: 26 Sep 2008 Posts: 51 Location: New York
|
|
|
|
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 |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Thank You ridgewalker58.
I will keep that in my mind. |
|
Back to top |
|
|
mdtanweer
New User
Joined: 26 Mar 2009 Posts: 6 Location: Bangalore
|
|
|
|
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 |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
mdtanweer
New User
Joined: 26 Mar 2009 Posts: 6 Location: Bangalore
|
|
|
|
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 |
|
|
Mathiv Anan
Active User
Joined: 23 Jul 2008 Posts: 106 Location: USA
|
|
|
|
Hi Mohammad,
Posting your code would be helpful to get a solution. |
|
Back to top |
|
|
mdtanweer
New User
Joined: 26 Mar 2009 Posts: 6 Location: Bangalore
|
|
|
|
@ 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 |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
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 |
|
|
|