Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to define and access an array in COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rajeevdas03
Warnings : 1

New User


Joined: 21 Jan 2006
Posts: 19
Location: Mumbai

PostPosted: Wed Oct 04, 2006 11:02 am    Post subject: How to define and access an array in COBOL
Reply with quote

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
View user's profile Send private message

DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Oct 04, 2006 10:35 pm    Post subject: Re: How to define and access an array in COBOL
Reply with quote

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
View user's profile Send private message
MFRASHEED

Active User


Joined: 14 Jun 2005
Posts: 186
Location: USA

PostPosted: Wed Oct 04, 2006 11:27 pm    Post subject: Re: How to define and access an array in COBOL
Reply with quote

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
View user's profile Send private message
karnataka

New User


Joined: 15 Sep 2006
Posts: 20
Location: bangalore

PostPosted: Fri Oct 06, 2006 11:33 am    Post subject:
Reply with quote

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
View user's profile Send private message
karnataka

New User


Joined: 15 Sep 2006
Posts: 20
Location: bangalore

PostPosted: Fri Oct 06, 2006 11:36 am    Post subject:
Reply with quote

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
View user's profile Send private message
rajeevdas03
Warnings : 1

New User


Joined: 21 Jan 2006
Posts: 19
Location: Mumbai

PostPosted: Sun Jan 07, 2007 8:28 pm    Post subject:
Reply with quote

Thanks Dave I got it
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Cobol to fetch the content by using s... arunc55 COBOL Programming 4 Fri Nov 17, 2017 1:25 pm
No new posts VBS and VB, COBOL syntax is the same ... natt.sut COBOL Programming 3 Sun Nov 12, 2017 6:36 am
No new posts COBOL - EXIT statement weird behavior anthony.pangestu COBOL Programming 0 Fri Oct 27, 2017 9:57 am
No new posts IEW2456E error when link-editing a C ... Senthilraj JCL & VSAM 0 Fri Oct 13, 2017 3:12 pm
No new posts User access certification In Mainfram... Virendra Shambharkar All Other Mainframe Topics 4 Tue Oct 03, 2017 12:32 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us