View previous topic :: View next topic
|
Author |
Message |
siddhartha biswas Currently Banned New User
Joined: 04 May 2008 Posts: 15 Location: india
|
|
|
|
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 |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
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 |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
siddhartha biswas Currently Banned New User
Joined: 04 May 2008 Posts: 15 Location: india
|
|
|
|
Thanks, but i need to hard code the data in the array, how can i do that? |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
siddhartha biswas Currently Banned New User
Joined: 04 May 2008 Posts: 15 Location: india
|
|
|
|
Thanks Ashimer...that was great |
|
Back to top |
|
|
ashimer
Active Member
Joined: 13 Feb 2004 Posts: 551 Location: Bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|