View previous topic :: View next topic |
Author |
Message |
gkreth Beginner
Joined: 28 May 2004 Posts: 29 Topics: 10
|
Posted: Thu Jul 22, 2004 2:01 pm Post subject: How to view/display the index of a SEARCH on an array |
|
|
I have the following array defined:
Code: | 01 WS-SCHOOL-TABLE1.
05 WS-SCHOOL-TBL1 OCCURS 10500 TIMES
ASCENDING KEY IS WS-SCHL-TG-ID
INDEXED BY SCHIDX1.
10 WS-SCHL-ENTRY1.
15 WS-SCHL-TG-ID PIC X(09).
01 WS-SCHOOL-TABLE2.
05 WS-SCHOOL-TBL2 OCCURS 10500 TIMES
ASCENDING KEY IS WS-SCHL-HOME-TG-ID
INDEXED BY SCHIDX2.
10 WS-SCHL-ENTRY2.
15 WS-SCHL-HOME-TG-ID PIC X(09).
15 WS-SCHL-TYPE PIC X(03).
01 WS-SCHIDX PIC 9(5) |
I also have the following code that searches this array:
Code: | SEARCH ALL WS-SCHOOL-TBL1
AT END
MOVE '999999000' TO EXT-SCHL-HOME-TG-ID
MOVE '999' TO EXT-SCHL-TYPE
WHEN WS-SCHL-TG-ID (SCHIDX1) = EXT-SCHL-TG-ID
SET SCHIDX2 TO SCHIDX1
DISPLAY 'SCHIDX1: ' SCHIDX1
MOVE WS-SCHL-HOME-TG-ID (SCHIDX2) TO
EXT-SCHL-HOME-TG-ID
MOVE WS-SCHL-TYPE (SCHIDX2) TO EXT-SCHL-TYPE
. |
What I'd like to know is: How do I view the contents of SCHIDX1? I have tried to DISPLAY the field, but I get this compile error:
Code: | 51250 IGYPS2074-S "SCHIDX1" was defined as a type that was invalid in this context. The statement was discarded. |
I have also tried moving SCHIDX1 to a numeric variable, but I get the same compile error.
Surely there must be a way to do this, but how?
Thanks,
--Greg |
|
Back to top |
|
|
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Thu Jul 22, 2004 2:08 pm Post subject: |
|
|
Hi Greg,
I am not sure if we can display the value of the index.
I have always used Xpediter to look at the value of the index. If you have Xpediter at your shop, try that out. _________________ Regards,
Programmer |
|
Back to top |
|
|
dhruv Beginner
Joined: 01 Jun 2004 Posts: 10 Topics: 1
|
Posted: Thu Jul 22, 2004 3:06 pm Post subject: |
|
|
Since INDEX variables are actually register notations, they must be in their native binary format.
So, the following statements should work
SET Working-storage-pic-9-variable TO SCHIDX1
DISPLAY working-storage-pic-9-variable
OR
SET working-storage-pic-9-comp-variable TO SCHIDX1
MOVE working-storage-pic-9-comp-variable TO working-storage-pic-9-disp
DISPLAY working-storage-pic-9-disp
I dont see why the above should not work.
Thanks |
|
Back to top |
|
|
vijaythomson Beginner
Joined: 23 Jul 2004 Posts: 1 Topics: 0
|
Posted: Fri Jul 23, 2004 11:07 am Post subject: |
|
|
SET Working-storage-pic-9-variable TO SCHIDX1
DISPLAY working-storage-pic-9-variable
OR
SET working-storage-pic-9-comp-variable TO SCHIDX1
MOVE working-storage-pic-9-comp-variable TO working-storage-pic-9-disp
DISPLAY working-storage-pic-9-disp
I TRIED BOTH THE WAYS BUT STILL ITS NOT SHOWING THE VALUE OF THE INDEX VARIABLE I THINK ONLY WAY IS XPEDITOR. |
|
Back to top |
|
|
Bithead Advanced
Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Fri Jul 23, 2004 11:16 am Post subject: |
|
|
Try this
Code: |
Define SUB1 PIC S9(8) COMP.
Define WS-SUB1 PIC 9(6).
PERFORM
VARYING SUB1
FROM +1 BY +1
UNTIL WS-SCHL-TG-ID (SUB1) = EXT-SCHL-TG-ID
OR SUB1 > +10500
END-PERFORM
MOVE SUB1 TO WS-SUB1
DISPLAY 'SUB1:' WS-SUB1
|
|
|
Back to top |
|
|
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Mon Jul 26, 2004 12:54 pm Post subject: |
|
|
Bithead,
You are right, but this would be a case while using sub-scripts.
Do we have a way out to display the value of an Index ? _________________ Regards,
Programmer |
|
Back to top |
|
|
Bithead Advanced
Joined: 03 Jan 2003 Posts: 550 Topics: 23 Location: Michigan, USA
|
Posted: Mon Jul 26, 2004 1:10 pm Post subject: |
|
|
Add the subscript code to get at the value of the index. I know of no way to get at the index itself. |
|
Back to top |
|
|
gkreth Beginner
Joined: 28 May 2004 Posts: 29 Topics: 10
|
Posted: Tue Jul 27, 2004 3:28 pm Post subject: |
|
|
vijaythomson and dhruv win the golden cigar!
Here's the code:
Code: | 01 WS-SCHOOL-TABLE1.
05 WS-SCHOOL-TBL1 OCCURS 100 TIMES
ASCENDING KEY IS WS-SCHL-TG-ID
INDEXED BY SCHIDX1.
10 WS-SCHL-ENTRY1.
15 WS-SCHL-TG-ID PIC 9(4) VALUE 0.
01 I PIC 9(4) VALUE 0.
01 J PIC 9(4) VALUE 0.
01 FOUND PIC X(1) VALUE SPACE.
...
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100
ADD 2 TO J
SET SCHIDX1 TO I
MOVE J TO WS-SCHL-TG-ID (I)
END-PERFORM
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 100
SEARCH ALL WS-SCHOOL-TBL1
AT END MOVE 'N' TO FOUND
WHEN WS-SCHL-TG-ID (SCHIDX1) = I
SET J TO SCHIDX1
MOVE 'Y' TO FOUND
END-SEARCH
IF FOUND = 'Y'
DISPLAY 'Found ' I ' in array slot ' J
ELSE
DISPLAY 'Did not find ' I ' in any array slots'
END-IF
END-PERFORM |
This gives me the following output:
Code: | Did not find 0001 in any array slots
Found 0002 in array slot 0001
Did not find 0003 in any array slots
Found 0004 in array slot 0002
Did not find 0005 in any array slots
Found 0006 in array slot 0003
Did not find 0007 in any array slots
Found 0008 in array slot 0004
Did not find 0009 in any array slots
Found 0010 in array slot 0005
Did not find 0011 in any array slots
Found 0012 in array slot 0006
Did not find 0013 in any array slots
Found 0014 in array slot 0007
Did not find 0015 in any array slots
Found 0016 in array slot 0008
Did not find 0017 in any array slots
Found 0018 in array slot 0009
Did not find 0019 in any array slots
Found 0020 in array slot 0010
Did not find 0021 in any array slots
Found 0022 in array slot 0011
Did not find 0023 in any array slots
...
Did not find 0099 in any array slots
Found 0100 in array slot 0050 |
So, the SET is the key to the whole thing!
Thanks so much for your help!
--Greg |
|
Back to top |
|
|
|
|