|
|
| Author |
Message |
rgupta71
New User
Joined: 21 Jun 2009 Posts: 60 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 |
|
 |
References
|
|
 |
PeterHolland
Active Member
Joined: 27 Oct 2009 Posts: 531 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
New User
Joined: 23 Jul 2008 Posts: 94 Location: India
|
|
|
|
Try this.
Set SAVE-INDEX to INDEX |
|
| Back to top |
|
 |
rgupta71
New User
Joined: 21 Jun 2009 Posts: 60 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 |
|
 |
Sambhaji
Active Member
Joined: 16 Feb 2007 Posts: 838 Location: Pune, India
|
|
|
|
| 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
New User
Joined: 21 Jun 2009 Posts: 60 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
Senior Member
Joined: 14 Jul 2008 Posts: 1054 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
New User
Joined: 21 Jun 2009 Posts: 60 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: 16 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
New User
Joined: 21 Jun 2009 Posts: 60 Location: Indore
|
|
|
|
Thank You ridgewalker58.
I will keep that in my mind. |
|
| Back to top |
|
 |
mdtanweer
New User
Joined: 26 Mar 2009 Posts: 3 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
New User
Joined: 23 Jul 2008 Posts: 94 Location: India
|
|
| Back to top |
|
 |
Anuj Dhawan
Global Moderator
Joined: 22 Apr 2006 Posts: 4081 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
Active Member
Joined: 14 Jan 2008 Posts: 991 Location: South Carolina, 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: 3 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 |
|
 |
|
|