IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Declare array with 3 fields. Pass 1 field & get back res


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
siddhartha biswas
Currently Banned

New User


Joined: 04 May 2008
Posts: 15
Location: india

PostPosted: Fri May 30, 2008 2:41 pm
Reply with quote

hi all,
I need to define an array in such a way that it should contain three fields..for example 'name', 'roll no', 'class' . This array has to be there in a sub program. When i pass any one field to the sub program, it should return the corresponding other two fields. For example if i pass 'name' i should get back ' roll no' and 'class'. Please suggest me a solution for this.
Back to top
View user's profile Send private message
the_gautam

Active User


Joined: 05 Jun 2005
Posts: 165
Location: Bangalore

PostPosted: Fri May 30, 2008 3:26 pm
Reply with quote

Code:
01 STUDENT-DETAIL.
     05 STUDENT-REC OCCURS 10 TIMES.
          10 STUD-NAME  PIC X(20).
          10 STUD-CLASS PIC X(02).
          10 STUD-ROLL  PIC 9(02).
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri May 30, 2008 3:32 pm
Reply with quote

How is this array being populated ???...

As per my understanding local variables to the subprogram are static ..meaning their value persists from one invocation to another ...

so define your array in the subprogram as

01 ws-array.
05 ws-arr occurs 100 times indexed by ws-indx.
10 name pic x(10).
10 roll-no pic 9(5).
10 class pic x(5).

after receiving the field from the main program use this fr search ..

set ws-indx to 1
search ws-arr
at end display 'not found'
when name(ws-indx) = 'received var' or
roll-no(ws-idx) = 'received var' or
class(ws-idx) = 'received var'

move name(ws-idx) to ws-sent-name
move roll-no(ws-idx) to ws-sent-roll
move class(ws-idx) to ws-sent-class.

this is a rough idea ...try this approach ...
Back to top
View user's profile Send private message
siddhartha biswas
Currently Banned

New User


Joined: 04 May 2008
Posts: 15
Location: india

PostPosted: Fri May 30, 2008 3:37 pm
Reply with quote

Thanks, but i need to hard code the data in the array, how can i do that?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri May 30, 2008 3:45 pm
Reply with quote

asy the array has 2 occurences

01 tab.
02 tab-val.
05 filler pic X(7) value 'sid99AB'
05 filler pic X(7) value 'idd33CD'

02 ws-array redefines tab-val occurs 2 times indexed by ws-indx.
05 name pic x(3).
05 roll-no pic 9(2).
05 class pic x(2).

this will have 1st array occurance name as 'sid' roll-no as 99 and class as 'AB' ...
just take care of the variable length ....
Back to top
View user's profile Send private message
siddhartha biswas
Currently Banned

New User


Joined: 04 May 2008
Posts: 15
Location: india

PostPosted: Fri May 30, 2008 4:06 pm
Reply with quote

Thanks Ashimer...that was great
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri May 30, 2008 4:10 pm
Reply with quote

You are welcome Siddharth

Quote:


As per my understanding local variables to the subprogram are static ..meaning their value persists from one invocation to another ...



in general and not always ... unless you CANCEL the program after the call or you declare your subprogram as IS INITIAL .
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri May 30, 2008 11:11 pm
Reply with quote

Hello,

Quote:
Thanks, but i need to hard code the data in the array, how can i do that?

Unless this is some one-time "special" or just some experiment, i would recommend that the values in the array not be hard-coded. It is far too trivial to simply read the values from an external file and move them into the array rather than making a program change every time a student name needs to be added, deleted, or changed. The initial array definition should be larger than the expected number of "student" entries.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts How to pass the PARM value to my targ... COBOL Programming 8
No new posts Dynamically pass table name to a sele... DB2 2
No new posts Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:

Back to Top