View previous topic :: View next topic
|
Author |
Message |
rajeevdas03 Warnings : 1 New User
Joined: 21 Jan 2006 Posts: 19 Location: Mumbai
|
|
|
|
HOW TO DEFINE ARRAY IN COBOL.
SUPPOSE I HAVE DEFINE NY ARRAY LIKE THIS
01 WS-TABLE ONE
05 WS-TABLE ONE OCCURS 10 TIMES PIC X(10).
HOW CAN WE ACCES 5th ELEMENT OF THIS TABLE USING SUBSCRIPT AND INDEX? PLS GIVE ME EXAMPLE |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
Rajeev,
I'm not sure if I understand your syntax.
Define and use a cobol table like this:
Code: |
01 WS-TABLE.
05 WS-TABLE-ENTRY PIC X(10) OCCURS 10 TIMES.
05 WS-TABLE-SUBSCRIPT PIC S9(3) COMP-3.
MOVE 5 TO WS-TABLE-SUBSCRIPT.
DISPLAY WS-TABLE-ENTRY(WS-TABLE-SUBSCRIPT).
(or)
DISPLAY WS-TABLE-ENTRY(5).
|
Dave |
|
Back to top |
|
|
MFRASHEED
Active User
Joined: 14 Jun 2005 Posts: 186 Location: USA
|
|
|
|
To answer other part of your question using INDEX.
Following is an example:
Code: |
01 TEST-TABLE.
05 TEST-TAB OCCURS 10 TIMES
INDEXED BY INDX-1.
10 TEST-DAT1 PIC X.
10 TEST-DAT2 PIC X.
|
To refrence a particular element in table use SET clause
Code: |
SET INDX-1 TO +5
DISPLAY TEST-DAT1(INDX-1)
|
If you want to process all elements then use PERFORM VARYING INDX-1 FROM +1 BY +1 just like how you would with sub-script variable. |
|
Back to top |
|
|
karnataka
New User
Joined: 15 Sep 2006 Posts: 20 Location: bangalore
|
|
|
|
IDENTIFICATION DIVISION.
PROGRAM-ID. OCCURPGM.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 ARRAY2.
02 OCCUR2 PIC 9(2) OCCURS 10 TIMES.
01 I PIC 9(2) VALUE 1.
01 VAR2 PIC 9(4) COMP-3.
01 SUB PIC 9(2) VALUE 1.
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM 100-ACCEPT-PARA.
PERFORM 200-DISPLAY-PARA.
STOP RUN.
100-ACCEPT-PARA.
PERFORM UNTIL I = 10
MOVE I TO OCCUR2 ( SUB)
ADD 1 TO I
ADD 1 TO SUB
END-PERFORM.
200-DISPLAY-PARA.
MOVE 5 TO SUB.
DISPLAY ' OCCUR2 ( 5) ===>'OCCUR2 ( 5). |
|
Back to top |
|
|
karnataka
New User
Joined: 15 Sep 2006 Posts: 20 Location: bangalore
|
|
|
|
hi,
the above code is to access 5th element of array using subscript . just check it out wheather it fullfil your request.
plz let me know if its wrong........
thanks.. |
|
Back to top |
|
|
rajeevdas03 Warnings : 1 New User
Joined: 21 Jan 2006 Posts: 19 Location: Mumbai
|
|
|
|
Thanks Dave I got it |
|
Back to top |
|
|
|